Files
RCU_C1P_Module/MCU_Driver/log_api.c
caocong d2d8800788 feat:新建项目文件
BLV主机C1P模块
2025-12-06 13:49:01 +08:00

867 lines
30 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/***********************************新日志数据存储函数 - 提供各种类型保存调用函数***************************************/
#include "rw_logging.h"
#include "SPI_SRAM.h"
#include "Log_api.h"
#include "string.h"
#include "spi_flash.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_ASK_TO_Reply_Record2(uint32_t port_addr,uint32_t baud_addr,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++] = 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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
/*******************************************************************************
* Function Name : LOG_Device_COMM_Send_Control_Record
* Description : Device_COMM类型 - RCU下发控制数据记录
* Input :
port :端口号
baud :通讯波特率
buff :数据
len :数据长度
* Return : None
*******************************************************************************/
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Send_Control_Record(uint8_t port,uint32_t baud,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_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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Send_Control_Record2(uint32_t port_addr,uint32_t baud_addr,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_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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
/*******************************************************************************
* Function Name : LOG_Device_COMM_Control_Reply_Record
* Description : Device_COMM类型 - RCY控制回复数据记录
* Input :
port :端口号
baud :通讯波特率
buff :数据
len :数据长度
* Return : None
*******************************************************************************/
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Control_Reply_Record(uint8_t port,uint32_t baud,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_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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Control_Reply_Record2(uint32_t port_addr,uint32_t baud_addr,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_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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Control_Reply_Record3(uint32_t port_addr,uint32_t baud_addr,uint32_t buff_addr,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_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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = SRAM_Read_Byte(buff_addr + i);
}
Log_write_sram(LogType_Device_COMM,Temp_Flash_Buff,temp_len);
}
}
/*******************************************************************************
* Function Name : LOG_Device_COMM_Adjust_Baud_Record
* Description : Device_COMM类型 - 设备波特率调整
* Input :
dev_type :设备类型
dev_addr :设备地址
baud :通讯波特率
way :改变方式0x01:连续通讯失败达到上限,0x02:通讯失败次数达到百分比上限
fail_num :失败次数
sum :总包数
num :当前通讯下标
* Return : None
*******************************************************************************/
__attribute__((section(".non_0_wait"))) void LOG_Device_COMM_Adjust_Baud_Record(uint8_t dev_type,uint8_t dev_addr,uint32_t baud,uint8_t way,uint8_t fail_num,uint8_t sum,uint8_t num)
{
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Device_COMM_bit )) )
{
uint8_t temp_buff[12];
uint16_t temp_len = 0;
memset(temp_buff,0,sizeof(temp_buff));
temp_buff[temp_len++] = LCOMM_Adjust_Baud;
temp_buff[temp_len++] = dev_type;
temp_buff[temp_len++] = dev_addr;
temp_buff[temp_len++] = baud & 0xFF;
temp_buff[temp_len++] = (baud >> 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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Global_Parameters,Temp_Flash_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_DevInfo_Record(uint8_t *buff,uint16_t len)
{
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Global_Parameters_bit )) )
{
uint16_t buff_len = len ;
uint16_t temp_len = 0;
if(buff_len >= 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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Global_Parameters,Temp_Flash_Buff,temp_len);
}
}
/*******************************************************************************
* Function Name : LOG_NET_COMM_Record
* Description : Net_COMM类型 - 网络通讯记录
* Input :
SocketId:套接字序号(1~4)
ip :接收的IP地址
port :接收的Port
buff :处理数据
len :数据长度
* Return : None
*******************************************************************************/
__attribute__((section(".non_0_wait"))) void LOG_NET_COMM_Send_Record(uint8_t SocketId,uint8_t *ip,uint16_t port,uint8_t *buff,uint16_t len)
{
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Net_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++] = 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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Net_COMM,Temp_Flash_Buff,temp_len);
}
}
/*******************************************************************************
* Function Name : LOG_NET_COMM_Record
* Description : Net_COMM类型 - 网络通讯记录
* Input :
SocketId:套接字序号(1~4)
ip :接收的IP地址
port :接收的Port
buff :处理数据
len :数据长度
* Return : None
*******************************************************************************/
__attribute__((section(".non_0_wait"))) void LOG_NET_COMM_Recv_Record(uint8_t SocketId,uint8_t *ip,uint16_t port,uint8_t *buff,uint16_t len)
{
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Net_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++] = 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<buff_len;i++)
{
Temp_Flash_Buff[temp_len++] = buff[i];
}
Log_write_sram(LogType_Net_COMM,Temp_Flash_Buff,temp_len);
}
}
/*******************************************************************************
* Function Name : LOG_LogicInfo_DebugRecord
* Description : Logic_Rec类型 - 逻辑信息 调试记录
* Input :
buff :处理数据
len :数据长度
* Return : None
*******************************************************************************/
__attribute__((section(".non_0_wait"))) void LOG_LogicInfo_DebugRecord(char *fmt,...)
{
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Logic_Record_bit )) )
{
uint16_t temp_len = 0;
memset(Temp_Flash_Buff,0,sizeof(Temp_Flash_Buff));
Temp_Flash_Buff[temp_len++] = LLogic_DebugString;
va_list ap; //定义一个char类型指针
va_start(ap, fmt); //指针地址赋值--初始化
//将参数列表里所有参数,按照格式化转换成字符串-存放到str指向的空间
temp_len += vsnprintf((char *)&Temp_Flash_Buff[1],512,fmt,ap);
va_end(ap); //将ap指针置为NULL
Log_write_sram(LogType_Logic_Record,(uint8_t *)Temp_Flash_Buff,temp_len);
}
}