Bachelorthesis/Modbus-CAPL/include/CAPL/include/ModbusEilClientCommon.cin

64 lines
1.5 KiB
Plaintext

/*@!Encoding:1252*/
includes
{
#include "EilCommon.cin"
#include "ModbusClientCommon.cin"
}
void ModbusConnectTo(char Remote_IP[], word Remote_Port)
{
EilConnectTo(Remote_IP, Remote_Port);
}
void ModbusConnectTo(dword Remote_IP, word Remote_Port)
{
EilConnectTo(Remote_IP, Remote_Port);
}
byte ModbusSnd(byte buffer[], word length)
{
return EilSnd(buffer, length);
}
void ModbusRecv()
{
EilRecv();
}
void ModbusDisconnect()
{
EilDisconnect();
}
long ModbusGetLastConnectionError(char string[])
{
return EilGetLastConnectionError(string);
}
void OnEthReceivePacket(long channel, long dir, long packet)
{
byte buffer[gMaxPacketLength];
long size;
if (dir == TX)
return;
if (EthGetTokenInt(packet, "arp", "protSourceAddr") == gRemoteIP) // this was our ARP package
{
if (EthGetTokenData(packet, "arp", "hwSourceAddr", elCount(gRemoteMac), gRemoteMac) == 6)
{
gtArp.Cancel();
writeDbg(ConnDebug, "Remote Mac: %02X:%02X:%02X:%02X:%02X:%02X", gRemoteMac[0], gRemoteMac[1], gRemoteMac[2], gRemoteMac[3], gRemoteMac[4], gRemoteMac[5]);
EilConnectTo2(); // create the UDP package
ModbusStartQueue();
}
return;
}
if (EthGetTokenInt(packet, "ipv4", "protocol") == 0x11 && EthGetTokenInt(packet, "ipv4", "source") == gRemoteIP) // if this is a UDP package from our server
{
size = EthGetThisData(0, gMaxPacketLength, buffer);
OnModbusReceive(0, 0, EthGetTokenInt(packet, "ipv4", "source"), gRemoteIP, buffer, size);
}
}