MS-DTU/MS-DTU-V1/User/uart_BDModule.c

585 lines
15 KiB
C
Raw Permalink Normal View History

2025-04-03 14:18:58 +08:00
/*
*********************************************************************************************************
* IAR Development Kits
* on the
*
* Nano100
*
* Filename : uart_BDModule.h
* Version : V1.00
* Programmer(s) : Qian Xianghong
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "includes.h"
const uint8_t BD_APP = RF_APP_AJH;
const uint8_t BD_PROTOCOL_VER = RF_PROTOCOL_VER_2;
loopbuff_t CC200A_TaskM;
uint8_t CC200A_TaskM_Data[sizeof(uint8_t) * (4 + 1)] = {0};
#define RF_SelfPSN (dcBuff.configBottle.PSN)
uint8_t BD_RF_MAC_FN = 0;
uint8_t BD_RF_APP_PN = 0;
uint8_t BD_RF_APP_IDX = 0;
// <20><><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD><EFBFBD>֡
bd_frame_t BD_Send_Frame, BD_RecvFrame;
// <20><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ϣ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>Ϣ
volatile uint8_t BD_semZjxx = 0, BD_semFkxx = 0;
bd_zjxx_t BD_Zjxx;
bd_fkxx_t BD_Fkxx;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>״̬
uint8_t BD_initStatus = 0;
volatile uint8_t BD_hasPowered = 0;
// <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t bd_cs_nor(uint8_t *message, int16_t len)
{
int16_t i;
uint8_t cs = 0;
for(i = 0; i < len; i++)
cs ^= message[i];
return cs;
}
// <20><>ʼ<EFBFBD><CABC>֡
void bd_initial_frame(bd_frame_t *frame, char *cmd)
{
memset((uint8_t *) frame, 0, sizeof(bd_frame_t));
frame->sof = BD_FRAME_SOF;
memmove(frame->cmd, cmd, 4);
frame->len = BD_MIN_FRAME_LEN; // С<><D0A1>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ת<EFBFBD><D7AA><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ģʽ
}
// ׷<>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t bd_append_payload(bd_frame_t *frame, uint8_t payload_len, uint8_t *payload)
{
if(frame->len < BD_MIN_FRAME_LEN || frame->len + payload_len > BD_MAX_FRAME_LEN)
return 0;
if(payload_len > 0)
memmove(frame->bd_payload + (frame->len - BD_MIN_FRAME_LEN), payload, payload_len);
frame->len += payload_len;
return 1;
}
void bd_prepare_send(bd_frame_t *frame)
{
uint8_t *buf = (uint8_t *) frame;
uint16_t len = frame->len;
frame->len = htons(len); // ת<><D7AA><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ģʽ
buf[len - 1] = bd_cs_nor(buf, len - 1); // <20><>дУ<D0B4><D0A3><EFBFBD><EFBFBD>
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
uint8_t bd_phy_valid(bd_frame_t *frame)
{
// ͨ<><CDA8><EFBFBD><EFBFBD>Ϣ֡
if(strncmp(frame->cmd, BD_TXXX, 4) == 0)
{
// ͨ<><CDA8>01<30><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ0<D6B4><30>ͨ<EFBFBD><CDA8>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ0<D4BF><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>00
if(frame->txxx.xxlb != 0x60 || ntohs(frame->txxx.bitLen) > 624)
return 0;
}
// <20><><EFBFBD><EFBFBD>֡У<D6A1><D0A3><EFBFBD>ɹ<EFBFBD>
return 1;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
uint8_t bd_rf_phy_valid(bd_rf_frame_t *frame)
{
if(frame->sof != RF_FRAME_SOF || frame->len < BD_RF_MIN_FRAME_LEN || frame->len > BD_RF_MAX_FRAME_LEN)
return 0;
if(frame->vendor_id != RF_MARK_LS || frame->app_id != BD_APP || frame->protocol_ver != BD_PROTOCOL_VER)
return 0;
if(rf_crc_16((uint8_t *) frame, frame->len) != 0)
return 0;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD>ɹ<EFBFBD>
return 1;
}
// mac<61><63>У<EFBFBD><D0A3>
uint8_t bd_rf_mac_valid(bd_rf_frame_t *frame, uint8_t dir)
{
if(frame->dir != dir)
return 0;
// mac<61><63>У<EFBFBD><D0A3><EFBFBD>ɹ<EFBFBD>
return 1;
}
// <20><><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0>SOF
void BD_SearchSOF(uint8_t *buf, uint16_t fromPos, uint16_t *len)
{
uint16_t i;
for(i = fromPos; i < *len && buf[i] != BD_FRAME_SOF; i++)
{
}
*len -= i;
memmove(buf, buf + i, *len);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>֡
char CC200A_recvBuff[100] = {0}; // <20><>չ<EFBFBD>ڴ<EFBFBD>
uint16_t CC200A_Idx = 0;
void CC200A_ParseFrame(uint8_t c)
{
if((CC200A_Idx==0)&&(c!='\n'))
return;
if(CC200A_Idx < 100)
CC200A_recvBuff[CC200A_Idx++] = c;
// <20><><EFBFBD>з<EFBFBD>
if((c == '\n')&&(CC200A_Idx>2))
{
// <20><><EFBFBD><EFBFBD>\nǰ<6E><C7B0><EFBFBD><EFBFBD>\r
if(CC200A_Idx > 0 && CC200A_recvBuff[CC200A_Idx - 1] == '\r')
CC200A_recvBuff[--CC200A_Idx] = 0;
// <20>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7BBB0><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
if(strstr(CC200A_recvBuff, "RDY"))
{
//DTU_recvBuff[idx] = 0;
printf("CC200A RDY");
}
// <20><><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
if(strstr(CC200A_recvBuff,"ERROR"))
{
printf("CC200A ERROR");
}
// û<><C3BB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
memset(CC200A_recvBuff, 0, DTU_RECVBUFF_SIZE);
CC200A_Idx = 0;
}
}
// <20>ȴ<EFBFBD>DTU<54><55><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
uint32_t CC200A_ParseResult(char *checkPattern, char *checkErrPattern, char *resultBuff, uint16_t waitSeconds)
{
uint8_t done = 0, timeOut;
uint32_t timeOutTick;
uint8_t u8DTU;
uint16_t count, idx = 0;
uint32_t ret = FALSE;
uint8_t strLen = strlen(checkPattern);
uint8_t errLen = strlen(checkErrPattern);
memset(DTU_recvBuff, 0, DTU_RECVBUFF_SIZE);
// <20><><EFBFBD><EFBFBD><E2B7B5><EFBFBD><EFBFBD>Ϣ
do
{
timeOut = 1;
timeOutTick = GetDelayTick(waitSeconds * 1000);
while(!IsTickOut(timeOutTick))
{
if(LoopBuff_GetCount(&CC200A_TaskM))
{
timeOut = 0;
break;
}
}
if(!timeOut)
{
count = LoopBuff_GetCount(&DTU_TaskM);
while(count--)
{
// ȡ<><C8A1><EFBFBD><EFBFBD>
memmove(&u8DTU, LoopBuff_GetDataPtr(&DTU_TaskM, DTU_TaskM.info.rdPtr), 1);
LoopBuff_RemoveItems(&DTU_TaskM, 1);
// if(u8DTU == '\n')
// printf("\\n");
// else if(u8DTU == '\r')
// printf("\\r");
// else
// printf("%c", u8DTU);
// <20><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD>͵<EFBFBD><CDB5><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>><3E><><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7>سɹ<D8B3>
if(strcmp(checkPattern, ">") == 0 && u8DTU == '>')
{
strcpy(resultBuff, ">");
ret = TRUE;
done = 1;
break;
}
// <20><><EFBFBD>з<EFBFBD>
if(u8DTU == '\n')
{
// <20><><EFBFBD><EFBFBD>\nǰ<6E><C7B0><EFBFBD><EFBFBD>\r
if(idx > 0 && DTU_recvBuff[idx - 1] == '\r')
DTU_recvBuff[--idx] = 0;
// <20>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7BBB0><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
if((strLen > 0 && strstr(DTU_recvBuff, checkPattern)) || (strLen == 0 && idx > 0))
{
DTU_recvBuff[idx] = 0;
strcpy(resultBuff, DTU_recvBuff);
ret = TRUE;
done = 1;
break;
}
// <20><><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
if(errLen > 0 && strstr(DTU_recvBuff, checkErrPattern))
{
DTU_recvBuff[idx] = 0;
strcpy(resultBuff, DTU_recvBuff);
ret = FALSE;
done = 1;
break;
}
// û<><C3BB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
memset(DTU_recvBuff, 0, DTU_RECVBUFF_SIZE);
idx = 0;
continue;
}
if(idx < DTU_RECVBUFF_SIZE)
DTU_recvBuff[idx++] = u8DTU;
}
}
} while(!done && !timeOut);
return ret;
}
// <20>Լ<EFBFBD>
uint8_t BD_Xtzj()
{
// uint8_t try_cnt;
// uint32_t stop_seconds;
// bd_initial_frame(&BD_Send_Frame, BD_XTZJ);
// bd_append_payload(&BD_Send_Frame, sizeof(bd_xtzj_t), BD_Send_Frame.bd_payload);
// bd_prepare_send(&BD_Send_Frame);
// for(try_cnt = 0; try_cnt < 1; try_cnt++)
// {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>־
// BD_semZjxx = 0;
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// UART_Transmit(&huart1, (uint8_t *) &BD_Send_Frame, ntohs(BD_Send_Frame.len));
// // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// stop_seconds = rf_get_seconds() + 2;
// while(rf_get_seconds() < stop_seconds)
// {
// if(BD_semZjxx)
// {
// printf("\nBD Module self check returned.\n");
// if(BD_Zjxx.antennaErr)
// printf("\nThe antenna has error!\n");
// if(BD_Zjxx.boardErr)
// printf("\nThe board has error!\n");
// if(BD_Zjxx.cardErr)
// printf("\nThe card has error!\n");
// if(BD_Zjxx.channelErr)
// printf("\nThe channel has error!\n");
// if(BD_Zjxx.snErr)
// printf("\nThe serial no has error!\n");
// if(BD_Zjxx.dataErr)
// printf("\nThe data has error!\n");
// if(BD_Zjxx.chkErr)
// printf("\nThe check has error!\n");
// if(BD_Zjxx.idErr)
// printf("\nThe id has error!\n");
// if(BD_Zjxx.phyErr)
// printf("\nThe physical has error!\n");
// if(!BD_Zjxx.antennaErr && !BD_Zjxx.boardErr && !BD_Zjxx.cardErr && !BD_Zjxx.channelErr
// && !BD_Zjxx.snErr && !BD_Zjxx.dataErr && !BD_Zjxx.chkErr && !BD_Zjxx.idErr && !BD_Zjxx.phyErr)
// {
// return 1;
// }
// break;
// }
// delay_ms(200);
// }
// delay_ms(500);
// }
// return 0;
}
void CC200A_IRQHandler(USART_Handle *huart)
{
// uint8_t c = (uint8_t) huart->Instance->RDR;
// printf("%c", c);
// // ֱ<>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
// CC200A_ParseFrame(c);
uint8_t u8DTU = (uint8_t) huart->Instance->RDR;
//if(DTU_uartPrint)
{
if(u8DTU == '\n')
printf("\\n\n");
else if(u8DTU == '\r')
printf("\\r");
else
printf("%c", u8DTU);
}
// <20><><EFBFBD><EFBFBD><EBBBBA>
//
// LoopBuff_PutItem(&CC200A_TaskM, &u8DTU);
if(u8DTU == 'Y')
printf("%c", u8DTU);
}
// <20><>ʼ<EFBFBD><CABC>
void CC200A_Init()
{
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
/**USART3 GPIO Configuration
PB6 ------> USART1_TX
PB7 ------> USART1_RX
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_7;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void CC200A_Open()
{
LL_USART_InitTypeDef USART_InitStruct = {0};
// <20><>PSN<53><4E>CRCУ<43><D0A3>ֵ<EFBFBD><D6B5>Ϊα<CEAA><CEB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//srand(rf_crc_16(dcBuff.configBottle.PSN, 6));
// BD_RF_MAC_FN = rand() % 256;
// BD_RF_APP_PN = rand() % 256;
// <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LoopBuff_Create(&CC200A_TaskM, sizeof(uint8_t), 4, 0, (uint32_t) CC200A_TaskM_Data);
//LL_USART_Disable(huart1.Instance);
huart1.RxISR = CC200A_IRQHandler;
// /* Peripheral clock enable */
// LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
// /* USART3 interrupt Init */
// NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
// NVIC_EnableIRQ(USART1_IRQn);
// USART_InitStruct.BaudRate = 115200;
// USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
// USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
// USART_InitStruct.Parity = LL_USART_PARITY_NONE;
// USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
// USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
// USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
// LL_USART_Init(USART1, &USART_InitStruct);
// LL_USART_ConfigAsyncMode(USART1);
// SET_BIT(USART1->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
// LL_USART_Enable(USART1);
}
// <20><>ʼ<EFBFBD><CABC>֡
void bd_rf_initial_frame(bd_rf_frame_t *frame)
{
memset((uint8_t *) frame, 0, sizeof(bd_rf_frame_t));
frame->len = BD_RF_MIN_FRAME_LEN;
}
// ׷<>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t bd_rf_append_payload(bd_rf_frame_t *frame, uint8_t payload_len, uint8_t *payload)
{
if(frame->len < BD_RF_MIN_FRAME_LEN || frame->len + payload_len > BD_RF_MAX_FRAME_LEN)
return 0;
if(payload_len > 0)
memmove(frame->app_payload + (frame->len - BD_RF_MIN_FRAME_LEN), payload, payload_len);
frame->len += payload_len;
return 1;
}
// ģ<><C4A3><EFBFBD>ϵ磬<CFB5><E7A3AC><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CC200A_PowerOn()
{
uint8_t i, count = 0;
char buff[40];
static uint8_t first = 1;
if(BD_hasPowered)
return;
printf("\nCC200A power on ...\n");
VCC_CC200A_ON();
VCC_CC200A_BCK_ON();
//delay_ms(2700);
if(CC200A_ParseResult("RDY", "", buff, 60))
{
printf("r RDY");
}
// if(DTU_ParseResult("+QURC: 5", "", buff, 30))
// {
// printf("r +QURC: 5");
// }
// if(DTU_ParseResult("+QURC: 0", "", buff, 30))
// {
// printf("r +QURC: 0");
// }
// if(DTU_ParseResult("+QURC: 3", "", buff, 30))
// {
// printf("r +QURC: 3");
// }
}
void CC200A_PowerOff()
{
// if(!BD_hasPowered)
// return;
BD_hasPowered = 0;
printf("\nCC200A_PowerOff ...\n");
VCC_CC200A_OFF();
VCC_CC200A_BCK_OFF();
delay_ms(200);
}
// <20><><EFBFBD>ڳ<EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD><CAB1>
extern uint16_t DTU_tmrQPendLong; // 120s
//extern uint16_t DTU_tmrQPendShort; // 5s
extern uint16_t DTU_tmrQPendSpec; // 40s
// Ӧ<>ò㷢<C3B2>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>
uint8_t CC200A_rf_app_send_data(uint8_t payload_len, uint8_t *payload)
{
// uint16_t i;
char cmd[80], buff[40];
//AT+QSMGT="TEST7",1,128,1,1,"TEST003"
sprintf(cmd, "AT+QSMGT=1,128,1,1,\"%s\"",payload);
if(!DTU_ExecuteCmd(cmd, "+QURC: 2", "ERROR", buff, DTU_tmrQPendSpec))
{
printf("\nsend err ...\n");
}
// break;
// if(strstr(buff, "+QIOPEN: 0,0"))
// {
// ret = TRUE;
// break;
// }
// uint8_t try_cnt;
// uint32_t stop_seconds;
// uint16_t crc;
// bd_rf_frame_t *rf = (bd_rf_frame_t *) BD_Send_Frame.txsq.bytes;
// S_RTC_TIME_DATA_T sRTC;
// // <20><>ʼ<EFBFBD><CABC>BD֡
// bd_initial_frame(&BD_Send_Frame, BD_TXSQ);
// // <20><>ʼ<EFBFBD><CABC>RF֡
// bd_rf_initial_frame(rf);
// // Ӧ<>ò<EFBFBD>
// bd_rf_append_payload(rf, payload_len, payload);
// rf->app_pn = BD_RF_APP_PN;
// rf->app_idx = 0; // <20>ݲ<EFBFBD>ʵ<EFBFBD>ְַ<D6B7><D6B0><EFBFBD><EFBFBD><EFBFBD>
// rf->app_tbc = 0;
// // net<65><74>
// rf->net_type = RF_NET_TYPE_DATA;
// // mac<61><63>
// rf->dir = RF_DIR_UP;
// rf->mac_type = RF_MAC_TYPE_DATA;
// rf->mac_ack_req = 0;
// rf->mac_fn = BD_RF_MAC_FN;
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// rf->sof = RF_FRAME_SOF;
// rf->vendor_id = RF_MARK_LS;
// rf->app_id = BD_APP;
// rf->protocol_ver = BD_PROTOCOL_VER;
// memmove(rf->srcPSN, RF_SelfPSN, 6);
// crc = rf_crc_16((uint8_t *) rf, rf->len - 2);
// ((uint8_t *) rf)[rf->len - 2] = crc >> 8;
// ((uint8_t *) rf)[rf->len - 1] = crc & 0xFF;
// // ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
// BD_Send_Frame.txsq.xxlb = 0x46; // <20><>ͨ<EFBFBD><CDA8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
// BD_Send_Frame.txsq.dstAddr[0] = (dcBuff.configDisplay.bdCommander >> 16) & 0xFF; // ָ<>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD><EFBFBD>
// BD_Send_Frame.txsq.dstAddr[1] = (dcBuff.configDisplay.bdCommander >> 8) & 0xFF;
// BD_Send_Frame.txsq.dstAddr[2] = (dcBuff.configDisplay.bdCommander & 0xFF);
// BD_Send_Frame.txsq.bitLen = htons(rf->len * 8);
// // ׷<><D7B7>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// bd_append_payload(&BD_Send_Frame,
// sizeof(BD_Send_Frame.txsq) - sizeof(BD_Send_Frame.txsq.bytes) + payload_len + BD_RF_MIN_FRAME_LEN,
// (uint8_t *) &BD_Send_Frame.txsq);
// // <20>޸<EFBFBD><DEB8><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cs
// bd_prepare_send(&BD_Send_Frame);
// for(try_cnt = 0; try_cnt < 3; try_cnt++)
// {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>־
// BD_semFkxx = 0;
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// UART_Transmit(&huart1, (uint8_t *) &BD_Send_Frame, ntohs(BD_Send_Frame.len));
//// for(i = 0; i < ntohs(BD_Send_Frame.len); i++)
//// printf("%02X ", ((uint8_t *) &BD_Send_Frame)[i]);
//// printf("\n");
// // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>s
// stop_seconds = rf_get_seconds() + 2;
// while(rf_get_seconds() < stop_seconds)
// {
// if(BD_semFkxx)
// {
// printf("\nBD Module feedback returned.\n");
// if(BD_Fkxx.fkbz == 0 && strncmp(BD_Fkxx.fjxx, BD_TXSQ, 4) == 0)
// {
// printf("\nThe message has send.\n");
// BD_RF_MAC_FN++;
// BD_RF_APP_PN++;
// // <20><>¼<EFBFBD><C2BC><EFBFBD>ͳɹ<CDB3><C9B9><EFBFBD>ʱ<EFBFBD><CAB1>
// RTC_GetDateAndTime(&sRTC);
// DTU_succTime = Calc_SecondsFromYear(INITIAL_YEAR, sRTC.u32Year, sRTC.u32Month, sRTC.u32Day,
// sRTC.u32Hour, sRTC.u32Minute, sRTC.u32Second);
// return 1;
// }
// printf("\nThe message has not send.\n");
// break;
// }
// delay_ms(200);
// }
// delay_ms(500);
// }
return 0;
}