?? task_route.c
字號:
#include "config_GD61.h"
#include "include_GD61.h"
////////////////////////////////////////////////////////////////////////////
extern volatile uint8 t_buf0[TX_BUFFER_LEN]; // UART0 sending buffer
extern volatile uint8 RF_Tx_Buffer[TX_BUFFER_LEN]; // UART0 sending buffer
extern uint16 PowerLine_ID; //number of line.
extern uint16 Line_Num; //=0x1111; //number of line
extern uint16 SourceAddr; //=0x2222; //source address
extern uint16 DestinationAddr; //=0x3333; //destination address
extern uint16 Pkg_SerialNum; //=0x4444; //serial number of package
extern uint16 ModuleAddress;
extern uint8 RoutingFlag; //function code
extern uint8 ActionValueLen; //action value corresponding to action code
extern uint8 SendByteCounter;
extern uint8 RFSendByteCounter;
extern uint8 CommandClrCount;
extern volatile uint8 CC1000Mode;
extern volatile uint8 RF_RxSynSemaphore;
extern volatile uint16 RF_TxCounter;
extern volatile uint8 RF_TxBitCounter;
extern volatile uint16 RFt_inp,RFt_outp,RF_TxCounter;
extern volatile uint8 RF_TxBitCounter; // bit pointer of data_byte in sending
extern volatile uint16 RFr_inp,RFr_outp,RF_RxCounter;
////////////////////////////////////////////////////////////////////////////
extern ROUTETABLE UpRouteTable[MAX_BRANCH_LINE_NUM];
extern ROUTETABLE DnRouteTable[MAX_BRANCH_LINE_NUM];
ROUTEDATA routeData[MAX_BRANCH_LINE_NUM];
ROUTETASK routeTask[MAX_ROUTE_TASK_NUM];
#ifdef RP_RELAY_ERROR
ROUTEDATA relayErrorData[MAX_BRANCH_LINE_NUM];
ROUTETASK relayErrorTask[MAX_ROUTE_TASK_NUM];
#endif
uint8 RoutePkgSerial;
uint8 BranchLineRouting;
uint16 Pkg_SerID_Routing;
////////////////////////////////////////////////////
void ClearUpRouteTable(void);
void ClearDnRouteTable(void);
void MakeRelayPackage(uint8 dirFlag);
void StopRelayBranch(void);
void RelayPkgSending(void);
void RF_RelayPkgSending(void);
void MakeStopRoutingPkg(void);
void MakeRFstopRoutePkg(void);
void KillRelayPackage(void);
void GetRouteData(uint8 *char_pt);
void ClearRouteData(void); //clear all data in routeData[]
////////////////////////////////////////////////////
// initialize(clear) up_direction route table
// state: ok
void ClearUpRouteTable(void)
{
uint8 i;
uint8 j;
for(i=0;i<MAX_BRANCH_LINE_NUM;i++){
UpRouteTable[i].vaildAddrItemNum=0x00;
for(j=0;j<MAX_ROUTE_ADDRESS_NUM;j++){
UpRouteTable[i].Dest_ADDR[j]=0x00;
}
}
}
////////////////////////////////////////////////////
// initialize(clear) down_direction route table
// state: ok
void ClearDnRouteTable(void)
{
uint8 i;
uint8 j;
for(i=0;i<MAX_BRANCH_LINE_NUM;i++){
DnRouteTable[i].vaildAddrItemNum=0x00;
for(j=0;j<MAX_ROUTE_ADDRESS_NUM;j++){
DnRouteTable[i].Dest_ADDR[j]=0x00;
}
}
}
///////////////////////////////////////////////////
// refer to Task_Relay file
// state:
void MakeRelayPackage(uint8 dirFlag)
{
uint8 branch;
uint8 addinbranch;
uint8 addressCnt;
uint8 index;
uint8 routingflag;
////
if(dirFlag == REVS_ROUTE_DIR){
routingflag = RoutingFlag^0x80; //reverse the package relay direction
}
else
{
routingflag = RoutingFlag; //keep the original relay direction
}
////
if((routingflag&0x80)==DOWN_DIRECTION_ROUTE){
Uart0SendString("making package in Dn direction.");
}
else{
Uart0SendString("making package in Up direction.");
}
//// get the valid address number.
////
index=0;
for(branch=0;branch<MAX_BRANCH_LINE_NUM;branch++){
//// get the valid address number.
if((routingflag&0x80)==DOWN_DIRECTION_ROUTE){
addressCnt=DnRouteTable[branch].vaildAddrItemNum;
}
else{
addressCnt=UpRouteTable[branch].vaildAddrItemNum;
}
//// make the task frame.
for(addinbranch=0;addinbranch<addressCnt;addinbranch++){
////
routeTask[index].activityFlag = ENABLE_FLAG; //enable the task
routeTask[index].waittingResponse = DISABLE_FLAG;
if(index==0x00){
routeTask[index].secondTimer = 0; //the first be sent immediately
}
else{ //set the executing timer
routeTask[index].secondTimer = TX_INTERVAL_TIME*index + TX_TIME_BIAS;
}
routeTask[index].branchLineNum = branch; //mark the subline for stop function.
////
routeTask[index].line_IDx = PowerLine_ID; //Line_Num; //power line number (23)
if(dirFlag == REVS_ROUTE_DIR){
routeTask[index].Source_ADDR = DestinationAddr; //destination address (67)
routeTask[index].Dest_ADDR = SourceAddr; //source address (45)
}
else
{
routeTask[index].Source_ADDR = SourceAddr; //destination address (67)
routeTask[index].Dest_ADDR = DestinationAddr; //source address (45)
}
routeTask[index].Pkg_SerialID = Pkg_SerialNum; //package serial number (89)
////
RoutePkgSerial++; RoutePkgSerial = RoutePkgSerial & 0x3f; //route package serial number
routingflag = routingflag & (~0x3f);
routeTask[index].routeFlag = routingflag|RoutePkgSerial;
if((routingflag & 0x80)==DOWN_DIRECTION_ROUTE)
{
routeTask[index].nextAddress=DnRouteTable[branch].Dest_ADDR[addinbranch];
}
else{
routeTask[index].nextAddress=UpRouteTable[branch].Dest_ADDR[addinbranch];
}
////
routeTask[index].pt = routeData[branch].datax; //&routedatabuff[i][0]
routeTask[index].charLen = routeData[branch].byteCounter; //char length
index++; //move to next route task
}
}
}
//////////////////////////////////////////////////////////////////////
//fill data into route data buffer
//status:
void GetRouteData(uint8 *char_pt)
{
uint8 charcnt;
uint8 branch_id;
uint8 *pt;
for(branch_id=0;branch_id<MAX_BRANCH_LINE_NUM;branch_id++){
pt=char_pt;
for(charcnt=0;charcnt<(ActionValueLen+2);charcnt++){ // 2 represent ActionValueLen and ActionCode
routeData[branch_id].datax[charcnt] = *pt++; // copy the relaying data to data buffer
}
routeData[branch_id].byteCounter=ActionValueLen+2; // ActionCode+ActionValueLen+Data(ActionValueLen)
}
}
////////////////////////////////////////////////////////////////////
void ClearRouteData(void) //clear all data in routeData[]
{
uint8 charcnt;
uint8 branch_id;
for(branch_id=0;branch_id<MAX_BRANCH_LINE_NUM;branch_id++){
for(charcnt=0;charcnt<MAX_RELAY_PKG_LEN;charcnt++){
// routeData[branch_id].datax[charcnt]=(branch_id+1)*(charcnt+1); //only for debug
routeData[branch_id].datax[charcnt]=0x00;
}
routeData[branch_id].byteCounter=MAX_RELAY_PKG_LEN;
}
}
////////////////////////////////////////////////////////////////////
// refer to Task_Relay file
// state:
void KillRelayPackage(void)
{
uint8 index;
for(index=0;index<MAX_ROUTE_TASK_NUM;index++){
routeTask[index].activityFlag = DISABLE_FLAG; //disable the task in same branch
routeTask[index].waittingResponse = DISABLE_FLAG; //disable the task in same branch
}
RF_RxSynSemaphore=0;
RF_TxBitCounter=0; // bit pointer of data_byte in sending
RF_TxCounter=0;
RFt_inp=0; RFt_outp=0;
RFr_inp=0; RFr_outp=0;
}
///////////////////////////////////////
// refer to Task_Relay file
// state:
void StopRelayBranch(void)
{
uint8 index;
uint8 counter;
////
if(Pkg_SerID_Routing==Pkg_SerialNum){ //check the package serial ID
for(index=0;index<MAX_ROUTE_TASK_NUM;index++){
if(BranchLineRouting==routeTask[index].branchLineNum){
routeTask[index].activityFlag = DISABLE_FLAG; //disable the task in same branch
routeTask[index].waittingResponse = DISABLE_FLAG; //disable the task in same branch
}
}
////
counter=1;
for(index=0;index<MAX_ROUTE_TASK_NUM;index++){
if(routeTask[index].activityFlag==ENABLE_FLAG){ //adjust the relay time of other branch
routeTask[index].secondTimer =TX_INTERVAL_TIME*counter;
counter++;
}
}
}
////
}
///////////////////////////////////////
// transmitting the package to be relay
// status: ok
void RelayPkgSending(void)
{
uint8 i;
uint8 j;
uint8 *buff_pt;
for(i=0;i<MAX_ROUTE_TASK_NUM;i++){
if(( routeTask[i].activityFlag==ENABLE_FLAG)&&(routeTask[i].secondTimer ==0)){
////
Uart0SendingOver(); //waitting for (00)
buff_pt=(uint8*)t_buf0; //point to transmit buffer
*buff_pt++ =(uint8)RF_START_FLAG; //start flag (01)
*buff_pt++ =(uint8)RF_START_FLAG;
*buff_pt++ =(routeTask[i].line_IDx)>>8; //power line number (23)
*buff_pt++ = routeTask[i].line_IDx;
*buff_pt++ =(routeTask[i].Source_ADDR)>>8; //source address (45)
*buff_pt++ = routeTask[i].Source_ADDR;
*buff_pt++ =(routeTask[i].Dest_ADDR)>>8; //destination address (67)
*buff_pt++ = routeTask[i].Dest_ADDR;
*buff_pt++ =(routeTask[i].Pkg_SerialID)>>8; //package serial number (89)
*buff_pt++ = routeTask[i].Pkg_SerialID;
//// route area
*buff_pt++ =routeTask[i].routeFlag; //direction moving package
*buff_pt++ =0x03; //byte counter
*buff_pt++ =0x01; //direction router address
*buff_pt++ =(routeTask[i].nextAddress)>>8; //destination address (67)
*buff_pt++ = routeTask[i].nextAddress;
SendByteCounter =15;
//// action area
for(j=0;j<routeTask[i].charLen;j++){
*buff_pt++ = *routeTask[i].pt++;
SendByteCounter++;
}
//// relay flag area
routeTask[i].activityFlag = DISABLE_FLAG; //disable finished task
routeTask[i].waittingResponse = ENABLE_FLAG;
BranchLineRouting=routeTask[i].branchLineNum; //used to stop relay this branch.
Pkg_SerID_Routing=routeTask[i].Pkg_SerialID;
Uart0SendAddCrc(SendByteCounter); //sending data in buffer
}
}
}
///////////////////////////////////////
// transmitting the package to be relay
// status: ok
void RF_RelayPkgSending(void)
{
uint8 i;
uint8 j;
uint8 *buff_pt;
for(i=0;i<MAX_ROUTE_TASK_NUM;i++){
if(( routeTask[i].activityFlag==ENABLE_FLAG)&&(routeTask[i].secondTimer ==0)){
////
RF_SendingOver(); //waitting for (00)
buff_pt = (uint8*)RF_Tx_Buffer; //point to transmit buffer
buff_pt = buff_pt+10; //reserve the synchronization semaphore
RFSendByteCounter=0; //8 bytes(SYN) + 2 CRC
*buff_pt++ =(uint8)RF_START_FLAG; //start flag (01)
*buff_pt++ =(uint8)RF_START_FLAG;
*buff_pt++ =(routeTask[i].line_IDx)>>8; // power line number (23)
*buff_pt++ = routeTask[i].line_IDx;
*buff_pt++ =(routeTask[i].Source_ADDR)>>8; //source address (45)
*buff_pt++ = routeTask[i].Source_ADDR;
*buff_pt++ =(routeTask[i].Dest_ADDR)>>8; //destination address (67)
*buff_pt++ = routeTask[i].Dest_ADDR;
*buff_pt++ =(routeTask[i].Pkg_SerialID)>>8; //package serial number (89)
*buff_pt++ = routeTask[i].Pkg_SerialID;
//// route area
*buff_pt++ =routeTask[i].routeFlag; //direction moving package
*buff_pt++ =0x03; //byte counter
*buff_pt++ =0x01; //direction router address
*buff_pt++ =(routeTask[i].nextAddress)>>8; //destination address (67)
*buff_pt++ = routeTask[i].nextAddress;
RFSendByteCounter += 15;
//// action area
for(j=0;j<routeTask[i].charLen;j++){
*buff_pt++ = *routeTask[i].pt++;
RFSendByteCounter++;
}
//// relay flag area
routeTask[i].activityFlag = DISABLE_FLAG; //disable finished task
routeTask[i].waittingResponse = ENABLE_FLAG;
BranchLineRouting=routeTask[i].branchLineNum;
Pkg_SerID_Routing=routeTask[i].Pkg_SerialID;
RF_SendAddCrc(RFSendByteCounter); //sending data in buffer
}
}
}
///////////////////////////////////////
// transmitting the package to be relay
// status: ok
void MakeStopRoutingPkg(void)
{
uint8 *buff_pt;
////
buff_pt=(uint8*)t_buf0; //point to transmit buffer
*buff_pt++ =(uint8)RF_START_FLAG; //start flag (01)
*buff_pt++ =(uint8)RF_START_FLAG;
*buff_pt++ =Line_Num>>8; // power line number (23)
*buff_pt++ =Line_Num;
*buff_pt++ =SourceAddr>>8; //source address (45)
*buff_pt++ =SourceAddr;
*buff_pt++ =DestinationAddr>>8; //destination address (67)
*buff_pt++ =DestinationAddr;
*buff_pt++ =Pkg_SerialNum>>8; //package serial number (89)
*buff_pt++ =Pkg_SerialNum;
//// route area
*buff_pt++ =RoutingFlag; //direction moving package
*buff_pt++ =0x03; //byte counter
*buff_pt++ =0x01; //direction router address
*buff_pt++ =ModuleAddress>>8; //destination address (67)
*buff_pt++ =ModuleAddress;
SendByteCounter =15;
//// data area
*buff_pt++= RESPONSE_PK;
*buff_pt++= 2;
*buff_pt++= Pkg_SerialNum>>8;
*buff_pt++= Pkg_SerialNum;
SendByteCounter+=4;
}
///////////////////////////////////////
// transmitting the package to be relay
// status: ok
void MakeRFstopRoutePkg(void)
{
uint8 *buff_pt;
buff_pt=(uint8*)RF_Tx_Buffer; //point to transmit buffer
////
buff_pt=buff_pt+10; //reserve the synchronization semaphore
RFSendByteCounter=0; //8 bytes(SYN) + 2 CRC
////
*buff_pt++ =(uint8)RF_START_FLAG; //start flag (01)
*buff_pt++ =(uint8)RF_START_FLAG;
*buff_pt++ =Line_Num>>8; // power line number (23)
*buff_pt++ =Line_Num;
*buff_pt++ =SourceAddr>>8; //source address (45)
*buff_pt++ =SourceAddr;
*buff_pt++ =DestinationAddr>>8; //destination address (67)
*buff_pt++ =DestinationAddr;
*buff_pt++ =Pkg_SerialNum>>8; //package serial number (89)
*buff_pt++ =Pkg_SerialNum;
//// route area
*buff_pt++ =RoutingFlag; //direction moving package
*buff_pt++ =0x03; //byte counter
*buff_pt++ =0x01; //direction router address
*buff_pt++ =ModuleAddress>>8; //destination address (67)
*buff_pt++ =ModuleAddress;
RFSendByteCounter+=15;
//// data area
*buff_pt++= RESPONSE_PK;
*buff_pt++= 2;
*buff_pt++= Pkg_SerialNum>>8;
*buff_pt++= Pkg_SerialNum;
RFSendByteCounter+=4;
}
/***************************************************************************
** End Of File
****************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -