 |
OMAPI
1.8
Open Movement Public API
|
Go to the documentation of this file.
45 #define _CRT_SECURE_NO_WARNINGS
57 #define printf(...) { fprintf(stdout, __VA_ARGS__); fflush(stdout); if (tee) { fprintf(stderr, __VA_ARGS__); } }
61 static const char *downloadPath =
".";
72 static void download_DeviceCallback(
void *reference,
int deviceId,
OM_DEVICE_STATUS status)
77 unsigned int sessionId;
78 int dataBlockSize = 0, dataOffsetBlocks = 0, dataNumBlocks = 0;
81 printf(
"DOWNLOAD #%d: Device CONNECTED\n", deviceId);
86 printf(
"DOWNLOAD #%d: SessionId = %d\n", deviceId, sessionId);
89 result =
OmGetDataRange(deviceId, &dataBlockSize, &dataOffsetBlocks, &dataNumBlocks, &startTime, &endTime);
91 printf(
"DOWNLOAD #%d: %d blocks data, at offset %d blocks (1 block = %d bytes)\n", deviceId, dataNumBlocks, dataOffsetBlocks, dataBlockSize);
95 OmDateTimeToString(startTime, startString);
96 OmDateTimeToString(endTime, endString);
97 printf(
"DOWNLOAD #%d: ... %s --> %s\n", deviceId, startString, endString);
101 if (dataNumBlocks - dataOffsetBlocks <= 0)
103 printf(
"DOWNLOAD #%d: Ignoring - no data stored.\n", deviceId);
110 file = (
char *)malloc(strlen(downloadPath) + 32);
113 strcpy(file, downloadPath);
115 if (file[strlen(file) - 1] !=
'\\') strcat(file,
"\\");
117 if (file[strlen(file) - 1] !=
'/') strcat(file,
"/");
121 sprintf(file + strlen(file),
"%010u-%05u.cwa", sessionId, deviceId);
124 printf(
"DOWNLOAD #%d: Starting download to file: %s\n", deviceId, file);
134 printf(
"DOWNLOAD #%d: Device REMOVED\n", deviceId);
140 printf(
"DOWNLOAD #%d: Error, unexpected status %d\n", deviceId, status);
147 static void download_DownloadCallback(
void *reference,
int deviceId,
OM_DOWNLOAD_STATUS status,
int value)
151 printf(
"DOWNLOAD #%d: Progress %d%%.\n", deviceId, value);
155 printf(
"DOWNLOAD #%d: Complete.\n", deviceId);
159 printf(
"DOWNLOAD #%d: Cancelled.\n", deviceId);
163 printf(
"DOWNLOAD #%d: Error. (Diagnostic 0x%04x)\n", deviceId, value);
167 printf(
"DOWNLOAD #%d: Unexpected status %d / 0x%04x\n", deviceId, status, value);
179 downloadPath = outpath;
191 printf(
"Waiting for devices...\n");
201 printf(
"Key pressed, shutting down...\n");
215 const char *outpath = NULL;
218 printf(
"DOWNLOAD: download data from all devices containing data.\n");
221 for (i = 1; i < argc; i++)
223 if (argv[i][0] ==
'-' && argv[i][1] ==
't' && argv[i][2] ==
'e' && argv[i][3] ==
'e' && argv[i][4] ==
'\0') {
tee = 1; }
224 else { outpath = argv[i]; }
232 printf(
"Usage: download <output-path>\n");
234 printf(
"Where: output-path: the directory to download the data files to.\n");
236 printf(
"Example: download .\n");
Device is being removed, or is already removed.
Device has been connected.
int OmSetDeviceCallback(OmDeviceCallback deviceCallback, void *reference)
Sets the callback function that is called whenever a device is added or removed.
const char * OmErrorString(int status)
Returns an error string for the specified API return code.
unsigned long OM_DATETIME
Data download completed successfully.
int download_main(int argc, char *argv[])
#define OM_FAILED(value)
Macro to check the specified return value for failure.
int OmBeginDownloading(int deviceId, int dataOffsetBlocks, int dataLengthBlocks, const char *destinationFile)
Begin downloading the data from the current device.
Data download failed with an error (the value parameter to OmDownloadCallback indicates a diagnostic ...
#define OM_VERSION
A numeric code for current API version defined in this header file.
int OmGetSessionId(int deviceId, unsigned int *sessionId)
Queries the specified device's session identifier.
void logCallback(void *reference, const char *message)
int OmGetDataRange(int deviceId, int *dataBlockSize, int *dataOffsetBlocks, int *dataNumBlocks, OM_DATETIME *startTime, OM_DATETIME *endTime)
Read the size, time-range, and internal chunking of the data buffer.
Data download progress (the value parameter to OmDownloadCallback indicates progress percentage)
int OmShutdown(void)
Shuts down the Open Movement API.
#define OM_DATETIME_BUFFER_SIZE
The size of a buffer to hold a string representation of an OM_DATETIME.
int OmSetLogCallback(OmLogCallback logCallback, void *reference)
Sets the callback function that is called whenever an API log message is written.
int OmSetLogStream(int fd)
Sets the stream to use for log messages.
Data download was cancelled cleanly.
int OmSetDownloadCallback(OmDownloadCallback downloadCallback, void *reference)
Sets the callback function that is called for download progress, completion, cancellation,...
OM_DOWNLOAD_STATUS
Download states used in the OmDownloadCallback handler.
int OmStartup(int version)
Initializes the Open Movement API.
int download(const char *outpath)
OM_DEVICE_STATUS
Device states used in the OmDeviceCallback handler.