Teste Flash
Dependencies: pulga-lorawan-drv Si1133 BME280
serial_cmds.cpp@70:99b7a15c09da, 2021-09-13 (annotated)
- Committer:
- MatteusCarr
- Date:
- Mon Sep 13 18:55:32 2021 +0000
- Revision:
- 70:99b7a15c09da
- Parent:
- 69:2d56b571c78e
Teste Flash
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ruschigo | 62:89df9529dbb0 | 1 | #include "serial.h" |
ruschigo | 62:89df9529dbb0 | 2 | |
pancotinho | 67:17addc7bf8c2 | 3 | gps_navPVT gps_data; |
ruschigo | 64:ed68ddac6360 | 4 | |
ruschigo | 62:89df9529dbb0 | 5 | bool SerialCommandRun(const char *msg) |
ruschigo | 62:89df9529dbb0 | 6 | { |
ruschigo | 62:89df9529dbb0 | 7 | char Option = msg[1]; /// recebo opcao |
ruschigo | 62:89df9529dbb0 | 8 | |
ruschigo | 62:89df9529dbb0 | 9 | switch (Option) |
ruschigo | 62:89df9529dbb0 | 10 | { |
ruschigo | 62:89df9529dbb0 | 11 | |
ruschigo | 62:89df9529dbb0 | 12 | case CMD_PRINT_LAST_GPS: |
pancotinho | 66:f40f985a6b97 | 13 | {int local_lat, local_log; |
pancotinho | 69:2d56b571c78e | 14 | |
pancotinho | 68:fc357095c8ef | 15 | gps_data = get_struct(); |
pancotinho | 69:2d56b571c78e | 16 | pc.printf("<g%d,%d\n>", (int)gps_data.lat, (int)gps_data.lon); |
pancotinho | 67:17addc7bf8c2 | 17 | pc.printf("<t%d/%d/%d-%d:%d:%d\n>", (int)gps_data.year, (int)gps_data.month,(int)gps_data.day, (int)gps_data.hour, (int)gps_data.min, (int)gps_data.sec); |
pancotinho | 67:17addc7bf8c2 | 18 | |
pancotinho | 66:f40f985a6b97 | 19 | break;} |
ruschigo | 64:ed68ddac6360 | 20 | |
ruschigo | 64:ed68ddac6360 | 21 | case CMD_SEND_HELLO: |
pancotinho | 66:f40f985a6b97 | 22 | {pc.printf("<hHello>"); |
ruschigo | 65:4090220e19d2 | 23 | char hello[100] = "helloWord\n"; |
ruschigo | 64:ed68ddac6360 | 24 | int ret; |
ruschigo | 65:4090220e19d2 | 25 | ret = lora_send_message((uint8_t*)hello, (uint16_t)strlen(hello)); |
ruschigo | 65:4090220e19d2 | 26 | if(ret > 0){ |
ruschigo | 64:ed68ddac6360 | 27 | pc.printf("Send OK\n"); |
ruschigo | 65:4090220e19d2 | 28 | } |
ruschigo | 65:4090220e19d2 | 29 | else{ |
ruschigo | 65:4090220e19d2 | 30 | ret == LORAWAN_STATUS_WOULD_BLOCK ? pc.printf("send - WOULD BLOCK\r\n") : pc.printf("\r\n send() Error \r\n"); |
ruschigo | 65:4090220e19d2 | 31 | //if (ret == LORAWAN_STATUS_WOULD_BLOCK) { |
ruschigo | 65:4090220e19d2 | 32 | //retry in 3 seconds |
ruschigo | 65:4090220e19d2 | 33 | //if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
ruschigo | 65:4090220e19d2 | 34 | //ev_queue.call_in(10000, send_message); |
ruschigo | 64:ed68ddac6360 | 35 | pc.printf("Fail to Send\n"); |
ruschigo | 65:4090220e19d2 | 36 | } |
pancotinho | 66:f40f985a6b97 | 37 | break;} |
pancotinho | 66:f40f985a6b97 | 38 | case CMD_SEND_LORAWAN_NO_RETRANS: |
pancotinho | 69:2d56b571c78e | 39 | {pc.printf("<w %s>", msg+2); |
pancotinho | 67:17addc7bf8c2 | 40 | char msg_lora [256]; |
pancotinho | 66:f40f985a6b97 | 41 | strncpy(msg_lora, msg+2, strlen(msg)); //original string, begin index (2), substring length |
pancotinho | 66:f40f985a6b97 | 42 | int ret1; |
pancotinho | 66:f40f985a6b97 | 43 | ret1 = lora_send_message((uint8_t*)msg_lora, (uint16_t)strlen(msg_lora)); |
pancotinho | 66:f40f985a6b97 | 44 | if(ret1 > 0){ |
pancotinho | 66:f40f985a6b97 | 45 | pc.printf("Send OK\n"); |
pancotinho | 66:f40f985a6b97 | 46 | } |
pancotinho | 66:f40f985a6b97 | 47 | else{ |
pancotinho | 66:f40f985a6b97 | 48 | ret1 == LORAWAN_STATUS_WOULD_BLOCK ? pc.printf("send - WOULD BLOCK\r\n") : pc.printf("\r\n send() Error \r\n"); |
pancotinho | 66:f40f985a6b97 | 49 | //if (ret == LORAWAN_STATUS_WOULD_BLOCK) { |
pancotinho | 66:f40f985a6b97 | 50 | //retry in 3 seconds |
pancotinho | 66:f40f985a6b97 | 51 | //if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
pancotinho | 66:f40f985a6b97 | 52 | //ev_queue.call_in(10000, send_message); |
pancotinho | 66:f40f985a6b97 | 53 | pc.printf("Fail to Send\n"); |
pancotinho | 66:f40f985a6b97 | 54 | } |
pancotinho | 66:f40f985a6b97 | 55 | break;} |
pancotinho | 67:17addc7bf8c2 | 56 | |
pancotinho | 67:17addc7bf8c2 | 57 | case CMD_SEND_LORAWAN_RETRANS: |
pancotinho | 69:2d56b571c78e | 58 | {pc.printf("<w %s>", msg+2); |
pancotinho | 67:17addc7bf8c2 | 59 | char msg_lora_retrans [256]; |
pancotinho | 67:17addc7bf8c2 | 60 | strncpy(msg_lora_retrans, msg+2, strlen(msg)); //original string, begin index (2), substring length |
pancotinho | 67:17addc7bf8c2 | 61 | int ret2; |
pancotinho | 67:17addc7bf8c2 | 62 | ret2 = lora_send_message((uint8_t*)msg_lora_retrans, (uint16_t)strlen(msg_lora_retrans)); |
pancotinho | 67:17addc7bf8c2 | 63 | if(ret2 > 0){ |
pancotinho | 67:17addc7bf8c2 | 64 | pc.printf("Send OK\n"); |
pancotinho | 67:17addc7bf8c2 | 65 | } |
pancotinho | 67:17addc7bf8c2 | 66 | else{ |
pancotinho | 67:17addc7bf8c2 | 67 | ret2 == LORAWAN_STATUS_WOULD_BLOCK ? pc.printf("send - WOULD BLOCK\r\n") : pc.printf("\r\n send() Error \r\n"); |
pancotinho | 67:17addc7bf8c2 | 68 | if (ret2 == LORAWAN_STATUS_WOULD_BLOCK) { |
pancotinho | 67:17addc7bf8c2 | 69 | //retry in 3 seconds |
pancotinho | 67:17addc7bf8c2 | 70 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
pancotinho | 67:17addc7bf8c2 | 71 | //ev_queue.call_in(10000, lora_send_message); |
pancotinho | 67:17addc7bf8c2 | 72 | wait_ms(3000); |
pancotinho | 67:17addc7bf8c2 | 73 | ret2 = lora_send_message((uint8_t*)msg_lora_retrans, (uint16_t)strlen(msg_lora_retrans)); |
pancotinho | 67:17addc7bf8c2 | 74 | } |
pancotinho | 67:17addc7bf8c2 | 75 | pc.printf("Fail to Send\n");} |
pancotinho | 67:17addc7bf8c2 | 76 | } |
pancotinho | 67:17addc7bf8c2 | 77 | break;} |
ruschigo | 62:89df9529dbb0 | 78 | } |
ruschigo | 62:89df9529dbb0 | 79 | |
ruschigo | 62:89df9529dbb0 | 80 | return true; |
ruschigo | 62:89df9529dbb0 | 81 | } |