Send file data through D7A Action Protocol demo.
Dependencies: modem_ref_helper
Diff: main.cpp
- Revision:
- 3:e905bf88e8a9
- Parent:
- 0:3058da317f01
- Child:
- 4:45576db9f66c
--- a/main.cpp Thu May 11 17:47:23 2017 +0000 +++ b/main.cpp Fri May 12 14:05:49 2017 +0000 @@ -221,6 +221,47 @@ } } +void modem_update_file(uint8_t fid, alp_file_header_t* header, uint8_t* data) +{ + alp_file_header_t remote_header; + + memset(&remote_header, 0, sizeof(alp_file_header_t)); + + // Read remote header + modem_read_fprop(fid, &remote_header, g_main_id); + modem_ready.wait(); + + // Add file in local file system + ram_fs_new(fid, (uint8_t*)header, data); + + // Update file + if (memcmp(&remote_header, header, sizeof(alp_file_header_t))) + { + PRINT("Updating file %d\n", fid); + // Delete + modem_delete_file(fid, g_main_id); + modem_ready.wait(); + // Restore in local file system + ram_fs_new(fid, (uint8_t*)header, data); + // Re-create + if (data) + { + modem_declare_file(fid, header, g_main_id); + } + else + { + modem_create_file(fid, header, g_main_id); + } + modem_ready.wait(); + } + else + { + PRINT("File %d up to date\n", fid); + } +} + + + /*** Main function ------------------------------------------------------------- ***/ int main() { @@ -229,7 +270,6 @@ PRINT("\r\n--- Starting new run ---\r\n"); FPRINT("(id:0x%08x)\r\n", osThreadGetId()); - alp_file_header_t hdr; static union { uint8_t b[8]; uint32_t w[2]; @@ -276,27 +316,15 @@ //DPRINT("UID: %08X%08X\n", HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1])); DPRINT("Register Files\n"); + // HOST Revision is a local file. Uses D7AActP Notification. - ram_fs_new(FID_HOST_REV, (uint8_t*)&h_rev, (uint8_t*)&f_rev); - my_get_alp_file_props(FID_HOST_REV, &hdr); - modem_declare_file(FID_HOST_REV, &hdr, g_main_id); - modem_ready.wait(); - + modem_update_file(FID_HOST_REV, (alp_file_header_t*)&h_rev, (uint8_t*)&f_rev); + // Create report file on modem. - modem_delete_file(FID_SENSOR_LIGHT, g_main_id); - modem_ready.wait(); - ram_fs_new(FID_SENSOR_LIGHT, (uint8_t*)&h_sensor_light, NULL); - my_get_alp_file_props(FID_SENSOR_LIGHT, &hdr); - modem_create_file(FID_SENSOR_LIGHT, &hdr, g_main_id); - modem_ready.wait(); - + modem_update_file(FID_SENSOR_LIGHT, (alp_file_header_t*)&h_sensor_light, NULL); + // Allow remote access. - modem_delete_file(FID_SENSOR_CONFIG, g_main_id); - modem_ready.wait(); - ram_fs_new(FID_SENSOR_CONFIG, (uint8_t*)&h_sensor_config, (uint8_t*)&f_sensor_config); - my_get_alp_file_props(FID_SENSOR_CONFIG, &hdr); - modem_declare_file(FID_SENSOR_CONFIG, &hdr, g_main_id); - modem_ready.wait(); + modem_update_file(FID_SENSOR_CONFIG, (alp_file_header_t*)&h_sensor_config, (uint8_t*)&f_sensor_config); // Configure URC: LQUAL on report file notification every 10 reports PRINT("Setup URCs\n");