00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "wge100_camera/wge100lib.h"
00036 #include "wge100_camera/host_netutil.h"
00037 #include <string.h>
00038 #include <cstdio>
00039 #include <cstdlib>
00040 #include <cstring>
00041 #include <cassert>
00042 #include <unistd.h>
00043
00044 int sensorread(IpCamList *camera, uint8_t reg)
00045 {
00046 uint16_t val;
00047
00048 if ( wge100ReliableSensorRead( camera, reg, &val, NULL ) != 0) {
00049 fprintf(stderr, "Could not get register.\n");
00050 return -1;
00051 }
00052
00053 return val;
00054 }
00055
00056 int sensorwrite(IpCamList *camera, uint8_t reg, uint16_t val)
00057 {
00058 if ( wge100ReliableSensorWrite( camera, reg, val, NULL ) != 0) {
00059 fprintf(stderr, "Could not set register.\n");
00060 return -1;
00061 }
00062 return 0;
00063 }
00064
00065 int usage(int argc, char **argv)
00066 {
00067 fprintf(stderr, "Usage: %s <camera_url> # Read all imager register\n", argv[0]);
00068 fprintf(stderr, " %s <camera_url> <register> # Read an imager registers\n", argv[0]);
00069 fprintf(stderr, " %s <camera_url> <register> <value> # Write an imager register\n", argv[0]);
00070 fprintf(stderr, " %s <camera_url> stresstest <register> # Repeatedly reads imager register\n", argv[0]);
00071 fprintf(stderr, " %s <camera_url> stresstest <register> <value> # Repeatedly writes value to imager register\n", argv[0]);
00072 fprintf(stderr, "Notes:\n");
00073 fprintf(stderr, "- All <register> and <value> values are in hexadecimal.\n");
00074 fprintf(stderr, "- This tool will never reconfigure the camera's IP address to allow its use during image streaming.\n");
00075 fprintf(stderr, "- Register accesses during image streaming may cause interruptions in the streaming.\n");
00076 return -1;
00077 }
00078
00079 int main(int argc, char** argv)
00080 {
00081 bool stress = false;
00082 bool write = false;
00083
00084 char **nextarg = argv + 1;
00085 char **endarg = argv;
00086 while (*endarg)
00087 endarg++;
00088
00089
00090 if (nextarg == endarg || !strcmp(*nextarg, "--help"))
00091 return usage(argc, argv);
00092 const char *camera_url = *nextarg++;
00093
00094
00095 IpCamList camera;
00096 const char *errmsg;
00097 int outval = wge100FindByUrl(camera_url, &camera, SEC_TO_USEC(0.1), &errmsg);
00098 if (outval)
00099 {
00100 fprintf(stderr, "Matching URL %s : %s\n", camera_url, errmsg);
00101 return -1;
00102 }
00103
00104 if (nextarg == endarg)
00105 {
00106 for (int i = 0; i < 256; i++)
00107 {
00108 if (i % 16 == 0)
00109 fprintf(stderr, "%02x: ", i);
00110
00111 if (i % 16 == 8)
00112 fprintf(stderr, "- ");
00113
00114 int value = sensorread(&camera, i);
00115 if (value == -1)
00116 fprintf(stderr, "??");
00117 else
00118 fprintf(stderr, "%04x ", value);
00119
00120 if ((i + 1) % 16 == 0)
00121 fprintf(stderr, "\n");
00122 }
00123 return 0;
00124 }
00125
00126 if (!strcmp(*nextarg, "stresstest"))
00127 {
00128 stress = true;
00129 if (++nextarg == endarg)
00130 return usage(argc, argv);
00131 }
00132
00133
00134 uint16_t val;
00135 uint8_t reg;
00136
00137 sscanf(*nextarg++, "%hhx", ®);
00138
00139 if (nextarg != endarg)
00140 {
00141 sscanf(*nextarg++, "%hx", &val);
00142 write = true;
00143 }
00144
00145 if (nextarg != endarg)
00146 return usage(argc, argv);
00147
00148 if (stress && !write)
00149 {
00150 int count = 0;
00151 while (1)
00152 {
00153 int oldval = sensorread(&camera, reg);
00154 fprintf(stderr, "Count %i reg %02x read: %04x\n", count++, reg, oldval);
00155 }
00156 }
00157 else if (stress)
00158 {
00159 int count = 0;
00160 uint16_t oldval = sensorread(&camera, reg);
00161 while (1)
00162 {
00163 sensorwrite(&camera, reg, val);
00164 int newval = sensorread(&camera, reg);
00165 fprintf(stderr, "Count %i Reg %02x was: %04x set: %04x read: %04x\n", count++, reg, oldval, val, newval);
00166 oldval = newval;
00167 }
00168 }
00169 else
00170 {
00171 uint16_t oldval = sensorread(&camera, reg);
00172 if (write)
00173 {
00174 sensorwrite(&camera, reg, val);
00175 int newval = sensorread(&camera, reg);
00176 fprintf(stderr, "Reg %02x was: %04x set: %04x read: %04x\n", reg, oldval, val, newval);
00177 }
00178 else
00179 fprintf(stderr, "Reg %02x read: %04x\n", reg, oldval);
00180 }
00181
00182 return 0;
00183 }