 |
OMAPI
1.8
Open Movement Public API
|
Go to the documentation of this file.
45 #define _CRT_SECURE_NO_WARNINGS
65 static void downloadmem_DeviceCallback(
void *reference,
int deviceId,
OM_DEVICE_STATUS status)
72 printf(
"DOWNLOADMEM #%d: Device CONNECTED\n", deviceId);
76 if (downloadStatus == NULL)
78 printf(
"ERROR: Unable to allocate a download status structure\n");
83 memset(downloadStatus, 0,
sizeof(downloadStatus));
95 downloadStatus->
buffer = (
unsigned char *)malloc(downloadStatus->
capacity);
96 if (downloadStatus->
buffer == NULL)
98 printf(
"ERROR: Unable to allocate a download buffer (%d bytes)\n", downloadStatus->
capacity);
104 printf(
"DOWNLOADMEM #%d: Starting download to memory\n", deviceId);
105 downloadStatus->
length = 0;
110 free(downloadStatus->
buffer);
111 free(downloadStatus);
118 printf(
"DOWNLOADMEM #%d: Device REMOVED\n", deviceId);
124 printf(
"DOWNLOADMEM #%d: Error, unexpected status %d\n", deviceId, status);
131 static void downloadmem_DownloadCallback(
void *reference,
int deviceId,
OM_DOWNLOAD_STATUS status,
int value)
137 printf(
"DOWNLOADMEM #%d: Progress %d%%.\n", deviceId, value);
141 printf(
"DOWNLOADMEM #%d: Complete.\n", deviceId);
143 if (downloadStatus == NULL)
145 printf(
"ERROR: No download status tracker.\n");
147 else if (downloadStatus->
buffer == NULL)
149 printf(
"ERROR: No download buffer.\n");
153 printf(
"ERROR: Download buffer offsets invalid.\n");
157 printf(
"ERROR: Download buffer was not filled.\n");
161 printf(
"SUCCESS: Download buffer filled in RAM: %d bytes at 0x%p\n", downloadStatus->
length, downloadStatus->
buffer);
167 printf(
"DOWNLOADMEM #%d: Cancelled.\n", deviceId);
171 printf(
"DOWNLOADMEM #%d: Error. (Diagnostic 0x%04x)\n", deviceId, value);
175 printf(
"DOWNLOADMEM #%d: Unexpected status %d / 0x%04x\n", deviceId, status, value);
181 if (downloadStatus != NULL)
184 if (downloadStatus->
buffer != NULL)
186 printf(
"NOTE: Freeing download buffer @0x%p\n", downloadStatus->
buffer);
187 free(downloadStatus->
buffer);
188 downloadStatus->
buffer = NULL;
190 free(downloadStatus);
198 static void downloadmem_DownloadChunkCallback(
void *reference,
int deviceId,
void *buffer,
int offset,
int length)
203 end = offset + length;
204 printf(
"DOWNLOADMEM #%d: Chunk @%d (of %d bytes) => %d bytes total\n", deviceId, offset, length, end);
207 if (downloadStatus == NULL)
209 printf(
"ERROR: No download status tracker.\n");
212 if (downloadStatus->
buffer == NULL)
214 printf(
"ERROR: No download buffer.\n");
217 if (offset < 0 || offset >= downloadStatus->
capacity || end < 0 || end > downloadStatus->
capacity)
219 printf(
"ERROR: Download chunk offsets out of range.\n");
224 memcpy(downloadStatus->
buffer + offset, buffer, length);
225 downloadStatus->
length = end;
245 printf(
"Waiting for devices...\n");
255 printf(
"Key pressed, shutting down...\n");
269 printf(
"DOWNLOADMEM: download data into RAM from all devices containing data.\n");
277 printf(
"Usage: downloadmem\n");
279 printf(
"Example: downloadmem\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.
Data download completed successfully.
int downloadmem_main(int argc, char *argv[])
#define OM_FAILED(value)
Macro to check the specified return value for failure.
int OmBeginDownloadingReference(int deviceId, int dataOffsetBlocks, int dataLengthBlocks, const char *destinationFile, void *reference)
Begin downloading the data from the current device, passing an additional reference.
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 OmSetDownloadChunkCallback(OmDownloadChunkCallback downloadChunkCallback, void *reference)
Sets the chunk callback function that is called when a new download chunk is received.
Data download progress (the value parameter to OmDownloadCallback indicates progress percentage)
int OmShutdown(void)
Shuts down the Open Movement API.
int OmGetDataFileSize(int deviceId)
Return the data file size of the specified device.
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.
OM_DEVICE_STATUS
Device states used in the OmDeviceCallback handler.