55 sum += htons(data[i]);
56 return htons(0xFFFF - sum);
66 fprintf(stderr,
"Flash read error. Aborting.\n");
70 uint16_t chk =
checksum((uint16_t *) namebuff);
73 fprintf(stderr,
"Previous camera name had bad checksum.\n");
76 id->cam_name[
sizeof(
id->cam_name) - 1] = 0;
77 printf(
"Previous camera name was: %s\n", id->
cam_name);
78 uint8_t *oldip = (uint8_t *) &id->
cam_addr;
79 printf(
"Previous camera IP: %i.%i.%i.%i\n", oldip[0], oldip[1], oldip[2], oldip[3]);
89 if (strlen(name) >
sizeof(
id->cam_name) - 1)
91 fprintf(stderr,
"Name is too long, the maximum number of characters is %zu.\n",
sizeof(id->
cam_name) - 1);
96 id->cam_name[
sizeof(
id->cam_name) - 1] = 0;
97 struct in_addr cam_ip;
98 if (!inet_aton(new_ip, &cam_ip))
100 fprintf(stderr,
"This is not a valid IP address: %s\n", new_ip);
103 id->cam_addr = cam_ip.s_addr;
104 id->checksum =
checksum((uint16_t *) namebuff);
108 fprintf(stderr,
"Flash write error. The camera name is an undetermined state.\n");
112 fprintf(stderr,
"Success! Restarting camera, should take about 10 seconds to come back up after this.\n");
119 int main(
int argc,
char **argv)
121 if ((argc != 4 && argc != 2) || !strcmp(argv[1],
"--help")) {
122 fprintf(stderr,
"Usage: %s <camera_url> <new_name> <new_default_ip> # Sets the camera name and default IP\n", argv[0]);
123 fprintf(stderr,
" %s <camera_url> # Reads the camera name and default IP\n", argv[0]);
124 fprintf(stderr,
"\nReads or writes the camera name and default IP address stored on the camera's flash.\n");
128 char *camera_url = argv[1];
136 fprintf(stderr,
"Matching URL %s : %s\n", camera_url, errmsg);
144 fprintf(stderr,
"Unable to create ARP entry (are you root?), continuing anyway\n");
146 fprintf(stderr,
"IP address configuration failed\n");
158 char *name = argv[2];
159 char *new_ip = argv[3];
char cam_name[CAMERA_NAME_LEN]
Should be zero terminated. Will be forcibly zero terminated otherwise.
#define FLASH_NAME_PAGENO
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 wge100Reset(IpCamList *camInfo)
int read_name(IpCamList *camera)
int wge100Configure(IpCamList *camInfo, const char *ipAddress, unsigned wait_us)
#define ERR_CONFIG_ARPFAIL
int wge100FindByUrl(const char *url, IpCamList *camera, unsigned wait_us, const char **errmsg)
int main(int argc, char **argv)
IPAddress cam_addr
Camera address at power-on.
int write_name(IpCamList *camera, char *name, char *new_ip)
uint16_t checksum(uint16_t *data)