479 lines
12 KiB
C
479 lines
12 KiB
C
|
|
/*
|
|||
|
|
*********************************************************************************************************
|
|||
|
|
* 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;
|
|||
|
|
|
|||
|
|
#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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
uint8_t 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>֡
|
|||
|
|
void BD_ParseFrame(uint8_t c)
|
|||
|
|
{
|
|||
|
|
static uint16_t RdIdx = 0;
|
|||
|
|
uint8_t *BD_ModuleData = (uint8_t *) &BD_RecvFrame;
|
|||
|
|
uint16_t i;
|
|||
|
|
uint8_t frameOk, frameErr;
|
|||
|
|
uint16_t len;
|
|||
|
|
|
|||
|
|
if(RdIdx == 0 && c != BD_FRAME_SOF)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
BD_ModuleData[RdIdx++] = c;
|
|||
|
|
|
|||
|
|
do
|
|||
|
|
{
|
|||
|
|
if(RdIdx < 7)
|
|||
|
|
break;
|
|||
|
|
len = (BD_ModuleData[5] << 8) | BD_ModuleData[6];
|
|||
|
|
|
|||
|
|
frameErr = (len < BD_MIN_FRAME_LEN || len > BD_MAX_FRAME_LEN);
|
|||
|
|
if(frameErr)
|
|||
|
|
{
|
|||
|
|
// <20><>1<EFBFBD><31>ʼѰ<CABC><D1B0>SOF
|
|||
|
|
BD_SearchSOF(BD_ModuleData, 1, &RdIdx);
|
|||
|
|
|
|||
|
|
if(RdIdx < 7)
|
|||
|
|
break;
|
|||
|
|
len = (BD_ModuleData[5] << 8) | BD_ModuleData[6];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
frameOk = (len >= BD_MIN_FRAME_LEN && len <= BD_MAX_FRAME_LEN && RdIdx >= len);
|
|||
|
|
if(frameOk)
|
|||
|
|
{
|
|||
|
|
if(bd_cs_nor(BD_ModuleData, len) == 0)
|
|||
|
|
{
|
|||
|
|
if(bd_phy_valid(&BD_RecvFrame))
|
|||
|
|
{
|
|||
|
|
if(strncmp(BD_RecvFrame.cmd, BD_TXXX, 4) == 0)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
else if(strncmp(BD_RecvFrame.cmd, BD_ZJXX, 4) == 0)
|
|||
|
|
{
|
|||
|
|
dcBuff.powerInfo.bdNumber = (BD_RecvFrame.selfAddr[0] << 16) | (BD_RecvFrame.selfAddr[1] << 8) | BD_RecvFrame.selfAddr[2];
|
|||
|
|
BD_Zjxx = BD_RecvFrame.zjxx;
|
|||
|
|
BD_semZjxx = 1;
|
|||
|
|
}
|
|||
|
|
else if(strncmp(BD_RecvFrame.cmd, BD_FKXX, 4) == 0)
|
|||
|
|
{
|
|||
|
|
BD_Fkxx = BD_RecvFrame.fkxx;
|
|||
|
|
BD_semFkxx = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Ѱ<EFBFBD><D1B0><EFBFBD><EFBFBD>һ֡
|
|||
|
|
RdIdx -= len;
|
|||
|
|
memmove(BD_ModuleData, BD_ModuleData + len, RdIdx);
|
|||
|
|
// <20><>0<EFBFBD><30>ʼѰ<CABC><D1B0>SOF
|
|||
|
|
BD_SearchSOF(BD_ModuleData, 0, &RdIdx);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
// <20><>1<EFBFBD><31>ʼѰ<CABC><D1B0>SOF
|
|||
|
|
BD_SearchSOF(BD_ModuleData, 1, &RdIdx);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} while(frameOk || frameErr);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <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_Write(UART0, (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 UART0_IRQHandler(void)
|
|||
|
|
////{
|
|||
|
|
//// uint8_t c;
|
|||
|
|
////
|
|||
|
|
//// if(UART_GET_INT_FLAG(UART0, UART_ISR_RDA_IS_Msk) || UART_GET_INT_FLAG(UART0, UART_ISR_RTO_IS_Msk)) /* Rx Ready or Time-out INT*/
|
|||
|
|
//// {
|
|||
|
|
////// do
|
|||
|
|
//// {
|
|||
|
|
//// c = UART0->RBR;
|
|||
|
|
////// printf("%02X ", c);
|
|||
|
|
//// // ֱ<>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|||
|
|
//// BD_ParseFrame(c);
|
|||
|
|
//// } //while(UART_IS_RX_READY(UART0));
|
|||
|
|
//// }
|
|||
|
|
|
|||
|
|
//// if(UART_GET_INT_FLAG(UART0, UART_ISR_BUF_ERR_IS_Msk)) /* Buffer Error INT */
|
|||
|
|
//// {
|
|||
|
|
//// UART_ClearIntFlag(UART0, UART_ISR_BUF_ERR_IS_Msk);
|
|||
|
|
//// }
|
|||
|
|
//// if(UART_GET_INT_FLAG(UART0, UART_ISR_RLS_IS_Msk)) /* RLS INT */
|
|||
|
|
//// {
|
|||
|
|
//// UART_ClearIntFlag(UART0, UART_ISR_RLS_IS_Msk);
|
|||
|
|
//// }
|
|||
|
|
////}
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC>
|
|||
|
|
void BD_Init()
|
|||
|
|
{
|
|||
|
|
//// /* Select IP clock source */
|
|||
|
|
//// CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_UART_CLK_DIVIDER(1));
|
|||
|
|
|
|||
|
|
//// /*---------------------------------------------------------------------------------------------------------*/
|
|||
|
|
//// /* Init I/O Multi-function */
|
|||
|
|
//// /*---------------------------------------------------------------------------------------------------------*/
|
|||
|
|
//// /* Set GPA multi-function pins for UART0 RXD and TXD */
|
|||
|
|
//// SYS->PA_H_MFP &= ~(SYS_PA_H_MFP_PA14_MFP_Msk | SYS_PA_H_MFP_PA15_MFP_Msk);
|
|||
|
|
//// SYS->PA_H_MFP |= (SYS_PA_H_MFP_PA14_MFP_UART0_RX | SYS_PA_H_MFP_PA15_MFP_UART0_TX);
|
|||
|
|
|
|||
|
|
//// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
//// CLK_EnableModuleClock(UART0_MODULE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void BD_Open()
|
|||
|
|
{
|
|||
|
|
// <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;
|
|||
|
|
|
|||
|
|
//// SYS_ResetModule(UART0_RST);
|
|||
|
|
|
|||
|
|
//// /* Configure UART and set UART Baudrate */
|
|||
|
|
//// UART_Open(UART0, 115200ul);
|
|||
|
|
////
|
|||
|
|
//// /* Enable RDA\RLS\Time-out Interrupt */
|
|||
|
|
//// UART_ENABLE_INT(UART0, (UART_IER_RDA_IE_Msk | UART_IER_BUF_ERR_IE_Msk | UART_IER_RLS_IE_Msk)); // | UART_IER_RTO_IE_Msk));
|
|||
|
|
//// /* Enable UART interrupt */
|
|||
|
|
//// NVIC_SetPriority(UART0_IRQn, 1);
|
|||
|
|
//// NVIC_EnableIRQ(UART0_IRQn);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <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 BD_PowerOn()
|
|||
|
|
{
|
|||
|
|
//// uint8_t i, count = 0;
|
|||
|
|
////
|
|||
|
|
//// if(BD_hasPowered)
|
|||
|
|
//// return;
|
|||
|
|
////
|
|||
|
|
//// printf("\nBD power on ...\n");
|
|||
|
|
|
|||
|
|
//// VCC_BD_ON();
|
|||
|
|
//// delay_ms(2700);
|
|||
|
|
|
|||
|
|
//// BD_initStatus = 0;
|
|||
|
|
//// if(BD_Xtzj())
|
|||
|
|
//// {
|
|||
|
|
////// for(i = 0; i < 6; i++)
|
|||
|
|
////// {
|
|||
|
|
////// if(BD_Zjxx.power[i] >= 2)
|
|||
|
|
////// count++;
|
|||
|
|
////// }
|
|||
|
|
////// if(count >= 2)
|
|||
|
|
//// {
|
|||
|
|
//// // <20><><EFBFBD><EFBFBD>״̬
|
|||
|
|
//// BD_initStatus = 1;
|
|||
|
|
//// }
|
|||
|
|
//// }
|
|||
|
|
|
|||
|
|
//// BD_hasPowered = 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void BD_PowerOff()
|
|||
|
|
{
|
|||
|
|
//// if(!BD_hasPowered)
|
|||
|
|
//// return;
|
|||
|
|
////
|
|||
|
|
//// BD_hasPowered = 0;
|
|||
|
|
|
|||
|
|
//// printf("\nBD power off ...\n");
|
|||
|
|
//// VCC_BD_OFF();
|
|||
|
|
//// delay_ms(200);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ӧ<>ò㷢<C3B2>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint8_t bd_rf_app_send_data(uint8_t payload_len, uint8_t *payload)
|
|||
|
|
{
|
|||
|
|
// uint16_t i;
|
|||
|
|
S_RTC_TIME_DATA_T sRTC;
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
// <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_Write(UART0, (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;
|
|||
|
|
}
|