public int SendMessage(CanPacket canPacket)
        {
            if (canPacket == null)
            {
                throw new ArgumentNullException(nameof(canPacket));
            }

            if (!isConnected)
            {
                return(-1);
            }

            var data = canPacket.RawBytes;

            int resultToReturn = 0;

            foreach (UdpClient client in udpSenderConnections)
            {
                int result = client.Send(data, data.Length, ipEndPointMulticast);
                if (result > resultToReturn)
                {
                    resultToReturn = result;
                }
            }

            return(resultToReturn);
        }
Exemplo n.º 2
0
        // send the canPacket over Pi socketcand interface
        public int SendMessage(CanPacket canPacket)
        {
            if (!isConnected)
            {
                return(-1);
            }

            //var data = canPacket.RawBytes;

            var data = new ArraySegment <byte>(canPacket.RawBytes, 0, 8);
            var send = new List <ArraySegment <byte> >()
            {
                data
            };
            int resultToReturn = 0;

            // send CAN to each client -> change to interface via socketCAN

            /*foreach (UdpClient client in udpSenderConnections)
             * {
             *  int result = client.Send(data, data.Length, ipEndPointMulticast);
             *  if (result > resultToReturn)
             *      resultToReturn = result;
             * }*/
            // send "send" message
            resultToReturn = sender.Send(send);

            return(resultToReturn);
        }
Exemplo n.º 3
0
        public bool InRange(CanPacket canPacket)
        {
            if (canPacket.CanId >= BaseAddress && canPacket.CanId <= HighAddress)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public int SendMessage(CanPacket canPacket)
        {
            if (ReceivedCanPacketCallBack == null)
            {
                return(-1);
            }

            ReceivedCanPacketCallBack?.Invoke(canPacket);
            return(1);
        }
        public bool InRange(CanPacket canPacket)
        {
            if (canPacket == null)
            {
                throw new ArgumentNullException(nameof(canPacket));
            }

            if (canPacket.CanId >= BaseAddress && canPacket.CanId <= HighAddress)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
        public CanPacket LatestPacket(uint canIdOffset)
        {
            CanPacket canPacket = (CanPacket)latestCanPackets[canIdOffset];

            if (canPacket == null)
            {
                return(null);
            }
            if (MilliValid != 0 && canPacket.MilisecondsSinceReceived > MilliValid)
            {
                return(null);
            }

            return(canPacket);
        }
Exemplo n.º 7
0
        private void CanPacketReceivedInternal(CanReceivedEventArgs e)
        {
            CanPacket canPacket = e.Message;

            uint canIdOffset = canPacket.CanId - BaseAddress;

            if (latestCanPackets.ContainsKey(canIdOffset))
            {
                latestCanPackets.Remove(canIdOffset);
            }
            latestCanPackets.Add(canIdOffset, canPacket);

            if (InRange(canPacket))
            {
                CanPacketReceived(canPacket);
            }
        }
        private void SplitCanPackets(byte[] data, IPAddress sourceIPAddress, int sourcePort)
        {
            Byte[] header     = data.Take(16).ToArray();
            Byte[] body       = data.Skip(16).ToArray();
            int    numPackets = body.Length / 14;

            for (int i = 0; i < numPackets; i++)
            {
                CanPacket canPacket = new CanPacket(header.Concat(body.Take(14).ToArray()).ToArray())
                {
                    SourceIPAddress = sourceIPAddress,
                    SourceIPPort    = sourcePort
                };

                ReceivedCanPacketCallBack?.Invoke(canPacket);

                body = body.Skip(14).ToArray();
            }
        }
 public CanReceivedEventArgs(CanPacket Message)
 {
     this.Message = Message;
 }
Exemplo n.º 10
0
 public abstract void CanPacketReceived(CanPacket canPacket);
Exemplo n.º 11
0
 // Used for testing only
 public void TestCanPacketReceived(CanPacket canPacket)
 {
     CanPacketReceivedInternal(new CanReceivedEventArgs(canPacket));
 }