45 #define _CRT_SECURE_NO_WARNINGS
49 #define Sleep(millis) sleep((millis) / 1000)
65 unsigned int nextSessionId = 0;
70 ifp = fopen(infile,
"rt");
82 while (ifp != NULL && !feof(ifp))
94 deviceIds = (
int *)malloc(numDevices *
sizeof(
int));
98 if (result < numDevices) { numDevices = result; }
101 for (i = 0; i < numDevices; i++)
103 int dataOffsetBlocks, dataNumBlocks;
104 unsigned int sessionId;
105 int deviceId = deviceIds[i];
106 char timeStartString[32], timeStopString[32];
109 while (nextSessionId == 0)
111 static char line[100];
112 if (fgets(line, 100, ifp) == NULL) {
break; }
113 nextSessionId = (
unsigned int)atoi(line);
115 if (nextSessionId == 0) {
break; }
126 printf(
"%d = CHARGING\n", deviceId);
131 result =
OmGetDataRange(deviceId, NULL, &dataOffsetBlocks, &dataNumBlocks, NULL, NULL);
139 if (dataNumBlocks - dataOffsetBlocks > 0)
141 printf(
"DEPLOY #%d: Ignoring - has data stored on the device.\n", deviceId);
144 printf(
"%d = HAS-DATA (run 'clear' example to reset)\n", deviceId);
152 printf(
"%d = ALREADY-DEPLOYED (run 'clear' example to reset)\n", deviceId);
166 tm = localtime(&
now);
167 nowTime =
OM_DATETIME_FROM_YMDHMS(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
169 printf(
"DEPLOY #%d: Synchronizing the time...\n", deviceId);
180 printf(
"DEPLOY #%d: Device time: %s\n", deviceId, OmDateTimeToString(time, buffer));
194 printf(
"DEPLOY #%d: Setting delayed start/stop times (start in 3 days at 9am, stop after 1 week)\n", deviceId);
197 now += 3 * 24 * 60 * 60;
198 tm = localtime(&
now);
202 startTime =
OM_DATETIME_FROM_YMDHMS(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
203 sprintf(timeStartString,
"%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
206 now += 7 * 24 * 60 * 60;
207 tm = localtime(&
now);
211 stopTime =
OM_DATETIME_FROM_YMDHMS(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
212 sprintf(timeStopString,
"%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
215 printf(
"DEPLOY #%d: Setting delayed start/stop times (start in 1 minute, stop after 1 minute)\n", deviceId);
219 tm = localtime(&
now);
220 startTime =
OM_DATETIME_FROM_YMDHMS(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
221 sprintf(timeStartString,
"%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
225 tm = localtime(&
now);
226 stopTime =
OM_DATETIME_FROM_YMDHMS(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
227 sprintf(timeStopString,
"%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
232 printf(
"DEPLOY #%d: Setting start: %s [%s]\n", deviceId, timeStartString, OmDateTimeToString(startTime, buffer));
233 printf(
"DEPLOY #%d: Setting stop: %s [%s]\n", deviceId, timeStopString, OmDateTimeToString(stopTime, buffer));
234 result =
OmSetDelays(deviceId, startTime, stopTime);
244 printf(
"DEPLOY #%d: Device delayed start: %s\n", deviceId, OmDateTimeToString(start, buffer));
245 printf(
"DEPLOY #%d: Device delayed stop: %s\n", deviceId, OmDateTimeToString(stop, buffer));
250 printf(
"DEPLOY #%d: Setting session id: %u\n", deviceId, nextSessionId);
255 unsigned int sessionId;
258 printf(
"DEPLOY #%d: Device session id: %u\n", deviceId, sessionId);
262 printf(
"DEPLOY #%d: Committing new settings...\n", deviceId);
266 printf(
"DEPLOYED,%u,%d,%s,%s\n", nextSessionId, deviceId, timeStartString, timeStopString);
269 fprintf(ofp,
"%u,%u,%s,%s\n", nextSessionId, deviceId, timeStartString, timeStopString);
290 if (ifp != NULL) { fclose(ifp); }
291 if (ofp != NULL) { fclose(ofp); }
300 printf(
"DEPLOY: batch setup of all fully-charged and clear devices.\n");
304 const char *infile = argv[1];
314 printf(
"Usage: deploy <input-file> [output-file]\n");
316 printf(
"Where: input-file: contains one numeric session identifier on each line to issue to each deployed device\n");
317 printf(
" output-file: will receive the mapping of device ids to each session identifiers\n");
319 printf(
"Example: deploy input.txt output.txt\n");