Commit 3fc554e9 authored by 李冠华's avatar 李冠华

feat:增加NVS测试用功能

parent ff202fcd
......@@ -2,6 +2,16 @@
[Subproject]
:sourceDir=..\..\source\Appliciation
RS485_Protocol_CRC16.c
RS485_Protocol_CRC16.h
RS485_Protocol_Lib.c
RS485_Protocol_Lib.h
RS485_Protocol_User.c
RS485_Protocol_User.h
Power_Controls.c
Power_Controls.h
NVS_Test.c
NVS_Test.h
api_RS485.c
api_RS485.h
R485_Communication_Matrix.c
......
......@@ -31,7 +31,7 @@ uint8_t checkresult;
uint8_t sendmsg[8];
uint8_t timenum = 0;
uint8_t firstflag = 0;
uint8_t RS485_data[64];
// uint8_t RS485_data[4] = {0,0,0,0};
uint8_t checknumwrong;
uint8_t zhenduanflag = 0;
uint8_t clearOdoFlag = 0;
......@@ -58,232 +58,78 @@ void get_key(void)
void datacheck(void)
{
RS485_send_time = 0;
RS485_TX_finish = 0;
uint16_t checksum = 0;
uint8_t arraynum = 0;
if(zhenduanflag == 0)
{
if(BarCode[0] == 0x59 && BarCode[1] == 0x44)
{
for(int i = 0;i<255;i++)
{
if(BarCode[i] == 0x4A && BarCode[i - 1] == 0x4B)
{
arraynum = i;
}
}
if(((BarCode[arraynum]) == 0x4A) && ((BarCode[arraynum-1]) == 0x4B))
{
for(int i = 0;i < 64;i++)
{
RS485_data[i] = BarCode[4+i];
}
switch (BarCode[2])
{
case 0x48:
memcpy(R485_ID48h.Msg,RS485_data,64);
checksum = Yadi_CAL_Data_Sum(&BarCode[2], 64 + 2);
if(checksum != BarCode[68])
{
checknumwrong = 1;
}
break;
case 0x49:
memcpy(R485_ID49h.Msg,RS485_data,64);
checksum = Yadi_CAL_Data_Sum(&BarCode[2], 64 + 2);
if(checksum != BarCode[68])
{
checknumwrong = 1;
}
break;
case 0x4A:
memcpy(R485_ID4Ah.Msg,RS485_data,64);
checksum = Yadi_CAL_Data_Sum(&BarCode[2], 64 + 2);
if(checksum != BarCode[68])
{
checknumwrong = 1;
}
break;
case 0x4F:
{
switch (BarCode[6])
{
case 0:
LineGetSta.power1 = (BarCode[7]<<8 |BarCode[8]);
if(LineGetSta.power1 < 24)
{
powerstdio = 1;
}
break;
case 1:
LineGetSta.ble1 = BarCode[7];
if(LineGetSta.ble1 == 0)
{
line_stdio = 1;
}
break;
case 2:
LineGetSta.turnleft1 = BarCode[7];
break;
case 3:
LineGetSta.turnright1 = BarCode[7];
break;
case 4:
LineGetSta.ABSlight1 = BarCode[7];
if(LineGetSta.ABSlight1 == 0)
{
line_stdio = 1;
}
break;
case 5:
LineGetSta.lowlight1 = BarCode[7];
if(LineGetSta.lowlight1 == 0)
{
line_stdio = 1;
}
break;
case 6:
LineGetSta.highlight1 = BarCode[7];
if(LineGetSta.highlight1 == 0)
{
line_stdio = 1;
}
break;
case 7:
LineGetSta.weizhilight1 = BarCode[7];
if(LineGetSta.weizhilight1 == 0)
{
line_stdio = 1;
}
break;
default:
break;
}
}
default:
break;
}
memset(RS485_data,0,64);
RS485_TX_finish = 0;
}
else
{
RS485_send_num--;
RS485_TX_finish = 0;
}
}
}
else if(zhenduanflag == 1)
{
if(BarCode[0] == 0x59 && BarCode[1] == 0x44)
{
for(int i = 0;i<255;i++)
{
if(BarCode[i] == 0x4A && BarCode[i - 1] == 0x4B)
{
arraynum = i;
}
}
// g_Stage = 1;
if(((BarCode[arraynum]) == 0x4A) && ((BarCode[arraynum-1]) == 0x4B))
{
switch (zhenduansendStep)
{
case 0:
if(BarCode[2] == 0x4F)
{
if(BarCode[4] == 0x50 && BarCode[5] == 0x3)
{
zhenduansendStep++;
RS485_TX_finish = 0;
}
}
break;
case 1:
if(BarCode[2] == 0x4F)
{
if(BarCode[4] == 0x67 && BarCode[5] == 0x1)
{
seed_value[0] = BarCode[6];
seed_value[1] = BarCode[7];
seed_value[2] = BarCode[8];
seed_value[3] = BarCode[9];
get_key();
zhenduansendStep++;
RS485_TX_finish = 0;
}
}
break;
case 2:
if(BarCode[2] == 0x4F)
{
if(BarCode[4] == 0x67 && BarCode[5] == 0x2)
{
zhenduansendStep++;
RS485_TX_finish = 0;
}
else
{
RS485_TX_finish = 0;
}
}
break;
case 3:
if(BarCode[2] == 0x4F)
{
if((BarCode[4] == 0x6E) && (BarCode[5] == 0x50) && (BarCode[6] == 0))
{
zhenduansendStep++;
RS485_TX_finish = 0;
}
if(BarCode[4] == 0x7F)
{
// wait_write_flag = 1;
RS485_TX_finish = 1;
}
}
else
{
RS485_TX_finish = 0;
}
break;
default:
break;
}
memset(RS485_data,0,64);
}
else
{
RS485_TX_finish = 0x0;
}
}
}
else
{
if(BarCode[0] == 0x59 && BarCode[1] == 0x44)
{
for(int i = 0;i<255;i++)
{
if(BarCode[i] == 0x4A && BarCode[i - 1] == 0x4B)
{
arraynum = i;
}
}
if(((BarCode[arraynum]) == 0x4A) && ((BarCode[arraynum-1]) == 0x4B))
{
if(BarCode[4] == 0x62 && BarCode[5] == 0x50 && BarCode[6] == 0)
{
memcpy(get_num_buf,BarCode+7,34 );
comparestart = 1;
zhenduanflag = 3;
}
}
}
}
// RS485_send_time = 0;
// // RS485_TX_finish = 0;
// uint16_t checksum = 0;
// uint8_t arraynum = 0;
// uint8_t Rs485DataArrayNum = 0U;
// // if(BarCode[0] == 0x59 && BarCode[1] == 0x44)
// // {
// // for(int i = 0;i<255;i++)
// // {
// // if(BarCode[i] == 0x4A && BarCode[i - 1] == 0x4B)
// // {
// // arraynum = i;
// // }
// // }
// // if(((BarCode[arraynum]) == 0x4A) && ((BarCode[arraynum-1]) == 0x4B))
// // {
// // for(int i = 0;i < 64;i++)
// // {
// // RS485_data[i] = BarCode[4+i];
// // }
// // switch (BarCode[2])
// // {
// // case 0x60:
// // memcpy(R485_ID60h.Msg,RS485_data,4);
// // // checksum = Yadi_CAL_Data_Sum(&BarCode[2], 64 + 2);
// // // if(checksum != BarCode[68])
// // // {
// // // checknumwrong = 1;
// // // }
// // break;
// // default:
// // break;
// // }
// // // memset(RS485_data,0,64);
// // // RS485_TX_finish = 0;
// // }
// // else
// // {
// // RS485_send_num--;
// // // RS485_TX_finish = 0;
// // }
// // RS485_TX_finish = 3U;
// // }
// for(int i = 0;i < 25 ;i++)
// {
// if((BarCode[i] == 0x4A) && (BarCode[i - 1] == 0x4B))
// {
// arraynum = i;
// }
// }
// if(((BarCode[arraynum]) == 0x4A) && ((BarCode[arraynum-1]) == 0x4B))
// {
// for(int i = arraynum; i > 0u; i--)
// {
// RS485_data[3 - Rs485DataArrayNum] = BarCode[arraynum - 3 - Rs485DataArrayNum];
// Rs485DataArrayNum ++;
// if (Rs485DataArrayNum >= 4u)
// {
// break;
// }
// }
// // memcpy(R485_ID60h.Msg,RS485_data,4);
// // R485_Receive_0x60();
// }
// else
// {
// RS485_send_num--;
// // RS485_TX_finish = 0;
// }
// RS485_TX_finish = 3U;
}
void BarCodeDataGet(void)
{
......@@ -392,16 +238,16 @@ void Recv_Byte(void)
// 解析协议
len = i;
if ( (len > 0) && (len < mDataBufLen) )
{
// 将未解析的数据移到头部
// Move unparsed data to the head
// if ( (len > 0) && (len < mDataBufLen) )
// {
// // 将未解析的数据移到头部
// // Move unparsed data to the head
memcpy(mDataBufLen, mDataBufLen + len, mDataBufLen - len);
// memcpy(mDataBufPtr, mDataBufPtr + len, mDataBufLen - len);
// memcpy(nowdata,mDataBufPtr + len,len);
// datacheck();
}
// // memcpy(nowdata,mDataBufPtr + len,len);
// // datacheck();
// }
// if()
mDataBufLen -= len;
datacheck();
......
......@@ -256,7 +256,7 @@ void Total_Check(void)
loc_Type_back = 0;
}
Function_Check_Ctrl(1); //Excel表格发报文。硬线信号
// Function_Check_Ctrl(1); //Excel表格发报文。硬线信号
Diag_Info_Init( );
Display_Init( );
// Send_Init();
......
......@@ -93,14 +93,14 @@ void Key_Operation_SW7(Key_Event_en_t enKeyEvent)
if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
{
if(zhenduanflag != 2 && zhenduanflag != 3)
{
zhenduanflag = 2;
}
else
{
zhenduanflag = 0;
}
// if(zhenduanflag != 2 && zhenduanflag != 3)
// {
// zhenduanflag = 2;
// }
// else
// {
// zhenduanflag = 0;
// }
}
else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
{
......@@ -116,20 +116,20 @@ void Key_Operation_SW8(Key_Event_en_t enKeyEvent)
{
if ( enKeyEvent == KEY_EVENT_SHORT_PRESS )
{
if(zhenduanflag == 0)
{
zhenduanflag = 1;
}
else
{
zhenduanflag = 0;
LINE_OUT_NEG_01 = 1;
LINE_OUT_NEG_02 = 1;
LINE_OUT_NEG_03 = 1;
LINE_OUT_NEG_04 = 1;
zhenduansendStep = 0;
}
RS485_TX_finish = 0;
// if(zhenduanflag == 0)
// {
// zhenduanflag = 1;
// }
// else
// {
// zhenduanflag = 0;
// LINE_OUT_NEG_01 = 1;
// LINE_OUT_NEG_02 = 1;
// LINE_OUT_NEG_03 = 1;
// LINE_OUT_NEG_04 = 1;
// zhenduansendStep = 0;
// }
// RS485_TX_finish = 0;
}
else if ( enKeyEvent == KEY_EVENT_LONG_PRESS )
......
#include "NVS_Test.h"
uint32_t BenCiXieRuNum = 0U;
uint32_t TotalExecutionNum = 0U;
uint32_t LastNum = 0U;
uint32_t BeforeLastNum = 0U;
uint32_t ReceivedValue = 0U;
uint8_t RenWuDelay = 0U;
uint8_t errNum = 0U;
uint32_t TurnOffPowerCount = 0U;
uint32_t TurnOffPowerCountHistory = 0U;
uint32_t JieShouDaoValue = 0U;
static void NVS_Test_BenCiXieRuNum(void);
void NVS_Test_Init(void)
{
BenCiXieRuNum = 0U;
TotalExecutionNum = 0U;
LastNum = 0xFFFFFFFFU;
BeforeLastNum = 0xFFFFFFFFU;
ReceivedValue = 0U;
RenWuDelay = 0U;
TurnOffPowerCount = 0U;
TurnOffPowerCountHistory = 0U;
errNum = 0U;
JieShouDaoValue = 0U;
RS485_TX_finish = 2U; /*发出的RS485信号标志位,初始化为2,不发不收*/
}
void NVS_Test_Service(void)
{
if(RS485_TX_finish == 2U)
{
if (errNum == 0U)
{
BeforeLastNum = LastNum;
LastNum = BenCiXieRuNum;
NVS_Test_BenCiXieRuNum();
RS485_TX_finish = 0U;/*上电后满足等待时间后,开始发第一帧信号*/
}
}
else if(RS485_TX_finish == 0U)
{
;/*执行发的功能*/
}
else
{
if(RS485_TX_finish == 3U)
{
if (TotalExecutionNum != 0U)
{
if(JieShouDaoValue != LastNum)
{
if ((JieShouDaoValue != BeforeLastNum) && (TurnOffPowerCount != TurnOffPowerCountHistory))
{
errNum ++;
}
else if (TurnOffPowerCount == TurnOffPowerCountHistory)
{
errNum ++;
}
if (JieShouDaoValue != BeforeLastNum)
{
errNum ++;
}
}
}
if (TurnOffPowerCount != TurnOffPowerCountHistory)
{
TurnOffPowerCountHistory = TurnOffPowerCount; /*断电后重启第一次对比标记,只有此时才执行对比上上次的值,之后不能对比*/
}
if (errNum == 0U)
{
BeforeLastNum = LastNum;
LastNum = BenCiXieRuNum;
NVS_Test_BenCiXieRuNum();
TotalExecutionNum ++;
RS485_TX_finish = 0U;/*执行读的功能,对比完没问题再重新外发*/
}
else
{
RS485_TX_finish = 0xFFU;/*不再执行任何收发操作*/
}
}
else
{
;/*等待仪表回复*/
}
}
}
void NVS_Test_DelayCount(void)
{
RenWuDelay ++ ;
}
static void NVS_Test_BenCiXieRuNum(void)
{
uint32_t hahaha = (((BenCiXieRuNum * 7U) / 3U) + 257U);
if (hahaha < 0xFFFFFFFF)
{
BenCiXieRuNum = hahaha;
}
else
{
BenCiXieRuNum = 1u;
}
}
#ifndef NVS_TEST_H__
#define NVS_TEST_H__
#include "RTE_GPIO.h"
#include "Key.h"
#include "Display_Info.h"
#include "Check_Ctrl.h"
#include "Barcode_Scanner.h"
#include "Task.h"
#define DUAN_DIAN_STATE 1 /*0--只控制13.5V电,1--控制所有电*/
extern uint32_t BenCiXieRuNum;
extern uint32_t TotalExecutionNum;
extern uint32_t LastNum;
extern uint32_t BeforeLastNum;
extern uint32_t ReceivedValue;
extern uint8_t RenWuDelay;
extern uint32_t TurnOffPowerCount;
extern uint32_t TurnOffPowerCountHistory;
extern uint8_t errNum;
extern uint32_t JieShouDaoValue;
extern void NVS_Test_Init(void);
extern void NVS_Test_Service(void);
extern void NVS_Test_DelayCount(void);
#endif
#include "Power_Controls.h"
uint16_t PowerCountNum = 0U;
uint8_t KL1530ON = 0U;
uint8_t ControlsStatus = DUAN_DIAN_STATE;
void Power_Controls_Init(void)
{
KL1530ON = 1U; /*默认上电,给所有继电器通电*/
}
void Power_Control_Count(void)
{
// if (PowerCountNum <= 250U)
// {
// KL1530ON = 1U;
// PowerCountNum ++;
// }
// else if ((PowerCountNum > 250U) && (PowerCountNum < 300U))
// {
// KL1530ON = 0U;
// PowerCountNum ++;
// }
// else
// {
// KL1530ON = 0U;
// PowerCountNum = 0U;
// }
KL1530ON = 1U;
}
void Power_KL15_KL30_Controls(void)
{
if(ControlsStatus == 1U)
{
if (KL1530ON == 1U)
{
LINE_OUT_NEG_01 = 1U;
LINE_OUT_NEG_02 = 1U;
LINE_OUT_NEG_03 = 1U;
LINE_OUT_NEG_04 = 1U;
}
else
{
LINE_OUT_NEG_01 = 0U;
LINE_OUT_NEG_02 = 0U;
LINE_OUT_NEG_03 = 0U;
LINE_OUT_NEG_04 = 0U;
}
}
else
{
if (KL1530ON == 1U)
{
LINE_OUT_NEG_01 = 1U;
}
else
{
LINE_OUT_NEG_01 = 0U;
}
}
}
#ifndef POWER_CONTROLS_H__
#define POWER_CONTROLS_H__
#include "RTE_GPIO.h"
#include "Key.h"
#include "Display_Info.h"
#include "Check_Ctrl.h"
#include "Barcode_Scanner.h"
#include "Task.h"
#define DUAN_DIAN_STATE 1 /*0--只控制13.5V电,1--控制所有电*/
extern uint8_t KL1530ON;
extern void Power_Controls_Init(void);
extern void Power_Control_Count(void);
extern void Power_KL15_KL30_Controls(void);
#endif
#include "R485_Communication_Matrix.h"
#include "Barcode_Scanner.h"
#include "string.h"
#include "NVS_Test.h"
uint8_t barcode_Msg[64];
uint32_t R485_Send_0x40(void)
{
......@@ -818,17 +820,17 @@ uint32_t R485_Send_0x47(void)
default:
break;
}
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
if(zhenduansendStep != 4)
{
u32sendendflag = R485_Send(0x47, R485_zhenduan_Msg, length);
}
RS485_send_time = 0;
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
}
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
return u32sendendflag;
}
uint8_t Send_Lineget_Msg[64];
......@@ -905,12 +907,12 @@ uint32_t R485_Send_Line_0x47(uint8_t n)
break;
}
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
u32sendendflag = R485_Send(0x47, Send_Lineget_Msg, 3);
RS485_send_time = 0;
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
}
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
return u32sendendflag;
}
uint8_t R485_zhenduan_Msg1[64];
......@@ -928,7 +930,7 @@ uint32_t R485_Sendcheck_0x47(void)
RS485_send_time = 0;
}
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
return u32sendendflag;
}
uint8_t Send_Lineget_Msg[64];
......@@ -1021,3 +1023,8 @@ uint32_t R485_Send_0x70(void)
// return u32sendendflag;
}
void R485_Receive_0x60(void)
{
JieShouDaoValue = (R485_ID60h.Sig.ReceivedValue1 + (R485_ID60h.Sig.ReceivedValue2 << 8u) + (R485_ID60h.Sig.ReceivedValue3 << 16u) + (R485_ID60h.Sig.ReceivedValue4 << 24u)) ;
}
\ No newline at end of file
......@@ -1101,6 +1101,20 @@ typedef union
}_ID0X4Dh_Data;
typedef union
{
uint8_t Msg[4];
struct
{
uint8_t ReceivedValue1 :8;
uint8_t ReceivedValue2 :8;
uint8_t ReceivedValue3 :8;
uint8_t ReceivedValue4 :8;
}Sig;
}_ID0X60h_Data;
typedef struct
{
......@@ -1121,6 +1135,7 @@ extern _ID0X49h_Data R485_ID49h;
extern _ID0X42h_Data R485_ID42h;
extern _ID0X4Ah_Data R485_ID4Ah;
extern _ID0X4Dh_Data R485_ID4Dh;
extern _ID0X60h_Data R485_ID60h;
extern uint8_t zhenduansendStep;
......@@ -1137,5 +1152,8 @@ extern uint32_t R485_Send_Line_0x47(uint8_t n);
extern uint32_t R485_Send_clear(void);
extern uint32_t R485_Sendcheck_0x47(void);
extern void R485_Receive_0x60(void);
extern uint8_t barcode_Msg[64];
#endif
/**
* @file Protocol_CRC16.c
* @brief CRC16计算
* @details CRC16计算
* @author myliu
* @date 2022.05.09
* @version V1.0
* @copyright myiu
*/
#include "RS485_Protocol_CRC16.h"
#include <stdio.h>
#include <stdint.h>
static const Protocol_uint8_t CRC16_TAB_H [ 256 ] = {0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u};
static const Protocol_uint8_t CRC16_TAB_L [ 256 ] = {0x00u, 0xC0u, 0xC1u, 0x01u, 0xC3u, 0x03u, 0x02u, 0xC2u, 0xC6u, 0x06u, 0x07u, 0xC7u, 0x05u, 0xC5u, 0xC4u, 0x04u, 0xCCu, 0x0Cu, 0x0Du, 0xCDu, 0x0Fu, 0xCFu, 0xCEu, 0x0Eu, 0x0Au, 0xCAu, 0xCBu, 0x0Bu, 0xC9u, 0x09u, 0x08u, 0xC8u, 0xD8u, 0x18u, 0x19u, 0xD9u, 0x1Bu, 0xDBu, 0xDAu, 0x1Au, 0x1Eu, 0xDEu, 0xDFu, 0x1Fu, 0xDDu, 0x1Du, 0x1Cu, 0xDCu, 0x14u, 0xD4u, 0xD5u, 0x15u, 0xD7u, 0x17u, 0x16u, 0xD6u, 0xD2u, 0x12u, 0x13u, 0xD3u, 0x11u, 0xD1u, 0xD0u, 0x10u, 0xF0u, 0x30u, 0x31u, 0xF1u, 0x33u, 0xF3u, 0xF2u, 0x32u, 0x36u, 0xF6u, 0xF7u, 0x37u, 0xF5u, 0x35u, 0x34u, 0xF4u, 0x3Cu, 0xFCu, 0xFDu, 0x3Du, 0xFFu, 0x3Fu, 0x3Eu, 0xFEu, 0xFAu, 0x3Au, 0x3Bu, 0xFBu, 0x39u, 0xF9u, 0xF8u, 0x38u, 0x28u, 0xE8u, 0xE9u, 0x29u, 0xEBu, 0x2Bu, 0x2Au, 0xEAu, 0xEEu, 0x2Eu, 0x2Fu, 0xEFu, 0x2Du, 0xEDu, 0xECu, 0x2Cu, 0xE4u, 0x24u, 0x25u, 0xE5u, 0x27u, 0xE7u, 0xE6u, 0x26u, 0x22u, 0xE2u, 0xE3u, 0x23u, 0xE1u, 0x21u, 0x20u, 0xE0u, 0xA0u, 0x60u, 0x61u, 0xA1u, 0x63u, 0xA3u, 0xA2u, 0x62u, 0x66u, 0xA6u, 0xA7u, 0x67u, 0xA5u, 0x65u, 0x64u, 0xA4u, 0x6Cu, 0xACu, 0xADu, 0x6Du, 0xAFu, 0x6Fu, 0x6Eu, 0xAEu, 0xAAu, 0x6Au, 0x6Bu, 0xABu, 0x69u, 0xA9u, 0xA8u, 0x68u, 0x78u, 0xB8u, 0xB9u, 0x79u, 0xBBu, 0x7Bu, 0x7Au, 0xBAu, 0xBEu, 0x7Eu, 0x7Fu, 0xBFu, 0x7Du, 0xBDu, 0xBCu, 0x7Cu, 0xB4u, 0x74u, 0x75u, 0xB5u, 0x77u, 0xB7u, 0xB6u, 0x76u, 0x72u, 0xB2u, 0xB3u, 0x73u, 0xB1u, 0x71u, 0x70u, 0xB0u, 0x50u, 0x90u, 0x91u, 0x51u, 0x93u, 0x53u, 0x52u, 0x92u, 0x96u, 0x56u, 0x57u, 0x97u, 0x55u, 0x95u, 0x94u, 0x54u, 0x9Cu, 0x5Cu, 0x5Du, 0x9Du, 0x5Fu, 0x9Fu, 0x9Eu, 0x5Eu, 0x5Au, 0x9Au, 0x9Bu, 0x5Bu, 0x99u, 0x59u, 0x58u, 0x98u, 0x88u, 0x48u, 0x49u, 0x89u, 0x4Bu, 0x8Bu, 0x8Au, 0x4Au, 0x4Eu, 0x8Eu, 0x8Fu, 0x4Fu, 0x8Du, 0x4Du, 0x4Cu, 0x8Cu, 0x44u, 0x84u, 0x85u, 0x45u, 0x87u, 0x47u, 0x46u, 0x86u, 0x82u, 0x42u, 0x43u, 0x83u, 0x41u, 0x81u, 0x80u, 0x40u};
/**
* 获取CRC16校验和
*/
/**
* @brief 计算传入数据的CRC16
* @param[in] pData 计算的数据内容
* @param[in] len 计算的数据长度
*
* @return 校验和
*
* @since 1.0.0
*/
Protocol_uint16_t RS485_getCheckSum(const Protocol_uint8_t *pData, int len)
{
Protocol_uint8_t u8_crc_h = 0xFFu;
Protocol_uint8_t u8_crc_l = 0xFFu;
Protocol_uint8_t u8_index = 0u;
Protocol_uint8_t i = 0u;
Protocol_uint16_t re_value;
int SaveLen = 0;
SaveLen = len;
while ( SaveLen-- )
{
u8_index = u8_crc_h ^ (pData [ i++ ]);
u8_crc_h = u8_crc_l ^ CRC16_TAB_H [ u8_index ];
u8_crc_l = CRC16_TAB_L [ u8_index ];
}
re_value = ( Protocol_uint16_t )u8_crc_h << 8u;
re_value |= u8_crc_l;
return re_value;
}
#ifndef RS485_PROTOCOL_CRC16_H
#define RS485_PROTOCOL_CRC16_H
// #include "Application.h"
#include "RS485_Protocol_Lib.h"
Protocol_uint16_t RS485_getCheckSum(const Protocol_uint8_t *pData, int len);
#endif
/**
* @file Protocol_Lib.c
* @brief 串口协议解析
* @details 串口协议解析
* @author myliu
* @date 2022.05.09
* @version V1.0
* @copyright myiu
*/
#include <stdio.h>
#include <string.h>
#include "RS485_Protocol_Lib.h"
#include "RS485_Protocol_CRC16.h"
static UARTOpen UARTOpen_Cbk;
static UARTSend UARTSend_Cbk;
static UARTRead UARTRead_Cbk;
static ProcParse ProcParseCbk;
static UARTClose UARTClose_Cbk;
static ProtocolSetData ProtocolSetData_Cbk;
static Protocol_uint8_t *mDataBufPtr = Protocol_NULL;
static Protocol_uint16_t mDataBufLen = 0;
static Protocol_uint32_t DataBufMaxLen = 0;
//#define DEBUG_PRO_DATA 0
/**
* @brief 初始化函数
* @param[in] pMemSpace 分配给协议库的内存空间,用来缓存串口数据
* @param[in] MemLen 分配的内存空间大小
* @param[in] pFunc 回调函数,包括串口打开、发送、读取、关闭,也包括解析后数据回传
* @param[in] ProcParseCbk 此回调函数,返回数据从FrameNo开始到CRC16之前,和ProtocolSetData_Cbk二选一
* @param[in] ProtocolSetData_Cbk 此回调函数,返回数据区分命令字、电源状态等,和ProcParseCbk二选一,详见结构体Protocol_Data_t
*
* @warning 此函数KL30和Wakeup都要调用,否则未分配内存,功能不好使,也有可能造成野指针复位
*
* @since 1.0.0
*/
void RS485_Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protocol_Func_t *pFunc)
{
mDataBufPtr = pMemSpace;
DataBufMaxLen = MemLen;
UARTOpen_Cbk = pFunc->UARTOpen_Cbk;
UARTSend_Cbk = pFunc->UARTSend_Cbk;
UARTRead_Cbk = pFunc->UARTRead_Cbk;
ProcParseCbk = pFunc->ProcParseCbk;
UARTClose_Cbk = pFunc->UARTClose_Cbk;
ProtocolSetData_Cbk = pFunc->ProtocolSetData_Cbk;
if ( UARTOpen_Cbk != Protocol_NULL )
{
UARTOpen_Cbk( );
}
return;
}
/**
* @brief 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
*
* @warning 此函数可自定义周期调用,建议20ms周期调用,最大不可超过协议的最小发送周期
*
* @since 1.0.0
*/
void RS485_Protocol_Service(void)
{
int len;
Protocol_uint32_t readNum = 0;
if ( UARTRead_Cbk != Protocol_NULL )
{
readNum = UARTRead_Cbk(mDataBufPtr + mDataBufLen, 256 - mDataBufLen);
if ( readNum > 0 )
{
mDataBufLen += readNum;
// 解析协议
len = RS485_Protocol_Parse(mDataBufPtr, mDataBufLen);
if ( (len > 0) && (len < mDataBufLen) )
{
// 将未解析的数据移到头部
// Move unparsed data to the head
memcpy(mDataBufPtr, mDataBufPtr + len, mDataBufLen - len);
}
mDataBufLen -= len;
}
}
}
/**
* @brief 协议解析函数,如外部获取数据(例如中断),可直接调用此函数解析数据
* @param[in] pData 协议数据内容
* @param[in] len 需要处理的协议数据长度
*
* @return 剩余已处理的数据长度
*
* @since 1.0.0
*/
Protocol_uint32_t RS485_Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len)
{
Protocol_uint32_t remainLen = len; // 剩余数据长度 Remaining data length
Protocol_uint32_t dataLen; // 数据包长度 Packet length
Protocol_uint32_t frameLen; // 帧长度 Frame length
Protocol_uint32_t frameSum;
Protocol_Data_t ProcData;
int i = 0;
int dataBuf [ 256 ];
/**
* 以下部分需要根据协议格式进行相应的修改,解析出每一帧的数据
*/
while ( remainLen >= DATA_PACKAGE_MIN_LEN )
{
// 找到一帧数据的数据头
// Find the data header of a frame of data
while ( (remainLen >= 2) && ((pData [ 0 ] != CMD_HEAD1) || (pData [ 1 ] != CMD_HEAD2)) )
{
pData++;
remainLen--;
continue;
}
if ( remainLen < DATA_PACKAGE_MIN_LEN )
{
break;
}
dataLen = pData [ 3 ];
frameLen = dataLen + DATA_PACKAGE_FIXED_LEN;
if ( frameLen > remainLen )
{
// 数据内容不全
break;
}
// 检测校验码 Checksum
frameSum = pData [ frameLen - 3 ];
if ( frameLen > 4 )
{
// if ( RS485_getCheckSum(pData + 2, frameLen - 4) == frameSum )
// {
// 解析一帧数据
if ( ProcParseCbk != Protocol_NULL )
{
ProcParseCbk(pData + 3, dataLen - 2);
}
if ( ProtocolSetData_Cbk != Protocol_NULL )
{
// ProcData.FrameNo = pData [ 3 ];
// ProcData.PowerSts = (pData [ 4 ] >> 6) & 0x03;
ProcData.CmdID = pData [ 2 ] & 0xFF;
ProcData.DataLen = (Protocol_uint8_t) pData [ 3 ];
memcpy(ProcData.Data, pData + 4, ProcData.DataLen);
ProtocolSetData_Cbk(&ProcData);
}
// }
// else
// {
// for ( i = 0; i < frameLen; ++i )
// {
// // dataBuf [ i ] = pData [ i ];
// }
// i = 0;
// }
}
pData += frameLen;
remainLen -= frameLen;
}
return len - remainLen;
}
/**
* 根据协议格式进行拼接
*/
/**
* @brief 串口协议数据拼接,如初始化发送函数,调用此函数后,数据已通过串口发送
* @param[in] cmdID 命令字
* @param[in] pData 协议数据内容(不包括协议头、长度、帧序号、命令字、校验和,从数据域算起)
* @param[in] len 数据域长度
*
* @return 已发送的数据长度
*
* @since 1.0.0
*/
Protocol_uint32_t RS485_Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_uint8_t *pData, Protocol_uint8_t len)
{
int i = 0;
Protocol_uint16_t checksum = 0;
Protocol_uint8_t dataBuf [ 256 ];
Protocol_uint32_t frameLen;
if ( len + DATA_PACKAGE_MIN_LEN > 256 )
{
// printf("sendProtocol data is too len !!!\n");
return 0;
}
dataBuf [ 0 ] = CMD_HEAD1;
dataBuf [ 1 ] = CMD_HEAD2; // 同步帧头 Sync frame header
dataBuf [ 2 ] = len + 4;
dataBuf [ 3 ] = 0; // 命令字节 Command byte
dataBuf [ 4 ] = ( Protocol_uint8_t )cmdID;
frameLen = 5;
// 数据 Data
for ( i = 0; i < len; ++i )
{
dataBuf [ frameLen ] = pData [ i ];
frameLen++;
}
// 校验码 Checksum
// checksum = RS485_getCheckSum(dataBuf + 2, frameLen - 2);
// dataBuf [ frameLen ] = (checksum >> 8) & 0x00FF;
// frameLen++;
// dataBuf [ frameLen ] = checksum & 0x00FF;
frameLen++;
if ( UARTSend_Cbk != Protocol_NULL )
{
return UARTSend_Cbk(dataBuf, frameLen);
}
else
{
return 0;
}
}
#ifndef RS485_PROTOCOL_LIB_H
#define RS485_PROTOCOL_LIB_H
/*
Platform_32Bit
Platform_16Bit
*/
#ifdef Platform_16Bit
#define Protocol_uint8_t unsigned char
#define Protocol_uint16_t unsigned int
#define Protocol_uint32_t unsigned long
#else
#define Protocol_uint8_t unsigned char
#define Protocol_uint16_t unsigned short
#define Protocol_uint32_t unsigned int
#define Protocol_uint64_t unsigned long long
#endif
#ifndef Protocol_NULL
#define Protocol_NULL ( void * )0u
#endif /* NULL */
/**<0xEB 0x90 长度 帧序号 命令字 DATA0-DATAN CRC16_1 CRC16_2*/
/**RS485通讯协议<0x59 0x44 报文ID 长度 DATA0-DATAN CRC16_1 0x4B 0x4A*/
#define DATA_PACKAGE_MIN_LEN 7 /**<0x59 0x44 报文ID 长度 CRC16_1 0x4B 0x4A */
#define DATA_PACKAGE_FIXED_LEN 7 /**< 未计算在长度内的数据 0x59 0x44 报文ID 长度 CRC16_1 0x4B 0x4A */
#define CMD_HEAD1 0x59
#define CMD_HEAD2 0x44
#define CMD_END1 0x4B
#define CMD_END2 0x4A
/**@struct Protocol_Data_t
* @brief 解析后的协议数据
*/
typedef struct
{
Protocol_uint8_t FrameNo; /**< 帧序号 */
Protocol_uint8_t PowerSts; /**< 电源状态 */
Protocol_uint8_t CmdID; /**< 命令字 */
Protocol_uint8_t DataLen; /**< 有效数据长度 DATA0-DATAN*/
Protocol_uint8_t Data [ 256 ]; /**< 有效数据内容 DATA0-DATAN*/
} Protocol_Data_t;
typedef Protocol_uint8_t (*UARTOpen)(void);
typedef Protocol_uint32_t (*UARTSend)(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
typedef Protocol_uint32_t (*UARTRead)(Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
typedef void (*ProtocolSetData)(const Protocol_Data_t *pData);
typedef void (*ProcParse)(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
typedef void (*UARTClose)(void);
/**@struct Protocol_Func_t
* @brief 协议解析回调函数
*/
typedef struct
{
UARTOpen UARTOpen_Cbk; /**< 串口打开回调 */
UARTSend UARTSend_Cbk; /**< 串口发送回调 */
UARTRead UARTRead_Cbk; /**< 串口读取回调 */
UARTClose UARTClose_Cbk; /**< 串口关闭回调 */
ProcParse ProcParseCbk; /**< 解析后的数据, 处理了数据包序号,命令字和电源状态,和ProcParse二选一 */
ProtocolSetData ProtocolSetData_Cbk; /**< 不包含 0xEB 0x90 + 长度 + CRC16_1 + CRC16_2,和ProtocolSetData二选一 */
} Protocol_Func_t;
void RS485_Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protocol_Func_t *pFunc);
void RS485_Protocol_Service(void);
Protocol_uint32_t RS485_Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len);
Protocol_uint32_t RS485_Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_uint8_t *pData, Protocol_uint8_t len);
#endif
#include "RS485_Protocol_User.h"
#include <stdio.h>
#include <stdint.h>
#include "string.h"
#include "R485_Communication_Matrix.h"
#define UART_TX_MAX_DEPTH 1024UL //(2 * 1024UL) // 4K
#define UART_RX_MAX_DEPTH (2 * 1024UL) // 4K
#define UART_DATA_BUF_LEN (2 * 1024UL) // 4K
typedef struct
{
Protocol_uint32_t read_pos;
Protocol_uint32_t write_pos;
Protocol_uint8_t Rx_Buffer [ UART_RX_MAX_DEPTH ];
} UARTRxBuf_t;
typedef struct
{
Protocol_uint32_t read_pos;
Protocol_uint32_t write_pos;
Protocol_uint8_t Tx_Buffer [ UART_TX_MAX_DEPTH ];
} UARTTxBuf_t;
static UARTRxBuf_t UARTRxBuf;
static UARTTxBuf_t UARTTxBuf;
static Protocol_uint8_t UsartDataBuf [ 256 ];
static Protocol_uint8_t mDataBufPtr [ UART_DATA_BUF_LEN ];
static Protocol_uint8_t RS485_Protocol_OpenUart(void);
static Protocol_uint32_t RS485_Protocol_UartRead(Protocol_uint8_t *pData, Protocol_uint32_t len);
static Protocol_uint32_t RS485_Protocol_UartSend(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
static void RS485_Protocol_UartHandle(const Protocol_Data_t *pData);
void RS485_Protocol_KL30_Wakeup_Init(void)
{
Protocol_Func_t pFunc;
pFunc.UARTOpen_Cbk = RS485_Protocol_OpenUart;
pFunc.UARTSend_Cbk = RS485_Protocol_UartSend;
pFunc.UARTRead_Cbk = RS485_Protocol_UartRead;
pFunc.UARTClose_Cbk = Protocol_NULL;
pFunc.ProcParseCbk = Protocol_NULL;
pFunc.ProtocolSetData_Cbk = RS485_Protocol_UartHandle;
UARTTxBuf.read_pos = 0;
UARTTxBuf.write_pos = 0;
UARTRxBuf.read_pos = 0;
UARTRxBuf.write_pos = 0;
RS485_Protocol_Init(mDataBufPtr, UART_DATA_BUF_LEN, &pFunc);
}
void RS485_RS485_Protocol_Send_Service(void)
{
Protocol_uint32_t i = 0u;
Protocol_uint32_t DataLen = 0u;
Protocol_uint32_t SendLen = 0u;
if ( UARTTxBuf.write_pos == UARTTxBuf.read_pos )
{
return;
}
if ( UARTTxBuf.write_pos > UARTTxBuf.read_pos )
{
DataLen = UARTTxBuf.write_pos - UARTTxBuf.read_pos;
}
else
{
DataLen = UART_TX_MAX_DEPTH - (UARTTxBuf.read_pos - UARTTxBuf.write_pos);
}
if ( DataLen > 255 )
{
SendLen = 255;
}
else
{
SendLen = DataLen;
}
for ( i = 0u; i < SendLen; i++ )
{
UsartDataBuf [ i ] = UARTTxBuf.Tx_Buffer [ UARTTxBuf.read_pos ];
UARTTxBuf.read_pos = (UARTTxBuf.read_pos + 1) % UART_TX_MAX_DEPTH;
}
// UART_Ch1_Send_Multiple_Byte(UsartDataBuf, SendLen);
}
static Protocol_uint8_t RS485_Protocol_OpenUart(void)
{
#if 0
UART_Channel_Config_st_t loc_config;
loc_config.u32UARTChEn = 1;
loc_config.u32UARTbps = 115200;
loc_config.pfnUARTConfirmCallBack = Protocol_NULL;
loc_config.pfnUARTReadMsgCallBack = UART_Put;
UART_Init(UART_RLIN31, &loc_config);
#endif
return 1;
}
static Protocol_uint32_t RS485_Protocol_UartRead(Protocol_uint8_t *pData, Protocol_uint32_t len)
{
Protocol_uint32_t i = 0;
Protocol_uint32_t DataLen = 0u;
Protocol_uint32_t ReadLen = 0u;
if ( UARTRxBuf.write_pos == UARTRxBuf.read_pos )
{
return 0; //队列空
}
if ( UARTRxBuf.write_pos > UARTRxBuf.read_pos )
{
DataLen = UARTRxBuf.write_pos - UARTRxBuf.read_pos;
}
else
{
DataLen = UART_RX_MAX_DEPTH - (UARTRxBuf.read_pos - UARTRxBuf.write_pos);
}
if ( len > DataLen )
{
ReadLen = DataLen;
}
else
{
ReadLen = len;
}
for ( i = 0u; i < ReadLen; i++ )
{
pData [ i ] = UARTRxBuf.Rx_Buffer [ UARTRxBuf.read_pos ];
UARTRxBuf.read_pos = (UARTRxBuf.read_pos + 1) % UART_RX_MAX_DEPTH;
}
return ReadLen;
}
static Protocol_uint32_t RS485_Protocol_UartSend(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len)
{
Protocol_uint32_t i = 0;
Protocol_uint32_t RemainLen = 0u;
if ( UARTTxBuf.write_pos >= UARTTxBuf.read_pos )
{
RemainLen = UART_TX_MAX_DEPTH - (UARTTxBuf.write_pos - UARTTxBuf.read_pos);
}
else
{
RemainLen = UARTTxBuf.read_pos - UARTTxBuf.write_pos;
}
if ( u32Len > RemainLen )
{
return 1; //队列已满,无法插入队列
}
for ( i = 0; i < u32Len; i++ )
{
UARTTxBuf.Tx_Buffer [ UARTTxBuf.write_pos ] = pData [ i ];
UARTTxBuf.write_pos = (UARTTxBuf.write_pos + 1) % UART_TX_MAX_DEPTH;
}
return 0;
}
uint8_t RS485_data[4] = {0,0,0,0};
static void RS485_Protocol_UartHandle(const Protocol_Data_t *pData)
{
if ( pData->CmdID == 0x60 )
{
RS485_data[0] = pData->Data[0];
RS485_data[1] = pData->Data[1];
RS485_data[2] = pData->Data[2];
RS485_data[3] = pData->Data[3];
memcpy(R485_ID60h.Msg, RS485_data, 4u);
R485_Receive_0x60();
RS485_TX_finish = 3U;
}
else
{
}
}
void RS485_UART_Put(Protocol_uint16_t Data)
{
Protocol_uint32_t nextPos = 0u;
nextPos = (UARTRxBuf.write_pos + 1) % UART_RX_MAX_DEPTH;
if ( nextPos == UARTRxBuf.read_pos )
{
//队列已满,无法插入队列
}
else
{
UARTRxBuf.Rx_Buffer [ UARTRxBuf.write_pos ] = (Protocol_uint8_t) Data;
UARTRxBuf.write_pos = (UARTRxBuf.write_pos + 1) % UART_RX_MAX_DEPTH;
}
//return;
}
#ifndef RS485_PROTOCOL_USER_H__
#define RS485_PROTOCOL_USER_H__
#include "RS485_Protocol_Lib.h"
void RS485_Protocol_KL30_Wakeup_Init(void);
void RS485_RS485_Protocol_Send_Service(void); // 10ms任务调用
void RS485_UART_Put(Protocol_uint16_t Data);
#endif
......@@ -20,6 +20,12 @@
#include "string.h"
#include "api_RS485.h"
#include "R485_Communication_Matrix.h"
#include "NVS_Test.h"
#include "Power_Controls.h"
#include "RS485_Protocol_CRC16.h"
#include "RS485_Protocol_Lib.h"
#include "RS485_Protocol_User.h"
/*******************************************************************************
* *
* ϵͳ��������ģʽ(SYS_MODE_OFF / SYS_MODE_ON / SYS_MODE_STANDBY )�����б� *
......@@ -93,67 +99,6 @@ void Sys_Run_Mode_10ms_Tasks_Group(void)
// UART_Ch0_Send_Multiple_Byte(testdata,3);
// RS485_User_Tx_Data();
if(clearOdoFlag == 0)
{
backsend();
// RS485_TX_finish = 0;
if(RS485_TX_finish == 0)
{
LINE_OUT_NEG_09 = 1;
if(LINE_OUT_NEG_09 == 1)
{
if(zhenduanflag == 0)
{
R485_Send_Line_0x47(MENU_CHECK_STEP);
RS485_User_Tx_Data();
comparestart = 0;
}
else if(zhenduanflag == 1)
{
R485_Send_0x47();
comparestart = 0;
}
else if(zhenduanflag == 2)
{
R485_Sendcheck_0x47();
}
else
{
;
}
}
// else
// {
// RS485_TX_finish = 0;
// }
}
else
{
LINE_OUT_NEG_09 = 0;
Recv_Byte();
}
queren = 0;
}
else
{
MENU_CHECK_STEP = 3;
backsend();
RS485_User_Tx_Data();
if(clearodotime < 3000)
clearodotime++;
if(clearodotime >= 1500)
{
// Port_SetPortPinLevel(2,9,PortGpioHigh);
queren = 1;
}
}
}
/*==============================================================================
......@@ -185,7 +130,38 @@ void Sys_Run_Mode_20ms_Tasks_Group0(void)
time100mssend = 0;
}
if(RS485_TX_finish == 0)
{
LINE_OUT_NEG_09 = 1;
if(LINE_OUT_NEG_09 == 1)
{
RS485_User_Tx_Data();
}
}
else
{
LINE_OUT_NEG_09 = 0;
// Recv_Byte();
RS485_Protocol_Service();
}
if (errNum == 0)
{
if((KL1530ON == 1) && (RenWuDelay >= 30U))
{
NVS_Test_Service();
}
else if ((KL1530ON == 1) && (RenWuDelay < 30U))
{
TurnOffPowerCount ++;
}
else
{
RenWuDelay = 0U;
RS485_TX_finish = 2U; /*断电置为0x2,不发不收*/
}
}
}
/*==============================================================================
......@@ -205,7 +181,7 @@ void Sys_Run_Mode_50ms_Tasks_Group(void)
timerms++;
}
Power_KL15_KL30_Controls();
// if ( timer_100ms >= 500 )
// {
......@@ -369,6 +345,8 @@ void Sys_Exact_50us_Tasks(void)
------------------------------------------------------------------------------*/
void Sys_Exact_100ms_Tasks(void)
{
Power_Control_Count();
NVS_Test_DelayCount();
// CHECK_IPK_COUNT( );
}
/*============================================================================*/
......
#include "api_RS485.h"
#include "R485_Communication_Matrix.h"
#include "string.h"
#include "NVS_Test.h"
#define R485_BUF_SIZE (1024 * 4 )
#define R485_UART_PORT (1)
#define R485_TX_OUT_MCU R485_TX
......@@ -31,6 +33,7 @@ _ID0X49h_Data R485_ID49h;
_ID0X42h_Data R485_ID42h;
_ID0X4Ah_Data R485_ID4Ah;
_ID0X4Dh_Data R485_ID4Dh;
_ID0X60h_Data R485_ID60h;
LineSta LineGetSta;
void R485_TX_Init(void)
......@@ -267,7 +270,7 @@ static void RS485_Receive_Data_Analysis(void)
uint32_t R485_Send(const uint16_t cmdID, const uint8_t* pData, uint8_t len)
{
uint8_t dataBuf[128];
uint8_t dataBuf[15];
int i = 0;
uint16_t checksum = 0;
uint32_t frameLen;
......@@ -295,8 +298,8 @@ uint32_t R485_Send(const uint16_t cmdID, const uint8_t* pData, uint8_t len)
}
// checksum = Yadi_CAL_Data_Sum(&dataBuf[2], R485_DATA_LEN + 2);
checksum = Yadi_CAL_Data_Sum(&dataBuf[2], len + 2);
// checksum = 0;
// checksum = Yadi_CAL_Data_Sum(&dataBuf[2], len + 2);
checksum = 0;
dataBuf[frameLen] = checksum;
frameLen++;
dataBuf[frameLen] = 0X4B;
......@@ -309,7 +312,7 @@ uint32_t R485_Send(const uint16_t cmdID, const uint8_t* pData, uint8_t len)
// }
uint8_t sendresult = 0;
sendresult = UART_Ch0_Send_Multiple_Byte(dataBuf,frameLen);
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
// while(1)
// {
if(sendresult == 0)
......@@ -334,7 +337,7 @@ void RS485_User_Tx_Data(void)
{
#if (0)
#if (1)
uint8_t flag = 0;
uint32_t sendfinishflag = 0;
// if(firstflag = 0)
......@@ -342,28 +345,28 @@ void RS485_User_Tx_Data(void)
memcpy(lastdata,nowdata,4);
// }
// m
sendmsgAll[0] = (uint8_t)sendnum & 0xFF;
sendmsgAll[1] = ((uint8_t)(sendnum >>8)) & 0xFF;
sendmsgAll[2] = ((uint8_t)(sendnum >>16)) & 0xFF;
sendmsgAll[3] = ((uint8_t)(sendnum >>24)) & 0xFF;
sendmsgAll[0] = (uint8_t)(BenCiXieRuNum & 0xFF);
sendmsgAll[1] = (uint8_t)((BenCiXieRuNum >> 8U) & 0xFF);
sendmsgAll[2] = (uint8_t)((BenCiXieRuNum >> 16U) & 0xFF);
sendmsgAll[3] = (uint8_t)((BenCiXieRuNum >> 24U) & 0xFF);
sendmsgAll[4] = ((uint8_t)(sendnum)) & 0xFF;
sendmsgAll[5] = ((uint8_t)(sendnum >>8)) & 0xFF;
sendmsgAll[6] = ((uint8_t)(sendnum >>16)) & 0xFF;
sendmsgAll[7] = ((uint8_t)(sendnum >>24)) & 0xFF;
sendmsgAll[4] = (uint8_t)(TotalExecutionNum & 0xFF);
sendmsgAll[5] = (uint8_t)((TotalExecutionNum >> 8U) & 0xFF);
sendmsgAll[6] = (uint8_t)((TotalExecutionNum >> 16U) & 0xFF);
sendmsgAll[7] = (uint8_t)((TotalExecutionNum >> 24U) & 0xFF);
if(RS485_TX_finish == 0)
{
// LINE_OUT_NEG_09 = 1;
switch (RS485_send_num)
{
case RS485_Tx_ID48_Idx:
case RS485_Tx_ID70_Idx:
sendfinishflag = R485_Send(0x70, sendmsgAll, 8);
RS485_TX_finish = 1;
// RS485_TX_finish = 0U;
if(sendfinishflag == 0)
{
RS485_TX_finish = 1U;
if(RS485_TX_finish == 1)
{
// RS485_send_num++;
......@@ -381,69 +384,69 @@ void RS485_User_Tx_Data(void)
}
break;
case RS485_Tx_ID49_Idx:
// case RS485_Tx_ID49_Idx:
sendfinishflag = R485_Send(0x71, sendmsgAll, 8);
RS485_TX_finish = 1;
if(sendfinishflag == 0)
{
// sendfinishflag = R485_Send(0x71, sendmsgAll, 8);
// RS485_TX_finish = 1;
// if(sendfinishflag == 0)
// {
if(RS485_TX_finish == 1)
{
// sendnum++;
RS485_send_num ++;
}
// if(RS485_TX_finish == 1)
// {
// // sendnum++;
// RS485_send_num ++;
// }
}
// uart_wait_tx_done(R485_UART_PORT, 100);
break;
case RS485_Tx_ID4A_Idx:
sendfinishflag = R485_Send(0x72, sendmsgAll, sizeof(sendmsgAll));
RS485_TX_finish = 1;
if(sendfinishflag == 0)
{
RS485_TX_finish = 1;
if(RS485_TX_finish == 1)
{
RS485_send_num++;
}
}
break;
case 3:
sendfinishflag = R485_Send(0x73, sendmsgAll, sizeof(sendmsgAll));
RS485_TX_finish = 1;
if(sendfinishflag == 0)
{
RS485_TX_finish = 1;
if(RS485_TX_finish == 1)
{
RS485_send_num++;
}
}
break;
case 4:
sendfinishflag = R485_Send(0x74, sendmsgAll, sizeof(sendmsgAll));
RS485_TX_finish = 1;
if(sendfinishflag == 0)
{
RS485_TX_finish = 1;
if(RS485_TX_finish == 1)
{
RS485_send_num++;
}
}
break;
// }
// // uart_wait_tx_done(R485_UART_PORT, 100);
// break;
// case RS485_Tx_ID4A_Idx:
// sendfinishflag = R485_Send(0x72, sendmsgAll, sizeof(sendmsgAll));
// RS485_TX_finish = 1;
// if(sendfinishflag == 0)
// {
// RS485_TX_finish = 1;
// if(RS485_TX_finish == 1)
// {
// RS485_send_num++;
// }
// }
// break;
// case 3:
// sendfinishflag = R485_Send(0x73, sendmsgAll, sizeof(sendmsgAll));
// RS485_TX_finish = 1;
// if(sendfinishflag == 0)
// {
// RS485_TX_finish = 1;
// if(RS485_TX_finish == 1)
// {
// RS485_send_num++;
// }
// }
// break;
// case 4:
// sendfinishflag = R485_Send(0x74, sendmsgAll, sizeof(sendmsgAll));
// RS485_TX_finish = 1;
// if(sendfinishflag == 0)
// {
// RS485_TX_finish = 1;
// if(RS485_TX_finish == 1)
// {
// RS485_send_num++;
// }
// }
// break;
default:
// sendnum++;
RS485_send_num = 0;
break;
RS485_TX_finish = 1;
// RS485_TX_finish = 1;
}
}
#endif
#if(1)
#if(0)
uint8_t flag = 0;
uint32_t sendfinishflag = 0;
......@@ -508,7 +511,7 @@ void backsend(void)
if(RS485_send_time>=20)
{
RS485_send_time = 0;
RS485_TX_finish = 0;
// RS485_TX_finish = 0;
sendnum--;
RS485_send_num--;
}
......
......@@ -15,15 +15,16 @@
typedef enum
{
RS485_Tx_ID48_Idx = 0,
RS485_Tx_ID49_Idx,
RS485_Tx_ID4A_Idx,
RS485_Tx_ID70_Idx,
// RS485_Tx_ID48_Idx = 0,
// RS485_Tx_ID49_Idx,
// RS485_Tx_ID4A_Idx,
RS485_Tx_ID70_Idx = 0,
RS485_Tx_ID71_Idx,
RS485_Tx_ID72_Idx,
RS485_Tx_ID73_Idx,
RS485_Tx_ID74_Idx,
RS485_Tx_ID_Idx_Max,
}RS485_Receive_ID_Idx_en_t;
typedef enum
......
......@@ -39,6 +39,11 @@
#include "Display_Info.h"
#include "FreIn_User.h"
#include "../UART/UART.h"
#include "NVS_Test.h"
#include "Power_Controls.h"
#include "RS485_Protocol_CRC16.h"
#include "RS485_Protocol_Lib.h"
#include "RS485_Protocol_User.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
......@@ -71,11 +76,13 @@ void Sys_Startup_Init(void)
WDT_Init( );
Sys_Tick_Timer_Call_Back_Reg(Sys_Process_ISR);
RTE_GPIO_Init( );
Power_Controls_Init();
NVS_Test_Init();
GPIO_SET_KEPP( );
RTE_ADC_Init( );
COM_CAN_Init( );
Can_Init( );
RS485_Protocol_KL30_Wakeup_Init();
enable_interrupt( );
Sys_Tick_Timer_Start( );
TFT_LCD_Startup( );
......@@ -92,9 +99,10 @@ void Sys_Startup_Init(void)
loc_config.en2UARTPolarity = UART_POLARITY_NORMAL;
loc_config.pfnUARTConfirmCallBack = 0;
loc_config.pfnUARTErrHandleCallBack = 0;
loc_config.pfnUARTReadMsgCallBack = UART_Put;
loc_config.pfnUARTReadMsgCallBack = RS485_UART_Put;
firstIGON = 1;
UART_Init(UART_RLIN30, &loc_config);
loc_config.enUARTLINMode = MODE_UART;
loc_config.u32UARTbps = 9600;
loc_config.enUARTOrder = UART_LSB;
......
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