Changeset 32c7682 in thomson for elec/CrO2/software/cro2.cpp
- Timestamp:
- Jan 28, 2012, 3:13:17 PM (12 years ago)
- Branches:
- main
- Children:
- c7b4218
- Parents:
- 96bc8fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/cro2.cpp
r96bc8fa r32c7682 5 5 */ 6 6 7 #include <iostream> 7 8 #include <stdio.h> 8 9 #include <stdlib.h> … … 15 16 16 17 #include "device.h" 18 #include "poller.h" 17 19 18 20 /* UI */ … … 29 31 30 32 33 Ihandle* motoron; 31 34 void GUI_open(int* argc, char*** argv) 32 35 { … … 48 51 ); 49 52 53 // CONTROL 54 motoron = IupProgressBar(); 55 IupSetAttribute(motoron, "RASTERSIZE", "16x16"); 56 57 // EXPLORE 50 58 Ihandle* platformlist = IupList(NULL); 51 59 IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL"); … … 59 67 Ihandle* tabs = IupTabs( 60 68 IupVbox( 61 IupLabel("Hello World"), 69 IupHbox( 70 IupLabel("Motor"), 71 motoron, 72 NULL 73 ), 74 IupHbox( 75 IupToggle("play",NULL), 76 IupToggle("REC",NULL), 77 NULL 78 ), 62 79 NULL 63 80 ), … … 89 106 IupShow(dialog); 90 107 108 // Run the timer 109 startPolling(); 110 91 111 IupMainLoop(); 92 112 … … 106 126 } 107 127 108 Device dev; // Constructor inits communication.109 // TODO handle thrown exceptions.128 try { 129 Device& dev = Device::getDevice(); // Constructor inits communication. 110 130 111 112 memset(buffer, 0, 275);113 nBytes = dev.read(buffer, sizeof(buffer));114 131 if(strcmp(argv[1], "get") == 0){ 132 memset(buffer, 0, 275); 133 nBytes = dev.read(buffer, sizeof(buffer)); 134 }else if(strcmp(argv[1], "put") == 0){ 115 135 116 while (dev.getStatus() & 8) 117 usleep(1000000); 136 // wait for motor on 137 while (dev.getStatus() & 8) 138 usleep(1000000); 118 139 119 FILE* fptr = fopen(argv[2], "rb"); 120 int blockid; 121 uint8_t blktype, blksize; 122 sscanf(argv[3], "%d", &blockid); 140 // load file 141 FILE* fptr = fopen(argv[2], "rb"); 142 int blockid; 143 uint8_t blktype, blksize; 144 sscanf(argv[3], "%d", &blockid); 123 145 124 do 125 { 146 // fast-forward to requested block 126 147 do 127 148 { 149 do 150 { 151 fread(&blktype, 1, 1, fptr); 152 if (feof(fptr)) 153 { 154 fprintf(stderr, "end of file.\n"); 155 fclose(fptr); 156 exit(0); 157 } 158 } 159 while(blktype != 0x5A); // skip sync header 160 128 161 fread(&blktype, 1, 1, fptr); 129 if (feof(fptr)) 162 fread(&blksize, 1, 1, fptr); 163 blksize -= 2; 164 fread(buffer, 1, blksize + 1, fptr); 165 if (blktype == 0) 130 166 { 131 fprintf(stderr, "end of file.\n"); 132 fclose(fptr); 133 exit(0); 167 // new file 168 printf("%.11s\n",buffer); 134 169 } 135 170 } 136 while (blktype != 0x5A); // skip sync header171 while (blockid --); 137 172 138 fread(&blktype, 1, 1, fptr); 139 fread(&blksize, 1, 1, fptr); 140 blksize -= 2; 141 fread(buffer, 1, blksize + 1, fptr); 142 if (blktype == 0) 143 { 144 // new file 145 printf("%.11s\n",buffer); 146 } 173 fclose(fptr); 174 175 nBytes = dev.write(buffer, blksize, blktype); 176 }else{ 177 // TODO print usage 178 exit(2); 147 179 } 148 while (blockid --);149 180 150 fclose(fptr); 151 152 nBytes = dev.write(buffer, blksize, blktype); 153 }else{ 154 GUI_open(&argc, &argv); 155 } 156 157 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror()); 158 return 0; 181 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror()); 182 return 0; 183 } 184 catch(const char* error) 185 { 186 std::cerr << error << std::endl; 187 } 159 188 } 160 189
Note:
See TracChangeset
for help on using the changeset viewer.