示例#1
0
 public PeriodicMessage(J1587Message msg, double interval, txJ1587Data txDelegate)
 {
     _MessageType         = PeriodicMessageType.J1587;
     _timeKeeper          = new System.Timers.Timer(interval);
     SendJ1587Data        = txDelegate;
     _j1587Message        = msg;
     _EventHandler        = new ElapsedEventHandler(_timeKeeper_Elapsed);
     _timeKeeper.Elapsed += _EventHandler;
     _timeKeeper.Enabled  = true;
 }
示例#2
0
        public static byte[] EncodeJ1587Message(J1587Message MessageToEncode)
        {
            byte i = 0;

            byte[] returnValue = new byte[MessageToEncode.dataLength + 3];

            returnValue[i++] = MessageToEncode.Priority;
            returnValue[i++] = MessageToEncode.MID;
            returnValue[i++] = MessageToEncode.PID;
            foreach (byte temp in MessageToEncode.data)
            {
                returnValue[i++] = temp;
            }

            return(returnValue);
        }
示例#3
0
        public static J1587Message DecodeJ1587Message(byte[] message)
        {
            //  If ECHO_MODE is turned on (NOT the default)
            //     TS @ [0-3], EchoByte @ [4], MID @ [5], PID @ [6], Data @ [7-(nLength-7)]
            //  If ECHO_MODE is turned off (default)
            //     TS @ [0-3], MID @ [4], PID @ [5], Data @ [6-(nLength-6)]

            J1587Message decoded = new J1587Message();

            decoded.TimeStamp  = (UInt32)((message[0] << 24) + (message[1] << 16) + (message[2] << 8) + message[3]); //DPA is big endian?
            decoded.MID        = message[4];
            decoded.PID        = message[5];
            decoded.dataLength = (UInt16)(message.Length - 6);
            decoded.data       = new byte[decoded.dataLength];
            Array.Copy(message, 6, decoded.data, 0, decoded.dataLength);

            return(decoded);
        }
示例#4
0
 public void SendData(J1587Message msgToSend)
 {
     if (J1587inst != null)
     {
         try
         {
             byte[]         txArray    = msgToSend.ToArray();
             RP1210_Returns returnTemp = J1939inst.RP1210_SendMessage(txArray, (short)txArray.Length, 0, 0);
             // Status Event
             //txtStatus.Text = returnTemp.ToString();
         }
         catch (Exception err)
         {
             // Status Event here
             //txtStatus.Text = err.Message.ToString();
         }
     }
 }
