Data reception demo.

Dependencies:   modem_ref_helper

Committer:
Jeej
Date:
Thu Oct 11 14:46:39 2018 +0000
Revision:
11:7df24b241621
Parent:
10:c262c5feac24
Child:
12:404a3ca64a44
Activate stack errors. Relaxed modem version check.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 0:02418479dcf7 1 // @autor: jeremie@wizzilab.com
Jeej 0:02418479dcf7 2 // @date: 2017-05-02
Jeej 0:02418479dcf7 3
Jeej 4:854f22f7962b 4 #include "modem_ref_helper.h"
Jeej 0:02418479dcf7 5 #include "modem_callbacks.h"
Jeej 4:854f22f7962b 6 #include "files.h"
Jeej 1:55636c88cd5e 7 #include "CriusOLED.h"
Jeej 1:55636c88cd5e 8
Jeej 2:6652be2d061f 9 #define RESTORE_TIME 30
Jeej 2:6652be2d061f 10 #define KEEP_ALIVE 3600
Jeej 6:2f0eb7aac143 11 #define MIN_REPORT_PERIOD (10) // Seconds
Jeej 1:55636c88cd5e 12
Jeej 0:02418479dcf7 13 Semaphore modem_ready(0);
Jeej 0:02418479dcf7 14 Queue<void, 8> g_file_modified;
Jeej 0:02418479dcf7 15
Jeej 9:72a15235e097 16 uint8_t id;
Jeej 2:6652be2d061f 17 uint32_t g_restore_time = RESTORE_TIME + 1;
Jeej 1:55636c88cd5e 18
Jeej 1:55636c88cd5e 19 void display_logo(void)
Jeej 1:55636c88cd5e 20 {
Jeej 1:55636c88cd5e 21 clear_display();
Jeej 1:55636c88cd5e 22 sendImage();
Jeej 1:55636c88cd5e 23 }
Jeej 1:55636c88cd5e 24
Jeej 9:72a15235e097 25 static void my_main_callback(uint8_t terminal, int8_t err, uint8_t id)
Jeej 9:72a15235e097 26 {
Jeej 9:72a15235e097 27 (void)id;
Jeej 9:72a15235e097 28
Jeej 10:c262c5feac24 29 if (ALP_ERR_NONE != err)
Jeej 10:c262c5feac24 30 {
Jeej 10:c262c5feac24 31 modem_print_error(ALP_ITF_TYPE_D7A, err);
Jeej 10:c262c5feac24 32 }
Jeej 9:72a15235e097 33
Jeej 9:72a15235e097 34 if (terminal)
Jeej 9:72a15235e097 35 {
Jeej 9:72a15235e097 36 modem_ready.release();
Jeej 9:72a15235e097 37 }
Jeej 9:72a15235e097 38 }
Jeej 9:72a15235e097 39
Jeej 1:55636c88cd5e 40 void thread_reset_display()
Jeej 1:55636c88cd5e 41 {
Jeej 3:e9ea4d325c01 42 FPRINT("(id:0x%08x)\r\n", osThreadGetId());
Jeej 2:6652be2d061f 43
Jeej 3:e9ea4d325c01 44 uint32_t time = 0;
Jeej 3:e9ea4d325c01 45 uint8_t status = 0;
Jeej 9:72a15235e097 46 uint8_t id = modem_get_id(my_main_callback);
Jeej 3:e9ea4d325c01 47
Jeej 1:55636c88cd5e 48 while (true)
Jeej 1:55636c88cd5e 49 {
Jeej 2:6652be2d061f 50 if (g_restore_time++ == RESTORE_TIME)
Jeej 1:55636c88cd5e 51 {
Jeej 1:55636c88cd5e 52 display_logo();
Jeej 1:55636c88cd5e 53 }
Jeej 3:e9ea4d325c01 54
Jeej 3:e9ea4d325c01 55 if ((time++ % KEEP_ALIVE) == 0)
Jeej 2:6652be2d061f 56 {
Jeej 3:e9ea4d325c01 57 // Keep alive: Report status
Jeej 9:72a15235e097 58 modem_write_file(FID_STATUS_FILE, &status, 0, SIZE_STATUS_FILE, id);
Jeej 4:854f22f7962b 59 modem_ready.wait();
Jeej 2:6652be2d061f 60 }
Jeej 2:6652be2d061f 61
Jeej 1:55636c88cd5e 62 Thread::wait(1000);
Jeej 1:55636c88cd5e 63 }
Jeej 1:55636c88cd5e 64 }
Jeej 0:02418479dcf7 65
Jeej 0:02418479dcf7 66 void thread_file_modified()
Jeej 0:02418479dcf7 67 {
Jeej 3:e9ea4d325c01 68 FPRINT("(id:0x%08x)\r\n", osThreadGetId());
Jeej 3:e9ea4d325c01 69
Jeej 0:02418479dcf7 70 uint8_t fid;
Jeej 0:02418479dcf7 71 osEvent evt;
Jeej 0:02418479dcf7 72
Jeej 0:02418479dcf7 73 while (true)
Jeej 0:02418479dcf7 74 {
Jeej 0:02418479dcf7 75 evt = g_file_modified.get();
Jeej 0:02418479dcf7 76 fid = (evt.status == osEventMessage)? (uint8_t)(uint32_t)evt.value.p : NULL;
Jeej 0:02418479dcf7 77
Jeej 0:02418479dcf7 78 switch (fid)
Jeej 0:02418479dcf7 79 {
Jeej 0:02418479dcf7 80 case FID_STRING_FILE:
Jeej 0:02418479dcf7 81 // Print string
Jeej 0:02418479dcf7 82 uint8_t str[SIZE_STRING_FILE];
Jeej 0:02418479dcf7 83 ram_fs_read(FID_STRING_FILE, 0, SIZE_STRING_FILE, (uint8_t*)&str);
Jeej 0:02418479dcf7 84 PRINT("STRING: ");
Jeej 0:02418479dcf7 85 PRINT((char*)str);
Jeej 0:02418479dcf7 86 PRINT("\r\n");
Jeej 1:55636c88cd5e 87
Jeej 1:55636c88cd5e 88 clear_display();
Jeej 7:84dc04f88c94 89 sendStrXY((char*)str,0,0);
Jeej 1:55636c88cd5e 90
Jeej 2:6652be2d061f 91 g_restore_time = 0;
Jeej 0:02418479dcf7 92 break;
Jeej 0:02418479dcf7 93 default:
Jeej 3:e9ea4d325c01 94 PRINT("Unknown file %d\n", fid);
Jeej 5:a44b6f60bfc7 95 break;
Jeej 0:02418479dcf7 96 }
Jeej 0:02418479dcf7 97 }
Jeej 0:02418479dcf7 98 }
Jeej 0:02418479dcf7 99
Jeej 0:02418479dcf7 100 modem_callbacks_t callbacks = {
Jeej 0:02418479dcf7 101 .read = my_read,
Jeej 0:02418479dcf7 102 .write = my_write,
Jeej 0:02418479dcf7 103 .read_fprop = my_read_fprop,
Jeej 0:02418479dcf7 104 .flush = my_flush,
Jeej 0:02418479dcf7 105 .remove = my_delete,
Jeej 3:e9ea4d325c01 106 .udata = my_udata,
Jeej 0:02418479dcf7 107 .lqual = my_lqual,
Jeej 0:02418479dcf7 108 .ldown = my_ldown,
Jeej 0:02418479dcf7 109 .reset = my_reset,
Jeej 9:72a15235e097 110 .boot = my_boot,
Jeej 9:72a15235e097 111 .busy = my_busy,
Jeej 0:02418479dcf7 112 };
Jeej 0:02418479dcf7 113
Jeej 0:02418479dcf7 114 /*** Main function ------------------------------------------------------------- ***/
Jeej 0:02418479dcf7 115 int main()
Jeej 0:02418479dcf7 116 {
Jeej 0:02418479dcf7 117 // Start & initialize
Jeej 4:854f22f7962b 118 #ifdef DEBUG_LED
Jeej 0:02418479dcf7 119 DBG_OPEN(DEBUG_LED);
Jeej 4:854f22f7962b 120 #else
Jeej 4:854f22f7962b 121 DBG_OPEN(NC);
Jeej 4:854f22f7962b 122 #endif
Jeej 5:a44b6f60bfc7 123 PRINT("\n"
Jeej 5:a44b6f60bfc7 124 "-----------------------------------------\n"
Jeej 5:a44b6f60bfc7 125 "-------- Demo Receive file data ---------\n"
Jeej 5:a44b6f60bfc7 126 "-----------------------------------------\n");
Jeej 5:a44b6f60bfc7 127
Jeej 0:02418479dcf7 128 FPRINT("(id:0x%08x)\r\n", osThreadGetId());
Jeej 0:02418479dcf7 129
Jeej 4:854f22f7962b 130 modem_helper_open(&callbacks);
Jeej 0:02418479dcf7 131
Jeej 9:72a15235e097 132 uint8_t id = modem_get_id(my_main_callback);
Jeej 3:e9ea4d325c01 133
Jeej 4:854f22f7962b 134 PRINT("Register Files\n");
Jeej 0:02418479dcf7 135 // Allow remote access.
Jeej 10:c262c5feac24 136 // The string file data is on this host, specify the data buffer.
Jeej 1:55636c88cd5e 137 modem_update_file(FID_STRING_FILE, (alp_file_header_t*)&h_string_file, (uint8_t*)&f_string_file);
Jeej 10:c262c5feac24 138 // The status file data is in the modem, do not specify a data buffer.
Jeej 3:e9ea4d325c01 139 modem_update_file(FID_STATUS_FILE, (alp_file_header_t*)&h_status_file, NULL);
Jeej 0:02418479dcf7 140
Jeej 2:6652be2d061f 141 // Put modem to listen to this access class
Jeej 2:6652be2d061f 142 d7a_xcl_t my_xcl = { .bf.s = 0, .bf.m = 2 };
Jeej 9:72a15235e097 143 modem_write_file(D7A_FID_DLL_CFG, &my_xcl, 0, sizeof(d7a_xcl_t), id);
Jeej 2:6652be2d061f 144 modem_ready.wait();
Jeej 2:6652be2d061f 145
Jeej 0:02418479dcf7 146 // Configure URC: LQUAL on report file notification every 10 reports
Jeej 0:02418479dcf7 147 PRINT("Setup URCs\n");
Jeej 9:72a15235e097 148 modem_enable_urc(ALP_URC_TYPE_LQUAL, IFID_REPORT, 10, true, id);
Jeej 0:02418479dcf7 149 modem_ready.wait();
Jeej 0:02418479dcf7 150
Jeej 0:02418479dcf7 151 PRINT("Start D7A Stack\n");
Jeej 11:7df24b241621 152 modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS | ALP_D7A_ISTAT_EOP, true, id);
Jeej 0:02418479dcf7 153 modem_ready.wait();
Jeej 0:02418479dcf7 154
Jeej 0:02418479dcf7 155 PRINT("Notify Modem Version\n");
Jeej 9:72a15235e097 156 modem_notify_file(D7A_FID_FIRMWARE_VERSION, 0, SIZE_HOST_REV, id);
Jeej 0:02418479dcf7 157 modem_ready.wait();
Jeej 0:02418479dcf7 158
Jeej 0:02418479dcf7 159 PRINT("Notify FW Version\n");
Jeej 10:c262c5feac24 160 uint8_t default_root_key[16] = DEFAULT_ROOT_KEY;
Jeej 10:c262c5feac24 161 modem_notify_host_rev((revision_t*)&f_rev, (alp_file_header_t*)&h_rev, default_root_key);
Jeej 0:02418479dcf7 162
Jeej 9:72a15235e097 163 modem_free_id(id);
Jeej 9:72a15235e097 164
Jeej 0:02418479dcf7 165 // Start file modified thread
Jeej 1:55636c88cd5e 166 Thread th_file_modified(osPriorityNormal, 512, NULL);
Jeej 0:02418479dcf7 167 osStatus status = th_file_modified.start(thread_file_modified);
Jeej 0:02418479dcf7 168 ASSERT(status == osOK, "Failed to start thread_file_modified (err: %d)\r\n", status);
Jeej 1:55636c88cd5e 169
Jeej 1:55636c88cd5e 170 // Start reset display thread
Jeej 3:e9ea4d325c01 171 Thread th_reset_display(osPriorityLow, 1024, NULL);
Jeej 1:55636c88cd5e 172 status = th_reset_display.start(thread_reset_display);
Jeej 1:55636c88cd5e 173 ASSERT(status == osOK, "Failed to start thread_reset_display (err: %d)\r\n", status);
Jeej 1:55636c88cd5e 174
Jeej 1:55636c88cd5e 175 // Initialize I2C and OLED Display
Jeej 1:55636c88cd5e 176 i2c.frequency(400000);
Jeej 1:55636c88cd5e 177 init_OLED();
Jeej 1:55636c88cd5e 178 displayOn();
Jeej 1:55636c88cd5e 179 reset_display();
Jeej 1:55636c88cd5e 180
Jeej 1:55636c88cd5e 181 display_logo();
Jeej 0:02418479dcf7 182
Jeej 4:854f22f7962b 183 #ifdef DEBUG_LED
Jeej 0:02418479dcf7 184 DigitalOut my_led(DEBUG_LED);
Jeej 0:02418479dcf7 185 #endif
Jeej 0:02418479dcf7 186
Jeej 0:02418479dcf7 187 // Set main task to lowest priority
Jeej 0:02418479dcf7 188 osThreadSetPriority(osThreadGetId(), osPriorityIdle);
Jeej 0:02418479dcf7 189 while(true)
Jeej 0:02418479dcf7 190 {
Jeej 0:02418479dcf7 191 Thread::wait(500);
Jeej 4:854f22f7962b 192 #ifdef DEBUG_LED
Jeej 0:02418479dcf7 193 my_led = !my_led;
Jeej 0:02418479dcf7 194 #endif
Jeej 0:02418479dcf7 195 }
Jeej 0:02418479dcf7 196 }