Send file data through D7A Action Protocol demo.
Dependencies: modem_ref_helper
Diff: main.cpp
- Revision:
- 5:4da1ea72e7b4
- Parent:
- 4:45576db9f66c
- Child:
- 6:d4512d8f5dff
--- a/main.cpp Mon May 15 15:58:31 2017 +0000 +++ b/main.cpp Thu May 18 13:48:39 2017 +0000 @@ -1,27 +1,11 @@ // @autor: jeremie@wizzilab.com // @date: 2017-05-02 -#include "mbed.h" -#include "rtos.h" -#include "WizziDebug.h" -#include "WizziCom.h" - -#include "hwcfg.h" -#include "files.h" -#include "ram_fs.h" +#include "modem_ref_helper.h" #include "modem_callbacks.h" - -#include "revision.h" -#include "alp_spec.h" -#include "alp_helpers.h" -#include "modem_ref.h" -#include "kal_fs.h" -#include "d7a_1x.h" -#include "alp.h" - +#include "files.h" #include "sensor.h" -WizziCom* g_modem_com; Semaphore modem_ready(0); sensor_config_t g_light_config; Queue<void, 8> g_file_modified; @@ -172,33 +156,13 @@ } } -// ============================================================}}} - -// Serial adapters to WizziLab's own architecture -// ============================================================{{{ - -void my_serial_input(WizziCom* com, WizziComPacket_t* pkt) -{ - modem_input(wizzicom_type_to_flow(pkt->type), pkt->data, pkt->length); - FREE(pkt); -} - -int my_serial_send(uint8_t* data1, uint8_t size1, uint8_t* data2, uint8_t size2) -{ - (void)size1; - - // Retrieve Flow ID from header and send packet - g_modem_com->send((WizziComPacketType)wizzicom_flow_to_type(data1[4]), size2, data2); - - return (size1 + size2); -} - modem_callbacks_t callbacks = { .read = my_read, .write = my_write, .read_fprop = my_read_fprop, .flush = my_flush, .remove = my_delete, + .udata = my_udata, .lqual = my_lqual, .ldown = my_ldown, .reset = my_reset, @@ -221,100 +185,22 @@ } } -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() { // Start & initialize +#ifdef DEBUG_LED DBG_OPEN(DEBUG_LED); +#else + DBG_OPEN(NC); +#endif PRINT("\r\n--- Starting new run ---\r\n"); FPRINT("(id:0x%08x)\r\n", osThreadGetId()); - static union { - uint8_t b[8]; - uint32_t w[2]; - } uid; - revision_t rev; - - // Hardware reset - DigitalOut reset_low(MODEM_PIN_RESET, 0); - Thread::wait(100); - - // Release reset - DigitalIn reset_release(MODEM_PIN_RESET); - Thread::wait(2000); - - // Open modem Com port - g_modem_com = new WizziCom(MODEM_PIN_TX, MODEM_PIN_RX, MODEM_PIN_IRQ_OUT, MODEM_PIN_IRQ_IN); - - // Redirect All Port traffic to my_serial_input - g_modem_com->attach(my_serial_input, WizziComPacketOther); - - // Open driver - modem_open(my_serial_send, &callbacks); + modem_helper_open(&callbacks); g_main_id = modem_get_id(my_main_callback); - - DPRINT("Start Modem Process (id=%d)\n", g_main_id); - Thread::wait(1000); - modem_read_file(D7A_FID_UID, (uint8_t*)&uid.b[0], 0, 8, g_main_id); - modem_ready.wait(); - - modem_read_file(D7A_FID_FIRMWARE_VERSION, (uint8_t*)&rev, 0, sizeof(revision_t), g_main_id); - modem_ready.wait(); - - PRINT("------------ D7A Modem infos ------------\r\n"); - PRINT_DATA(" - UID: ", "%02X", uid.b, 8, "\r\n"); - PRINT(" - Manufacturer ID: %08X\r\n", rev.manufacturer_id); - PRINT(" - Device ID: %08X\r\n", rev.device_id); - PRINT(" - Hardware version: %08X\r\n", rev.hw_version); - PRINT(" - Firmware version: v%d.%d.%d\r\n", rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch); - PRINT(" - File system CRC: 0x%08x\r\n", rev.fs_crc); - PRINT("-----------------------------------------\r\n"); - - //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. @@ -353,7 +239,7 @@ status = th_sensor_light.start(thread_sensor_light); ASSERT(status == osOK, "Failed to start thread_sensor_light (err: %d)\r\n", status); -#if (DEBUG_LED != NC) +#ifdef DEBUG_LED DigitalOut my_led(DEBUG_LED); #endif @@ -362,7 +248,7 @@ while(true) { Thread::wait(500); -#if (DEBUG_LED != NC) +#ifdef DEBUG_LED my_led = !my_led; #endif }