Data reception demo.
Dependencies: modem_ref_helper CRC
Diff: main.cpp
- Revision:
- 1:55636c88cd5e
- Parent:
- 0:02418479dcf7
- Child:
- 2:6652be2d061f
--- a/main.cpp Thu May 11 17:48:47 2017 +0000 +++ b/main.cpp Fri May 12 14:03:27 2017 +0000 @@ -19,11 +19,34 @@ #include "d7a_1x.h" #include "alp.h" +#include "CriusOLED.h" + +#define RESTORE_TIME 30 + WizziCom* g_modem_com; Semaphore modem_ready(0); Queue<void, 8> g_file_modified; uint8_t g_main_id; +uint32_t g_time = RESTORE_TIME + 1; + +void display_logo(void) +{ + clear_display(); + sendImage(); +} + +void thread_reset_display() +{ + while (true) + { + if (g_time++ == RESTORE_TIME) + { + display_logo(); + } + Thread::wait(1000); + } +} void thread_file_modified() { @@ -44,6 +67,11 @@ PRINT("STRING: "); PRINT((char*)str); PRINT("\r\n"); + + clear_display(); + sendStrXY((char*)str,2,0); + + g_time = 0; break; default: break; @@ -140,6 +168,45 @@ } } +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() { @@ -148,7 +215,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]; @@ -196,18 +262,10 @@ 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); // Allow remote access. - modem_delete_file(FID_STRING_FILE, g_main_id); - modem_ready.wait(); - ram_fs_new(FID_STRING_FILE, (uint8_t*)&h_string_file, (uint8_t*)&f_string_file); - my_get_alp_file_props(FID_STRING_FILE, &hdr); - modem_declare_file(FID_STRING_FILE, &hdr, g_main_id); - modem_ready.wait(); + modem_update_file(FID_STRING_FILE, (alp_file_header_t*)&h_string_file, (uint8_t*)&f_string_file); // Configure URC: LQUAL on report file notification every 10 reports PRINT("Setup URCs\n"); @@ -227,9 +285,22 @@ modem_ready.wait(); // Start file modified thread - Thread th_file_modified(osPriorityNormal, 1024, NULL); + Thread th_file_modified(osPriorityNormal, 512, NULL); osStatus status = th_file_modified.start(thread_file_modified); ASSERT(status == osOK, "Failed to start thread_file_modified (err: %d)\r\n", status); + + // Start reset display thread + Thread th_reset_display(osPriorityNormal, 512, NULL); + status = th_reset_display.start(thread_reset_display); + ASSERT(status == osOK, "Failed to start thread_reset_display (err: %d)\r\n", status); + + // Initialize I2C and OLED Display + i2c.frequency(400000); + init_OLED(); + displayOn(); + reset_display(); + + display_logo(); #ifdef DEBUG_LED DigitalOut my_led(DEBUG_LED);