Sending and reception of big data file (1kB example)
Dependencies: modem_ref_helper CRC DebouncedInterrupt
main.cpp@15:9a9cfb0c3c4e, 2021-02-17 (annotated)
- Committer:
- Jeej
- Date:
- Wed Feb 17 11:11:23 2021 +0000
- Revision:
- 15:9a9cfb0c3c4e
- Parent:
- 14:a0241090f967
- Child:
- 16:2990b7d21ca2
v2.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeej | 0:a2bbc478f812 | 1 | // @autor: jeremie@wizzilab.com |
Jeej | 0:a2bbc478f812 | 2 | // @date: 2017-12-14 |
Jeej | 0:a2bbc478f812 | 3 | |
Jeej | 0:a2bbc478f812 | 4 | #include "DebouncedInterrupt.h" |
Jeej | 15:9a9cfb0c3c4e | 5 | #include "modem_d7a.h" |
Jeej | 0:a2bbc478f812 | 6 | #include "modem_callbacks.h" |
Jeej | 0:a2bbc478f812 | 7 | #include "files.h" |
Jeej | 0:a2bbc478f812 | 8 | #include "crc.h" |
Jeej | 0:a2bbc478f812 | 9 | |
Jeej | 0:a2bbc478f812 | 10 | #define CHUNK_SIZE 128 |
Jeej | 0:a2bbc478f812 | 11 | |
Jeej | 0:a2bbc478f812 | 12 | Semaphore button_user(0); |
Jeej | 0:a2bbc478f812 | 13 | Semaphore modem_ready(0); |
Jeej | 0:a2bbc478f812 | 14 | Queue<touch_t, 8> g_file_modified; |
Jeej | 0:a2bbc478f812 | 15 | |
Jeej | 1:76a8a3cc5f2e | 16 | // This describe the upload interface |
Jeej | 1:76a8a3cc5f2e | 17 | // Do not modify uncommented parameters |
Jeej | 15:9a9cfb0c3c4e | 18 | alp_itf_d7a_cfg_t report_itf = { |
Jeej | 0:a2bbc478f812 | 19 | .type = ALP_ITF_TYPE_D7A, |
Jeej | 14:a0241090f967 | 20 | .cfg.to.byte = D7A_CTF_ENCODE(0), |
Jeej | 14:a0241090f967 | 21 | .cfg.te.byte = D7A_CTF_ENCODE(0), |
Jeej | 0:a2bbc478f812 | 22 | .cfg.qos.bf.resp = D7A_RESP_PREFERRED, |
Jeej | 6:33dfecc85ebf | 23 | .cfg.qos.bf.retry = ALP_RPOL_ONESHOT, |
Jeej | 1:76a8a3cc5f2e | 24 | .cfg.addressee.ctrl.bf.nls = D7A_NLS_AES_CCM_64, // Security level |
Jeej | 0:a2bbc478f812 | 25 | .cfg.addressee.ctrl.bf.idf = D7A_ID_NBID, |
Jeej | 9:26cd994b5303 | 26 | .cfg.addressee.xcl.bf = {.s = 2, .m = 0x1}, // Gateway access class |
Jeej | 9:26cd994b5303 | 27 | .cfg.addressee.id[0] = D7A_CTF_ENCODE(4), |
Jeej | 0:a2bbc478f812 | 28 | }; |
Jeej | 0:a2bbc478f812 | 29 | |
Jeej | 0:a2bbc478f812 | 30 | // Interrupt Service Routine on button press. |
Jeej | 0:a2bbc478f812 | 31 | void button_push_isr( void ) |
Jeej | 0:a2bbc478f812 | 32 | { |
Jeej | 0:a2bbc478f812 | 33 | button_user.release(); |
Jeej | 0:a2bbc478f812 | 34 | } |
Jeej | 0:a2bbc478f812 | 35 | |
Jeej | 1:76a8a3cc5f2e | 36 | // Upload thread |
Jeej | 0:a2bbc478f812 | 37 | void button_user_thread() |
Jeej | 0:a2bbc478f812 | 38 | { |
Jeej | 0:a2bbc478f812 | 39 | osEvent evt; |
Jeej | 1:76a8a3cc5f2e | 40 | output_file_t* output; |
Jeej | 0:a2bbc478f812 | 41 | uint32_t sent = 0; |
Jeej | 15:9a9cfb0c3c4e | 42 | int err; |
Jeej | 15:9a9cfb0c3c4e | 43 | alp_payload_t* alp; |
Jeej | 15:9a9cfb0c3c4e | 44 | alp_payload_t* rsp; |
Jeej | 15:9a9cfb0c3c4e | 45 | |
Jeej | 15:9a9cfb0c3c4e | 46 | PRINT("Register Files\n"); |
Jeej | 15:9a9cfb0c3c4e | 47 | ram_fs_new(FID_OUTPUT_FILE, (uint8_t*)&h_output_file, (uint8_t*)&f_output_file); |
Jeej | 15:9a9cfb0c3c4e | 48 | ram_fs_new(FID_INPUT_FILE, (uint8_t*)&h_input_file, (uint8_t*)&f_input_file); |
Jeej | 15:9a9cfb0c3c4e | 49 | |
Jeej | 15:9a9cfb0c3c4e | 50 | modem_declare_file(FID_OUTPUT_FILE, (alp_file_header_t*)&h_output_file); |
Jeej | 15:9a9cfb0c3c4e | 51 | modem_declare_file(FID_INPUT_FILE, (alp_file_header_t*)&h_input_file); |
Jeej | 15:9a9cfb0c3c4e | 52 | |
Jeej | 15:9a9cfb0c3c4e | 53 | PRINT("Enable D7A interface\n"); |
Jeej | 15:9a9cfb0c3c4e | 54 | modem_d7a_enable_itf(); |
Jeej | 15:9a9cfb0c3c4e | 55 | |
Jeej | 15:9a9cfb0c3c4e | 56 | // Host revision file is in the modem. Update it. |
Jeej | 15:9a9cfb0c3c4e | 57 | PRINT("Update host revision\n"); |
Jeej | 15:9a9cfb0c3c4e | 58 | modem_write_file(FID_HOST_REV, &f_rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 59 | |
Jeej | 15:9a9cfb0c3c4e | 60 | // Retrieve modem revision |
Jeej | 15:9a9cfb0c3c4e | 61 | PRINT("Send revision\n"); |
Jeej | 15:9a9cfb0c3c4e | 62 | revision_t rev; |
Jeej | 15:9a9cfb0c3c4e | 63 | modem_read_file(FID_WM_REV, &rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 64 | |
Jeej | 15:9a9cfb0c3c4e | 65 | // Send both to the server |
Jeej | 15:9a9cfb0c3c4e | 66 | // Build payload |
Jeej | 15:9a9cfb0c3c4e | 67 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 68 | alp = alp_payload_rsp_f_data(alp, FID_WM_REV, &rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 69 | alp = alp_payload_rsp_f_data(alp, FID_HOST_REV, &f_rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 70 | // Send |
Jeej | 15:9a9cfb0c3c4e | 71 | modem_remote_raw_alp((void*)&report_itf, alp, NULL, 10000); |
Jeej | 0:a2bbc478f812 | 72 | |
Jeej | 1:76a8a3cc5f2e | 73 | // Directly get data pointer to avoid reading file |
Jeej | 1:76a8a3cc5f2e | 74 | output = (output_file_t*)ram_fs_get_data(FID_OUTPUT_FILE); |
Jeej | 1:76a8a3cc5f2e | 75 | |
Jeej | 1:76a8a3cc5f2e | 76 | // Update file CRC (Calculate CRC on string without end of string) |
Jeej | 1:76a8a3cc5f2e | 77 | output->crc = crc32((char*)output->data, strlen((char*)output->data)); |
Jeej | 1:76a8a3cc5f2e | 78 | |
Jeej | 0:a2bbc478f812 | 79 | while (true) |
Jeej | 0:a2bbc478f812 | 80 | { |
Jeej | 0:a2bbc478f812 | 81 | Timer tim; |
Jeej | 0:a2bbc478f812 | 82 | bool is_ok; |
Jeej | 1:76a8a3cc5f2e | 83 | uint32_t output_length = strlen((char*)output->data) + 1; // +1 as data is a string, send end of string |
Jeej | 0:a2bbc478f812 | 84 | |
Jeej | 0:a2bbc478f812 | 85 | // Wait for button press |
Jeej | 1:76a8a3cc5f2e | 86 | PRINT("Press user button to send file. (%d bytes)\n", output_length); |
Jeej | 15:9a9cfb0c3c4e | 87 | //button_user.acquire(); |
Jeej | 15:9a9cfb0c3c4e | 88 | osDelay(5000); |
Jeej | 0:a2bbc478f812 | 89 | |
Jeej | 1:76a8a3cc5f2e | 90 | // Update file CRC (Calculate CRC on string without end of string) |
Jeej | 1:76a8a3cc5f2e | 91 | output->crc = crc32((char*)output->data, output_length - 1); |
Jeej | 1:76a8a3cc5f2e | 92 | |
Jeej | 0:a2bbc478f812 | 93 | sent = 0; |
Jeej | 0:a2bbc478f812 | 94 | tim.start(); |
Jeej | 0:a2bbc478f812 | 95 | |
Jeej | 0:a2bbc478f812 | 96 | // Send chunks |
Jeej | 1:76a8a3cc5f2e | 97 | while (sent < output_length) |
Jeej | 0:a2bbc478f812 | 98 | { |
Jeej | 0:a2bbc478f812 | 99 | is_ok = false; |
Jeej | 15:9a9cfb0c3c4e | 100 | uint32_t chunk_size = min_u32(CHUNK_SIZE, output_length - sent); |
Jeej | 0:a2bbc478f812 | 101 | uint32_t chunk_offset = sent; |
Jeej | 0:a2bbc478f812 | 102 | |
Jeej | 1:76a8a3cc5f2e | 103 | PRINT("Sending chunk %4d/%4d (%3d bytes)... ", chunk_offset, output_length, chunk_size); |
Jeej | 0:a2bbc478f812 | 104 | FLUSH(); |
Jeej | 15:9a9cfb0c3c4e | 105 | |
Jeej | 15:9a9cfb0c3c4e | 106 | // Build payload |
Jeej | 15:9a9cfb0c3c4e | 107 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 108 | alp = alp_payload_rsp_f_data(alp, FID_OUTPUT_FILE, &(output->data[chunk_offset]), chunk_offset, chunk_size); |
Jeej | 0:a2bbc478f812 | 109 | |
Jeej | 15:9a9cfb0c3c4e | 110 | // Send |
Jeej | 15:9a9cfb0c3c4e | 111 | err = modem_remote_raw_alp((void*)&report_itf, alp, &rsp, 60000); |
Jeej | 15:9a9cfb0c3c4e | 112 | |
Jeej | 15:9a9cfb0c3c4e | 113 | if (ALP_ERR_UNKNOWN == err) |
Jeej | 0:a2bbc478f812 | 114 | { |
Jeej | 15:9a9cfb0c3c4e | 115 | PRINT("TIMEOUT.\n"); |
Jeej | 0:a2bbc478f812 | 116 | } |
Jeej | 0:a2bbc478f812 | 117 | else |
Jeej | 0:a2bbc478f812 | 118 | { |
Jeej | 15:9a9cfb0c3c4e | 119 | err = alp_payload_get_err(rsp); |
Jeej | 15:9a9cfb0c3c4e | 120 | if (ALP_ERR_NONE <= err) |
Jeej | 15:9a9cfb0c3c4e | 121 | { |
Jeej | 15:9a9cfb0c3c4e | 122 | sent += chunk_size; |
Jeej | 15:9a9cfb0c3c4e | 123 | is_ok = true; |
Jeej | 15:9a9cfb0c3c4e | 124 | PRINT("OK.\n"); |
Jeej | 15:9a9cfb0c3c4e | 125 | } |
Jeej | 15:9a9cfb0c3c4e | 126 | else |
Jeej | 15:9a9cfb0c3c4e | 127 | { |
Jeej | 15:9a9cfb0c3c4e | 128 | modem_print_error(report_itf.type, err); |
Jeej | 15:9a9cfb0c3c4e | 129 | } |
Jeej | 0:a2bbc478f812 | 130 | } |
Jeej | 15:9a9cfb0c3c4e | 131 | |
Jeej | 15:9a9cfb0c3c4e | 132 | alp_payload_free(rsp); |
Jeej | 0:a2bbc478f812 | 133 | } |
Jeej | 0:a2bbc478f812 | 134 | |
Jeej | 0:a2bbc478f812 | 135 | double time_s = tim.read(); |
Jeej | 0:a2bbc478f812 | 136 | if (sent) |
Jeej | 0:a2bbc478f812 | 137 | { |
Jeej | 0:a2bbc478f812 | 138 | PRINT("%d bytes sent in %.3fs (%d B/s)\n", sent, time_s, (int)((double)sent/time_s)); |
Jeej | 0:a2bbc478f812 | 139 | } |
Jeej | 0:a2bbc478f812 | 140 | |
Jeej | 0:a2bbc478f812 | 141 | if (is_ok) |
Jeej | 0:a2bbc478f812 | 142 | { |
Jeej | 0:a2bbc478f812 | 143 | // Send CRC |
Jeej | 15:9a9cfb0c3c4e | 144 | PRINT("Sendind CRC 0x%08X... ", output->crc); |
Jeej | 15:9a9cfb0c3c4e | 145 | |
Jeej | 15:9a9cfb0c3c4e | 146 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 147 | alp = alp_payload_rsp_f_data(alp, FID_OUTPUT_FILE, &(output->crc), offsetof(output_file_t, crc), sizeof_field(output_file_t, crc)); |
Jeej | 0:a2bbc478f812 | 148 | |
Jeej | 15:9a9cfb0c3c4e | 149 | // Send |
Jeej | 15:9a9cfb0c3c4e | 150 | err = modem_remote_raw_alp((void*)&report_itf, alp, &rsp, 60000); |
Jeej | 15:9a9cfb0c3c4e | 151 | |
Jeej | 15:9a9cfb0c3c4e | 152 | if (ALP_ERR_UNKNOWN == err) |
Jeej | 0:a2bbc478f812 | 153 | { |
Jeej | 15:9a9cfb0c3c4e | 154 | PRINT("TIMEOUT.\n"); |
Jeej | 15:9a9cfb0c3c4e | 155 | } |
Jeej | 15:9a9cfb0c3c4e | 156 | else |
Jeej | 15:9a9cfb0c3c4e | 157 | { |
Jeej | 15:9a9cfb0c3c4e | 158 | err = alp_payload_get_err(rsp); |
Jeej | 15:9a9cfb0c3c4e | 159 | if (ALP_ERR_NONE <= err) |
Jeej | 0:a2bbc478f812 | 160 | { |
Jeej | 15:9a9cfb0c3c4e | 161 | PRINT("OK.\n"); |
Jeej | 0:a2bbc478f812 | 162 | } |
Jeej | 15:9a9cfb0c3c4e | 163 | else |
Jeej | 0:a2bbc478f812 | 164 | { |
Jeej | 15:9a9cfb0c3c4e | 165 | modem_print_error(report_itf.type, err); |
Jeej | 0:a2bbc478f812 | 166 | } |
Jeej | 15:9a9cfb0c3c4e | 167 | } |
Jeej | 15:9a9cfb0c3c4e | 168 | |
Jeej | 15:9a9cfb0c3c4e | 169 | alp_payload_free(rsp); |
Jeej | 0:a2bbc478f812 | 170 | } |
Jeej | 0:a2bbc478f812 | 171 | } |
Jeej | 0:a2bbc478f812 | 172 | } |
Jeej | 0:a2bbc478f812 | 173 | |
Jeej | 0:a2bbc478f812 | 174 | void thread_file_modified() |
Jeej | 0:a2bbc478f812 | 175 | { |
Jeej | 0:a2bbc478f812 | 176 | touch_t* touch; |
Jeej | 0:a2bbc478f812 | 177 | osEvent evt; |
Jeej | 0:a2bbc478f812 | 178 | uint8_t chunk[CHUNK_SIZE]; |
Jeej | 15:9a9cfb0c3c4e | 179 | int err; |
Jeej | 15:9a9cfb0c3c4e | 180 | alp_payload_t* alp; |
Jeej | 0:a2bbc478f812 | 181 | |
Jeej | 0:a2bbc478f812 | 182 | while (true) |
Jeej | 0:a2bbc478f812 | 183 | { |
Jeej | 0:a2bbc478f812 | 184 | evt = g_file_modified.get(); |
Jeej | 0:a2bbc478f812 | 185 | touch = (evt.status == osEventMessage)? (touch_t*)evt.value.p : NULL; |
Jeej | 0:a2bbc478f812 | 186 | ASSERT(touch != NULL, "NULL touch pointer!\n"); |
Jeej | 0:a2bbc478f812 | 187 | |
Jeej | 0:a2bbc478f812 | 188 | switch (touch->fid) |
Jeej | 0:a2bbc478f812 | 189 | { |
Jeej | 1:76a8a3cc5f2e | 190 | case FID_OUTPUT_FILE: |
Jeej | 1:76a8a3cc5f2e | 191 | output_file_t* output; |
Jeej | 1:76a8a3cc5f2e | 192 | uint32_t output_length; |
Jeej | 1:76a8a3cc5f2e | 193 | |
Jeej | 1:76a8a3cc5f2e | 194 | // Directly get data pointer to avoid reading file |
Jeej | 1:76a8a3cc5f2e | 195 | output = (output_file_t*)ram_fs_get_data(FID_OUTPUT_FILE); |
Jeej | 1:76a8a3cc5f2e | 196 | |
Jeej | 1:76a8a3cc5f2e | 197 | output_length = strlen((char*)output->data); |
Jeej | 1:76a8a3cc5f2e | 198 | |
Jeej | 1:76a8a3cc5f2e | 199 | // Update file CRC (Calculate CRC on string without end of string) |
Jeej | 1:76a8a3cc5f2e | 200 | output->crc = crc32((char*)output->data, output_length); |
Jeej | 1:76a8a3cc5f2e | 201 | |
Jeej | 1:76a8a3cc5f2e | 202 | PRINT("NEW OUTPUT CRC 0x%08X (on %d bytes)\n", output->crc, output_length); |
Jeej | 1:76a8a3cc5f2e | 203 | break; |
Jeej | 0:a2bbc478f812 | 204 | case FID_INPUT_FILE: |
Jeej | 1:76a8a3cc5f2e | 205 | input_file_t* input; |
Jeej | 1:76a8a3cc5f2e | 206 | uint32_t input_length; |
Jeej | 1:76a8a3cc5f2e | 207 | uint32_t crc; |
Jeej | 1:76a8a3cc5f2e | 208 | |
Jeej | 1:76a8a3cc5f2e | 209 | // Directly get data pointer to avoid reading file |
Jeej | 1:76a8a3cc5f2e | 210 | input = (input_file_t*)ram_fs_get_data(FID_INPUT_FILE); |
Jeej | 1:76a8a3cc5f2e | 211 | |
Jeej | 1:76a8a3cc5f2e | 212 | input_length = strlen((char*)input->data); |
Jeej | 1:76a8a3cc5f2e | 213 | |
Jeej | 1:76a8a3cc5f2e | 214 | // Calculate CRC |
Jeej | 1:76a8a3cc5f2e | 215 | crc = crc32((char*)input->data, input_length); |
Jeej | 0:a2bbc478f812 | 216 | |
Jeej | 0:a2bbc478f812 | 217 | // Check if CRC has been updated |
Jeej | 1:76a8a3cc5f2e | 218 | if ((offsetof(input_file_t, crc) == touch->offset) && (sizeof_field(input_file_t, crc) == touch->length)) |
Jeej | 0:a2bbc478f812 | 219 | { |
Jeej | 1:76a8a3cc5f2e | 220 | PRINT("INPUT CRC 0x%08X CRC 0x%08X (on %d bytes)\n", input->crc, crc, input_length); |
Jeej | 0:a2bbc478f812 | 221 | |
Jeej | 1:76a8a3cc5f2e | 222 | if (input->crc != crc) |
Jeej | 0:a2bbc478f812 | 223 | { |
Jeej | 0:a2bbc478f812 | 224 | // delete CRC |
Jeej | 1:76a8a3cc5f2e | 225 | input->crc = 0; |
Jeej | 0:a2bbc478f812 | 226 | } |
Jeej | 0:a2bbc478f812 | 227 | |
Jeej | 0:a2bbc478f812 | 228 | // Send CRC as confirmation |
Jeej | 1:76a8a3cc5f2e | 229 | PRINT("COMFIRM CRC 0x%08X\n", input->crc); |
Jeej | 15:9a9cfb0c3c4e | 230 | |
Jeej | 15:9a9cfb0c3c4e | 231 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 232 | alp = alp_payload_rsp_f_data(alp, FID_INPUT_FILE, &(input->crc), offsetof(input_file_t, crc), sizeof_field(input_file_t, crc)); |
Jeej | 0:a2bbc478f812 | 233 | |
Jeej | 15:9a9cfb0c3c4e | 234 | // Send |
Jeej | 15:9a9cfb0c3c4e | 235 | err = modem_remote_raw_alp((void*)&report_itf, alp, NULL, 3000); |
Jeej | 15:9a9cfb0c3c4e | 236 | |
Jeej | 15:9a9cfb0c3c4e | 237 | if (ALP_ERR_NONE <= err) |
Jeej | 0:a2bbc478f812 | 238 | { |
Jeej | 15:9a9cfb0c3c4e | 239 | PRINT("OK.\n"); |
Jeej | 15:9a9cfb0c3c4e | 240 | } |
Jeej | 15:9a9cfb0c3c4e | 241 | else |
Jeej | 15:9a9cfb0c3c4e | 242 | { |
Jeej | 15:9a9cfb0c3c4e | 243 | modem_print_error(report_itf.type, err); |
Jeej | 15:9a9cfb0c3c4e | 244 | } |
Jeej | 0:a2bbc478f812 | 245 | } |
Jeej | 1:76a8a3cc5f2e | 246 | else |
Jeej | 1:76a8a3cc5f2e | 247 | { |
Jeej | 1:76a8a3cc5f2e | 248 | PRINT("Got chunk %4d/%4d (%3d bytes)\n", touch->offset, sizeof_field(input_file_t, data), touch->length); |
Jeej | 15:9a9cfb0c3c4e | 249 | ram_fs_read(touch->fid, chunk, touch->offset, touch->length); |
Jeej | 1:76a8a3cc5f2e | 250 | //PRINT("%s\n", chunk); |
Jeej | 1:76a8a3cc5f2e | 251 | //PRINT_DATA("chunk end:", "%02X", &(chunk[touch->length-4]), 4, "\n"); |
Jeej | 1:76a8a3cc5f2e | 252 | |
Jeej | 1:76a8a3cc5f2e | 253 | PRINT("NEW INPUT CRC 0x%08X (on %d bytes)\n", crc, input_length); |
Jeej | 1:76a8a3cc5f2e | 254 | } |
Jeej | 0:a2bbc478f812 | 255 | break; |
Jeej | 0:a2bbc478f812 | 256 | default: |
Jeej | 0:a2bbc478f812 | 257 | PRINT("TOUCH FID %d OFF %d LEN %d\n", touch->fid, touch->offset, touch->length); |
Jeej | 0:a2bbc478f812 | 258 | break; |
Jeej | 0:a2bbc478f812 | 259 | } |
Jeej | 0:a2bbc478f812 | 260 | |
Jeej | 0:a2bbc478f812 | 261 | FREE(touch); |
Jeej | 0:a2bbc478f812 | 262 | } |
Jeej | 0:a2bbc478f812 | 263 | } |
Jeej | 0:a2bbc478f812 | 264 | |
Jeej | 15:9a9cfb0c3c4e | 265 | modem_ref_callbacks_t callbacks = { |
Jeej | 0:a2bbc478f812 | 266 | .read = my_read, |
Jeej | 0:a2bbc478f812 | 267 | .write = my_write, |
Jeej | 0:a2bbc478f812 | 268 | .read_fprop = my_read_fprop, |
Jeej | 0:a2bbc478f812 | 269 | .flush = my_flush, |
Jeej | 0:a2bbc478f812 | 270 | .remove = my_delete, |
Jeej | 0:a2bbc478f812 | 271 | .udata = my_udata, |
Jeej | 0:a2bbc478f812 | 272 | .lqual = my_lqual, |
Jeej | 0:a2bbc478f812 | 273 | .ldown = my_ldown, |
Jeej | 0:a2bbc478f812 | 274 | .reset = my_reset, |
Jeej | 6:33dfecc85ebf | 275 | .boot = my_boot, |
Jeej | 6:33dfecc85ebf | 276 | .busy = my_busy, |
Jeej | 0:a2bbc478f812 | 277 | }; |
Jeej | 0:a2bbc478f812 | 278 | |
Jeej | 0:a2bbc478f812 | 279 | |
Jeej | 0:a2bbc478f812 | 280 | /*** Main function ------------------------------------------------------------- ***/ |
Jeej | 0:a2bbc478f812 | 281 | int main() { |
Jeej | 0:a2bbc478f812 | 282 | // Start & initialize |
Jeej | 0:a2bbc478f812 | 283 | #ifdef DEBUG_LED |
Jeej | 0:a2bbc478f812 | 284 | DBG_OPEN(DEBUG_LED); |
Jeej | 0:a2bbc478f812 | 285 | #else |
Jeej | 0:a2bbc478f812 | 286 | DBG_OPEN(NC); |
Jeej | 0:a2bbc478f812 | 287 | #endif |
Jeej | 0:a2bbc478f812 | 288 | PRINT("\n" |
Jeej | 0:a2bbc478f812 | 289 | "-----------------------------------------\n" |
Jeej | 0:a2bbc478f812 | 290 | "------------- Demo Big File -------------\n" |
Jeej | 0:a2bbc478f812 | 291 | "-----------------------------------------\n"); |
Jeej | 1:76a8a3cc5f2e | 292 | |
Jeej | 15:9a9cfb0c3c4e | 293 | modem_open(&callbacks); |
Jeej | 0:a2bbc478f812 | 294 | |
Jeej | 0:a2bbc478f812 | 295 | // Start file modified thread |
Jeej | 15:9a9cfb0c3c4e | 296 | Thread th_file_modified(osPriorityNormal, 4096, NULL); |
Jeej | 0:a2bbc478f812 | 297 | osStatus status = th_file_modified.start(thread_file_modified); |
Jeej | 0:a2bbc478f812 | 298 | ASSERT(status == osOK, "Failed to start thread_file_modified (err: %d)\r\n", status); |
Jeej | 0:a2bbc478f812 | 299 | |
Jeej | 0:a2bbc478f812 | 300 | #ifdef DEBUG_BUTTON |
Jeej | 0:a2bbc478f812 | 301 | DebouncedInterrupt user_interrupt(DEBUG_BUTTON); |
Jeej | 0:a2bbc478f812 | 302 | user_interrupt.attach(button_push_isr, IRQ_FALL, 500, true); |
Jeej | 0:a2bbc478f812 | 303 | |
Jeej | 0:a2bbc478f812 | 304 | Thread but_th(osPriorityNormal, 4096, NULL); |
Jeej | 0:a2bbc478f812 | 305 | status = but_th.start(button_user_thread); |
Jeej | 0:a2bbc478f812 | 306 | ASSERT(status == osOK, "Failed to start but thread (err: %d)\r\n", status); |
Jeej | 0:a2bbc478f812 | 307 | #else |
Jeej | 0:a2bbc478f812 | 308 | #error You need a button to use this APP as is |
Jeej | 0:a2bbc478f812 | 309 | #endif |
Jeej | 0:a2bbc478f812 | 310 | |
Jeej | 0:a2bbc478f812 | 311 | #ifdef DEBUG_LED |
Jeej | 0:a2bbc478f812 | 312 | DigitalOut my_led(DEBUG_LED); |
Jeej | 0:a2bbc478f812 | 313 | #endif |
Jeej | 0:a2bbc478f812 | 314 | |
Jeej | 0:a2bbc478f812 | 315 | // Set main task to lowest priority |
Jeej | 11:dc0e19b2d4a0 | 316 | osThreadSetPriority(osThreadGetId(), osPriorityLow); |
Jeej | 0:a2bbc478f812 | 317 | while(true) |
Jeej | 0:a2bbc478f812 | 318 | { |
Jeej | 11:dc0e19b2d4a0 | 319 | ThisThread::sleep_for(500); |
Jeej | 0:a2bbc478f812 | 320 | #ifdef DEBUG_LED |
Jeej | 0:a2bbc478f812 | 321 | my_led = !my_led; |
Jeej | 0:a2bbc478f812 | 322 | #endif |
Jeej | 0:a2bbc478f812 | 323 | } |
Jeej | 0:a2bbc478f812 | 324 | } |