57 >> (7 - (column & 7))) & 1);
61 int row,
int column,
int value)
63 int bitIndex;
int byteIndex;
72 bitIndex = (7 - (column & 7));
75 pointer->
pixels[byteIndex] =
76 (((~(1<<bitIndex))&(pointer->
pixels[byteIndex]))|((value?1:0)<<bitIndex));
87 if((destination == NULL) || (source0 == NULL) || (source1 == NULL))
94 destination->
pixels[index] =
107 if((destination == NULL) || (source0 == NULL) || (source1 == NULL))
114 destination->
pixels[index] =
127 if((destination == NULL) || (source0 == NULL) || (source1 == NULL))
134 destination->
pixels[index] =
145 if(destination == NULL)
152 destination->
pixels[index] =
153 (~destination->
pixels[index]);
169 return (attributes->
readOnly ==
'R');
182 return (attributes->
hidden ==
'H');
195 return (attributes->
system ==
'S');
208 return (attributes->
volumeID ==
'V');
234 return (attributes->
archive ==
'A');
243 int errorValue;
int retVal0;
int retVal1;
static int resetTries;
245 resetTries = CMUCAM4_RESET_TRIES;
246 errorValue = setjmp(_env);
248 if(resetTries-- <= 0)
256 _state = DEACTIVATED;
257 _setReadTimeout(CMUCAM4_RESET_TIMEOUT);
264 _com.
begin(resetTries ? CMUCOM4_FAST_BAUD_RATE : CMUCOM4_MEDIUM_BAUD_RATE);
265 _com.
write((uint8_t)
'\0');
266 _com.
write((uint8_t)
'\0');
267 _com.
write((uint8_t)
'\0');
268 _com.
write(
"\rRS\r");
271 _com.
begin(CMUCOM4_MEDIUM_BAUD_RATE);
272 _com.
write((uint8_t)
'\0');
273 _com.
write((uint8_t)
'\0');
274 _com.
write((uint8_t)
'\0');
275 _com.
write(
"\rRS\r");
278 _com.
begin(CMUCOM4_SLOW_BAUD_RATE);
279 _com.
write((uint8_t)
'\0');
280 _com.
write((uint8_t)
'\0');
281 _com.
write((uint8_t)
'\0');
282 _com.
write(
"\rRS\r");
286 _waitForString(
"\rCMUcam4 v");
289 if(sscanf(_resBuffer,
"%1d.%2d ", &retVal0, &retVal1) != 2)
294 _version = ((_CMUcam4_version) ((retVal0 * 100) + retVal1));
298 case VERSION_100:
break;
299 case VERSION_101:
break;
300 case VERSION_102:
break;
301 case VERSION_103:
break;
310 _setReadTimeout(CMUCAM4_NON_FS_TIMEOUT);
316 case VERSION_101: _com.
write(CMUCOM4_MEDIUM_BR_STRING);
break;
318 case VERSION_103: _com.
write(resetTries ?
319 CMUCOM4_FAST_BR_STRING :
320 CMUCOM4_MEDIUM_BR_STRING);
break;
323 _com.
write((uint8_t)
'\r');
330 case VERSION_101: _com.
begin(CMUCOM4_MEDIUM_BAUD_RATE);
break;
332 case VERSION_103: _com.
begin(resetTries ?
333 CMUCOM4_FAST_BAUD_RATE :
334 CMUCOM4_MEDIUM_BAUD_RATE);
break;
337 _com.
write((uint8_t)
'\r');
343 _setReadTimeout(CMUCAM4_NON_FS_TIMEOUT);
349 case VERSION_101: _com.
write(CMUCOM4_MEDIUM_SB_STRING);
break;
351 case VERSION_103: _com.
write(resetTries ?
352 CMUCOM4_FAST_SB_STRING :
353 CMUCOM4_MEDIUM_SB_STRING);
break;
356 _com.
write((uint8_t)
'\r');
366 if(_state == DEACTIVATED)
371 _state = DEACTIVATED;
393 return _commandWrapper(
"SD\r", CMUCAM4_NON_FS_TIMEOUT);
398 return _commandWrapper(
"SL\r", CMUCAM4_NON_FS_TIMEOUT);
407 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
408 "CB %d\r", brightness) < CMUCAM4_CMD_BUFFER_SIZE)
409 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
415 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
416 "CC %d\r", contrast) < CMUCAM4_CMD_BUFFER_SIZE)
417 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
423 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
424 "CR %d\r", reg) < CMUCAM4_CMD_BUFFER_SIZE)
425 ? _intCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
431 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
432 "CW %d %d %d\r", reg, value, mask) < CMUCAM4_CMD_BUFFER_SIZE)
433 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
443 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
444 "AG %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
445 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
451 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
452 "AW %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
453 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
463 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
464 "HM %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
465 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
471 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
472 "VF %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
473 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
483 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
484 "BW %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
485 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
491 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
492 "NG %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
493 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
503 return _intCommandWrapper(
"GB\r", CMUCAM4_NON_FS_TIMEOUT);
508 int errorValue;
int resultValue;
long returnValue;
510 if((errorValue = _commandWrapper(
"GD\r", CMUCAM4_NON_FS_TIMEOUT)))
515 if((errorValue = setjmp(_env)))
521 resultValue = (sscanf(_resBuffer,
"%ld ", &returnValue) == 1);
529 return _intCommandWrapper(
"GP\r", CMUCAM4_NON_FS_TIMEOUT);
534 return _intCommandWrapper(
"GR\r", CMUCAM4_NON_FS_TIMEOUT);
539 return _intCommandWrapper(
"PI\r", CMUCAM4_NON_FS_TIMEOUT);
544 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
545 "PO %d %d\r", direction, output) < CMUCAM4_CMD_BUFFER_SIZE)
546 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
552 return _intCommandWrapper(
"TI\r", CMUCAM4_NON_FS_TIMEOUT);
557 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
558 "TO %d %d\r", direction, output) < CMUCAM4_CMD_BUFFER_SIZE)
559 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
565 return _intCommandWrapper(
"GI\r", CMUCAM4_NON_FS_TIMEOUT);
570 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
571 "SO %d %d\r", directions, outputs) < CMUCAM4_CMD_BUFFER_SIZE)
572 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
578 return _voidCommandWrapper(
"L0\r", CMUCAM4_NON_FS_TIMEOUT);
583 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
584 "L1 %ld\r", frequency) < CMUCAM4_CMD_BUFFER_SIZE)
585 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
595 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
596 "GS %d\r", servo) < CMUCAM4_CMD_BUFFER_SIZE)
597 ? _intCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
603 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
604 "SS %d %d %d\r", servo, active, pulseLength) < CMUCAM4_CMD_BUFFER_SIZE)
605 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
611 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
612 "AP %d %d\r", active, reverse) < CMUCAM4_CMD_BUFFER_SIZE)
613 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
619 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
620 "AT %d %d\r", active, reverse) < CMUCAM4_CMD_BUFFER_SIZE)
621 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
627 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
628 "PP %d %d\r", proportionalGain, derivativeGain) < CMUCAM4_CMD_BUFFER_SIZE)
629 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
635 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
636 "TP %d %d\r", proportionalGain, derivativeGain) < CMUCAM4_CMD_BUFFER_SIZE)
637 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
647 return _voidCommandWrapper(
"M0\r", CMUCAM4_NON_FS_TIMEOUT);
652 return _voidCommandWrapper(
"M1\r", CMUCAM4_NON_FS_TIMEOUT);
657 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
658 "MF %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
659 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
665 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
666 "MS %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
667 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
677 int errorValue;
int resultValue;
684 if((errorValue = _commandWrapper(
"GT\r", CMUCAM4_NON_FS_TIMEOUT)))
689 if((errorValue = setjmp(_env)))
695 resultValue = (sscanf(_resBuffer,
"%d %d %d %d %d %d ",
709 int errorValue;
int resultValue;
716 if((errorValue = _commandWrapper(
"GW\r", CMUCAM4_NON_FS_TIMEOUT)))
721 if((errorValue = setjmp(_env)))
727 resultValue = (sscanf(_resBuffer,
"%d %d %d %d ",
739 return _voidCommandWrapper(
"ST\r", CMUCAM4_NON_FS_TIMEOUT);
743 int greenMin,
int greenMax,
744 int blueMin,
int blueMax)
746 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
747 "ST %d %d %d %d %d %d\r",
748 redMin, redMax, greenMin, greenMax, blueMin, blueMax)
749 < CMUCAM4_CMD_BUFFER_SIZE)
750 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
756 return _voidCommandWrapper(
"SW\r", CMUCAM4_NON_FS_TIMEOUT);
760 int bottomRightX,
int bottomRightY)
762 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
764 topLeftX, topLeftY, bottomRightX, bottomRightY)
765 < CMUCAM4_CMD_BUFFER_SIZE)
766 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
772 int errorValue;
static int resetTries;
char cmdBuffer[CMUCAM4_IC_LENGTH];
774 if(_state == DEACTIVATED)
779 if(snprintf(cmdBuffer, CMUCAM4_IC_LENGTH,
780 CMUCAM4_IC_STRING, (_version / 100), (_version % 100))
781 >= (
int) CMUCAM4_IC_LENGTH)
786 resetTries = CMUCAM4_IDLE_TRIES;
787 errorValue = setjmp(_env);
789 if(resetTries-- <= 0)
794 _setReadTimeout(CMUCAM4_IDLE_TIMEOUT);
795 _com.
write((uint8_t)
'\0');
796 _com.
write((uint8_t)
'\0');
797 _com.
write((uint8_t)
'\0');
798 _com.
write(
"\rGV\r");
799 _waitForString(cmdBuffer);
806 return _commandWrapper(
"TC\r", CMUCAM4_NON_FS_TIMEOUT);
810 int greenMin,
int greenMax,
811 int blueMin,
int blueMax)
813 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
814 "TC %d %d %d %d %d %d\r",
815 redMin, redMax, greenMin, greenMax, blueMin, blueMax)
816 < CMUCAM4_CMD_BUFFER_SIZE)
817 ? _commandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
823 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
824 "TW %d %d %d\r", redRange, greenRange, blueRange)
825 < CMUCAM4_CMD_BUFFER_SIZE)
826 ? _commandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
832 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
833 "GH %d %d\r", channel, bins)
834 < CMUCAM4_CMD_BUFFER_SIZE)
835 ? _commandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
841 return _commandWrapper(
"GM\r", CMUCAM4_NON_FS_TIMEOUT);
853 if((errorValue = _responceWrapper(
'F')))
858 if(strcmp(_resBuffer,
"F ") != 0)
863 if((errorValue = setjmp(_env)))
870 return (_readWithTimeout() ==
'\r')
876 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
883 if((errorValue = _responceWrapper(
'H')))
890 if((*buffer) ==
'\0')
895 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
898 if((*buffer) !=
'\0')
908 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
915 if((errorValue = _responceWrapper(
'H')))
922 if((*buffer) ==
'\0')
927 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
930 if((*buffer) !=
'\0')
940 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
947 if((errorValue = _responceWrapper(
'H')))
954 if((*buffer) ==
'\0')
959 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
962 if((*buffer) !=
'\0')
972 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
979 if((errorValue = _responceWrapper(
'H')))
986 if((*buffer) ==
'\0')
991 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
994 if((*buffer) !=
'\0')
1004 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
1011 if((errorValue = _responceWrapper(
'H')))
1018 if((*buffer) ==
'\0')
1023 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
1026 if((*buffer) !=
'\0')
1036 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
1043 if((errorValue = _responceWrapper(
'H')))
1050 if((*buffer) ==
'\0')
1055 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
1058 if((*buffer) !=
'\0')
1068 int errorValue;
char * buffer = (_resBuffer +
sizeof(
'H'));
size_t counter;
1075 if((errorValue = _responceWrapper(
'H')))
1082 if((*buffer) ==
'\0')
1087 pointer->
bins[counter] = ((uint8_t) strtol(buffer, &buffer, 10));
1090 if((*buffer) !=
'\0')
1107 if((errorValue = _responceWrapper(
'S')))
1112 return (sscanf(_resBuffer,
1113 "S %d %d %d %d %d %d %d %d %d %d %d %d ",
1125 &(pointer->
BStDev)) == 12)
1138 if((errorValue = _responceWrapper(
'T')))
1143 return (sscanf(_resBuffer,
1144 "T %d %d %d %d %d %d %d %d ",
1158 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1159 "PM %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1160 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1166 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1167 "LM %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1168 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1174 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1175 "SM %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1176 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1182 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1183 "TM %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1184 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1190 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1191 "CT %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1192 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1198 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1199 "HT %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1200 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1206 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1207 "IF %d\r", active) < CMUCAM4_CMD_BUFFER_SIZE)
1208 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1214 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1215 "NF %d\r", threshold) < CMUCAM4_CMD_BUFFER_SIZE)
1216 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)
1225 const char * attributes)
1227 if((fileOrDirectoryPathName == NULL) || (attributes == NULL))
1232 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1233 "CA \"%s\" \"%s\"\r", fileOrDirectoryPathName, attributes)
1234 < CMUCAM4_CMD_BUFFER_SIZE)
1235 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1241 if(directoryPathAndName == NULL)
1246 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1247 "CD \"%s\"\r", directoryPathAndName)
1248 < CMUCAM4_CMD_BUFFER_SIZE)
1249 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1255 int errorValue;
int resultValue;
1262 if((errorValue = _commandWrapper(
"DI\r", CMUCAM4_FS_TIMEOUT)))
1267 if((errorValue = setjmp(_env)))
1276 resultValue = (sscanf(_resBuffer,
1277 "\"%" CMUCAM4_VL_LENGTH_STR
"c\" "
1278 "\"%" CMUCAM4_FST_LENGTH_STR
"c\" "
1279 "%lxh %lxh %lu %lu %lu %lu ",
1295 int errorValue;
int resultValue;
1302 if((errorValue = _commandWrapper(
"DS\r", CMUCAM4_FS_TIMEOUT)))
1307 if((errorValue = setjmp(_env)))
1314 resultValue = (sscanf(_resBuffer,
1325 return _voidCommandWrapper(
"FM\r", CMUCAM4_FS_TIMEOUT);
1329 size_t size,
unsigned long offset)
1331 int errorValue;
unsigned long directorySize;
1333 if((errorValue = _commandWrapper(
"LS\r", CMUCAM4_FS_TIMEOUT)))
1338 if((errorValue = setjmp(_env)))
1343 for(directorySize = 0; 1; directorySize++)
1347 if((*_resBuffer) ==
':')
1352 if((pointer != NULL) && (offset <= directorySize) &&
1353 ((directorySize - offset) < ((
unsigned long) size)))
1355 memset(pointer[directorySize - offset].name,
1357 memset(pointer[directorySize - offset].attributes,
1360 if(sscanf(_resBuffer,
1361 " \"%" CMUCAM4_NAME_LENGTH_STR
"c\" "
1362 "%" CMUCAM4_ATTR_LENGTH_STR
"c ",
1363 pointer[directorySize - offset].name,
1364 pointer[directorySize - offset].attributes) != 2)
1369 pointer[directorySize - offset].
size = 0;
1371 if(strchr(pointer[directorySize - offset].attributes,
'D') == NULL)
1373 if(sscanf(_resBuffer,
1374 " \"%*" CMUCAM4_NAME_LENGTH_STR
"c\" "
1375 "%*" CMUCAM4_ATTR_LENGTH_STR
"c "
1377 &(pointer[directorySize - offset].size)) != 1)
1385 return (
long) directorySize;
1390 if(directoryPathAndName == NULL)
1395 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1396 "MK \"%s\"\r", directoryPathAndName)
1397 < CMUCAM4_CMD_BUFFER_SIZE)
1398 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1403 const char * newEntryPathAndName)
1405 if((oldEntryPathAndName == NULL) || (newEntryPathAndName == NULL))
1410 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1411 "MV \"%s\" \"%s\"\r", oldEntryPathAndName, newEntryPathAndName)
1412 < CMUCAM4_CMD_BUFFER_SIZE)
1413 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1419 if((filePathAndName == NULL) || (textToAppend == NULL))
1424 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1425 "PL \"%s\" \"%s\"\r", filePathAndName, textToAppend)
1426 < CMUCAM4_CMD_BUFFER_SIZE)
1427 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1432 size_t size,
unsigned long offset)
1434 int errorValue;
unsigned long fileSize;
1436 if(filePathAndName == NULL)
1441 if(snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1442 "PR \"%s\"\r", filePathAndName) >= CMUCAM4_CMD_BUFFER_SIZE)
1447 if((errorValue = _commandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)))
1452 if((errorValue = setjmp(_env)))
1459 if(sscanf(_resBuffer,
"%lu ", &fileSize) != 1)
1464 _readBinary(buffer, size, fileSize, offset);
1467 return (
long) fileSize;
1472 if(fileOrDirectoryPathAndName == NULL)
1477 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1478 "RM \"%s\"\r", fileOrDirectoryPathAndName)
1479 < CMUCAM4_CMD_BUFFER_SIZE)
1480 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1486 return _voidCommandWrapper(
"UM\r", CMUCAM4_FS_TIMEOUT);
1495 return _voidCommandWrapper(
"DB\r", CMUCAM4_FS_TIMEOUT);
1500 return (snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1501 "DF %d %d\r", horizontalResolution, verticalResolution)
1502 < CMUCAM4_CMD_BUFFER_SIZE)
1503 ? _voidCommandWrapper(_cmdBuffer, CMUCAM4_FS_TIMEOUT)
1516 if((errorValue = _commandWrapper(
"SB\r", CMUCAM4_NON_FS_TIMEOUT)))
1521 if((errorValue = setjmp(_env)))
1528 if(_readWithTimeout() !=
'\r')
1539 size_t horizonalSize,
size_t horizontalOffset,
1540 size_t verticalSize,
size_t verticalOffset)
1542 int errorValue;
int serialBuffer0;
int serialBuffer1;
1543 size_t indexX;
size_t indexY;
size_t resolutionX;
size_t resolutionY;
1545 resolutionX = (CMUCAM4_FRAME_H_RES >> horizontalResolution);
1546 resolutionY = (CMUCAM4_FRAME_V_RES >> verticalResolution);
1548 if(snprintf(_cmdBuffer, CMUCAM4_CMD_BUFFER_SIZE,
1549 "SF %d %d\r", horizontalResolution, verticalResolution)
1550 >= CMUCAM4_CMD_BUFFER_SIZE)
1555 if((errorValue = _commandWrapper(_cmdBuffer, CMUCAM4_NON_FS_TIMEOUT)))
1560 if((errorValue = setjmp(_env)))
1565 for(indexX = 0; indexX < resolutionX; indexX++)
1567 _setReadTimeout(CMUCAM4_NON_FS_TIMEOUT);
1571 if((*_resBuffer) ==
':')
1581 if(strcmp(_resBuffer,
"DAT:") != 0)
1591 if(strcmp(_resBuffer,
"DAT: ") != 0)
1599 for(indexY = 0; indexY < resolutionY; indexY++)
1601 serialBuffer0 = (_readWithTimeout() & 0xFF);
1602 serialBuffer1 = (_readWithTimeout() & 0xFF);
1604 if((buffer != NULL) && (horizontalOffset <= indexX) &&
1605 ((indexX - horizontalOffset) < horizonalSize) &&
1606 (verticalOffset <= indexY) &&
1607 ((indexY - verticalOffset) < verticalSize))
1609 buffer[((indexY - verticalOffset) * horizonalSize)
1610 + (indexX - horizontalOffset)]
1611 = ((uint16_t) (serialBuffer0 | (serialBuffer1 << 8)));
1615 if(_readWithTimeout() !=
'\r')
1629 int CMUcam4::_voidCommandWrapper(
const char * command,
unsigned long timeout)
1633 if((errorValue = _commandWrapper(command, timeout)))
1638 if((errorValue = setjmp(_env)))
1647 int CMUcam4::_intCommandWrapper(
const char * command,
unsigned long timeout)
1649 int errorValue;
int resultValue;
int returnValue;
1651 if((errorValue = _commandWrapper(command, timeout)))
1656 if((errorValue = setjmp(_env)))
1662 resultValue = (sscanf(_resBuffer,
"%d ", &returnValue) == 1);
1668 int CMUcam4::_commandWrapper(
const char * command,
unsigned long timeout)
1677 if((errorValue = setjmp(_env)))
1682 _setReadTimeout(timeout);
1683 _com.
write(command);
1689 int CMUcam4::_responceWrapper(
char responce)
1693 if(_state == DEACTIVATED)
1698 if((errorValue = setjmp(_env)))
1703 _setReadTimeout(CMUCAM4_NON_FS_TIMEOUT);
1709 if((*_resBuffer) == responce)
1714 if((*_resBuffer) ==
':')
1719 if(strcmp(_resBuffer,
"F ") == 0)
1723 if(_readWithTimeout() !=
'\r')
1733 void CMUcam4::_waitForIdle()
1739 if(_startsWithString(
"MSG"))
1746 if((*_resBuffer) !=
':')
1755 void CMUcam4::_waitForResponce()
1759 if(strcmp(_resBuffer,
"NCK") == 0)
1763 if((*_resBuffer) ==
':')
1771 if(strcmp(_resBuffer,
"ACK") != 0)
1777 void CMUcam4::_receiveData()
1783 if(_startsWithString(
"MSG"))
1794 void CMUcam4::_handleError()
1796 int errorValue;
int sum;
size_t index;
size_t length;
1798 if(_startsWithString(
"ERR"))
1800 sum = 0; length = strlen(_resBuffer);
1802 for(index = 0; index < length; index++)
1804 sum += _resBuffer[index];
1809 case CMUCAM4_CAMERA_TIMEOUT_ERROR_SUM:
1812 case CMUCAM4_CAMERA_CONNECTION_ERROR_SUM:
1815 case CMUCAM4_DISK_IO_ERROR_SUM:
1818 case CMUCAM4_FILE_SYSTEM_CORRUPTED_SUM:
1821 case CMUCAM4_FILE_SYSTEM_UNSUPPORTED_SUM:
1824 case CMUCAM4_CARD_NOT_DETECTED_SUM:
1827 case CMUCAM4_DISK_MAY_BE_FULL_SUM:
1830 case CMUCAM4_DIRECTORY_FULL_SUM:
1833 case CMUCAM4_EXPECTED_AN_ENTRY_SUM:
1836 case CMUCAM4_EXPECTED_A_DIRECTORY_SUM:
1839 case CMUCAM4_ENTRY_NOT_ACCESSIBLE_SUM:
1842 case CMUCAM4_ENTRY_NOT_MODIFIABLE_SUM:
1845 case CMUCAM4_ENTRY_NOT_FOUND_SUM:
1849 case CMUCAM4_ENTRY_ALREADY_EXISTS_SUM:
1853 case (CMUCAM4_ENTRY_ALREADY_EXISTS_SUM -
's'):
1856 case CMUCAM4_DIRECTORY_LINK_MISSING_SUM:
1859 case CMUCAM4_DIRECTORY_NOT_EMPTY_SUM:
1862 case CMUCAM4_NOT_A_DIRECTORY_SUM:
1865 case CMUCAM4_NOT_A_FILE_SUM:
1874 if((*_resBuffer) ==
':')
1876 longjmp(_env, errorValue);
1883 void CMUcam4::_waitForString(
const char *
string)
1885 size_t index;
size_t length = strlen(
string);
1886 memset(_resBuffer,
'\0', CMUCAM4_RES_BUFFER_SIZE);
1890 for(index = 1; index < length; index++)
1892 _resBuffer[index - 1] = _resBuffer[index];
1895 _resBuffer[length - 1] = _readWithTimeout();
1897 while(strcmp(_resBuffer,
string) != 0);
1900 int CMUcam4::_startsWithString(
const char *
string)
1902 return (strncmp(_resBuffer,
string, strlen(
string)) == 0);
1905 void CMUcam4::_readBinary(uint8_t * buffer,
size_t size,
1906 unsigned long packetSize,
1907 unsigned long packetOffset)
1909 int serialBuffer;
unsigned long serialCounter;
1911 for(serialCounter = 0; serialCounter < packetSize; serialCounter++)
1913 serialBuffer = _readWithTimeout();
1915 if((buffer != NULL) && (packetOffset <= serialCounter) &&
1916 ((serialCounter - packetOffset) < ((
unsigned long) size)))
1918 buffer[serialCounter - packetOffset] = ((uint8_t) serialBuffer);
1923 void CMUcam4::_readText()
1925 int serialBuffer;
size_t serialCounter = 0;
1926 memset(_resBuffer,
'\0', CMUCAM4_RES_BUFFER_SIZE);
1930 serialBuffer = _readWithTimeout();
1932 if(serialBuffer ==
'\r')
1937 _resBuffer[serialCounter++] = serialBuffer;
1939 if(serialCounter >= CMUCAM4_RES_BUFFER_SIZE)
1944 switch(serialCounter)
1948 if((*_resBuffer) ==
':')
1955 case (
sizeof(
"F ") - 1):
1957 if(strcmp(_resBuffer,
"F ") == 0)
1964 case (
sizeof(
"DAT:") - 1):
1966 if(_state == ACTIVATED)
1973 if(strcmp(_resBuffer,
"DAT:") == 0)
1989 case (
sizeof(
"DAT: ") - 1):
1991 if(_state == ACTIVATED)
2003 if(strcmp(_resBuffer,
"DAT: ") == 0)
2019 void CMUcam4::_setReadTimeout(
unsigned long timeout)
2025 int CMUcam4::_readWithTimeout()