fixed if/else

This commit is contained in:
Timm Bogner 2022-07-09 20:22:33 -05:00
parent e10315bc28
commit 59196b7829
2 changed files with 31 additions and 23 deletions

View File

@ -154,28 +154,28 @@ if(current_millis-last_millis >= 1000){
#endif
if (newData) {
switch (newData) {
case event_espnowg: //ESP-NOW General
case event_espnowg:
ESPNOWG_ACT
break;
case event_espnow1: //ESP-NOW #1
case event_espnow1:
ESPNOW1_ACT
break;
case event_espnow2: //ESP-NOW #2
case event_espnow2:
ESPNOW2_ACT
break;
case event_serial: //Serial
case event_serial:
SERIAL_ACT
break;
case event_mqtt: //MQTT
case event_mqtt:
MQTT_ACT
break;
case event_lorag: //LoRa General
case event_lorag:
LORAG_ACT
break;
case event_lora1: //LoRa #1
case event_lora1:
LORA1_ACT
break;
case event_lora2: //LoRa #2
case event_lora2:
LORA2_ACT
break;
}

View File

@ -159,9 +159,15 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&incMAC, mac, sizeof(incMAC));
DBG("Incoming ESP-NOW.");
ln = len / sizeof(DataReading);
if (memcmp(&incMAC, &ESPNOW1, 6) == 0) newData = event_espnow1;
else if (memcmp(&incMAC, &ESPNOW2, 6) == 0) newData = event_espnow2;
else newData = event_espnowg;
if (memcmp(&incMAC, &ESPNOW1, 6) == 0) {
newData = event_espnow1;
return;
}
if (memcmp(&incMAC, &ESPNOW2, 6) == 0) {
newData = event_espnow2;
return;
}
newData = event_espnowg;
}
void getSerial() {
String incomingString = UART_IF.readStringUntil('\n');
@ -290,18 +296,20 @@ void getLoRa() {
uint8_t packet[packetSize];
uint8_t incLORAMAC[2];
LoRa.readBytes((uint8_t *)&packet, packetSize);
// for (int i = 0; i < packetSize; i++) {
// UART_IF.println(packet[i], HEX);
// }
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet
memcpy(&theData, &packet[5], packetSize - 5); //Split off data portion of packet
if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) newData = event_lora1; //Check if it is from a registered sender
else if (memcmp(&incLORAMAC, &LoRa2, 2) == 0) newData = event_lora2;
else newData = event_lorag;
ln = (packetSize - 5) / sizeof(DataReading);
DBG("Incoming LoRa.");
ln = (packetSize - 5) / sizeof(DataReading);
DBG("Incoming LoRa.");
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet
memcpy(&theData, &packet[5], packetSize - 5); //Split off data portion of packet
if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) { //Check if it is from a registered sender
newData = event_lora1;
return;
}
if (memcmp(&incLORAMAC, &LoRa2, 2) == 0) {
newData = event_lora2;
return;
}
newData = event_lorag;
}
}
#endif