55 sum += htons(data[i]);
56 return htons(0xFFFF - sum);
63 fprintf(stderr,
"Reading old calibration...\n");
67 fprintf(stderr,
"Flash read error. Aborting.\n");
71 uint16_t chk =
checksum((uint16_t *) calbuff);
74 fprintf(stderr,
"Previous camera calibration had bad checksum.\n");
78 calbuff[
sizeof(calbuff) - 2] = 0;
79 printf(
"%s\n", calbuff);
88 bzero(calbuff,
sizeof(calbuff));
90 fprintf(stderr,
"\nWriting new calibration...\n");
93 if (strcmp(filename,
"-"))
94 f = fopen(filename,
"r");
97 fprintf(stderr,
"Enter new calibration information on standard input.\n");
102 fprintf(stderr,
"Unable to open file %s.\n", filename);
105 int maxsize =
sizeof(calbuff) -
sizeof(uint16_t) - 1;
106 int bytesread = fread(calbuff, 1, maxsize + 1, f);
108 if (bytesread > maxsize)
110 fprintf(stderr,
"File %s is too long. At most %i bytes can be stored.\n", filename, maxsize);
113 calbuff[bytesread] = 0;
121 fprintf(stderr,
"Flash write error. The camera calibration is an undetermined state.\n");
125 fprintf(stderr,
"Success!\n");
132 bzero(calbuff,
sizeof(calbuff));
134 fprintf(stderr,
"\nClearing calibration...\n");
139 fprintf(stderr,
"Flash write error. The camera calibration is an undetermined state.\n");
143 fprintf(stderr,
"Success!\n");
147 int main(
int argc,
char **argv)
149 if ((argc != 3 && argc != 2) || !strcmp(argv[1],
"--help")) {
150 fprintf(stderr,
"Usage: %s <camera_url> <calibration_file> # Sets the camera calibration information\n", argv[0]);
151 fprintf(stderr,
" %s <camera_url> - # Sets the camera calibration information from stdin\n", argv[0]);
152 fprintf(stderr,
" %s <camera_url> --invalidate # Invalidates the camera calibration information\n", argv[0]);
153 fprintf(stderr,
" %s <camera_url> # Reads the camera calibration information\n", argv[0]);
154 fprintf(stderr,
"\nReads or writes the camera calibration information stored on the camera's flash.\n");
158 char *camera_url = argv[1];
166 fprintf(stderr,
"Matching URL %s : %s\n", camera_url, errmsg);
174 fprintf(stderr,
"Unable to create ARP entry (are you root?), continuing anyway\n");
176 fprintf(stderr,
"IP address configuration failed\n");
188 char *filename = argv[2];
190 if (strcmp(filename,
"--invalidate"))
int wge100ReliableFlashRead(const IpCamList *camInfo, uint32_t address, uint8_t *pageDataOut, int *retries)
int wge100ReliableFlashWrite(const IpCamList *camInfo, uint32_t address, const uint8_t *pageDataIn, int *retries)
int wge100Configure(IpCamList *camInfo, const char *ipAddress, unsigned wait_us)
int read_calibration(IpCamList *camera)
#define ERR_CONFIG_ARPFAIL
uint16_t checksum(uint16_t *data)
int main(int argc, char **argv)
int wge100FindByUrl(const char *url, IpCamList *camera, unsigned wait_us, const char **errmsg)
int clear_calibration(IpCamList *camera, char *filename)
int write_calibration(IpCamList *camera, char *filename)
#define FLASH_CALIBRATION_PAGENO