From cf057722a98ddb316a258cc76fd7343aa4891fef Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 3 Jul 2023 14:08:33 +0800 Subject: [PATCH] reformat prepare send tx data from if else to switch case --- LoRaWAN/App/lora_app.c | 136 ++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 62 deletions(-) diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 0de4d11..d89cfc5 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -732,79 +732,91 @@ static uint8_t PrepareSendTxData(void) // For occupancy over time process + switch (sts_work_mode) { + case STS_WIRED_MODE: - if (sts_work_mode == STS_WIRED_MODE) - { - AppData.Buffer[i++] = sts_mtmcode1; - AppData.Buffer[i++] = sts_mtmcode2; - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //01 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.battery_Pct); //02 Battery Level % - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV >>8); //03 Battery mV MSB - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV ); //04 Battery mV LSB - APP_LOG(TS_OFF, VLEVEL_L,"\r\n######| Mode S1 BAT % BAT mV |" - "\r\n######| %1d %1d %2d% %4d mV|\r\n", - sts_work_mode, AppData.Buffer[2], AppData.Buffer[3], batteryLevelmV); + AppData.Buffer[i++] = sts_mtmcode1; + AppData.Buffer[i++] = sts_mtmcode2; + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //01 Sensor head #1 status + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.battery_Pct); //02 Battery Level % + AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV >>8); //03 Battery mV MSB + AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV ); //04 Battery mV LSB + APP_LOG(TS_OFF, VLEVEL_L,"\r\n######| Mode S1 BAT % BAT mV |" + "\r\n######| %1d %1d %2d% %4d mV|\r\n", + sts_work_mode, AppData.Buffer[2], AppData.Buffer[3], batteryLevelmV); - } else - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.lamp_bar_color); //01 - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.workmode); //02 WORK MODE + break; + + case STS_NETWORK_MODE: + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.lamp_bar_color); //01 + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.workmode); //02 WORK MODE - if (sts_work_mode == STS_NETWORK_MODE) - { AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //03 Sensor head #1 status AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor2_on_off); //04 Sensor head #2 status AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor3_on_off); //05 Sensor head #3 status AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor4_on_off); //06 Sensor head #4 status APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S1 S2 S3 S4 |" - "\r\n######| %1d %1d %1d %1d %1d %1d |\r\n", - AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2],AppData.Buffer[3], AppData.Buffer[4],AppData.Buffer[5]); - } else if (sts_work_mode == STS_REEDSWITCH_MODE) - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.battery_Pct); //02 Battery Level % - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV >>8); //03 Battery mV MSB - AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV ); //04 Battery mV LSB - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S1 VBAT in mV|" - "\r\n######| %1d %1d %1d %2d% %4d mV|\r\n", - AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2],AppData.Buffer[3], batteryLevelmV); + "\r\n######| Color Mode S1 S2 S3 S4 |" + "\r\n######| %1d %1d %1d %1d %1d %1d |\r\n", + AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2],AppData.Buffer[3], AppData.Buffer[4],AppData.Buffer[5]); + break; - } else if (sts_work_mode == STS_RSS_MODE) + case STS_REEDSWITCH_MODE: + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.lamp_bar_color); //01 + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.workmode); //02 WORK MODE + + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //03 Sensor head #1 status + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.battery_Pct); //02 Battery Level % + AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV >>8); //03 Battery mV MSB + AppData.Buffer[i++] = (uint8_t)(0xFF & batteryLevelmV ); //04 Battery mV LSB + APP_LOG(TS_OFF, VLEVEL_L, + "\r\n######| Color Mode S1 VBAT in mV|" + "\r\n######| %1d %1d %1d %2d% %4d mV|\r\n", + AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2],AppData.Buffer[3], batteryLevelmV); + break; + + case STS_RSS_MODE: + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.lamp_bar_color); //01 + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.workmode); //02 WORK MODE + + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor2_on_off); //03 Sensor head #2 status + //AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor3_on_off); // Sensor head #3 status + //AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor4_on_off); // Sensor head #4 status + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance>>8); //04 MSB distance + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance); //05 LSB distance + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score >>8); //06 MSB score + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score); //07 LSB score + AppData.Buffer[i++] = (uint8_t)(0xFF & sts_occupancy_overtime_state); //08 occupancy over time or not + APP_LOG(TS_OFF, VLEVEL_L, + "\r\n######| Color Mode S2 |Distance(mm) MotionScore|" + "\r\n######| %1d %1d %1d |%04d %04d |\r\n", + AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2], (uint16_t)o6_data.rss_presence_distance,(uint16_t)o6_data.rss_presence_score); + + + break; + + default: + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.lamp_bar_color); //01 + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.workmode); //02 WORK MODE + + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //03 Sensor head #1 status + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor2_on_off); //04 Sensor head #2 status + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor3_on_off); //05 Sensor head #3 status + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor4_on_off); //06 Sensor head #4 status + if (o6_data.state_sensor2_on_off !=0) { - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor2_on_off); //03 Sensor head #2 status - //AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor3_on_off); // Sensor head #3 status - //AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor4_on_off); // Sensor head #4 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance>>8); //04 MSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance); //05 LSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score >>8); //06 MSB score - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score); //07 LSB score - AppData.Buffer[i++] = (uint8_t)(0xFF & sts_occupancy_overtime_state); //08 occupancy over time or not - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S2 |Distance(mm) MotionScore|" - "\r\n######| %1d %1d %1d |%04d %04d |\r\n", - AppData.Buffer[0], AppData.Buffer[1], AppData.Buffer[2], (uint16_t)o6_data.rss_presence_distance,(uint16_t)o6_data.rss_presence_score); - } else { - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor1_on_off); //03 Sensor head #1 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor2_on_off); //04 Sensor head #2 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor3_on_off); //05 Sensor head #3 status - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.state_sensor4_on_off); //06 Sensor head #4 status - if (o6_data.state_sensor2_on_off !=0) - { - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance>>8); //07 MSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance); //08 LSB distance - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score >>8); //09 MSB score - AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score); //10 LSB score - } - AppData.Buffer[i++] = (uint8_t)(0xFF & sts_occupancy_overtime_state); //11 occupancy over time or not - APP_LOG(TS_OFF, VLEVEL_L, - "\r\n######| Color Mode S1 S2 S3 S4 |Distance(mm) MotionScore|" - "\r\n######| %1d %1d %1d %1d %1d %1d |%04d %04d |\r\n", - AppData.Buffer[0], AppData.Buffer[1],AppData.Buffer[2], AppData.Buffer[3],AppData.Buffer[4], AppData.Buffer[5], (uint16_t)o6_data.rss_presence_distance,(uint16_t)o6_data.rss_presence_score); + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance>>8); //07 MSB distance + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_distance); //08 LSB distance + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score >>8); //09 MSB score + AppData.Buffer[i++] = (uint8_t)(0xFF & o6_data.rss_presence_score); //10 LSB score } - - } + AppData.Buffer[i++] = (uint8_t)(0xFF & sts_occupancy_overtime_state); //11 occupancy over time or not + APP_LOG(TS_OFF, VLEVEL_L, + "\r\n######| Color Mode S1 S2 S3 S4 |Distance(mm) MotionScore|" + "\r\n######| %1d %1d %1d %1d %1d %1d |%04d %04d |\r\n", + AppData.Buffer[0], AppData.Buffer[1],AppData.Buffer[2], AppData.Buffer[3],AppData.Buffer[4], AppData.Buffer[5], (uint16_t)o6_data.rss_presence_distance,(uint16_t)o6_data.rss_presence_score); + break; + } return i; }