📄 commpc.c
字号:
g_chSendPCBuf[11] = '0';
g_chSendPCBuf[12] = '0';
g_chSendPCBuf[13] = '0';
g_chSendPCBuf[14] = '0';
g_chSendPCBuf[15] = '0';
g_chSendPCBuf[16] = '3';
g_chSendPCBuf[17] = ((intOff + chBit) / 100) % 10 + 48;
g_chSendPCBuf[18] = ((intOff + chBit) / 10) % 10 + 48;
g_chSendPCBuf[19] = ((intOff + chBit)) % 10 + 48;
}
else
{//报告 告警
g_chSendPCBuf[11] = '0';
g_chSendPCBuf[12] = '0';
g_chSendPCBuf[13] = '3';
g_chSendPCBuf[14] = ((intOff + chBit) / 100) % 10 + 48;
g_chSendPCBuf[15] = ((intOff + chBit) / 10) % 10 + 48;
g_chSendPCBuf[16] = ((intOff + chBit)) % 10 + 48;
g_chSendPCBuf[17] = '0';
g_chSendPCBuf[18] = '0';
g_chSendPCBuf[19] = '0';
}
//加 检查和--不能按 ASCII 码 相加
i = g_chOderID - 48;
i += 9;//肯定是 009
for(j = 0; j < 9; j++)
{
i = i + g_chSendPCBuf[11 + j] - 48;//已经是 ASCII 要减48
}
i %= 10000;//最大 4 位
g_chSendPCBuf[20] = ((i / 1000) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[21] = ((i / 100) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[22] = ((i / 10) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[23] = (i % 10) + 48;//在这里要把它转为String!
//加 尾 *
g_chSendPCBuf[24] = '*';
//尾巴指针
//肯定发送
g_chSendPCTail = 24;
g_chSendPCHead = 0;
g_chSendPCBuf_Stat = 1;//马上去发吧
}
return(1);
}
/**************************************
*功能: 发上电信息
*参数:
*返回:
*备注: 自动加 # 局号 流水号 校验和 *
**************************************/
unsigned char AutoInsertSendPCBuf(unsigned char *pData,unsigned char chLen)//2002-10-11 17:04 自动加 局号、流水号、检查和
{//报告---可以等待,
if((g_chSendPCBuf_Stat == 2) || (g_chSendPCBuf_Stat == 3))
{//在 RS 232 方式下 等待 4 毫秒 , 在 DTMF 下 应该不可能发生该问题
return(0);//只能 采用丢掉的办法
}
if(chLen < SendPcBufMAX - 20)
{
unsigned int i,j;
//加 头 #
g_chSendPCBuf[1] = '#';
//加 局号
for(i = 0; i < 4; i++)
{
g_chSendPCBuf[2 + i] = *(unsigned char *)(StationID_Info + i);//是ASC码
}
//加 流水号
g_chSendPCBuf[6] = g_chOderID;
//加 信息
for(i = 0; i < chLen; i++)
{
g_chSendPCBuf[7 + i] = *(pData + i) + 48;//表明信息不是ASC码
}
//加 检查和--不能按 ASCII 码 相加
i = g_chOderID - 48;
i = i + *(pData + 1) * 100;
i = i + *(pData + 2) * 10;
i = i + *(pData + 3);
for(j = 4; j < chLen; j++)
{
i = i + *(pData + j);//不要减48
}
i %= 10000;//最大 4 位
g_chSendPCBuf[7 + chLen] = ((i / 1000) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[8 + chLen] = ((i / 100) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[9 + chLen] = ((i / 10) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[10 + chLen] = (i % 10) + 48;//在这里要把它转为String!
//加 尾 *
g_chSendPCBuf[11 + chLen] = '*';
//尾巴指针
//肯定发送
g_chSendPCTail = 11 + chLen;
g_chSendPCHead = 0;
g_chSendPCBuf_Stat = 1;//马上去发吧
}
return(1);
}
unsigned char ParamAutoInsertSendPCBuf(unsigned char chParamID,unsigned char *pData,unsigned char chLen)//2002-10-11 17:04 自动加 局号、流水号、检查和
{//报告---可以等待,
if((g_chSendPCBuf_Stat == 2) || (g_chSendPCBuf_Stat == 3))
{//在 RS 232 方式下 等待 4 毫秒 , 在 DTMF 下 应该不可能发生该问题
return(0);//只能 采用丢掉的办法
}
//if(chLen < SendPcBufMAX - 20)
{
unsigned int j;
unsigned char chSumCheck = 0;
//加 头 #
g_chSendPCBuf[1] = '#';
// C3
g_chSendPCBuf[2] = 'C';
g_chSendPCBuf[3] = '3';
g_chSendPCBuf[4] = ((chParamID / 10) % 10) + 48;
g_chSendPCBuf[5] = (chParamID % 10) + 48;
g_chSendPCBuf[6] = ((chLen / 10) % 10) + 48;//参数的长度
g_chSendPCBuf[7] = (chLen % 10) + 48;
for(j = 0; j < chLen; j++)
{
g_chSendPCBuf[8 + j] = *(pData + j);//得到的是 参数,应该已经是 ASCII了
}
//j 用来 作为计算校验和的变量。
for(j = 4; j < 8 + chLen; j++)//10 = 7 + 3
{
chSumCheck += (g_chSendPCBuf[j] - 48);
}
g_chSendPCBuf[8 + chLen] = ((chSumCheck / 100) % 10) + 48;
g_chSendPCBuf[9 + chLen] = ((chSumCheck / 10) % 10) + 48;
g_chSendPCBuf[10 + chLen] = (chSumCheck % 10) + 48;
//加 尾 *
g_chSendPCBuf[11 + chLen] = '*';
//尾巴指针
//肯定发送
g_chSendPCTail = 11 + chLen;
g_chSendPCHead = 0;
g_chSendPCBuf_Stat = 1;//马上去发吧
}
return(1);
}
unsigned char AutoEnvSevenInsertSendPCBufTen(unsigned char chClass)//2002-10-11 17:04 自动加 局号、流水号、检查和
{//报告---可以等待,
if((g_chSendPCBuf_Stat == 2) || (g_chSendPCBuf_Stat == 3))
{//在 RS 232 方式下 等待 4 毫秒 , 在 DTMF 下 应该不可能发生该问题
return(0);//只能 采用丢掉的办法
}
//if(4 < SendPcBufMAX - 20)
{
unsigned int i,j;
//加 头 #
g_chSendPCBuf[1] = '#';
//加 头 CC
g_chSendPCBuf[2] = 'C';
g_chSendPCBuf[3] = 'C';
//加 局号
for(i = 0; i < 4; i++)
{
g_chSendPCBuf[4 + i] = *(unsigned char *)(StationID_Info + i);//是ASC码
}
//加 流水号
g_chSendPCBuf[8] = g_chOderID;
//加 事件类别 告警盘数据上传 07
g_chSendPCBuf[9] = '0';
g_chSendPCBuf[10] = '7';
//加 监测通道 001---使用 g_chPushBit0to7
g_chSendPCBuf[11] = '0';
g_chSendPCBuf[12] = '0';
g_chSendPCBuf[13] = g_chPushBit0to7 + 49;//48 + 1
//加 类型 chClass 10 工频数据
g_chSendPCBuf[14] = '1';
g_chSendPCBuf[15] = '0';
//加 信息 消息的状态字(7位)
if(chClass == 10)
{
if(g_chGP_Mark & (1 << g_chPushBit0to7))
{//报告警
//
g_chSendPCBuf[16] = '0';
g_chSendPCBuf[17] = '2';
g_chSendPCBuf[18] = (g_intGP_CurrentAlert[g_chPushBit0to7] / 1000) % 10 + 48;
g_chSendPCBuf[19] = (g_intGP_CurrentAlert[g_chPushBit0to7] / 100) % 10 + 48;
g_chSendPCBuf[20] = (g_intGP_CurrentAlert[g_chPushBit0to7] / 10) % 10 + 48;
g_chSendPCBuf[21] = (g_intGP_CurrentAlert[g_chPushBit0to7] % 10) + 48;
}
else
{//报恢复
g_chSendPCBuf[16] = '0';
g_chSendPCBuf[17] = '0';
g_chSendPCBuf[18] = (g_intGP_CurrentRestore[g_chPushBit0to7] / 1000) % 10 + 48;
g_chSendPCBuf[19] = (g_intGP_CurrentRestore[g_chPushBit0to7] / 100) % 10 + 48;
g_chSendPCBuf[20] = (g_intGP_CurrentRestore[g_chPushBit0to7] / 10) % 10 + 48;
g_chSendPCBuf[21] = (g_intGP_CurrentRestore[g_chPushBit0to7] % 10) + 48;
}
//固定数值
g_chSendPCBuf[22] = (g_intGP_FixedCurrent[g_chPushBit0to7] / 1000) % 10 + 48;
g_chSendPCBuf[23] = (g_intGP_FixedCurrent[g_chPushBit0to7] / 100) % 10 + 48;
g_chSendPCBuf[24] = (g_intGP_FixedCurrent[g_chPushBit0to7] / 10) % 10 + 48;
g_chSendPCBuf[25] = (g_intGP_FixedCurrent[g_chPushBit0to7] % 10) + 48;
}
else
{
g_chSendPCBuf[13] = chClass + 49;//48 + 1
if(g_chGP_Status & (1 << chClass))
{//alert
g_chSendPCBuf[16] = '0';
g_chSendPCBuf[17] = '2';
}
else
{//restore
g_chSendPCBuf[16] = '0';
g_chSendPCBuf[17] = '0';
}
g_chSendPCBuf[18] = (g_intGP_Current[chClass] / 1000) % 10 + 48;
g_chSendPCBuf[19] = (g_intGP_Current[chClass] / 100) % 10 + 48;
g_chSendPCBuf[20] = (g_intGP_Current[chClass] / 10) % 10 + 48;
g_chSendPCBuf[21] = (g_intGP_Current[chClass] % 10) + 48;
//固定数值
g_chSendPCBuf[22] = (g_intGP_FixedCurrent[chClass] / 1000) % 10 + 48;
g_chSendPCBuf[23] = (g_intGP_FixedCurrent[chClass] / 100) % 10 + 48;
g_chSendPCBuf[24] = (g_intGP_FixedCurrent[chClass] / 10) % 10 + 48;
g_chSendPCBuf[25] = (g_intGP_FixedCurrent[chClass] % 10) + 48;
}
//加 检查和--不能按 ASCII 码 相加 4-----25
i = 0;
for(j = 4; j < 26; j++)
{
i = i + g_chSendPCBuf[j] - 48;//要减48
}
i %= 1000;//最大 4 位
g_chSendPCBuf[26] = ((i / 100) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[27] = ((i / 10) % 10) + 48;//在这里要把它转为String!
g_chSendPCBuf[28] = (i % 10) + 48;//在这里要把它转为String!
//加 尾 *
g_chSendPCBuf[29] = '*';
//尾巴指针
//肯定发送
g_chSendPCTail = 29;
g_chSendPCHead = 0;
g_chSendPCBuf_Stat = 1;//马上去发吧
}
return(1);
}
unsigned char AutoEnvSixInsertSendPCBufTwo(unsigned char chClass)//2002-10-11 17:04 自动加 局号、流水号、检查和
{//报告---可以等待,
if((g_chSendPCBuf_Stat == 2) || (g_chSendPCBuf_Stat == 3))
{//在 RS 232 方式下 等待 4 毫秒 , 在 DTMF 下 应该不可能发生该问题
return(0);//只能 采用丢掉的办法
}
//if(4 < SendPcBufMAX - 20)
{
unsigned int i,j;
//加 头 #
g_chSendPCBuf[1] = '#';
//加 头 CC
g_chSendPCBuf[2] = 'C';
g_chSendPCBuf[3] = 'C';
//加 局号
for(i = 0; i < 4; i++)
{
g_chSendPCBuf[4 + i] = *(unsigned char *)(StationID_Info + i);//是ASC码
}
//加 流水号
g_chSendPCBuf[8] = g_chOderID;
//加 事件类别 告警盘状态上传 06
g_chSendPCBuf[9] = '0';
g_chSendPCBuf[10] = '6';
//加 监测通道 001---使用 g_chPushBit0to7
g_chSendPCBuf[11] = '0';
g_chSendPCBuf[12] = '0';
g_chSendPCBuf[13] = '1';//没有通道
//加 类型 chClass 1://door case 3://DC... case 6://温度-----有害气体只看数据!
g_chSendPCBuf[14] = (chClass / 10) % 10 + 48;
g_chSendPCBuf[15] = (chClass % 10) + 48;
//加 信息 消息的状态字(2位)
switch(chClass)
{
case 1://door
g_chSendPCBuf[16] = (g_chDoorStat / 10) % 10 + 48;
g_chSendPCBuf[17] = (g_chDoorStat % 10) + 48;
break;
case 3://dc
g_chSendPCBuf[16] = '0';
if(g_chEnv_Status & EnvStat_DC)
{// alert
if(g_chEnv_LowHign & EnvStat_DC)
{
g_chSendPCBuf[17] = '2';
}
else
{
g_chSendPCBuf[17] = '1';
}
}
else
{//restore
g_chSendPCBuf[17] = '0';
}
break;
case 6://temperature
g_chSendPCBuf[16] = '0';
if(g_chEnv_Status & EnvStat_Temperature)
{// alert
if(g_chEnv_LowHign & EnvStat_Temperature)
{
g_chSendPCBuf[17] = '2';
}
else
{
g_chSendPCBuf[17] = '1';
}
}
else
{//restore
g_chSendPCBuf[17] = '0';
}
break;
default:
AutoEnvSevenInsertSendPCBufError();
return(0);
}
//加 检查和--不能按 ASCII 码 相加 4-----25
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -