Changeset 88642a4 in thomson


Ignore:
Timestamp:
Jan 16, 2012, 9:54:55 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
197a1cc
Parents:
d46151a
Message:

Add motor on detection.

git-svn-id: svn://localhost/thomson@8 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/powerSwitch.c

    rd46151a r88642a4  
    2121#include <string.h>
    2222#include <stdint.h>
     23#include <unistd.h>
     24
    2325#include <lusb0_usb.h>    /* this is libusb, see http://libusb.sourceforge.net/ */
    2426
     
    3234#define PRODUCTSTRING "CrO2"
    3335
     36/* These are the vendor specific SETUP commands implemented by our USB device */
    3437#define PSCMD_CONFIG  0
    3538#define PSCMD_GET   1
    3639#define PSCMD_PUT   2
    37 /* These are the vendor specific SETUP commands implemented by our USB device */
     40#define PSCMD_STATUS   3
    3841
    3942static void usage(char *name)
     
    178181    }else if(strcmp(argv[1], "put") == 0){
    179182
     183                do
     184                {
     185                        // Wait for motor on
     186                        nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, PSCMD_STATUS, 0,0, (char*)buffer, 1, 5000);
     187                        usleep(1000000);
     188                } while (buffer[0] & 8);
     189
     190
    180191                FILE* fptr = fopen(argv[2], "rb");
    181192                int blockid;
     
    185196                do
    186197                {
    187                         fread(buffer, 1, 18, fptr); // skip sync header
     198                        do
     199                        {
     200                                fread(&blktype, 1, 1, fptr);
     201                                if (feof(fptr))
     202                                {
     203                                        fprintf(stderr, "end of file.\n");
     204                                        fclose(fptr);
     205                                        usb_close(handle);
     206                                        exit(0);
     207                                }
     208                        }
     209                        while(blktype != 0x5A); // skip sync header
     210
    188211                        fread(&blktype, 1, 1, fptr);
    189212                        fread(&blksize, 1, 1, fptr);
    190213                        blksize -= 2;
    191214                        fread(buffer, 1, blksize + 1, fptr);
     215                        if (blktype == 0)
     216                        {
     217                                // new file
     218                                printf("%.11s\n",buffer);
     219                        }
    192220                }
    193221                while (blockid --);
     
    206234
    207235        if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());
    208 
    209236    usb_close(handle);
    210237    return 0;
Note: See TracChangeset for help on using the changeset viewer.