1.首先设置节点
接收节点R,发送节点S,
2.设置TCP/IP configration
配置R和S的IP地址,如果需要设置Vlan和优先级,则设置即可。
3.编写系统变量(切记不是环境变量)
建立系统变量,为制作panel做好准备
4.制作panle
在制作panle时可以参考CANoe自带的模板
代码也可以直接复制模板内的,并加以修改。
variables
{
UdpSocket gSocket;
char in_char_array[145]="ffff8108888888000000101010200c00000000000002006000010020100010100000300000001060000100202000101000003000000010000000c00090400ac1000630011d6d9";// ??????16??
byte out_byte_array[200];
}
on start
{
// Open an UDP socket. As source address 0.0.0.0 is used, this means that
// the configure address of the TCP/IP stack is used. See TCP/IP stack
// configuration dialog in the simulation setup
// As port no ist used, this means a source port is dynamically assign
// by the TCP/IP stack.
// gSocket = UdpSocket::Open( IP_Endpoint(182.118.0.0:30490) );// ?????IP
gSocket = UdpSocket::Open( IP_Endpoint(0.0.0.0:30490) );// ??????
//gSocket = UdpSocket::Open( IP_Endpoint(0.0.0.0));// ???????,?????????
if (IpGetLastError() != 0)
{
write( "<%BASE_FILE_NAME%> UdpSocket::Open failed with result %d", IpGetLastError());
}
}
on preStop
{
、
gSocket.Close();
}
on sysvar sysvar::huts::TxButton
{
if (@this == 1)
{
char text[200];
sysGetVariableString( sysvar::huts::TxText, text, elcount(text) );
gSocket.SendTo( IP_Endpoint(xx.xx.0.xx:30490), text, strlen(text) );
EnableControl( "huts", "TxButton", 0 );
}
}
byte GBF_ConvertHexStrToByteArray(char hexRawData[], byte outByteArr[])// ????16??????
{
word i;
word offset;
word hexLength;
byte tmpVal;
byte retVal;
char tmpErrStr[200];
byte outdword;
const byte dataType = 2;
byte gcNok = 0;
byte gcOk = 1;
retVal = gcNok;
offset = 0;
outdword = 0;
hexLength = strlen(hexRawData);
if( hexRawData[0] == '0' && hexRawData[1] == 'x' )
offset = 2;
if ( dataType < (hexLength - offset)/2 )
{
snprintf(tmpErrStr, elcount (tmpErrStr), "GBF_ConvertHexStrToInt: ERROR: Hex Data
is %d which is more than a dword can hold!", hexLength);
write ("Error in GBF_ConvertHexStrToInt: string is: %s",hexRawData);
write(tmpErrStr);
}
else
{ */
retVal = gcOk;
for (i = offset; i < hexLength; i++)
{
outdword = outdword << 4;
tmpVal = (byte)hexRawData[i];
if (tmpVal >= 0x30 && tmpVal <= 0x39) //0-9
tmpVal = tmpVal - 0x30;
else if(tmpVal >= 'A' && tmpVal <= 'F') //A-F
tmpVal = tmpVal - 0x37;
else if (tmpVal >= 'a' && tmpVal <= 'f') //a-f
tmpVal = tmpVal - 0x57;
else
{
snprintf(tmpErrStr, elcount (tmpErrStr), "GBF_ConvertHexStrToInt: ERROR:
Invalid Hex data found in Hex string at position %d", i);
write(tmpErrStr);
retVal = gcNok;
break;
}
outdword = outdword | tmpVal; //one nibble at a time....
if(i%dataType == dataType-1)
outByteArr[i/dataType] = outdword;
}
return retVal;
}
on key 't'
{
GBF_ConvertHexStrToByteArray(in_char_array,out_byte_array);
write("out_byte_array ={0x%x,0x%x} ",out_byte_array[0],out_byte_array[1]);
gSocket.SendTo( IP_Endpoint(xx.xx.0.xx:30490),out_byte_array, 72 );
}
on key 'k'
{
GBF_ConvertHexStrToByteArray(in_char_array,out_byte_array);
write("out_byte_array ={0x%x,0x%x} ",out_byte_array[0],out_byte_array[1]);
gSocket.SendTo( IP_Endpoint(182.18.0.0:30490),out_byte_array, 72 );
}
本代码: on key"k" 可以实现 hex形式发送
Txbutton 可以实现String 字符串发送。