示例#5
0
        private void tmrJ1939_Tick(object sender, EventArgs e)
        {
            if (J1939inst != null)
            {
                try
                {
                    while (true)
                    {
                        byte[]           response  = J1939inst.RP1210_ReadMessage(0);
                        DataRecievedArgs EventArgs = new DataRecievedArgs();
                        EventArgs.J1939 = true;

                        rp1210.J1939Message message = RP121032.DecodeJ1939Message(response);
                        EventArgs.RecievedJ1939Message = message;
                        string datastring    = zcrc.ByteArrayToHexString(message.data);
                        string displayString = "RX J1939 - " + message.TimeStamp + " PGN: " + message.PGN + " SA: " + message.SourceAddress;
                        displayString += " DA: " + message.DestinationAddress + " Pri: " + message.Priority;
                        displayString += " Data: " + datastring + Environment.NewLine;
                        txtRX.AppendText(displayString);

                        datastring = datastring.Remove(datastring.Length - 1, 1);
                        datastring = datastring.Replace(" ", ", ");

                        if (chkLogToFile.Checked)
                        {
                            UInt32 canID = (UInt32)((message.Priority << 26) + (message.PGN << 8) + message.SourceAddress);
                            RxLogger.WriteLine("H RXJ1939, {0:d}, {1:x}, {2}", message.TimeStamp, canID, datastring);
                        }

                        OnDataRecieved(EventArgs);
                    }
                }
                catch (Exception err)
                {
                    txtStatus.Text = err.Message;
                }

                if (TxLogger != null)
                {
                    while (((timeKeeper == null) || (timeKeeper.ElapsedMilliseconds > nextMessageTimeMs)) && !TxLogger.EndOfStream)
                    {
                        string txline = TxLogger.ReadLine();
                        txtTX.AppendText(txline + Environment.NewLine);
                        txline = txline.Replace(" ", "");
                        string[] rawdata = txline.Split(new char[] { ',' });

                        if (!TimeOffsetsCalculated)
                        {
                            TxLogTimeOffsetMs     = Convert.ToUInt32(rawdata[1]);
                            timeKeeper            = Stopwatch.StartNew();
                            TimeOffsetsCalculated = true;
                        }
                        else
                        {
                            nextMessageTimeMs = Convert.ToUInt32(rawdata[1]) - TxLogTimeOffsetMs;
                        }

                        if ((rawdata[0] == "HRXJ1939") && (J1939inst != null))
                        {
                            nextJ1939Message                    = new J1939Message();
                            nextJ1939Message.TimeStamp          = Convert.ToUInt32(rawdata[1]);
                            nextJ1939Message.SourceAddress      = (short)(Convert.ToInt32(rawdata[2], 16) & 0x00FF);
                            nextJ1939Message.Priority           = (byte)(Convert.ToInt32(rawdata[2], 16) >> 26);
                            nextJ1939Message.PGN                = (UInt16)((Convert.ToInt32(rawdata[2], 16) >> 8) & 0xFFFF);
                            nextJ1939Message.DestinationAddress = 0xFF;
                            string[] strArrayTemp = new string[rawdata.Length - 3];
                            Array.Copy(rawdata, 3, strArrayTemp, 0, rawdata.Length - 3);
                            nextJ1939Message.data       = Array.ConvertAll(strArrayTemp, x => Convert.ToByte(x, 16));
                            nextJ1939Message.dataLength = (UInt16)(rawdata.Length - 3);

                            if (timeKeeper.ElapsedMilliseconds > nextMessageTimeMs)
                            {
                                byte[]         txArray    = RP121032.EncodeJ1939Message(nextJ1939Message);
                                RP1210_Returns returnTemp = J1939inst.RP1210_SendMessage(txArray, (short)txArray.Length, 0, 0);
                                txtStatus.Text = returnTemp.ToString();
                            }
                        }
                        else if ((rawdata[0] == "HRXJ1708") && (J1587inst != null))
                        {
                            nextJ1587Message           = new J1587Message();
                            nextJ1587Message.TimeStamp = Convert.ToUInt32(rawdata[1]);
                            nextJ1587Message.Priority  = 8;
                            nextJ1587Message.MID       = Convert.ToByte(rawdata[2], 16);
                            nextJ1587Message.PID       = Convert.ToByte(rawdata[3], 16);
                            string[] strArrayTemp = new string[rawdata.Length - 4];
                            Array.Copy(rawdata, 3, strArrayTemp, 0, rawdata.Length - 4);
                            nextJ1587Message.data       = Array.ConvertAll(strArrayTemp, x => Convert.ToByte(x, 16));
                            nextJ1587Message.dataLength = (UInt16)(rawdata.Length - 4);

                            if (timeKeeper.ElapsedMilliseconds > nextMessageTimeMs)
                            {
                                byte[]         txArray    = nextJ1587Message.ToArray();
                                RP1210_Returns returnTemp = J1587inst.RP1210_SendMessage(txArray, (short)(txArray.Length - 1), 0, 0);
                                txtStatus.Text = returnTemp.ToString();
                            }
                        }
                    }
                }
            }
            if (J1587inst != null)
            {
                byte[] response = J1587inst.RP1210_ReadMessage(0);

                rp1210.J1587Message message = RP121032.DecodeJ1587Message(response);
                string datastring           = zcrc.ByteArrayToHexString(message.data);
                string displayString        = "RX J1587 - " + message.TimeStamp + " MID: " + message.MID + " PID: " + message.PID;
                displayString += " Data: " + zcrc.ByteArrayToHexString(message.data) + Environment.NewLine;
                txtRX.AppendText(displayString);

                datastring = datastring.Remove(datastring.Length - 1, 1);
                datastring = datastring.Replace(" ", ", ");

                if (chkLogToFile.Checked)
                {
                    RxLogger.WriteLine("H RXJ1708, {0:d}, {1:x2}, {2:x2}, {3}", message.TimeStamp, message.MID, message.PID, datastring);
                }
            }
        }
示例#6
0
        public void SendPeriodicMessage(J1587Message msgToSend, double interval)
        {
            PeriodicMessage newMessage = new PeriodicMessage(msgToSend, interval, SendData);

            PeriodicMessages.Add(newMessage);
        }