OMAPI  1.8
Open Movement Public API
record.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2012, Newcastle University, UK.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23  * POSSIBILITY OF SUCH DAMAGE.
24  */
25 
43 /* Headers - need a sleep function to wait */
44 #ifdef _WIN32
45 #define _CRT_SECURE_NO_WARNINGS
46 #include <windows.h>
47 #else
48 #include <unistd.h>
49 #define Sleep(millis) sleep((millis) / 1000)
50 #endif
51 #include <time.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <stdbool.h>
55 #include <string.h>
56 
57 
58 /* API header */
59 #include "omapi.h"
60 
61 static FILE *ofp = NULL;
63 
64 struct deviceInfo_tag;
65 typedef struct deviceInfo_tag
66 {
67  int deviceId;
70 } deviceInfo_t;
72 
73 static devicestatus_t *getDeviceStatus(int deviceId)
74 {
75  // Find existing
76  for (deviceInfo_t *di = deviceInfo; di != NULL; di = di->next)
77  {
78  if (di->deviceId == deviceId)
79  {
80  return &di->status;
81  }
82  }
83  // Insert
84  deviceInfo_t *newDeviceInfo = (deviceInfo_t *)malloc(sizeof(deviceInfo_t));
85  memset(newDeviceInfo, 0, sizeof(deviceInfo_t));
86  newDeviceInfo->deviceId = deviceId;
87  newDeviceInfo->status = DEVICE_DISCONNECTED;
88  newDeviceInfo->next = deviceInfo; // chain to existing
89  deviceInfo = newDeviceInfo; // new head of chain
90  return &newDeviceInfo->status;
91 }
92 
93 
94 // Start time
95 int startDays = 1, startHour = 0;
96 int durationDays = 8, endHour = 0;
97 int minBatt = 85;
98 int debugMode = 0;
99 
100 
101 // Experimental: Check NAND id
102 #define ID_NAND
103 
104 #ifdef ID_NAND
105 // "NANDID=%02x:%02x:%02x:%02x:%02x:%02x,%d\r\n", id[0], id[1], id[2], id[3], id[4], id[5], nandPresent
106 static const char NAND_DEVICE_DONT_CARE[6] = {0x00};
107 static const char NAND_DEVICE_HY27UF084G2x[6] = { 0xAD, 0xDC, 0x00 }; // "NAND_DEVICE_ALT"
108 //?? 0xad,0xdc,0x84,0x25,0xad,0x00,
109 static const char NAND_DEVICE_HY27UF084G2B[6] = { 0xAD, 0xDC, 0x10, 0x95, 0x54, 0x00 }; // 1 "NAND_DEVICE"
110 static const char NAND_DEVICE_HY27UF084G2M[6] = { 0xAD, 0xDC, 0x80, 0x95, 0xAD, 0x00 }; // 2 (one matched by "NAND_DEVICE_ALT", the on-board check terminates after the first two bytes as it matches against NAND_DEVICE_HY27UF084G2x)
111 static const char NAND_DEVICE_MT29F8G08AAA[6] = { 0x2C, 0xD3, 0x90, 0x2E, 0x64, 0x00 }; // 3
112 static const char NAND_DEVICE_S34ML04G1[6] = { 0x01, 0xDC, 0x90, 0x95, 0x54, 0x00 }; // 4 "NAND_DEVICE_ALT2"
113 static const char NAND_DEVICE_MT29F8G08ABADA[6] = { 0x2C, 0xDC, 0x90, 0x95, 0x56, 0x00 }; // 5 "NAND_DEVICE_ALT3" (actually 4G NAND_DEVICE_MT29F4G..., the on-board check terminates after the first two bytes)
114 static const char NAND_DEVICE_AX6[6] = { 0xC2, 0xDC, 0x90, 0x95, 0x56, 0x00 }; // 6 AX6
115 
116 
117 static int OmGetNandId(int deviceId, unsigned char *id, int *present, int *identified)
118 {
119  int status;
120  char response[256], *parts[16] = {0};
121  unsigned char localId[6] = {0};
122  int tempId[6] = {0};
123  int i;
124 
125  status = OmCommand(deviceId, "\r\nSTATUS 7\r\n", response, 255, "NANDID=", 2000, parts, 15);
126  if (OM_FAILED(status)) return status;
127  // "NANDID=0"
128  if (parts[1] == NULL) { return OM_E_UNEXPECTED_RESPONSE; }
129  if (sscanf(parts[1], "%x:%x:%x:%x:%x:%x", &tempId[0], &tempId[1], &tempId[2], &tempId[3], &tempId[4], &tempId[5]) != 6) { return OM_E_UNEXPECTED_RESPONSE; }
130  for (i = 0; i < 6; i++) { localId[i] = (unsigned char)tempId[i]; }
131  if (id != NULL) { memcpy(id, localId, 6); }
132  if (identified != NULL)
133  {
134  *identified = -2;
135  if (memcmp(NAND_DEVICE_HY27UF084G2B, (char *)localId, 6) == 0) { *identified = 1; }
136  else if (memcmp(NAND_DEVICE_HY27UF084G2M, (char *)localId, 6) == 0) { *identified = 2; }
137  else if (memcmp(NAND_DEVICE_MT29F8G08AAA, (char *)localId, 6) == 0) { *identified = 3; }
138  else if (memcmp(NAND_DEVICE_S34ML04G1, (char *)localId, 6) == 0) { *identified = 4; }
139  else if (memcmp(NAND_DEVICE_MT29F8G08ABADA, (char *)localId, 6) == 0) { *identified = 5; }
140  else if (memcmp(NAND_DEVICE_AX6, (char *)localId, 6) == 0) { *identified = 6; }
141  }
142  if (parts[2] == NULL) { return OM_E_UNEXPECTED_RESPONSE; }
143  if (present != NULL)
144  {
145  *present = atoi(parts[2]);
146  }
147  return OM_OK;
148 }
149 #endif
150 
151 static int onlySingleId = -1;
152 static int onlySingleIdReturn = -1;
153 
154 static bool hasGyro(int deviceId)
155 {
156  char serialBuffer[OM_MAX_PATH];
157  if (OM_FAILED(OmGetDeviceSerial(deviceId, serialBuffer))) return false;
158  return memcmp(serialBuffer, "AX6", 3) == 0;
159 }
160 
162 {
163  int result;
164  char timeString[32];
165  time_t now;
166  struct tm *tm;
167  OM_DATETIME nowTime;
168  int firmwareVersion, hardwareVersion;
169  int battery;
170 
171  /* Check battery level */
172  battery = OmGetBatteryLevel(deviceId);
173  if (OM_FAILED(battery)) { printf("ERROR: OmGetBatteryLevel() %s\n", OmErrorString(battery)); return 0; }
174  else
175  {
176  printf("RECORD #%d: Battery at %d%% (%s)\n", deviceId, battery, (battery >= 100) ? "charged" : "charging");
177  }
178 
179  /* Check hardware and firmware versions */
180  result = OmGetVersion(deviceId, &firmwareVersion, &hardwareVersion);
181  if (OM_FAILED(result)) { printf("ERROR: OmGetVersion() %s\n", OmErrorString(result)); return 0; }
182  printf("RECORD #%d: Firmware %d, Hardware %d\n", deviceId, firmwareVersion, hardwareVersion);
183 
184 #ifdef ID_NAND
185  /* NAND ID */
186  {
187  unsigned char nandId[6] = { 0 };
188  int nandType = -1;
189  memset(nandId, 0, sizeof(nandId));
190  result = OmGetNandId(deviceId, nandId, NULL, &nandType);
191  if (result == OM_E_NOT_IMPLEMENTED) { fprintf(stderr, "NOTE: This firmware doesn't support NANDID command\n"); }
192  else if (result == OM_E_UNEXPECTED_RESPONSE) { fprintf(stderr, "NOTE: Unexpected NANDID response (firmware probably doesn't support NANDID command)\n"); }
193  else if (OM_FAILED(result)) { fprintf(stderr, "ERROR: Problem running OmGetNandId() %s\n", OmErrorString(result)); return 0; }
194  else
195  {
196  const char *nandDescription;
197  switch (nandType)
198  {
199  case 1: nandDescription = "STANDARD (HY27UF084G2B)"; break; // NAND_DEVICE_HY27UF084G2B
200  case 2: nandDescription = "ALTERNATE (HY27UF084G2M)"; break; // NAND_DEVICE_HY27UF084G2M
201  case 3: nandDescription = "MICRON (MT29F8G08AAA)"; break; // NAND_DEVICE_MT29F8G08AAA
202  case 4: nandDescription = "SPANSION (S34ML04G1)"; break; // NAND_DEVICE_S34ML04G1
203  case 5: nandDescription = "MICRON (MT29F4G08ABADA)"; break; // id "NAND_DEVICE_MT29F8G08ABADA", but actually 4 Gb model
204  case 6: nandDescription = "AX6"; break; // AX6
205  default: nandDescription = "UNKNOWN!"; break;
206  }
207 
208  fprintf(stderr, "RECORD #%d: NAND type =%d %s [%02x:%02x:%02x:%02x:%02x:%02x]\n", deviceId, nandType, nandDescription, nandId[0], nandId[1], nandId[2], nandId[3], nandId[4], nandId[5]);
209  if (nandType <= 0) { printf("ERROR: OmGetNandId() not known type (try again to be sure) [%02x:%02x:%02x:%02x:%02x:%02x].\n", nandId[0], nandId[1], nandId[2], nandId[3], nandId[4], nandId[5]); return 0; } // ERROR: Not known type
210  }
211  }
212 #endif
213 
214  /* Get NAND information */
215  {
216  int memoryHealth = 0;
217  memoryHealth = OmGetMemoryHealth(deviceId);
218  if (OM_FAILED(memoryHealth)) { fprintf(stderr, "ERROR: OmGetMemoryHealth() %s\n", OmErrorString(result)); return 0; }
219  // Spare blocks
220  fprintf(stderr, "RECORD #%d: Memory health =%d\n", deviceId, memoryHealth);
221  if (memoryHealth == 0) { printf("ERROR: OmGetMemoryHealth() no spare planes.\n"); return 0; }
222  else if (memoryHealth < OM_MEMORY_HEALTH_ERROR) { printf("ERROR: OmGetMemoryHealth() in error region.\n"); return 0; }
223  else if (memoryHealth < OM_MEMORY_HEALTH_WARNING) { printf("ERROR: OmGetMemoryHealth() in warning region.\n"); return 0; }
224  }
225 
226  /* Synchronize the time */
227  now = time(NULL);
228  tm = localtime(&now);
229  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);
230  sprintf(timeString, "%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);
231 
232  fprintf(stderr, "RECORD #%d: Synchronizing the time...\n", deviceId);
233  result = OmSetTime(deviceId, nowTime);
234  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmSetTime() %s\n", OmErrorString(result)); return 0; }
235 
236  /* Set the accelerometer (+gyro) configuration */
237  int range = OM_ACCEL_DEFAULT_RANGE;
238  bool gyro = hasGyro(deviceId);
239  fprintf(stderr, "RECORD #%d: Device has gyro: %s\n", deviceId, gyro ? "true" : "false");
240  if (gyro)
241  {
242  range |= 2000 << 16;
243  }
244  result = OmSetAccelConfig(deviceId, OM_ACCEL_DEFAULT_RATE, range);
245  fprintf(stderr, "RECORD #%d: Setting accelerometer (+gyro) configuration...\n", deviceId);
246  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmSetAccelConfig() %s\n", OmErrorString(result)); return 0; }
247 
248  /* Set the session id (use the deviceId) */
249  result = OmSetSessionId(deviceId, deviceId);
250  fprintf(stderr, "RECORD #%d: Setting session id: %u\n", deviceId, deviceId);
251  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmSetSessionId() %s\n", OmErrorString(result)); return 0; }
252 
253  /* Clear the max samples setting */
254  OmSetMaxSamples(deviceId, 0);
255 
256  /* Clear the metadata */
257  OmSetMetadata(deviceId, NULL, 0);
258 
259  /* Set the debug setting*/
260  char debugCommand[128];
261  sprintf(debugCommand, "\r\nDEBUG %d\r\n", debugMode);
262  OmCommand(deviceId, debugCommand, NULL, 0, "DEBUG=", 2000, NULL, 0);
263 
264 #if 1
265  {
266  time_t now;
267  struct tm *tm;
268  OM_DATETIME startTime, stopTime;
269 
270  /* Get the current time */
271  now = time(NULL);
272 
273  printf("RECORD #%d: Setting delayed start/stop times (start in +%d day(s) at %02d:00:00, stop after %d day(s) at %02d:00:00)\n", deviceId, startDays, startHour, durationDays, endHour);
274 
275  /* Start recording on the day 1 day from now, at midnight on that day */
276  now += startDays * 24 * 60 * 60; /* 1 day in seconds */
277  tm = localtime(&now);
278  tm->tm_hour = startHour;
279  tm->tm_min = 0;
280  tm->tm_sec = 0;
281  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);
282  printf("RECORD #%d: START %04d-%02d-%02d %02d:%02d:%02d\n", deviceId, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
283 
284  /* Stop recording 8 days from that day, at midnight */
285  now += durationDays * 24 * 60 * 60; /* 8 days in seconds */
286  tm = localtime(&now);
287  tm->tm_hour = endHour;
288  tm->tm_min = 0;
289  tm->tm_sec = 0;
290  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);
291  printf("RECORD #%d: STOP %04d-%02d-%02d %02d:%02d:%02d\n", deviceId, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
292 
293  result = OmSetDelays(deviceId, startTime, stopTime);
294  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmSetDelays() %s\n", OmErrorString(result)); return 0; }
295  }
296 
297 #else
298  /* Set the delayed start/stop times */
299  fprintf(stderr, "RECORD #%d: Setting start/stop: ZERO/INFINITY\n", deviceId);
301  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmSetDelays() %s\n", OmErrorString(result)); return 0; }
302 #endif
303 
304  /* Commit the new settings */
305  fprintf(stderr, "RECORD #%d: Committing new settings...\n", deviceId);
306  result = OmEraseDataAndCommit(deviceId, OM_ERASE_WIPE);
307  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmEraseDataAndCommit() %s\n", OmErrorString(result)); return 0; }
308 
309  /* The device is ready for recording */
310  fprintf(stderr, "RECORD,%u,%s,%d,%d\n", deviceId, timeString, battery, firmwareVersion);
311  printf("RECORD,%u,%s,%d,%d\n", deviceId, timeString, battery, firmwareVersion);
312  if (ofp != NULL)
313  {
314  fprintf(ofp, "RECORD,%u,%s,%d,%d\n", deviceId, timeString, battery, firmwareVersion);
315  fflush(ofp);
316  }
317 
318  return 1;
319 }
320 
321 
322 /* Device updated */
323 static void record_DeviceCallback(void *reference, int deviceId, OM_DEVICE_STATUS status)
324 {
325  if (status == OM_DEVICE_CONNECTED)
326  {
327  fprintf(stderr, "RECORD #%d: Device CONNECTED\n", deviceId);
328  *getDeviceStatus(deviceId) = DEVICE_CONNECTED;
329  if (onlySingleId <= 0) OmSetLed(deviceId, OM_LED_YELLOW);
330  }
331  else if (status == OM_DEVICE_REMOVED)
332  {
333  fprintf(stderr, "RECORD #%d: Device REMOVED\n", deviceId);
334  *getDeviceStatus(deviceId) = DEVICE_DISCONNECTED;
335  }
336  else
337  {
338  fprintf(stderr, "RECORD #%d: Error, unexpected status %d\n", deviceId, status);
339  }
340  return;
341 }
342 
343 
344 /* Record function */
345 int record(const char *outfile)
346 {
347  int result;
348 
349  /* Open the input and output files */
350  if (outfile != NULL)
351  {
352  ofp = fopen(outfile, "at");
353  }
354 
355  /* Set device callback before API startup to get initially-connected devices through the callback */
356  OmSetDeviceCallback(record_DeviceCallback, NULL);
357 
358  /* Start the API */
359  result = OmStartup(OM_VERSION);
360  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmStartup() %s\n", OmErrorString(result)); return -1; }
361 
362  for (;;)
363  {
364  static int maxDevices = 0;
365  static int *deviceIds = NULL;
366  int numDevices;
367  int numCharging = 0;
368  int i;
369 
370  /* Get devices */
371  numDevices = OmGetDeviceIds(NULL, 0);
372  if (numDevices > maxDevices) { maxDevices = numDevices; deviceIds = (int *)realloc(deviceIds, sizeof(int) * maxDevices); }
373  numDevices = OmGetDeviceIds(deviceIds, maxDevices);
374  if (numDevices > maxDevices) { numDevices = maxDevices; }
375  fprintf(stderr, "%d... ", numDevices);
376  for (i = 0; i < numDevices; i++)
377  {
378  int deviceId = deviceIds[i];
379 
380  if (onlySingleId > 0 && deviceId != onlySingleId) { continue; }
381 
382  if (*getDeviceStatus(deviceId) == DEVICE_CONNECTED)
383  {
384  // Check battery...
385  int battery = OmGetBatteryLevel(deviceId);
386  if (OM_FAILED(battery)) { printf("ERROR: OmGetBatteryLevel(%d) %s\n", deviceId, OmErrorString(battery)); *getDeviceStatus(deviceId) = DEVICE_ERROR; }
387  else
388  {
389  fprintf(stderr, "[%d@%d%%];", deviceId, battery);
390 
391  // If sufficient battery (or setting a specific device), set-up to record
392  if (onlySingleId > 0 || battery >= minBatt)
393  {
394  int ret;
395  fprintf(stderr, "\n");
396  ret = record_setup(deviceId);
397  if (ret == 1)
398  {
399  *getDeviceStatus(deviceId) = DEVICE_DONE;
400  if (onlySingleId <= 0) OmSetLed(deviceId, OM_LED_MAGENTA);
401 onlySingleIdReturn = 0;
402  }
403  else
404  {
405  *getDeviceStatus(deviceId) = DEVICE_ERROR;
406  if (onlySingleId <= 0) OmSetLed(deviceId, OM_LED_RED);
407 onlySingleIdReturn = 1;
408  }
409  } else { numCharging++; }
410  }
411  }
412  }
413  fprintf(stderr, "\n");
414 
415  if (onlySingleId > 0) { break; }
416 
417  /* Wait 5 seconds */
418  Sleep(5000);
419  }
420 
421  /* Shutdown the API */
422  result = OmShutdown();
423  if (OM_FAILED(result)) { fprintf(stderr, "ERROR: OmShutdown() %s\n", OmErrorString(result)); return -1; }
424 
425  /* Close the input and output files */
426  if (ofp != NULL) { fclose(ofp); }
427 
428  if (onlySingleId > 0) { return onlySingleIdReturn; }
429  return 0;
430 }
431 
432 
433 /* Main function */
434 int record_main(int argc, char *argv[])
435 {
436  printf("RECORD: batch sets clear and record fully-charged devices.\n");
437  printf("\n");
438  if (argc > 1)
439  {
440  int i;
441  const char *outfile = NULL;
442 
443  for (i = 1; i < argc; i++)
444  {
445  if (strcmp(argv[i], "-id") == 0)
446  {
447  onlySingleId = (int)strtoul(argv[++i], NULL, 10);
448  printf("*** SINGLE ID MODE FOR %d ***\n", onlySingleId);
449  }
450  else if (strcmp(argv[i], "-startdays") == 0) { startDays = atoi(argv[++i]); printf("PARAM: startDays=%d\n", startDays); }
451  else if (strcmp(argv[i], "-starthour") == 0) { startHour = atoi(argv[++i]); printf("PARAM: startHour=%d\n", startHour); }
452  else if (strcmp(argv[i], "-durationdays") == 0) { durationDays = atoi(argv[++i]); printf("PARAM: durationDays=%d\n", durationDays); }
453  else if (strcmp(argv[i], "-endhour") == 0) { endHour = atoi(argv[++i]); printf("PARAM: endHour=%d\n", endHour); }
454  else if (strcmp(argv[i], "-minbatt") == 0) { minBatt = atoi(argv[++i]); printf("PARAM: minBatt=%d\n", minBatt); }
455  else if (strcmp(argv[i], "-debugmode") == 0) { debugMode = atoi(argv[++i]); printf("PARAM: debugmode=%d\n", debugMode); }
456  else if (argv[i][0] == '-') { printf("WARNING: Ignoring parameter: %s\n", argv[i]); }
457  else
458  {
459  outfile = argv[i];
460  }
461  }
462 
463  return record(outfile);
464  }
465  else
466  {
467  printf("Usage: record <output-file>\n");
468  printf("\n");
469  printf("Where: output-file: will receive the device ids\n");
470  printf("\n");
471  printf("Example: deploy output.csv\n");
472  printf("\n");
473  }
474  return -1;
475 }
476 
OM_ACCEL_DEFAULT_RANGE
#define OM_ACCEL_DEFAULT_RANGE
Default accelerometer range configuration is +/- 8 G.
Definition: omapi.h:761
OmSetSessionId
int OmSetSessionId(int deviceId, unsigned int sessionId)
Sets the specified device's session identifier to be used at the next recording session.
OM_DATETIME_FROM_YMDHMS
#define OM_DATETIME_FROM_YMDHMS(year, month, day, hours, minutes, seconds)
Macro to create a packed date/time value from components.
Definition: omapi.h:1073
OM_DATETIME_INFINITE
#define OM_DATETIME_INFINITE
Special date/time value for "infinitely late".
Definition: omapi.h:1090
OM_DEVICE_REMOVED
Device is being removed, or is already removed.
Definition: omapi.h:289
deviceInfo_tag::status
devicestatus_t status
Definition: record.c:68
OM_DEVICE_CONNECTED
Device has been connected.
Definition: omapi.h:290
now
unsigned long long now(void)
Definition: verify.c:180
OmSetDeviceCallback
int OmSetDeviceCallback(OmDeviceCallback deviceCallback, void *reference)
Sets the callback function that is called whenever a device is added or removed.
OmErrorString
const char * OmErrorString(int status)
Returns an error string for the specified API return code.
omapi.h
Open Movement API.
record_setup
int record_setup(int deviceId)
Definition: record.c:161
OmGetMemoryHealth
int OmGetMemoryHealth(int deviceId)
Determine the health of the NAND flash memory on the specified device.
OM_DATETIME
unsigned long OM_DATETIME
Definition: omapi.h:332
OM_LED_RED
rgb(1,0,0) Red
Definition: omapi.h:491
Sleep
#define Sleep(millis)
Definition: record.c:49
OmSetMaxSamples
int OmSetMaxSamples(int deviceId, int value)
Sets the specified device's 'maximum sample' value.
OM_OK
#define OM_OK
Return code: Success.
Definition: omapi.h:1019
OmCommand
int OmCommand(int deviceId, const char *command, char *buffer, size_t bufferSize, const char *expected, unsigned int timeoutMs, char **parseParts, int parseMax)
Issues a direct command over the CDC port for a particular device.
OM_LED_YELLOW
rgb(1,1,0) Yellow
Definition: omapi.h:493
startHour
int startHour
Definition: record.c:95
DEVICE_ERROR
Definition: record.c:62
record_main
int record_main(int argc, char *argv[])
Definition: record.c:434
deviceInfo
deviceInfo_t * deviceInfo
Definition: record.c:71
OM_FAILED
#define OM_FAILED(value)
Macro to check the specified return value for failure.
Definition: omapi.h:1033
devicestatus_t
devicestatus_t
Definition: record.c:62
OmSetLed
int OmSetLed(int deviceId, OM_LED_STATE ledState)
Sets the specified device's LED colour.
durationDays
int durationDays
Definition: record.c:96
OM_E_UNEXPECTED_RESPONSE
#define OM_E_UNEXPECTED_RESPONSE
Return code: Device response was not as expected.
Definition: omapi.h:1030
OM_E_NOT_IMPLEMENTED
#define OM_E_NOT_IMPLEMENTED
Return code: Requested functionality not implemented, either at the API level on this platform or the...
Definition: omapi.h:1026
OM_ACCEL_DEFAULT_RATE
#define OM_ACCEL_DEFAULT_RATE
Default accelerometer rate configuration is 100Hz.
Definition: omapi.h:753
OmSetAccelConfig
int OmSetAccelConfig(int deviceId, int rate, int range)
Sets the specified device's accelerometer configuration to be used at the next recording session.
OmGetVersion
int OmGetVersion(int deviceId, int *firmwareVersion, int *hardwareVersion)
Returns the firmware and hardware versions of the specified device.
deviceInfo_tag
Definition: record.c:65
OM_DATETIME_ZERO
#define OM_DATETIME_ZERO
Special date/time value for "infinitely early".
Definition: omapi.h:1089
OmGetBatteryLevel
int OmGetBatteryLevel(int deviceId)
Queries the specified device for the current battery charging level.
OM_VERSION
#define OM_VERSION
A numeric code for current API version defined in this header file.
Definition: omapi.h:225
OM_MEMORY_HEALTH_ERROR
#define OM_MEMORY_HEALTH_ERROR
Threshold at or below which the OmGetMemoryHealth() result should be treated as a failure.
Definition: omapi.h:431
OmSetTime
int OmSetTime(int deviceId, OM_DATETIME time)
Sets the specified device's internal real time clock.
deviceInfo_tag::deviceId
int deviceId
Definition: record.c:67
deviceInfo_tag::next
struct deviceInfo_tag * next
Definition: record.c:69
minBatt
int minBatt
Definition: record.c:97
OM_LED_MAGENTA
rgb(1,0,1) Magenta
Definition: omapi.h:492
printf
#define printf(...)
Definition: download.c:57
OmShutdown
int OmShutdown(void)
Shuts down the Open Movement API.
OmSetDelays
int OmSetDelays(int deviceId, OM_DATETIME startTime, OM_DATETIME stopTime)
Sets the specified device's delayed activation start and stop times to use for a new recording sessio...
OM_ERASE_WIPE
All blocks on the NAND flash memory are cleared, the file-system is cleanly re-created,...
Definition: omapi.h:698
OmGetDeviceSerial
int OmGetDeviceSerial(int deviceId, char *serialBuffer)
Return the full USB serial string identity for the specified device.
OM_MEMORY_HEALTH_WARNING
#define OM_MEMORY_HEALTH_WARNING
Threshold at or below which the OmGetMemoryHealth() result should be treated as a warning.
Definition: omapi.h:432
endHour
int endHour
Definition: record.c:96
OmGetDeviceIds
int OmGetDeviceIds(int *deviceIds, int maxDevices)
Obtains the device IDs of all connected devices.
deviceInfo_t
struct deviceInfo_tag deviceInfo_t
DEVICE_CONNECTED
Definition: record.c:62
record
int record(const char *outfile)
Definition: record.c:345
OmSetMetadata
int OmSetMetadata(int deviceId, const char *metadata, int size)
Sets the specified device's metadata scratch buffer to be used for the next recording session.
OmStartup
int OmStartup(int version)
Initializes the Open Movement API.
DEVICE_DONE
Definition: record.c:62
DEVICE_DISCONNECTED
Definition: record.c:62
OmEraseDataAndCommit
int OmEraseDataAndCommit(int deviceId, OM_ERASE_LEVEL eraseLevel)
Erases the specified device storage and commits the metadata and settings.
OM_MAX_PATH
#define OM_MAX_PATH
Macro for the maximum path length of a data filename.
Definition: omapi.h:840
outfile
FILE * outfile
Definition: verify.c:154
OM_DEVICE_STATUS
OM_DEVICE_STATUS
Device states used in the OmDeviceCallback handler.
Definition: omapi.h:287
debugMode
int debugMode
Definition: record.c:98
startDays
int startDays
Definition: record.c:95