/***********************************新日志数据存储函数 - 提供各种类型保存调用函数***************************************/ #include "rw_logging.h" #include "SPI_SRAM.h" #include "Log_api.h" #include "string.h" #include "spi_flash.h" #include #include #include #include uint32_t SYS_Log_Switch = (LogType_Launcher_SWITCH << LogType_Launcher_bit) + \ (LogType_SYS_Record_SWITCH << LogType_SYS_Record_bit) + \ (LogType_Device_COMM_SWITCH << LogType_Device_COMM_bit) + \ (LogType_Device_Online_SWITCH << LogType_Device_Online_bit) + \ (LogType_Global_Parameters_SWITCH << LogType_Global_Parameters_bit) + \ (LogType_Net_COMM_SWITCH << LogType_Net_COMM_bit) + \ (LogType_Logic_Record_SWITCH << LogType_Logic_Record_bit); /******************************************************************************* * Function Name : LOG_Launcher_APP_Check_Record * Description : Launcher类型 - 校验APP * Input : state :状态 0x00:相同 0x01:不同 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Launcher_APP_Check_Record(uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) ) { uint8_t temp_buff[3] = {0}; temp_buff[0] = LLauncher_App_Check; temp_buff[1] = state; Log_write_sram(LogType_Launcher,temp_buff,2); } } /******************************************************************************* * Function Name : LOG_Launcher_APP_Check_Record * Description : Launcher类型 - 校验APP * Input : state :状态 0x00:成功 0x01:失败 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Launcher_Read_App_Record(uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) ) { uint8_t temp_buff[3] = {0}; temp_buff[0] = LLauncher_Read_App; temp_buff[1] = state; Log_write_sram(LogType_Launcher,temp_buff,2); } } /******************************************************************************* * Function Name : LOG_Launcher_Write_Flash_Record * Description : Launcher类型 - Flash写入 * Input : addr :写入地址 len :写入长度 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Launcher_Write_Flash_Record(uint32_t addr,uint16_t len) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) ) { uint8_t temp_buff[7] = {0}; temp_buff[0] = LLauncher_Write_Flash; temp_buff[1] = addr & 0xFF; temp_buff[2] = (addr >> 8) & 0xFF; temp_buff[3] = (addr >> 16) & 0xFF; temp_buff[4] = (addr >> 24) & 0xFF; temp_buff[5] = len & 0xFF; temp_buff[6] = (len >> 8) & 0xFF; Log_write_sram(LogType_Launcher,temp_buff,7); } } /******************************************************************************* * Function Name : LOG_Launcher_Factory_Reset_Record * Description : Launcher类型 - 恢复出厂设置 * Input : * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Launcher_Factory_Reset_Record(void) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) ) { uint8_t temp_buff[3] = {0}; temp_buff[0] = LLauncher_Factory_Reset; temp_buff[1] = 0x00; Log_write_sram(LogType_Launcher,temp_buff,2); } } /******************************************************************************* * Function Name : LOG_SYS_PHY_Change_Record * Description : SYS_Record类型 - PHY状态记录 * Input : state :状态 0x00:拔出 0x01:插入 0x02:TCP超时 0x03:TCP断开 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_PHY_Change_Record(uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[3] = {0}; temp_buff[0] = LSYS_PHY_Change; temp_buff[1] = state; Log_write_sram(LogType_SYS_Record,temp_buff,2); } } /******************************************************************************* * Function Name : LOG_SYS_DevInfo_Error_Record * Description : SYS_Record类型 - 设备链表读取信息错误记录 * Input : dev :设备类型 addr :设备地址 info_addr :设备链表信息存储地址 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_DevInfo_Error_Record(uint8_t dev,uint8_t addr,uint32_t info_addr) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[8] = {0}; temp_buff[0] = LSYS_DevInfo_Error; temp_buff[1] = dev; temp_buff[2] = addr; temp_buff[3] = info_addr & 0xFF; temp_buff[4] = (info_addr >> 8) & 0xFF; temp_buff[5] = (info_addr >> 16) & 0xFF; temp_buff[6] = (info_addr >> 24) & 0xFF; Log_write_sram(LogType_SYS_Record,temp_buff,7); } } /******************************************************************************* * Function Name : LOG_SYS_API_State_Record * Description : SYS_Record类型 - API状态记录 * Input : API_way :升级方式 0x01:串口 0x02:网络 state :状态 0x01:写入成功 0x02:写入失败 0x03:文件块数错误 0x04:MD5校验错误 0x05:CRC校验错误 0x06:跳转Launcher * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_API_State_Record(uint8_t API_way,uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[8] = {0}; uint8_t temp_len = 0; temp_buff[temp_len++] = LSYS_API_State; temp_buff[temp_len++] = API_way; temp_buff[temp_len++] = state; Log_write_sram(LogType_SYS_Record,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_SYS_NET_Argc_Record * Description : SYS_Record类型 - 网络参数记录 * Input : IP :当前网络IP地址 - 4Byte MAC :当前网络MAC地址 - 4Byte DNS_IP1 :DNS解析域名IP1 - 云端服务器 - 4Byte DNS_IP2 :DNS解析域名IP2 - TFTP服务器 - 4Byte DNS_IP3 :DNS解析域名IP3 - MQTT服务器 - 4Byte * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_NET_Argc_Record(uint8_t *IP,uint8_t *MAC,uint8_t *DNS_IP1,uint8_t *DNS_IP2,uint8_t *DNS_IP3) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[40] = {0}; uint8_t temp_len = 0; temp_buff[temp_len++] = LSYS_NET_ARGC; temp_buff[temp_len++] = IP[0]; temp_buff[temp_len++] = IP[1]; temp_buff[temp_len++] = IP[2]; temp_buff[temp_len++] = IP[3]; temp_buff[temp_len++] = MAC[0]; temp_buff[temp_len++] = MAC[1]; temp_buff[temp_len++] = MAC[2]; temp_buff[temp_len++] = MAC[3]; temp_buff[temp_len++] = MAC[4]; temp_buff[temp_len++] = MAC[5]; temp_buff[temp_len++] = DNS_IP1[0]; temp_buff[temp_len++] = DNS_IP1[1]; temp_buff[temp_len++] = DNS_IP1[2]; temp_buff[temp_len++] = DNS_IP1[3]; temp_buff[temp_len++] = DNS_IP2[0]; temp_buff[temp_len++] = DNS_IP2[1]; temp_buff[temp_len++] = DNS_IP2[2]; temp_buff[temp_len++] = DNS_IP2[3]; temp_buff[temp_len++] = DNS_IP3[0]; temp_buff[temp_len++] = DNS_IP3[1]; temp_buff[temp_len++] = DNS_IP3[2]; temp_buff[temp_len++] = DNS_IP3[3]; Log_write_sram(LogType_SYS_Record,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_SYS_MQTT_Argc_Record * Description : SYS_Record类型 - MQTT参数记录 * Input : productkey :产品秘钥 - 12Byte devname :设备名 - 65Byte devsecret :设备秘钥 - 33Byte publish :发布地址 - 65Byte sublish :订阅地址 - 65Byte * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_MQTT_Argc_Record(uint8_t *productkey,uint8_t *devname,uint8_t *devsecret,uint8_t *publish,uint8_t *sublish) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LSYS_MQTT_ARGC; for(uint8_t i=0;i<12;i++) { Temp_Flash_Buff[temp_len++] = productkey[i]; } for(uint8_t i=0;i<65;i++) { Temp_Flash_Buff[temp_len++] = devname[i]; } for(uint8_t i=0;i<33;i++) { Temp_Flash_Buff[temp_len++] = devsecret[i]; } for(uint8_t i=0;i<65;i++) { Temp_Flash_Buff[temp_len++] = publish[i]; } for(uint8_t i=0;i<65;i++) { Temp_Flash_Buff[temp_len++] = sublish[i]; } Log_write_sram(LogType_SYS_Record,Temp_Flash_Buff,temp_len); } } /******************************************************************************* * Function Name : LOG_SYS_Server_Comm_State_Record * Description : SYS_Record类型 - 云端通讯状态记录 * Input : state :状态 0x00:离线 0x01:在线 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_Server_Comm_State_Record(uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[8] = {0}; uint8_t temp_len = 0; temp_buff[temp_len++] = LSYS_Server_Comm_State; temp_buff[temp_len++] = state; Log_write_sram(LogType_SYS_Record,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_SYS_NET_Argc_Record * Description : SYS_Record类型 - 网络初始化前参数记录 * Input : IP :默认网络IP地址 - 4Byte Gateway :默认网络网关地址 - 4Byte IP_Mask :默认网络子网掩码 - 4Byte DNS_Add :DNS地址 - 4Byte ArgcFlag :网络参数标志 - 1Byte DHCPFlag :DHCP使能标志 - 1Byte ServerFlag :服务器标志 - 1Byte * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_NET_Argc_Init_Record(uint8_t *IP,uint8_t *Gateway,uint8_t *IP_Mask,uint8_t *DNS_Add,uint8_t ArgcFlag,uint8_t DHCPFlag,uint8_t ServerFlag) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[40] = {0}; uint8_t temp_len = 0; temp_buff[temp_len++] = LSYS_NET_DefaultARGC; temp_buff[temp_len++] = IP[0]; temp_buff[temp_len++] = IP[1]; temp_buff[temp_len++] = IP[2]; temp_buff[temp_len++] = IP[3]; temp_buff[temp_len++] = Gateway[0]; temp_buff[temp_len++] = Gateway[1]; temp_buff[temp_len++] = Gateway[2]; temp_buff[temp_len++] = Gateway[3]; temp_buff[temp_len++] = IP_Mask[0]; temp_buff[temp_len++] = IP_Mask[1]; temp_buff[temp_len++] = IP_Mask[2]; temp_buff[temp_len++] = IP_Mask[3]; temp_buff[temp_len++] = DNS_Add[0]; temp_buff[temp_len++] = DNS_Add[1]; temp_buff[temp_len++] = DNS_Add[2]; temp_buff[temp_len++] = DNS_Add[3]; temp_buff[temp_len++] = ArgcFlag; temp_buff[temp_len++] = DHCPFlag; temp_buff[temp_len++] = ServerFlag; Log_write_sram(LogType_SYS_Record,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_SYS_NET_Argc_Record * Description : SYS_Record类型 - 网络初始化前参数记录 * Input : state:状态 0x01:点按 0x02:长按 0x03:长按松开 0x04:达到恢复出厂设置状态 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_SYS_RCUKey_State_Record(uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_SYS_Record_bit )) ) { uint8_t temp_buff[5] = {0}; uint8_t temp_len = 0; temp_buff[temp_len++] = LSYS_RCUKey_State; temp_buff[temp_len++] = state; Log_write_sram(LogType_SYS_Record,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_Device_COMM_ASK_TO_Reply_Record * Description : Device_COMM类型 - RCU轮询回复变化数据记录 * Input : port :端口号 baud :通讯波特率 data_tick :询问时间戳 buff :数据 len :数据长度 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Device_COMM_ASK_TO_Reply_Record(uint8_t port,uint32_t baud,uint32_t data_tick,uint8_t *buff,uint16_t len) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Device_COMM_bit )) ) { uint16_t buff_len = len ; if(buff_len >= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_ASK_TO_Reply; Temp_Flash_Buff[temp_len++] = port; Temp_Flash_Buff[temp_len++] = baud & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 8) & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 16) & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 24) & 0xFF; for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_ASK_TO_Reply; Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(port_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 1); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 2); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 3); for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_Send_Control; Temp_Flash_Buff[temp_len++] = port; Temp_Flash_Buff[temp_len++] = baud & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 8) & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 16) & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 24) & 0xFF; for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_Send_Control; Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(port_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 1); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 2); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 3); for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_Control_Reply; Temp_Flash_Buff[temp_len++] = port; Temp_Flash_Buff[temp_len++] = baud & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 8) & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 16) & 0xFF; Temp_Flash_Buff[temp_len++] = (baud >> 24) & 0xFF; for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_Control_Reply; Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(port_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 1); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 2); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 3); for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LCOMM_Control_Reply; Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(port_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 1); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 2); Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(baud_addr + 3); for(uint16_t i=0;i> 8) & 0xFF; temp_buff[temp_len++] = (baud >> 16) & 0xFF; temp_buff[temp_len++] = (baud >> 24) & 0xFF; temp_buff[temp_len++] = way; temp_buff[temp_len++] = fail_num; temp_buff[temp_len++] = sum; temp_buff[temp_len++] = num; Log_write_sram(LogType_Device_COMM,temp_buff,temp_len); } } __attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Adjust_Baud_Record2(uint32_t dev_type,uint32_t dev_addr,uint32_t baud_addr) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Device_COMM_bit )) ) { uint8_t temp_buff[8]; uint16_t temp_len = 0; memset(temp_buff,0,sizeof(temp_buff)); temp_buff[temp_len++] = LCOMM_Adjust_Baud; temp_buff[temp_len++] = SRAM_Read_Byte(dev_type); temp_buff[temp_len++] = SRAM_Read_Byte(dev_addr); temp_buff[temp_len++] = SRAM_Read_Byte(baud_addr); temp_buff[temp_len++] = SRAM_Read_Byte(baud_addr + 1); temp_buff[temp_len++] = SRAM_Read_Byte(baud_addr + 2); temp_buff[temp_len++] = SRAM_Read_Byte(baud_addr + 3); Log_write_sram(LogType_Device_COMM,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_Device_Online_Record * Description : Device_Online类型 - 设备离线记录 * Input : dev :设备类型 addr :设备地址 state :设备状态 - 0x00:离线,0x01:设备在线 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Device_Online_Record(uint8_t dev,uint8_t addr,uint8_t state) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Device_Online_bit )) ) { uint8_t temp_buff[6]; uint16_t temp_len = 0; memset(temp_buff,0,sizeof(temp_buff)); temp_buff[temp_len++] = dev; temp_buff[temp_len++] = addr; temp_buff[temp_len++] = state; Log_write_sram(LogType_Device_Online,temp_buff,temp_len); } } /******************************************************************************* * Function Name : LOG_Global_ParaInfo_Record * Description : Global_Parameters类型 - 全局参数记录 定期10分钟记录 * Input : buff :设备类型 len :设备地址 * Return : None *******************************************************************************/ __attribute__((section(".non_0_wait"))) void LOG_Global_ParaInfo_Record(uint8_t *buff,uint16_t len) { if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Global_Parameters_bit )) ) { uint16_t buff_len = len ; if(buff_len >= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LGlobal_Para; for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LGlobal_Dev; for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LNetComm_Send; Temp_Flash_Buff[temp_len++] = SocketId; Temp_Flash_Buff[temp_len++] = ip[0]; Temp_Flash_Buff[temp_len++] = ip[1]; Temp_Flash_Buff[temp_len++] = ip[2]; Temp_Flash_Buff[temp_len++] = ip[3]; Temp_Flash_Buff[temp_len++] = (port) & 0xFF; Temp_Flash_Buff[temp_len++] = (port >> 8) & 0xFF; for(uint16_t i=0;i= 512) buff_len = 512; //记录长度最长512Byte uint16_t temp_len = 0; memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff)); Temp_Flash_Buff[temp_len++] = LNetComm_Recv; Temp_Flash_Buff[temp_len++] = SocketId; Temp_Flash_Buff[temp_len++] = ip[0]; Temp_Flash_Buff[temp_len++] = ip[1]; Temp_Flash_Buff[temp_len++] = ip[2]; Temp_Flash_Buff[temp_len++] = ip[3]; Temp_Flash_Buff[temp_len++] = (port) & 0xFF; Temp_Flash_Buff[temp_len++] = (port >> 8) & 0xFF; for(uint16_t i=0;i