Teste Flash

Dependencies:   pulga-lorawan-drv Si1133 BME280

Committer:
pancotinho
Date:
Fri Mar 12 13:33:06 2021 +0000
Revision:
67:17addc7bf8c2
Parent:
66:f40f985a6b97
Child:
68:fc357095c8ef
added gps time

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