📄 df9000wh.c
字号:
Purpose: 电度传送.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_Send_DD(INT8U port)
{
ProtocolBuf *p=NULL;
INT8U num;
INT8U value[200];
INT32U Name;
struct DBInfo info;
if(port == COM1) p=COM1Buf;
else if(port == COM2) p=COM2Buf;
Name = DMERGE(p->rxbuf[9],p->rxbuf[8],p->rxbuf[7],p->rxbuf[6]);
p->txbuf[6] = '9';
p->txbuf[7] = '3';
p->txbuf[8] = '1';
p->txbuf[9] = '1';
p->txbuf[10] = p->rxbuf[10];
info.SuperID = ROOTID;
info.DevID = GetDevIDOfName(Name);
info.Type = DDDATA;
info.Start = 0;
info.Num = DBCfgs[info.DevID].DDNum;
DBRead(value, &info);
num = info.Num;
memcpy (p->txbuf+15, value, num * 4);
p->txbuf[11] = LOW(0x0);
p->txbuf[12] = HIGH(0x0);
p->txbuf[13] = LOW(num-1);
p->txbuf[14] = HIGH(num-1);
WHRes(port, p->rxbuf[3], p->rxbuf[4], num*4+9);
}
/*------------------------------------------------------------------------
Procedure: CWH9000::WH_Send_SYSINFO ID:1
Purpose: 系统信息传送.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_Send_SYSINFO(INT8U port)
{
ProtocolBuf *p=NULL;
INT32U DOffset,i;
INT16U WLength,WSysinfonum,j,num;
INT32U Name;
struct DBInfo info;
struct SYS_INFO_Data whSYSINFO;
struct SysInfo_t InfoStruct;
if(port == COM1) p=COM1Buf;
else if(port == COM2) p=COM2Buf;
memset(p->txbuf,0,WH_BUF_SIZE);
DOffset = DMERGE(p->rxbuf[17],p->rxbuf[16],p->rxbuf[15],p->rxbuf[14]);
WLength = MERGE(p->rxbuf[19],p->rxbuf[18]);
Name = DMERGE(p->rxbuf[9],p->rxbuf[8],p->rxbuf[7],p->rxbuf[6]);
if(DOffset >= SYSINFOLIMIT)
DOffset = 0;
if((DOffset+WLength) >= SYSINFOLIMIT)
WLength = SYSINFOLIMIT - DOffset;
if (WLength >= 5)
WLength = 5;
info.SuperID = GetDevIDOfName(Name);
info.DevID = info.SuperID;
info.Type = INFODATA;
info.Start = 0;
info.Num = 1;
DBRead((INT8U*)&whSYSINFO, &info);
WSysinfonum = whSYSINFO.CurPos;
p->txbuf[6] = '9';
p->txbuf[7] = '3';
p->txbuf[8] = '1';
p->txbuf[9] = '1';
p->txbuf[10] = 'O';
p->txbuf[11] = 'R';
p->txbuf[12] = 'R';
p->txbuf[13] = 'E';
p->txbuf[14] = LOW(DOffset);
p->txbuf[15] = HIGH(DOffset);
p->txbuf[16] = DLOW(DOffset);
p->txbuf[17] = DHIGH(DOffset);
//old p->txbuf[18] = LOW(WLength);
//old p->txbuf[19] = HIGH(WLength);
p->txbuf[18] = LOW(WLength);
p->txbuf[19] = HIGH(WLength);
p->txbuf[20] = LOW(WSysinfonum);
p->txbuf[21] = HIGH(WSysinfonum);
p->txbuf[22] = 0;
p->txbuf[23] = 0;
p->txbuf[24] = LOW(SYSINFOLIMIT);
p->txbuf[25] = HIGH(SYSINFOLIMIT);
for(i=DOffset;i<(DOffset+WLength);i++)
{
info.DevID = GetDevIDOfName(Name);
info.Type = INFODATA;
info.Start = i%SYSINFOLIMIT;
info.Num = 1;
DBRead((INT8U*)&whSYSINFO, &info);
p->txbuf[26+(i-DOffset)*sizeof(InfoStruct)] = LOW(whSYSINFO.SysInfo.AppID);
p->txbuf[27+(i-DOffset)*sizeof(InfoStruct)] = HIGH(whSYSINFO.SysInfo.AppID);
for(j = 0;j < 60; j++)
{
p->txbuf[28+j+(i-DOffset)*sizeof(InfoStruct)] = whSYSINFO.SysInfo.err[j];
}
}
num = WLength*sizeof(InfoStruct)+20;
WHRes(port, p->rxbuf[3], p->rxbuf[4], num);
}
/*------------------------------------------------------------------------
Procedure: CWH9000::WH_YKSELECT ID:1
Purpose: 遥控预置、撤销.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_YKSELECT(INT8U port)
{
INT16U YKID,YKATTIB;
BOOL YKYZOK = FALSE;
INT32U Name;
ProtocolBuf *p=NULL;
struct BOCode code;
struct DBInfo info;
if(port == COM1)
{
p=COM1Buf;
WHYKMutex = FALSE;
}
else if(port == COM2)
{
p=COM2Buf;
WHYKMutex = 1;
}
Name = DMERGE(p->rxbuf[9],p->rxbuf[8],p->rxbuf[7],p->rxbuf[6]);
p->txbuf[6] = '9';
p->txbuf[7] = '3';
p->txbuf[8] = '1';
p->txbuf[9] = '1';
p->txbuf[10] = p->rxbuf[10];
p->txbuf[11] = p->rxbuf[11];
p->txbuf[12] = p->rxbuf[12];
p->txbuf[13] = p->rxbuf[13];
YKID = MERGE(p->rxbuf[12],p->rxbuf[11]);
YKATTIB = MERGE(p->rxbuf[14],p->rxbuf[13]);
if((p->rxbuf[13]&WH_YK_OPERATESTATUS)==WH_YK_HE)
{
code.Control = 0x40;
YKYZOK = TRUE;
}
else if((p->rxbuf[13]&WH_YK_OPERATESTATUS)==WH_YK_FEN)
{
code.Control = 0x80;
YKYZOK = TRUE;
}
else
code.Control = 0;
if(p->rxbuf[13] & WH_YK_DEL)
code.Control |= 0x20;
info.SuperID = ROOTID;
info.DevID = GetDevIDOfName(Name);
info.Type = BORESQ;
info.Start = YKID;
info.Num = BOSELECT;
code.Status = 0;
DBOperate ((INT8U*)&code, &info);
if (code.Status != BORCOK)
{
p->txbuf[14] = code.Status;
WHRes(port, p->rxbuf[3], p->rxbuf[4], 9);
}
}
/*------------------------------------------------------------------------
Procedure: CWH9000::WH_YKEXE ID:1
Purpose: 遥控执行.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_YKEXE(INT8U port)
{
INT16U YKID,YKATTIB;
BOOL YKYZOK = FALSE;
INT32U Name;
ProtocolBuf *p=NULL;
struct BOCode code;
struct DBInfo info;
if(port == COM1)
{
p=COM1Buf;
WHYKMutex = FALSE;
}
else if(port == COM2)
{
p=COM2Buf;
WHYKMutex = 1;
}
Name = DMERGE(p->rxbuf[9],p->rxbuf[8],p->rxbuf[7],p->rxbuf[6]);
p->txbuf[6] = '9';
p->txbuf[7] = '3';
p->txbuf[8] = '1';
p->txbuf[9] = '1';
p->txbuf[10] = p->rxbuf[10];
p->txbuf[11] = p->rxbuf[11];
p->txbuf[12] = p->rxbuf[12];
p->txbuf[13] = p->rxbuf[13];
YKID = MERGE(p->rxbuf[12],p->rxbuf[11]);
YKATTIB = MERGE(p->rxbuf[14],p->rxbuf[13]);
if((p->rxbuf[13] & WH_YK_DEL) == 0)
{
if((p->rxbuf[13]&WH_YK_OPERATESTATUS)==WH_YK_HE)
{
code.Control = 0x40;
YKYZOK = TRUE;
}
if((p->rxbuf[13]&WH_YK_OPERATESTATUS)==WH_YK_FEN)
{
code.Control = 0x80;
YKYZOK = TRUE;
}
if(YKYZOK == TRUE)
{
info.SuperID = ROOTID;
info.DevID = GetDevIDOfName(Name);
info.Type = BORESQ;
info.Start = YKID;
info.Num = BOOPERATE;
code.Status = 0;
DBOperate ((INT8U*)&code, &info);
if (code.Status != BORCOK)
{
p->txbuf[14] = code.Status;
WHRes(port, p->rxbuf[3], p->rxbuf[4], 9);
}
}
}
}
/*------------------------------------------------------------------------
Procedure: WH_READ_CLOCK
Purpose: 读硬件时钟.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_READ_CLOCK(INT8U port)
{
ProtocolBuf *p=NULL;
struct SysTime_t SysTime;
if(port == COM1) p=COM1Buf;
else if(port == COM2) p=COM2Buf;
GetTime((void *)&SysTime, SYSTIME);
p->txbuf[6] = '9';
p->txbuf[7] = '3';
p->txbuf[8] = '1';
p->txbuf[9] = '1';
p->txbuf[10] = LOW(SysTime.Year);
p->txbuf[11] = HIGH(SysTime.Year);
p->txbuf[12] = SysTime.Month;
p->txbuf[13] = SysTime.Day;
p->txbuf[14] = SysTime.Hour;
p->txbuf[15] = SysTime.Minute;
p->txbuf[16] = SysTime.Second;
p->txbuf[17] = LOW(SysTime.MSecond);
p->txbuf[18] = HIGH(SysTime.MSecond);
WHRes(port, p->rxbuf[3], p->rxbuf[4], 13);
}
/*------------------------------------------------------------------------
Procedure: WH_WRITE_CLOCK
Purpose: 读硬件时钟.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_WRITE_CLOCK(INT8U port)
{
ProtocolBuf *p=NULL;
struct SysTime_t SysTime;
if(port == COM1) p=COM1Buf;
else if(port == COM2) p=COM2Buf;
p->txbuf[6] = '9';
p->txbuf[7] = '3';
p->txbuf[8] = '1';
p->txbuf[9] = '1';
SysTime.Year = MERGE(p->rxbuf[11],p->rxbuf[10]);
SysTime.Month = p->rxbuf[12];
SysTime.Day = p->rxbuf[13];
SysTime.Hour = p->rxbuf[14];
SysTime.Minute = p->rxbuf[15];
SysTime.Second = p->rxbuf[16];
SysTime.MSecond = MERGE(p->rxbuf[18],p->rxbuf[17]);
SetTime((void *)&SysTime,SYSTIME);
WHACK(port);
}
/*------------------------------------------------------------------------
Procedure: WH_Send_Ttuname()()
Purpose: 发送TTU名称
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WHReset(INT8U port)
{
}
/*------------------------------------------------------------------------
Procedure: WHACK
Purpose: 返回ACK.
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WHACK(INT8U port)
{
ProtocolBuf *p=NULL;
if(port == COM1) p=COM1Buf;
else if(port == COM2) p=COM2Buf;
WHRes(port, WH_ACK, p->rxbuf[4], 0);
}
/*------------------------------------------------------------------------
Procedure: WHNAK
Purpose:
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WHNAK(INT8U port,INT8U error)
{
ProtocolBuf *p=NULL;
if(port == COM1) p=COM1Buf;
else if(port == COM2) p=COM2Buf;
p->txbuf[4] = error;
WHRes(port, WH_NAK, p->txbuf[4], 0);
}
/*------------------------------------------------------------------------
Procedure: WH_READ_BUFF
Purpose:
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_READ_BUFF(INT8U port,INT8U read_port)
{
if(read_port == port)
// WHNAK(port,3);
return ;
else
{
if(read_port == COM1)
VIEW_USART = WH_VIEW_BUFF_USART0;
else
VIEW_USART = WH_VIEW_BUFF_USART1;
}
WHACK(port);
}
/*------------------------------------------------------------------------
Procedure: WH_STOP_READ_BUFF
Purpose:
Input:
Output:
Errors:
------------------------------------------------------------------------*/
void WH_STOP_READ_BUFF(INT8U port)
{
VIEW_USART = 0;
WHACK(port);
}
BOOL USART_READ_LENGTH(INT8U port,INT8U Length)
{
if(port == COM1)
{
if((Usart0.Rxc_Wr>Usart0.Rxc_Rd && Usart0.Rxc_Wr-Usart0.Rxc_Rd>=Length)
||(Usart0.Rxc_Wr<Usart0.Rxc_Rd && Usart0.Rxc_Wr+RXC_BUFF_SIZE-Usart0.Rxc_Rd>=Length))
return TRUE;
}
else if(port == COM2)
{
if((Usart1.Rxc_Wr>Usart1.Rxc_Rd && Usart1.Rxc_Wr-Usart1.Rxc_Rd>=Length)
||(Usart1.Rxc_Wr<Usart1.Rxc_Rd && Usart1.Rxc_Wr+RXC_BUFF_SIZE-Usart1.Rxc_Rd>=Length))
return TRUE;
}
return FALSE;
}
void WHYKRespond(struct SysPort *info, struct DBBOOPInfo *msg, INT8U Port)
{
INT8U buf[20];
INT16U i, rc;
INT32U name;
buf[0] = 0xFF;
buf[1] = 0x09;
buf[2] = 0x00;
switch (((struct DBBOOPInfo*)msg)->Flag & 0x03)
{
case BOOPSELECT:
buf[3] = WH_SELECT|0x80;
break;
case BOOPOPERATE:
buf[3] = WH_EXE|0x80;
break;
}
for (i=0; i<info->DevNum; i++)
{
if (info->DBCfgs[i].DevID == msg->DevID)
{
if (info->DBCfgs[i].Flag & FDBLOGIC)
buf[4] = WH_EXT_BOOBJ_LOGIC | 0x80;
else
buf[4] = WH_EXT_BOOBJ_REAL | 0x80;
break;
}
}
buf[5] = SendVerifyHead(buf, 5);
name = GetNameofDevID(msg->DevID);
buf[6] = LOW(name);
buf[7] = HIGH(name);
buf[8] = DLOW(name);
buf[9] = DHIGH(name);
buf[10] = 0x05;
buf[11] = LOW(msg->SID);
buf[12] = HIGH(msg->SID);
buf[13] = LOW(msg->Status);
buf[14] = HIGH(msg->Status);
if(msg->Flag&BOOPERROR)
buf[14] |= 0x01;
rc = WHCRC16(&buf[1], 14);
buf[15] = LOW(rc);
buf[16] = HIGH(rc);
WriteX(buf, 17, Port);
}
//在boot程序中获得串口地址
INT16U WHGetAddr(INT16U Port)
{
INT16U i, rc = 0;
for (i=0; i<SysCfg.PortNum; i++)
{
if (SysPorts[i].PortID == Port)
{
rc = SysPorts[i].DBCfgs->Address;
}
}
if (!rc)
{
rc = MyCfg.Addr;
}
return (rc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -