📄 main.c
字号:
STBuf[TransCounter++]=0x0A;
//Frame ID
memcpy(&STBuf[TransCounter],cCANFid,sizeof(cCANFid));
TransCounter+= sizeof(cCANFid)-1;
//------------临时加入调试---------------------------
if(TempBuf[4] == 0x10)
{
temp = 1;
}
//-------------------------------------------------------
for(i=1;i<5;i++)
{
CanHexToRs232ASCII(&STBuf[TransCounter],TempBuf[i]);
TransCounter += 2;
}
STBuf[TransCounter++]=0x0D;STBuf[TransCounter++]=0x0A;
//Frame Data
memcpy(&STBuf[TransCounter],cCANData,sizeof(cCANData));
TransCounter+= sizeof(cCANData)-1;
if(CRBuf.CANRcvFS.Bits.DLC_BIT >8)
{
CRBuf.CANRcvFS.Bits.DLC_BIT =8;
}
for(i=5;i<CRBuf.CANRcvFS.Bits.DLC_BIT+5;i++)
{
CanHexToRs232ASCII(&STBuf[TransCounter],TempBuf[i]);
TransCounter += 2;
}
STBuf[TransCounter++]=0x0D;
STBuf[TransCounter++]=0x0A;
STBuf[TransCounter++]=0x0D;
STBuf[TransCounter++]=0x0A;
//Sead
//Uart0Send(TransCounter, STBuf);
//-------------临时加入调试---------------------
//if(1 == temp)
{
temp = 0;
Uart0Send(TransCounter, STBuf);
}
}
/*
************************************************************************************************************************
**函数原型 : void Can_8byte_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Flag[4],uint8 Data_Type,
uint8 Send_Data[8],uint8 Cmd)
**参数说明 : Can_Channel 表示通道号 、Data_Lenth字节数 、Can_Flag[4] 标志符 ;Data_Type:数据类型
Send_Data 表示所要发出的数据; Cmd 表示命令
**返回 值 : 无
**说 明 : Can 总线发送8字节数据
************************************************************************************************************************
*/
void Can_8byte_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 Data_Type,uint8 Send_Data[8],uint8 Cmd)
{
uint8 i;
SRBuf[0] = Can_Channel;
SRBuf[1] = Data_Lenth;
for(i = 2; i < 5; i++)
{
SRBuf[i] = Can_Addr[i - 2];
}
SRBuf[5] = Can_Addr[3] | Data_Type;
for(i = 0; i < 8; i++)
{
SRBuf[6 + i] = Send_Data[i];
}
SRBuf[14] = Cmd;
while(1 == RS232DataToCan());
}
/*
************************************************************************************************************************
**函数原型 : void Can_Check_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 Data_Type,uint8 CmdABC)
**参数说明 : Can_Channel 表示通道号; Data_Lenth :发送字节数 、 Can_Addr:can地址;Data_Type: 数据类型 dl0-4
Send_DataABC 表示所要发出的数据; CmdABC 表示命令 (0x00,0x02,Can_Locoal_Addr,BackData,0x01)
**返回 值 : 无
**说 明 : Can 循检回应
************************************************************************************************************************
*/
void Can_Check_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 BackData,uint8 CmdABC)
{
uint8 j,send_buffer[8];
send_buffer[0] = 0x01; //0x02断路器,0x03隔刀
send_buffer[1] = BackData;
for(j = 0;j < 6;j++)
{
send_buffer[j+2] = 0x00;
}
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,0x05,send_buffer,CmdABC); //can 通讯 数据帧
DelayNS(1);
}
/*
************************************************************************************************************************
**函数原型 : void Can_CheckState_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 Data_Type,uint8 CmdABC)
**参数说明 : Can_Channel 表示通道号; Data_Lenth :发送字节数 、 Can_Addr:can地址;Data_Type: 数据类型 dl0-4
Send_DataABC 表示所要发出的数据; CmdABC 表示命令 (0x00,0x02,Can_Locoal_Addr,0x05,0x01)
**返回 值 : 无
**说 明 : Can 断路器开关状态查询回应,数据回应帧
************************************************************************************************************************
*/
void Can_CheckState_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 Data_Type,uint8 CmdABC)
{
uint8 j,send_buffer[8];
send_buffer[0] = 0x07; //0x02断路器,0x03隔刀
send_buffer[1] = 0x55;
for(j = 0;j < 6;j++)
{
send_buffer[j+2] = 0x00;
}
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,send_buffer,CmdABC); //can 通讯 数据帧
DelayNS(1);
}
/*
************************************************************************************************************************
**函数原型 : void Can_Request_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 Data_Type,uint8 CmdABC)
**参数说明 : Can_Channel 表示通道号; Data_Lenth :发送字节数 、 Can_Addr:can地址;Data_Type: 数据类型 dl0-4
Send_DataABC 表示所要发出的数据; CmdABC 表示命令,Request_type表示请求类型(0x00,0x03,Can_Locoal_Addr,0x01,0x01,Open_Current_220KV)
**返回 值 : 无
**说 明 : Can 断路器收到数据,向上位机发送请求
************************************************************************************************************************
*/
void Can_Request_Send(uint8 Can_Channel,uint8 Data_Lenth,uint8 Can_Addr[4],uint8 Data_Type,uint8 CmdABC)
{
uint8 j,send_buffer[8];
send_buffer[0] = 0x06; //数据类型06
send_buffer[1] = 0x0b; //发送字节数
send_buffer[2] = 0xb8;
for(j = 0;j < 5;j++)
{
send_buffer[j+3] = 0x00;
}
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,send_buffer,CmdABC); //can 通讯 数据帧
DelayNS(1);
}
/*
************************************************************************************************************************
**函数原型 : void Can_ABC_Send(uint8 Can_Channel,uint8 Open_Close,uint8 Can_Addr[4],
uint8 CmdABC,uint16 Lenth)
**参数说明 : Can_Channel 表示通道号; Open_Close :选择发送合闸或分闸数据 、 Can_Addr:can地址
Send_DataABC 表示所要发出的数据数组
; CmdABC 表示命令 lenth :数据数组的长度
**返回 值 : 无
**说 明 : Can 总线发送采样数据(1,1,Can_Locoal_Addr,1,Send_Lenth)
************************************************************************************************************************
*/
void Can_ABC_Send(uint8 Can_Channel,uint8 Open_Close,uint8 Can_Addr[4],uint8 CmdABC,uint16 Lenth)
{
uint8 i;
uint16 j;
uint8 send_buffer[8];
uint8 Data_Lenth,Data_Type;
//////////////////////////////////////////////////////////////////////////////
for(i = 0;i < 8;i++) //can 通讯 同步信号0xeb,0x90,...
{
send_buffer[i] = Can_syn[i];
}
Data_Lenth = 0x08;
Data_Type = 0x02; //同步帧
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,send_buffer,CmdABC);
DelayNS(1);
//////////////////////////////////////////////////////////////////////////////
for(j = 0;j < 8;j++) //can 通讯 控制帧
{
send_buffer[j] = Can_ctl[j];
}
Data_Lenth = 0x03;
Data_Type = 0x03; //控制帧
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,send_buffer,CmdABC);
DelayNS(1);
//////////////////////////////////////////////////////////////////////////////
Data_Lenth = 0x08;
Data_Type = 0x04;
for(i = 0; i < Lenth/4; i++)
{
for(j=0;j<4;j++)
{
send_buffer[2*j] = Calc_Data[j].byte.high;
send_buffer[2*j+1] = Calc_Data[j].byte.low;
}
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,send_buffer,CmdABC);
DelayNS(1);
SendByte('l');
}
}
/*
************************************************************************************************************************
**函数原型 : void Can_ABC_Send(uint8 Can_Channel,uint8 Open_Close,uint8 Can_Addr[4],
uint8 CmdABC,uint16 Lenth)
**参数说明 : Can_Channel 表示通道号; Open_Close :选择发送合闸或分闸数据 、 Can_Addr:can地址
Send_DataABC 表示所要发出的数据数组
; CmdABC 表示命令 lenth :数据数组的长度
**返回 值 : 无
**说 明 : Can 总线发送采样数据(1,1,Can_Locoal_Addr,1,Send_Lenth)
************************************************************************************************************************
*/
void Can_Switch_Send(uint8 Can_Channel,uint8 Can_Addr[4],uint8 CmdABC)
{
uint8 i;
uint16 j;
uint8 temp[8];
uint8 Data_Lenth,Data_Type;
//////////////////////////////////////////////////////////////////////////////
for(i = 0;i < 8;i++)
{
temp[i] = Can_syn[i];
}
Data_Lenth = 0x08;
Data_Type = 0x02;
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,temp,CmdABC);
DelayNS(1);
for(i = 0;i < 8;i++)
{
temp[i] = Can_Switch_Data[i];
}
Data_Lenth = 0x03;
Data_Type = 0x03;
Can_8byte_Send(0,3,Can_Addr,3,temp,1);
DelayNS(1);
Data_Lenth = 0x08;
Data_Type = 0x04;
if(switch_data[0].time>0)
{
j=switch_data[0].time - 0;
}
else
{
j=1024 - 0 + switch_data[0].time;
}
temp[0] = j>>8;
temp[1] = j;
temp[2] = j>>8;
temp[3] = j;
temp[4] = j>>8;
temp[5] = j;
temp[6] = 0xaa;//switch_data[0].state;
Can_8byte_Send(Can_Channel,Data_Lenth,Can_Addr,Data_Type,temp,CmdABC);
//Can_8byte_Send(0,3,Can_Addr,4,temp,1);
}
UINT8 ToASC(UINT8 in)
{
UINT8 temp = '0';
switch(in)
{
case 0x01:temp='1';break;
case 0x02:temp='2';break;
case 0x04:temp='3';break;
case 0x08:temp='4';break;
case 0x10:temp='5';break;
case 0x20:temp='6';break;
case 0x40:temp='7';break;
case 0x80:temp='8';break;
default:temp='0';break;
}
return(temp);
}
void com_send(uint16 tt,uint8 com)
{
uint8 cc,dd,ee,gg,hh;
uint16 aa;
aa=tt;
cc=aa/10000;
dd=(aa-cc*10000)/1000;
ee=(aa-cc*10000-dd*1000)/100;
gg=(aa-cc*10000-dd*1000-ee*100)/10;
hh=(aa-cc*10000-dd*1000-ee*100)%10;
if(com==1)
{
if(cc!=0)
SendByte(cc+0x30);
SendByte(dd+0x30);
SendByte(ee+0x30);
SendByte(gg+0x30);
SendByte(hh+0x30);
}
else
{
if(cc!=0)
Uart1SendByte(cc+0x30);
Uart1SendByte(dd+0x30);
Uart1SendByte(ee+0x30);
Uart1SendByte(gg+0x30);
Uart1SendByte(hh+0x30);
}
}
void two_send(uint8 tt,uint8 com)
{
UINT8 temp = '0';
temp=tt / 0x10;
if(temp<0x0a)
temp=temp+0x30;
else
temp=temp+0x57;
if(com==1)
SendByte(temp);
else
Uart1SendByte(temp);
temp=tt % 0x10;
if(temp<0x0a)
temp=temp+0x30;
else
temp=temp+0x57;
if(com==1)
SendByte(temp);
else
Uart1SendByte(temp);
}
void four_send(uint16 tt,uint8 com)
{
UINT8 temp = '0';
temp=tt>>12 & 0x0f;
if(temp<0x0a)
temp=temp+0x30;
else
temp=temp+0x57;
if(com==1)
SendByte(temp);
else
Uart1SendByte(temp);
temp=tt>>8 &0x0f;
if(temp<0x0a)
temp=temp+0x30;
else
temp=temp+0x57;
if(com==1)
SendByte(temp);
else
Uart1SendByte(temp);
temp=tt>>4 & 0x0f;
if(temp<0x0a)
temp=temp+0x30;
else
temp=temp+0x57;
if(com==1)
SendByte(temp);
else
Uart1SendByte(temp);
temp=tt & 0x0f;
if(temp<0x0a)
temp=temp+0x30;
else
temp=temp+0x57;
if(com==1)
SendByte(temp);
else
Uart1SendByte(temp);
}
#define SendLenth 1000
#define WSendLenth 500
uint8 Data_Send()
{
uint16 tem16;
uint8 buf8[7];
uint16 ii,jj,x1,x2;
uint8 dx,retd=0;
ii=0;
x1=SendLenth;
Uart1SendByte(0x0d);
Uart1SendByte('\n');
printstr("Send Start",2);
Uart1SendByte(0x0d);
Uart1SendByte('\n');
/*
if(StartSampleDot<100)
StartSampleDot=StartSampleDot+2900;
else
StartSampleDot=StartSampleDot-100;
*/
do
{
dx=0;
buf8[0]=0;
buf8[1]=Locoal_Addr;
buf8[2]=6;
jj=SendLenth*6;
buf8[3]=jj>>8;
buf8[4]=jj;
buf8[5]=x1>>8;
buf8[6]=x1;
for(jj=0;jj<3;jj++)
{
SendByte(0xeb);
SendByte(0x90);
}
for(jj=0;jj<7;jj++)
{
SendByte(buf8[jj]);
}
tem16=CRC_16(buf8,7);
for(jj=0;jj<WSendLenth;jj++)
{
if(StartSampleDot>=3000)
{
x2=StartSampleDot-3000;
}
else
{
x2=StartSampleDot;
}
StartSampleDot++;
SendByte(Calc_Data[x2].byte.high);
SendByte(Calc_Data[x2].byte.low);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -