Teste Flash

Dependencies:   pulga-lorawan-drv Si1133 BME280

Committer:
pancotinho
Date:
Fri Mar 26 13:43:43 2021 +0000
Revision:
68:fc357095c8ef
Parent:
67:17addc7bf8c2
Child:
69:2d56b571c78e
serial update

Who changed what in which revision?

UserRevisionLine numberNew 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;
ruschigo 63:4ec1808fb547 14 //gps_get_lat_lon(&local_lat, &local_log);
ruschigo 63:4ec1808fb547 15 //get_latitude
pancotinho 67:17addc7bf8c2 16 //pc.printf("<g%d,%d\n>", get_latitude(), get_longitude());
pancotinho 68:fc357095c8ef 17 gps_data = get_struct();
pancotinho 67:17addc7bf8c2 18 pc.printf("<g%d,%d\n>", (int)gps_data.lat, (int)gps_data.lon);
pancotinho 67:17addc7bf8c2 19
pancotinho 67:17addc7bf8c2 20 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 21
pancotinho 66:f40f985a6b97 22 break;}
ruschigo 64:ed68ddac6360 23
ruschigo 64:ed68ddac6360 24 case CMD_SEND_HELLO:
pancotinho 66:f40f985a6b97 25 {pc.printf("<hHello>");
ruschigo 65:4090220e19d2 26 char hello[100] = "helloWord\n";
ruschigo 64:ed68ddac6360 27 int ret;
ruschigo 65:4090220e19d2 28 ret = lora_send_message((uint8_t*)hello, (uint16_t)strlen(hello));
ruschigo 65:4090220e19d2 29 if(ret > 0){
ruschigo 64:ed68ddac6360 30 pc.printf("Send OK\n");
ruschigo 65:4090220e19d2 31 }
ruschigo 65:4090220e19d2 32 else{
ruschigo 65:4090220e19d2 33 ret == LORAWAN_STATUS_WOULD_BLOCK ? pc.printf("send - WOULD BLOCK\r\n") : pc.printf("\r\n send() Error \r\n");
ruschigo 65:4090220e19d2 34 //if (ret == LORAWAN_STATUS_WOULD_BLOCK) {
ruschigo 65:4090220e19d2 35 //retry in 3 seconds
ruschigo 65:4090220e19d2 36 //if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
ruschigo 65:4090220e19d2 37 //ev_queue.call_in(10000, send_message);
ruschigo 64:ed68ddac6360 38 pc.printf("Fail to Send\n");
ruschigo 65:4090220e19d2 39 }
pancotinho 66:f40f985a6b97 40 break;}
pancotinho 66:f40f985a6b97 41 case CMD_SEND_LORAWAN_NO_RETRANS:
pancotinho 66:f40f985a6b97 42 {pc.printf("<w %s>", msg[+2]);
pancotinho 67:17addc7bf8c2 43 char msg_lora [256];
pancotinho 66:f40f985a6b97 44 strncpy(msg_lora, msg+2, strlen(msg)); //original string, begin index (2), substring length
pancotinho 66:f40f985a6b97 45 int ret1;
pancotinho 66:f40f985a6b97 46 ret1 = lora_send_message((uint8_t*)msg_lora, (uint16_t)strlen(msg_lora));
pancotinho 66:f40f985a6b97 47 if(ret1 > 0){
pancotinho 66:f40f985a6b97 48 pc.printf("Send OK\n");
pancotinho 66:f40f985a6b97 49 }
pancotinho 66:f40f985a6b97 50 else{
pancotinho 66:f40f985a6b97 51 ret1 == LORAWAN_STATUS_WOULD_BLOCK ? pc.printf("send - WOULD BLOCK\r\n") : pc.printf("\r\n send() Error \r\n");
pancotinho 66:f40f985a6b97 52 //if (ret == LORAWAN_STATUS_WOULD_BLOCK) {
pancotinho 66:f40f985a6b97 53 //retry in 3 seconds
pancotinho 66:f40f985a6b97 54 //if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
pancotinho 66:f40f985a6b97 55 //ev_queue.call_in(10000, send_message);
pancotinho 66:f40f985a6b97 56 pc.printf("Fail to Send\n");
pancotinho 66:f40f985a6b97 57 }
pancotinho 66:f40f985a6b97 58 break;}
pancotinho 67:17addc7bf8c2 59
pancotinho 67:17addc7bf8c2 60 case CMD_SEND_LORAWAN_RETRANS:
pancotinho 67:17addc7bf8c2 61 {pc.printf("<w %s>", msg[+2]);
pancotinho 67:17addc7bf8c2 62 char msg_lora_retrans [256];
pancotinho 67:17addc7bf8c2 63 strncpy(msg_lora_retrans, msg+2, strlen(msg)); //original string, begin index (2), substring length
pancotinho 67:17addc7bf8c2 64 int ret2;
pancotinho 67:17addc7bf8c2 65 ret2 = lora_send_message((uint8_t*)msg_lora_retrans, (uint16_t)strlen(msg_lora_retrans));
pancotinho 67:17addc7bf8c2 66 if(ret2 > 0){
pancotinho 67:17addc7bf8c2 67 pc.printf("Send OK\n");
pancotinho 67:17addc7bf8c2 68 }
pancotinho 67:17addc7bf8c2 69 else{
pancotinho 67:17addc7bf8c2 70 ret2 == LORAWAN_STATUS_WOULD_BLOCK ? pc.printf("send - WOULD BLOCK\r\n") : pc.printf("\r\n send() Error \r\n");
pancotinho 67:17addc7bf8c2 71 if (ret2 == LORAWAN_STATUS_WOULD_BLOCK) {
pancotinho 67:17addc7bf8c2 72 //retry in 3 seconds
pancotinho 67:17addc7bf8c2 73 if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
pancotinho 67:17addc7bf8c2 74 //ev_queue.call_in(10000, lora_send_message);
pancotinho 67:17addc7bf8c2 75 wait_ms(3000);
pancotinho 67:17addc7bf8c2 76 ret2 = lora_send_message((uint8_t*)msg_lora_retrans, (uint16_t)strlen(msg_lora_retrans));
pancotinho 67:17addc7bf8c2 77 }
pancotinho 67:17addc7bf8c2 78 pc.printf("Fail to Send\n");}
pancotinho 67:17addc7bf8c2 79 }
pancotinho 67:17addc7bf8c2 80 break;}
ruschigo 62:89df9529dbb0 81 }
ruschigo 62:89df9529dbb0 82
ruschigo 62:89df9529dbb0 83 return true;
ruschigo 62:89df9529dbb0 84 }