基于Canoe开发以太UDP转CANFD通信协议GW脚本

某大厂牛马打工人

1.创建工程

首先创建一个以太和CAN的节点

2.设置协议栈的配置

3.capl脚本的编写

includes
{
  
  #include "Core_Objects.cin"
  #include "Core_Objects_protocol.cin"
  #include "..\Core_Construction_Area\Core_Construction_Area.cin"
  #include "..\Core_Lanes_Adjacent\Core_Lanes_Adjacent.cin"
  #include "..\Core_Lanes_Host_protocol\Core_Lanes_Host_protocol.cin"
}

variables
{
  dword gUdpSocketHandle = 0;
  dword gServerUdpPort = 1274; // Service is provided on this port
  CHAR gRxBuffer[1472]; // Max. UDP payload without fragmentation
  LONG gResult;
  CHAR gErrorText[200];
  const   int gLenPduRaw = 32767;
  char  gPduRawStr[gLenPduRaw]="";
  CHAR textData[20] = "Hello UDP Client";
  byte dup_payload[2500];
  byte canbuffer[64];
  byte Core_Objects_payload[2500];
  byte Core_Construction_Area_payload[1000];
  byte Core_Lanes_Host_payload[1000];
  byte Core_Lanes_Adjacent_payload[1000];
  dword startbyte_Core_Objects;
  dword startbyte_Core_Construction_Area;
  dword startbyte_Core_Lanes_Host;
  dword startbyte_Core_Lanes_Adjacent;
  dword Core_Objects_length;
  dword Core_Construction_Area_length;
  dword Core_Lanes_Host_length;
  dword Core_Lanes_Adjacent_length;
}

on start
{
  // Open UDP socket
  gUdpSocketHandle = UdpOpen(ipGetAddressAsNumber("225.5.23.1"),gServerUdpPort);
  // Check for valid socket handle
  if (gUdpSocketHandle == ~0)
  {
    write("<%BASE_FILE_NAME%> UdpOpen failed: Result %d", IpGetLastError());
  }
  else // Socket handle valid
  {
    // Get received data
    UdpSendTo(gUdpSocketHandle,ipGetAddressAsNumber("198.18.36.1"),65521,textData, strlen(textData));
    UdpReceiveFrom(gUdpSocketHandle, gRxBuffer, elcount(gRxBuffer));
    // Check for error
    if ( IpGetLastSocketError(gUdpSocketHandle) != 997 )
    {
      IpGetLastSocketErrorAsString(gUdpSocketHandle, gErrorText, elcount(gErrorText));
      write("<%BASE_FILE_NAME%> UdpReceiveFrom failed, %s (Result %d)", gErrorText, IpGetLastSocketError(gUdpSocketHandle));
    }
  }
}

// Callback function for reception from UDP client
OnUdpReceiveFrom(dword socket, long resul

  • 19
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值