Commit 5459550e authored by limm's avatar limm

1,修复死机问题改为复位;

2,修复退出老化方式;
3,增加三个设备绑定,解绑操作;
parent 1de4b7b1
...@@ -88,7 +88,7 @@ typedef enum{ ...@@ -88,7 +88,7 @@ typedef enum{
#define DisplayCharB 0x73 // ??? #define DisplayCharB 0x73 // ???
#define DisplayCharE 0x79 // E #define DisplayCharE 0x79 // E
#define DisplayCharF 0x78 // F #define DisplayCharF 0x78 // F
#define DisplayCharr 0x58 // r #define DisplayCharr 0x30 // r
#define DisplayCharL 0x51 #define DisplayCharL 0x51
#define DisplayCharo 0x33 #define DisplayCharo 0x33
......
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
#include <stdint.h> #include <stdint.h>
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
//#define USATR_1_DEBUG 1 //#define USATR_1_DEBUG 1
#if (USATR_1_DEBUG == 1) #if (USATR_1_DEBUG == 1)
...@@ -68,7 +66,7 @@ typedef enum {TP_ERROR = 0, TP_SUCCESS = !TP_ERROR} TP_ErrorStatus; ...@@ -68,7 +66,7 @@ typedef enum {TP_ERROR = 0, TP_SUCCESS = !TP_ERROR} TP_ErrorStatus;
#define SOF_LOW_BYTE_DEF 0X55 #define SOF_LOW_BYTE_DEF 0X55
#define USART_RECIVE_LEN_DEF 40 //串口最多一次接受的数据量 #define USART_RECIVE_LEN_DEF 40 //串口最多一次接受的数据量
#define USART_RECIVE_DEPTH 5 //缓存的深度 #define USART_RECIVE_DEPTH 3 //缓存的深度
//透传数据接受最大间隔时间,超时未接收到数据,停止一串数据接收 //透传数据接受最大间隔时间,超时未接收到数据,停止一串数据接收
#define DEF_TRANSPARENT_MAXIMUM_INTERVAL 100 //(ms) #define DEF_TRANSPARENT_MAXIMUM_INTERVAL 100 //(ms)
...@@ -100,17 +98,14 @@ typedef struct _Recive_usart_data_deal ...@@ -100,17 +98,14 @@ typedef struct _Recive_usart_data_deal
//homebuf buf缓存 //homebuf buf缓存
#define _IO volatile /*!< Defines 'read / write' permissions */
typedef struct _Recive_usart_buff typedef struct _Recive_usart_buff
{ {
TP_u8 Usart_buff[USART_RECIVE_DEPTH][USART_RECIVE_LEN_DEF]; //homebus 缓存存放区 TP_u8 Usart_buff[USART_RECIVE_DEPTH][USART_RECIVE_LEN_DEF]; //homebus 缓存存放区
_IO TP_u8 Usart_buff_len[USART_RECIVE_DEPTH]; //homebus 缓存区长度
TP_u8 Usart_buff_len[USART_RECIVE_DEPTH]; //homebus 缓存区长度 _IO TP_u8 Buff_send_serial_num; //BUFF发送序列
_IO TP_u8 Download_serial_num; //BUFF缓存序列
TP_u8 Buff_send_serial_num; //BUFF发送序列
TP_u8 Download_serial_num; //BUFF缓存序列
}RECIVE_USART_BUFF; }RECIVE_USART_BUFF;
//协议中的功能码 //协议中的功能码
......
...@@ -106,8 +106,8 @@ extern TIMEING_OPTION _Time_Power_Off; ...@@ -106,8 +106,8 @@ extern TIMEING_OPTION _Time_Power_Off;
#define ENABLE_FAST_AGING_TEST 0 #define ENABLE_FAST_AGING_TEST 0
#if ENABLE_FAST_AGING_TEST #if ENABLE_FAST_AGING_TEST
#define FAST_AGING_STEP1_TIME 60 //1min #define FAST_AGING_STEP1_TIME (60) //1min
#define FAST_AGING_STEP2_TIME 150 //2.5min #define FAST_AGING_STEP2_TIME (3*60) //2.5min
#else #else
#define FAST_AGING_STEP1_TIME (15*60) //15min #define FAST_AGING_STEP1_TIME (15*60) //15min
#define FAST_AGING_STEP2_TIME (60*60*4) //4h #define FAST_AGING_STEP2_TIME (60*60*4) //4h
...@@ -276,6 +276,7 @@ void delay_operate_calibrate_temper_Task_Stop(void); ...@@ -276,6 +276,7 @@ void delay_operate_calibrate_temper_Task_Stop(void);
void delay_operate_delay_off_Task_Start(void); void delay_operate_delay_off_Task_Start(void);
void delay_operate_delay_off_Task_Stop(void); void delay_operate_delay_off_Task_Stop(void);
void Reset_DelayOFF_timer(u8 device_type); void Reset_DelayOFF_timer(u8 device_type);
void task_exit_aging_test_start(void);
#define Network_Control(join_or_leave) Send_Device_Data(0,_OPCODE_SET_NET_STATE,&join_or_leave,1) #define Network_Control(join_or_leave) Send_Device_Data(0,_OPCODE_SET_NET_STATE,&join_or_leave,1)
#define proximity_triagger_report_zigbee() do{ uint8_t res = 1; \ #define proximity_triagger_report_zigbee() do{ uint8_t res = 1; \
......
...@@ -54,6 +54,8 @@ typedef struct ...@@ -54,6 +54,8 @@ typedef struct
u16 screen_save_time; //屏保时间 00 代表30 u16 screen_save_time; //屏保时间 00 代表30
u16 filter_wash_time; //滤网清洗时间 3000 u16 filter_wash_time; //滤网清洗时间 3000
u8 no_disturb_mode; //勿扰模式 0 u8 no_disturb_mode; //勿扰模式 0
u8 air_product_id;
u8 air_type;
}OLED_AIR_DSD; }OLED_AIR_DSD;
typedef struct typedef struct
{ {
...@@ -173,6 +175,7 @@ void delay_confirm_fan_speed(void); // ...@@ -173,6 +175,7 @@ void delay_confirm_fan_speed(void); //
void Control_LED_ON_OFF(u8 onoff_bits); void Control_LED_ON_OFF(u8 onoff_bits);
u8 Key_Operate_Config_Operation(u8 keyid,u8 keyEvent); u8 Key_Operate_Config_Operation(u8 keyid,u8 keyEvent);
u8 IsLocalConfigMode(void); u8 IsLocalConfigMode(void);
u8 kAllLedIsBlinking(void);
void Display_Up_Contend(u8 device_type); void Display_Up_Contend(u8 device_type);
void Setup_Mode_Handle (void); void Setup_Mode_Handle (void);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __HARDWARE_INIT_H__ #define __HARDWARE_INIT_H__
#include "Key.h" #include "Key.h"
#define Flash_Base_Addr 0x00007000 #define Flash_Base_Addr 0x00007400
#define NO_FMC_WRITE 0xFFFFFFFF #define NO_FMC_WRITE 0xFFFFFFFF
#define OFFSET_ADDR 4 #define OFFSET_ADDR 4
#define BYTE_ADDR 8 #define BYTE_ADDR 8
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#define SOF_HIGH_BYTE_DEF 0XAA #define SOF_HIGH_BYTE_DEF 0XAA
#define SOF_LOW_BYTE_DEF 0X55 #define SOF_LOW_BYTE_DEF 0X55
#define MAX_USART_RECIVE_LEN 50 //串口最多一次接受的数据量 #define MAX_USART_RECIVE_LEN 56 //串口最多一次接受的数据量
#define USART_RECIVE_DEPTHS 5 //缓存的深度 #define USART_RECIVE_DEPTHS 3 //缓存的深度
...@@ -55,14 +55,10 @@ typedef struct ...@@ -55,14 +55,10 @@ typedef struct
typedef struct typedef struct
{ {
TP_u8 Usart_buff[USART_RECIVE_DEPTH][MAX_USART_RECIVE_LEN]; //homebus 缓存存放区 TP_u8 Usart_buff[USART_RECIVE_DEPTHS][MAX_USART_RECIVE_LEN]; //homebus 缓存存放区
_IO TP_u8 Usart_buff_len[USART_RECIVE_DEPTHS]; //homebus 缓存区长度
TP_u8 Usart_buff_len[USART_RECIVE_DEPTHS]; //homebus 缓存区长度 _IO TP_u8 Buff_send_serial_num; //BUFF发送序列
_IO TP_u8 Download_serial_num; //BUFF缓存序列
TP_u8 Buff_send_serial_num; //BUFF发送序列
TP_u8 Download_serial_num; //BUFF缓存序列
}RECIVE_USART_DATA_BUFF; }RECIVE_USART_DATA_BUFF;
//协议中的功能码 //协议中的功能码
typedef struct typedef struct
...@@ -85,10 +81,10 @@ typedef struct ...@@ -85,10 +81,10 @@ typedef struct
void uart0_data_deal_init(void); void uart0_data_deal_init(void);
void uart_msg_deal(void); void uart_msg_deal(void);
void proximity_triagger_report(void); void proximity_triagger_report(void);
u8 Usart_recive_deal(TP_uc8 *data,TP_uc16 len); u8 Usart_recive_deal(TP_uc8 *data,TP_uc8 len);
u8 uart_msg_recive(u8 RcvChar); u8 uart_msg_recive(u8 RcvChar);
void ack_info(PROTOCOL_DEAL recv_data, TP_uc8* arg, TP_u8 len); void ack_info(PROTOCOL_DEAL recv_data, TP_uc8* arg, TP_u8 len);
TP_u16 CreateCrc16_Self(const u8* msg, TP_u32 len) ; TP_u16 CreateCrc16_Self(const u8* msg, TP_u8 len) ;
static void send_crc_error_data(TP_u16 seq_data); static void send_crc_error_data(TP_u16 seq_data);
void uart_protocol_send(PROTOCOL_SEND_MSG send_protocol,TP_u16 SEQ); void uart_protocol_send(PROTOCOL_SEND_MSG send_protocol,TP_u16 SEQ);
#endif #endif
......
...@@ -75,6 +75,11 @@ Lcd_Status_Info_t LCDAutoSystemModeSettingIconCTR_t = ...@@ -75,6 +75,11 @@ Lcd_Status_Info_t LCDAutoSystemModeSettingIconCTR_t =
u16 guSetLCDShowTime = SysLCDShowTimer; u16 guSetLCDShowTime = SysLCDShowTimer;
#if 1 // add by dingmz_frc.20201215
extern u8 g_u8Temp_Buffer[];
extern u8 g_u8Temp_Length;
#endif
void PWM_init(void) void PWM_init(void)
{ {
// PWM0 frequency is 100Hz, duty 30%, // PWM0 frequency is 100Hz, duty 30%,
...@@ -102,113 +107,119 @@ u16 GetLCDShowTime( void ) ...@@ -102,113 +107,119 @@ u16 GetLCDShowTime( void )
void BL55072A_Init(uint8_t slaver_addr,u32 freq) void BL55072A_Init(uint8_t slaver_addr,u32 freq)
{ {
u8 err = 0xff; u8 err = 0xff;
u8 Send_Buffer[10] = {0}; //u8 Send_Buffer[10] = {0};
u8 length = 0; //u8 length = 0;
g_u8slaver_addr = slaver_addr; g_u8slaver_addr = slaver_addr;
I2C_SW_Open(freq); I2C_SW_Open(freq);
CLK_SysTickDelay(5000); //delay 5ms CLK_SysTickDelay(5000); //delay 5ms
Send_Buffer[length++] = BL55072A_CMD_APCTL_OFF; g_u8Temp_Length = 0;
Send_Buffer[length++] = BL55072A_CMD_MODESET_ON; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_APCTL_OFF;
Send_Buffer[length++] = BL55072A_CMD_ICSET_RST; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON;
Send_Buffer[length++] = BL55072A_CMD_DISCTL_PSM1; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET_RST;
Send_Buffer[length++] = BL55072A_CMD_ICSET; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
err = I2C_SW_Send(g_u8slaver_addr,Send_Buffer,length); err = I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
printf("Bl55072A init err = (%d),length = (%d)\r\n", err, length); //printf("Bl55072A init err = (%d),length = (%d)\r\n", err, length);
} }
void BL55072A_DisplayON(void) void BL55072A_DisplayON(void)
{ {
uint8_t buffer[20] = {0}; //uint8_t buffer[20] = {0};
uint8_t length = 0; //uint8_t length = 0;
buffer[length++] = BL55072A_CMD_APCTL_OFF; g_u8Temp_Length = 0;
buffer[length++] = BL55072A_CMD_DISCTL_PSM1; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_APCTL_OFF;
buffer[length++] = BL55072A_CMD_ICSET; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
buffer[length++] = BL55072A_CMD_BLKCTL_OFF; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
buffer[length++] = 0xFC; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_BLKCTL_OFF;
buffer[length++] = BL55072A_CMD_MODESET_ON & 0x7F; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFC;
g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON & 0x7F;
I2C_SW_Send(g_u8slaver_addr,buffer,length); I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
//printf("BL55072A Display ON err = (%d),length = (%d)\r\n", err, length); //printf("BL55072A Display ON err = (%d),length = (%d)\r\n", err, length);
} }
void BL55072A_Clear(void) void BL55072A_Clear(void)
{ {
uint8_t buffer[20] = {0}; //uint8_t buffer[20] = {0};
uint8_t length = 0; //uint8_t length = 0;
buffer[length++] = BL55072A_CMD_DISCTL_PSM1; g_u8Temp_Length = 0;
buffer[length++] = BL55072A_CMD_BLKCTL_OFF; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
buffer[length++] = 0xFC; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_BLKCTL_OFF;
buffer[length++] = BL55072A_CMD_MODESET_ON; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFC;
buffer[length++] = BL55072A_CMD_ICSET; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON;
buffer[length++] = BL55072A_CMD_ADSET; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ADSET;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
buffer[length++] = 0x00; g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
I2C_SW_Send(g_u8slaver_addr,buffer,length); I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
//printf("BL55072A Display Test err = (%d),length = (%d)\r\n", err, length); //printf("BL55072A Display Test err = (%d),length = (%d)\r\n", err, length);
} }
void BL55072A_DisplayALL(void) void BL55072A_DisplayALL(void)
{ {
u8 Send_Buffer[20] = {0}; //u8 Send_Buffer[20] = {0};
u8 length = 0; //u8 length = 0;
Send_Buffer[length++] = BL55072A_CMD_DISCTL_PSM1; g_u8Temp_Length = 0;
Send_Buffer[length++] = BL55072A_CMD_BLKCTL_OFF; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
Send_Buffer[length++] = 0xFE; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_BLKCTL_OFF;
Send_Buffer[length++] = BL55072A_CMD_MODESET_ON; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFE;
Send_Buffer[length++] = BL55072A_CMD_ICSET; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON;
Send_Buffer[length++] = BL55072A_CMD_ADSET; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ADSET;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
Send_Buffer[length++] = 0xFF; g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
I2C_SW_Send(g_u8slaver_addr,Send_Buffer,length); I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
//printf("BL55072A Display Test err = (%d),length = (%d)\r\n", err, length); //printf("BL55072A Display Test err = (%d),length = (%d)\r\n", err, length);
} }
static u8 Buffer_Temp[5] = {0};
u8 BL55072A_ReadByte(u8 addr) u8 BL55072A_ReadByte(u8 addr)
{ {
u8 buffer[4] = {0}; static u8 tmp = 0;
u8 length = 0;
u8 tmp; memset(Buffer_Temp,0,sizeof(Buffer_Temp));
Buffer_Temp[0] = BL55072A_CMD_ICSET;
buffer[length++] = BL55072A_CMD_ICSET; Buffer_Temp[1] = BL55072A_CMD_ADSET | addr | 0x80; //cmd end
buffer[length++] = BL55072A_CMD_ADSET | addr | 0x80; //cmd end I2C_SW_Send(g_u8slaver_addr, Buffer_Temp, 2);
I2C_SW_Send(g_u8slaver_addr, buffer, length);
I2C_SW_Get_Without_Delay(g_u8slaver_addr,(u8 *)&tmp,1); I2C_SW_Get_Without_Delay(g_u8slaver_addr,(u8 *)&tmp,1);
return (tmp&0xff); return (tmp&0xff);
} }
void BL55072A_DisplayGeneral(u8 addr,u8 control_bits,u8 display_bits) void BL55072A_DisplayGeneral(u8 addr,u8 control_bits,u8 display_bits)
{ {
u8 buffer[6] = {0}; static u8 Data = 0;
u8 length = 0; static u8 i = 0;
u8 Data = 0; static u8 tmp = 0;
u8 i = 0; memset(Buffer_Temp,0,sizeof(Buffer_Temp));
u8 tmp = BL55072A_ReadByte(addr); i = Data = 0;
tmp = BL55072A_ReadByte(addr);
//printf("BL55072A_DisplayGeneral,Process Before TMP DATA = %x\r\n", tmp); //printf("BL55072A_DisplayGeneral,Process Before TMP DATA = %x\r\n", tmp);
buffer[length++] = BL55072A_CMD_ICSET; Buffer_Temp[0] = BL55072A_CMD_ICSET;
buffer[length++] = BL55072A_CMD_ADSET | addr; //cmd end Buffer_Temp[1] = BL55072A_CMD_ADSET | addr; //cmd end
for(i = 0;i<4;i++) for(i = 0;i<4;i++)
{ {
...@@ -228,8 +239,8 @@ void BL55072A_DisplayGeneral(u8 addr,u8 control_bits,u8 display_bits) ...@@ -228,8 +239,8 @@ void BL55072A_DisplayGeneral(u8 addr,u8 control_bits,u8 display_bits)
} }
tmp = ((tmp&0x0f) | (Data<<4) ); tmp = ((tmp&0x0f) | (Data<<4) );
//printf("BL55072A_DisplayGeneral,Process After TMP=%x, DATA = %x\r\n",tmp, Data); //printf("BL55072A_DisplayGeneral,Process After TMP=%x, DATA = %x\r\n",tmp, Data);
buffer[length++] = tmp; //cmd end Buffer_Temp[2] = tmp; //cmd end
I2C_SW_Send(g_u8slaver_addr, buffer, length); I2C_SW_Send(g_u8slaver_addr, Buffer_Temp, 3);
//printf("BL55072A_DisplayGeneral,err = (%d),length = (%d)\r\n", err, length); //printf("BL55072A_DisplayGeneral,err = (%d),length = (%d)\r\n", err, length);
} }
......
...@@ -32,7 +32,6 @@ readme: 使 ...@@ -32,7 +32,6 @@ readme: 使
#include "hardware_init.h" #include "hardware_init.h"
#include "Key.h" #include "Key.h"
/************************************************************************************************************** /**************************************************************************************************************
此文件内部使用,不允许外部使用,不用更改 此文件内部使用,不允许外部使用,不用更改
***************************************************************************************************************/ ***************************************************************************************************************/
...@@ -44,13 +43,13 @@ static TP_u32 status_check_time = 0x00; ...@@ -44,13 +43,13 @@ static TP_u32 status_check_time = 0x00;
static void send_crc_error(TP_u16 seq_data); static void send_crc_error(TP_u16 seq_data);
static TP_u8 Usart_recive_write_buff(TP_uc8 *data,TP_uc16 len); static TP_u8 Usart_recive_write_buff(TP_uc8 *data,TP_uc16 len);
TP_u16 CreateCrc16(TP_uc8* msg, TP_u32 len); TP_u16 CreateCrc16(TP_uc8* msg, TP_u8 len);
static void (*uart_data_send)(TP_uc8* msg,TP_u32 len); static void (*uart_data_send)(TP_uc8* msg,TP_u32 len);
static void (*non_permeable_opcode_analysis)(PROTOCOL_DEAL protocol_data); static void (*non_permeable_opcode_analysis)(PROTOCOL_DEAL protocol_data);
static void (*transparent_opcode_analysis)(PROTOCOL_DEAL protocol_data); static void (*transparent_opcode_analysis)(PROTOCOL_DEAL protocol_data);
static TP_ErrorStatus transparent_protocol_analysis(TP_uc8 *data,TP_uc32 len); static TP_ErrorStatus transparent_protocol_analysis(TP_uc8 *data,TP_uc8 len);
/************************************************************************************************************** /**************************************************************************************************************
全局变量,用于 transparent_protocol_send 全局变量,用于 transparent_protocol_send
...@@ -67,6 +66,10 @@ const PROTOCOL_SEND opcode_force_assert = {0x00,0x0002,0x10,&opcode_force_assert ...@@ -67,6 +66,10 @@ const PROTOCOL_SEND opcode_force_assert = {0x00,0x0002,0x10,&opcode_force_assert
//SEQ //SEQ
TP_u16 tp_report_seq_num = 0; TP_u16 tp_report_seq_num = 0;
#if 1 // add by dingmz_frc.20201215
extern u8 g_u8Temp_Buffer[];
extern u8 g_u8Temp_Length;
#endif
#define EXAMPLE #define EXAMPLE
/************************************************************************************************************** /**************************************************************************************************************
...@@ -346,27 +349,27 @@ void transparent_msg_deal(void) ...@@ -346,27 +349,27 @@ void transparent_msg_deal(void)
void transparent_protocol_send(PROTOCOL_SEND send_protocol,TP_u16 SEQ) void transparent_protocol_send(PROTOCOL_SEND send_protocol,TP_u16 SEQ)
{ {
static TP_u8 KK_Buf[125] = {0}; //static TP_u8 KK_Buf[125] = {0};
TP_u16 KK_CRC16_Num = 0; //计算校验值 TP_u16 KK_CRC16_Num = 0; //计算校验值
memset(KK_Buf,0,sizeof(KK_Buf)); //memset(KK_Buf,0,sizeof(KK_Buf));
KK_Buf[0] = 0xAA; g_u8Temp_Buffer[0] = 0xAA;
KK_Buf[1] = 0x55; g_u8Temp_Buffer[1] = 0x55;
KK_Buf[2] = send_protocol.ARG_len + 6; //长度 7 g_u8Temp_Buffer[2] = send_protocol.ARG_len + 6; //长度 7
KK_Buf[4] = (SEQ & 0xff); //序列号L g_u8Temp_Buffer[4] = (SEQ & 0xff); //序列号L
KK_Buf[3] = send_protocol.ControlField; //控制域: 不需要ack g_u8Temp_Buffer[3] = send_protocol.ControlField; //控制域: 不需要ack
KK_Buf[5] = send_protocol.ARG_len+3; g_u8Temp_Buffer[5] = send_protocol.ARG_len+3;
KK_Buf[6] = send_protocol.Channel_ID; //下行协议: 信道00 g_u8Temp_Buffer[6] = send_protocol.Channel_ID; //下行协议: 信道00
KK_Buf[7] = ((send_protocol.Opcode >> 8) & 0xff); //下行协议: Opcode_H g_u8Temp_Buffer[7] = ((send_protocol.Opcode >> 8) & 0xff); //下行协议: Opcode_H
KK_Buf[8] = (send_protocol.Opcode & 0xff); //下行协议: Opcode_L g_u8Temp_Buffer[8] = (send_protocol.Opcode & 0xff); //下行协议: Opcode_L
memcpy(&KK_Buf[9],send_protocol.ARG,send_protocol.ARG_len); memcpy(&g_u8Temp_Buffer[9],send_protocol.ARG,send_protocol.ARG_len);
//KK_Buf[9] = 0X00; //KK_Buf[9] = 0X00;
KK_CRC16_Num = CreateCrc16((TP_uc8*)&KK_Buf[3],KK_Buf[2]); KK_CRC16_Num = CreateCrc16((TP_uc8*)&g_u8Temp_Buffer[3],g_u8Temp_Buffer[2]);
KK_Buf[send_protocol.ARG_len + 9] = (KK_CRC16_Num>>8) & 0xff; //校验值 CRC_H g_u8Temp_Buffer[send_protocol.ARG_len + 9] = (KK_CRC16_Num>>8) & 0xff; //校验值 CRC_H
KK_Buf[send_protocol.ARG_len + 10] = KK_CRC16_Num & 0xff; //校验值 CRC_L g_u8Temp_Buffer[send_protocol.ARG_len + 10] = KK_CRC16_Num & 0xff; //校验值 CRC_L
uart_data_send(KK_Buf,send_protocol.ARG_len + 11); uart_data_send(g_u8Temp_Buffer,send_protocol.ARG_len + 11);
} }
...@@ -450,9 +453,15 @@ static TP_u8 Usart_recive_write_buff(TP_uc8 *data,TP_uc16 len) ...@@ -450,9 +453,15 @@ static TP_u8 Usart_recive_write_buff(TP_uc8 *data,TP_uc16 len)
*******************************************************************************/ *******************************************************************************/
//AA 55 07 80 01 04 00 10 11 01 F5 91 //AA 55 07 80 01 04 00 10 11 01 F5 91
//0 1 2 3 4 5 6 7 8 9 10 11 //0 1 2 3 4 5 6 7 8 9 10 11
static TP_ErrorStatus transparent_protocol_analysis(TP_uc8 *data,TP_uc32 len) static TP_ErrorStatus transparent_protocol_analysis(TP_uc8 *data, TP_uc8 len)
{ {
PROTOCOL_DEAL Usart_protocol_deal = {0}; PROTOCOL_DEAL Usart_protocol_deal = {0};
if((data == NULL) || (len < 5) || (len > USART_RECIVE_LEN_DEF))
{
//printf("non valied msg,discard it all\r\n");
return TP_ERROR;
}
Usart_protocol_deal.SEQ = *(data + 4); //记录 seq 的值 Usart_protocol_deal.SEQ = *(data + 4); //记录 seq 的值
if(BYTE_MOVE(*(data + len -2),*(data + len -1)) != CreateCrc16(data+ 3,len - 5)) //CRC校验 if(BYTE_MOVE(*(data + len -2),*(data + len -1)) != CreateCrc16(data+ 3,len - 5)) //CRC校验
...@@ -501,10 +510,10 @@ static void send_crc_error(TP_u16 seq_data) ...@@ -501,10 +510,10 @@ static void send_crc_error(TP_u16 seq_data)
/* /*
接收到的数据crc错误回复 接收到的数据crc错误回复
*/ */
TP_u16 CreateCrc16(u8* msg, TP_u32 len) TP_u16 CreateCrc16(u8* msg, TP_u8 len)
{ {
TP_u16 crc = 0xFFFF; TP_u16 crc = 0xFFFF;
TP_u32 i, j = 0; TP_u8 i, j = 0;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
......
...@@ -26,8 +26,9 @@ void VCNL3040_Init(u8 i2cAddress) ...@@ -26,8 +26,9 @@ void VCNL3040_Init(u8 i2cAddress)
} }
static u32 VCNL3040_WriteCommand(ECommand_ID command,u16 Data) static u32 VCNL3040_WriteCommand(ECommand_ID command,u16 Data)
{ {
u32 error = 0; // error code static u32 error = 0; // error code
u8 cmd_buf[4] = {0}; static u8 cmd_buf[4] = {0};
error = 0;
cmd_buf[0] = command ; cmd_buf[0] = command ;
cmd_buf[1] = Data ; cmd_buf[1] = Data ;
cmd_buf[2] = Data>>8 ; cmd_buf[2] = Data>>8 ;
...@@ -37,7 +38,7 @@ static u32 VCNL3040_WriteCommand(ECommand_ID command,u16 Data) ...@@ -37,7 +38,7 @@ static u32 VCNL3040_WriteCommand(ECommand_ID command,u16 Data)
} }
u16 VCNL3040_ReadBytes(ECommand_ID command) u16 VCNL3040_ReadBytes(ECommand_ID command)
{ {
u8 cmd_buf[4] = {0}; static u8 cmd_buf[4] = {0};
cmd_buf[0] = command ; cmd_buf[0] = command ;
I2C_SW_Send_Without_Stop(_VCNL3040_Addr, cmd_buf,1); I2C_SW_Send_Without_Stop(_VCNL3040_Addr, cmd_buf,1);
memset(cmd_buf,0,sizeof(cmd_buf)); memset(cmd_buf,0,sizeof(cmd_buf));
......
...@@ -99,7 +99,7 @@ static void send_temperature(uint8_t state) ...@@ -99,7 +99,7 @@ static void send_temperature(uint8_t state)
static void send_poll_check(void) static void send_poll_check(void)
{ {
uint8_t data[FRAME_LEN] = {0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; static uint8_t data[FRAME_LEN] = {0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
data[9] = CRC_check(data, 9); data[9] = CRC_check(data, 9);
......
...@@ -11,6 +11,11 @@ extern u8 boad_test_falg[6]; ...@@ -11,6 +11,11 @@ extern u8 boad_test_falg[6];
u16 g_u16 = 0; u16 g_u16 = 0;
#if 1 // add by dingmz_frc.20201215
extern u8 g_u8Temp_Buffer[];
extern u8 g_u8Temp_Length;
#endif
void uart0_data_deal_init(void) void uart0_data_deal_init(void)
{ {
memset(&static_transparent_msg_info,0,sizeof(RECIVE_USART_DATA_HANDLE)); memset(&static_transparent_msg_info,0,sizeof(RECIVE_USART_DATA_HANDLE));
...@@ -19,30 +24,26 @@ void uart0_data_deal_init(void) ...@@ -19,30 +24,26 @@ void uart0_data_deal_init(void)
static TP_u8 uart_recive_write_buff(TP_uc8 *data,TP_uc16 len) static TP_u8 uart_recive_write_buff(TP_uc8 *data,TP_uc16 len)
{ {
TP_u8 rem_serial = 0; TP_u8 rem_serial = 0;
if(len > USART_RECIVE_LEN_DEF)
{ if( len <= MAX_USART_RECIVE_LEN ) {
//DEBUG_USATR1("data too long"); rem_serial = static_transprent_buff.Download_serial_num;
return 0;
} if( static_transprent_buff.Download_serial_num > (USART_RECIVE_DEPTHS - 1))
{
rem_serial = static_transprent_buff.Download_serial_num; static_transprent_buff.Download_serial_num = 0;
rem_serial = static_transprent_buff.Download_serial_num; //add by YWQ
if(static_transprent_buff.Download_serial_num > (USART_RECIVE_DEPTHS - 1)) }
{
static_transprent_buff.Download_serial_num = 0;
rem_serial = static_transprent_buff.Download_serial_num; //add by YWQ memcpy(&static_transprent_buff.Usart_buff[rem_serial][0],data,len);
} static_transprent_buff.Usart_buff_len[static_transprent_buff.Download_serial_num] = len;
static_transprent_buff.Download_serial_num++;
memcpy(&static_transprent_buff.Usart_buff[rem_serial][0],data,len);
static_transprent_buff.Usart_buff_len[static_transprent_buff.Download_serial_num] = len; if(static_transprent_buff.Download_serial_num == static_transprent_buff.Buff_send_serial_num)
static_transprent_buff.Download_serial_num ++; {
//printf("data deal too slow");
if(static_transprent_buff.Download_serial_num == static_transprent_buff.Buff_send_serial_num) static_transprent_buff.Download_serial_num = rem_serial;
{ return 0;
//printf("data deal too slow"); }
static_transprent_buff.Download_serial_num = rem_serial;
return 0;
} }
return 1; return 1;
...@@ -66,7 +67,7 @@ u8 uart_msg_recive(u8 RcvChar) ...@@ -66,7 +67,7 @@ u8 uart_msg_recive(u8 RcvChar)
} }
else if(static_transparent_msg_info.Recive_len == 3) else if(static_transparent_msg_info.Recive_len == 3)
{ {
if((RcvChar < (USART_RECIVE_LEN_DEF - 5)) && (RcvChar > 4)) //长度在正常值之间 if((RcvChar < (MAX_USART_RECIVE_LEN - 5)) && (RcvChar > 4)) //长度在正常值之间
{ {
static_transparent_msg_info.Data[static_transparent_msg_info.Recive_len ++] = RcvChar; static_transparent_msg_info.Data[static_transparent_msg_info.Recive_len ++] = RcvChar;
static_transparent_msg_info.Data_len = RcvChar; static_transparent_msg_info.Data_len = RcvChar;
...@@ -76,7 +77,7 @@ u8 uart_msg_recive(u8 RcvChar) ...@@ -76,7 +77,7 @@ u8 uart_msg_recive(u8 RcvChar)
static_transparent_msg_info.Recive_len = 0x00; //这串数据不对 static_transparent_msg_info.Recive_len = 0x00; //这串数据不对
} }
} }
else if((static_transparent_msg_info.Recive_len > 3) && (static_transparent_msg_info.Recive_len < (USART_RECIVE_LEN_DEF - 2))) //接受数据 else if((static_transparent_msg_info.Recive_len > 3) && (static_transparent_msg_info.Recive_len < (MAX_USART_RECIVE_LEN - 2))) //接受数据
{ {
static_transparent_msg_info.Data[static_transparent_msg_info.Recive_len ++] = RcvChar; static_transparent_msg_info.Data[static_transparent_msg_info.Recive_len ++] = RcvChar;
...@@ -102,7 +103,7 @@ void uart_msg_deal(void) ...@@ -102,7 +103,7 @@ void uart_msg_deal(void)
if(static_transprent_buff.Buff_send_serial_num != static_transprent_buff.Download_serial_num) if(static_transprent_buff.Buff_send_serial_num != static_transprent_buff.Download_serial_num)
{ {
if(static_transprent_buff.Buff_send_serial_num >5) if((static_transprent_buff.Buff_send_serial_num >USART_RECIVE_DEPTHS)||(static_transprent_buff.Download_serial_num >USART_RECIVE_DEPTHS))
{ {
return; //防止内存溢出导致错误值 return; //防止内存溢出导致错误值
} }
...@@ -117,15 +118,19 @@ void uart_msg_deal(void) ...@@ -117,15 +118,19 @@ void uart_msg_deal(void)
static_transprent_buff.Buff_send_serial_num++; static_transprent_buff.Buff_send_serial_num++;
} }
} }
u8 Usart_recive_deal(TP_uc8 *data,TP_uc16 len)
u8 Usart_recive_deal(TP_uc8 *data, TP_uc8 len )
{ {
PROTOCOL_DEAL Usart_protocol_deal = {0}; PROTOCOL_DEAL Usart_protocol_deal = {0};
u8 arg_data[20] = {0}; u8 arg_data[20] = {0};
if( (data == NULL) ||(len >40))
//printf("66:len = %d\r\n", len);
if((data == NULL) || (len < 6) || (len > MAX_USART_RECIVE_LEN))
{ {
//printf("non valied msg,discard it all\r\n"); //printf("non valied msg,discard it all\r\n");
return 0; return DEAL_ERROR;
} }
//printf("77\r\n");
Usart_protocol_deal.SEQ = BYTE_MOVE(*(data + 5),*(data + 6)); Usart_protocol_deal.SEQ = BYTE_MOVE(*(data + 5),*(data + 6));
// for(i = 0;i<len;i++) // for(i = 0;i<len;i++)
// printf("data[%d] = %x",i,data[i] ); // printf("data[%d] = %x",i,data[i] );
...@@ -135,7 +140,7 @@ u8 Usart_recive_deal(TP_uc8 *data,TP_uc16 len) ...@@ -135,7 +140,7 @@ u8 Usart_recive_deal(TP_uc8 *data,TP_uc16 len)
send_crc_error_data(Usart_protocol_deal.SEQ); send_crc_error_data(Usart_protocol_deal.SEQ);
return DEAL_ERROR; return DEAL_ERROR;
} }
Usart_protocol_deal.Opcode = BYTE_MOVE(*(data + 9),*(data + 10)); //赋值功能码 Usart_protocol_deal.Opcode = BYTE_MOVE(*(data + 9),*(data + 10)); //赋值功能码
Usart_protocol_deal.Channel_ID = *(data + 8); Usart_protocol_deal.Channel_ID = *(data + 8);
Usart_protocol_deal.ControlField = 0x20; Usart_protocol_deal.ControlField = 0x20;
...@@ -257,30 +262,30 @@ void proximity_triagger_report(void) ...@@ -257,30 +262,30 @@ void proximity_triagger_report(void)
void uart_protocol_send(PROTOCOL_SEND_MSG send_protocol,TP_u16 SEQ) void uart_protocol_send(PROTOCOL_SEND_MSG send_protocol,TP_u16 SEQ)
{ {
TP_u8 KK_Buf[125] = {0}; //TP_u8 KK_Buf[125] = {0};
TP_u16 KK_CRC16_Num = 0; //计算校验值 TP_u16 KK_CRC16_Num = 0; //计算校验值
memset(KK_Buf,0,sizeof(KK_Buf)); //memset(KK_Buf,0,sizeof(KK_Buf));
KK_Buf[0] = 0xAA; g_u8Temp_Buffer[0] = 0xAA;
KK_Buf[1] = 0x55; g_u8Temp_Buffer[1] = 0x55;
KK_Buf[2] = (send_protocol.ARG_len + 7)>>8; //长度 7 g_u8Temp_Buffer[2] = (send_protocol.ARG_len + 7)>>8; //长度 7
KK_Buf[3] = (send_protocol.ARG_len + 7)&0xff; //长度 7 g_u8Temp_Buffer[3] = (send_protocol.ARG_len + 7)&0xff; //长度 7
KK_Buf[5] = (SEQ>>8) & 0xff; //序列号H g_u8Temp_Buffer[5] = (SEQ>>8) & 0xff; //序列号H
KK_Buf[6] = (SEQ & 0xff); //序列号L g_u8Temp_Buffer[6] = (SEQ & 0xff); //序列号L
KK_Buf[4] = send_protocol.ControlField; //控制域: 不需要ack g_u8Temp_Buffer[4] = send_protocol.ControlField; //控制域: 不需要ack
KK_Buf[7] = send_protocol.ARG_len+3; //长度 g_u8Temp_Buffer[7] = send_protocol.ARG_len+3; //长度
KK_Buf[8] = send_protocol.Channel_ID; //下行协议: 信道00 g_u8Temp_Buffer[8] = send_protocol.Channel_ID; //下行协议: 信道00
KK_Buf[9] = ((send_protocol.Opcode >> 8) & 0xff); //下行协议: Opcode_H g_u8Temp_Buffer[9] = ((send_protocol.Opcode >> 8) & 0xff); //下行协议: Opcode_H
KK_Buf[10] = (send_protocol.Opcode & 0xff); //下行协议: Opcode_L g_u8Temp_Buffer[10] = (send_protocol.Opcode & 0xff); //下行协议: Opcode_L
memcpy(&KK_Buf[11],send_protocol.ARG,send_protocol.ARG_len); memcpy(&g_u8Temp_Buffer[11],send_protocol.ARG,send_protocol.ARG_len);
//KK_Buf[9] = 0X00; //KK_Buf[9] = 0X00;
KK_CRC16_Num = CreateCrc16_Self((TP_uc8*)&KK_Buf[4],send_protocol.ARG_len + 7); KK_CRC16_Num = CreateCrc16_Self((TP_uc8*)&g_u8Temp_Buffer[4],send_protocol.ARG_len + 7);
KK_Buf[send_protocol.ARG_len + 11] = (KK_CRC16_Num>>8) & 0xff; //校验值 CRC_H g_u8Temp_Buffer[send_protocol.ARG_len + 11] = (KK_CRC16_Num>>8) & 0xff; //校验值 CRC_H
KK_Buf[send_protocol.ARG_len + 12] = KK_CRC16_Num & 0xff; //校验值 CRC_L g_u8Temp_Buffer[send_protocol.ARG_len + 12] = KK_CRC16_Num & 0xff; //校验值 CRC_L
UART0_Send_Bytes(KK_Buf,send_protocol.ARG_len + 13); UART0_Send_Bytes(g_u8Temp_Buffer,send_protocol.ARG_len + 13);
} }
/* /*
接收到的数据crc错误回复 接收到的数据crc错误回复
...@@ -305,7 +310,7 @@ static void send_crc_error_data(TP_u16 seq_data) ...@@ -305,7 +310,7 @@ static void send_crc_error_data(TP_u16 seq_data)
/* /*
接收到的数据crc错误回复 接收到的数据crc错误回复
*/ */
TP_u16 CreateCrc16_Self(const u8* msg, TP_u32 len) TP_u16 CreateCrc16_Self(const u8* msg, TP_u8 len)
{ {
TP_u16 crc = 0xFFFF; TP_u16 crc = 0xFFFF;
TP_u32 i, j = 0; TP_u32 i, j = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment