#include "stdint.h" #include "string.h" #include "stdio.h" #include "stm32f0xx_ll_gpio.h" #include "lora.h" #include "user_tim.h" #include "user_flash.h" #include "user_data_process.h" extern volatile uint8_t LORA_STATE; struct recData_process { const char *recData; void (*function) (int argc, char *argv[]); }; static void lora_state (int argc, char *argv[]); static void lora_recv(int argc, char *argv[]); struct recData_process recData_processes[] = { /*lora status check*/ "\r\n+STATUS:", lora_state, "\r\n^STATUS:", lora_state, "^STATUS:", lora_state, "\r\n^LRRECV:", lora_recv, }; /******************************************************************************* **lora_state(int argc, char *argv[]) **功能描述: **入口参数:int argc char *argv[] **输出:无 *******************************************************************************/ static void lora_state(int argc, char *argv[]) { switch(argv[0][strlen(recData_processes[argc].recData)]-0x30) { case LORA_RESET: LORA_STATE = LORA_RESET; StopTIM(TIM17); break; case LORA_P2P: LORA_STATE = LORA_P2P; StopTIM(TIM17); break; case LORA_NOT_JOIN: LORA_STATE = LORA_NOT_JOIN; StopTIM(TIM17); break; case LORA_JOINED: LORA_STATE = LORA_JOINED; StartTIM(TIM17); break; case LORA_JOINED_ABP: LORA_STATE = LORA_JOINED; StartTIM(TIM17); break; default : break; } } /******************************************************************************* **函数名称:lora_recv(int argc, char *argv[]) **功能描述: **入口参数:int argc char *argv[] **输出:无 *******************************************************************************/ static void lora_recv(int argc, char *argv[]) { for(int i = 0; i< strlen(argv[0]);i++) { if(argv[0][i] == '<') { switch(argv[0][i+2]-0x30) { case LEVEL_0: save_config(INTERVAL_TIME_LEVEL_0); break; case LEVEL_1: save_config(INTERVAL_TIME_LEVEL_1); break; case LEVEL_2: save_config(INTERVAL_TIME_LEVEL_2); break; case LEVEL_3: save_config(INTERVAL_TIME_LEVEL_3); break; case LEVEL_4: save_config(INTERVAL_TIME_LEVEL_4); break; case LEVEL_5: save_config(INTERVAL_TIME_LEVEL_5); break; case LEVEL_6: save_config(INTERVAL_TIME_LEVEL_6); break; case LEVEL_7: save_config(INTERVAL_TIME_LEVEL_7); break; case LEVEL_8: save_config(INTERVAL_TIME_LEVEL_8); break; default : break; } break; } } } /******************************************************************************* **函数名称:data_process(char *str) **功能描述:处理lora模块接收的数据 **入口参数:char *str 要处理的数据 **输出:无 *******************************************************************************/ void data_process(char *str) { int i; int argc; char* argv[5]={NULL}; argv[0] = str; for (i = 0; i < sizeof(recData_processes)/sizeof(struct recData_process); i++) { if(strncmp(str, recData_processes[i].recData,8) == 0) { argc = i; recData_processes[i].function(argc, argv); break; } } }