Esempio n. 1
0
        // push a message
        public void pushMessage(canMessage2 msg)
        {
            List <canMessage2> ls = new List <canMessage2>();

            ls.Add(msg);
            pushMessageList(ls);
        }
Esempio n. 2
0
        private ErrorCode checkStartArgs(CanMessageSendTool can_tool, canMessage2 req, canMessageId resp_id)
        {
            ErrorCode err = ErrorCode.Ok;

            // check
            if (!m_self_test && (can_tool == null || !can_tool.IsSendingAllowed()))
            {
                // check the can tool (expect self_tests)
                err = ErrorCode.InvalidArg;
            }
            else if (req == null || resp_id == null)
            {
                // make sure we have not empty request and response
                err = ErrorCode.InvalidArg;
            }
            else if (req.Data.Count() == 0 || (req.Data.Count() + 1) > tx_message_len_max)
            {
                // check request data len (we do not support multi-frame sending)
                err = ErrorCode.InvalidArg;
            }
            else if (req.Id.Is29bit != resp_id.Is29bit)
            {
                // make sure request proto == response proto
                err = ErrorCode.InvalidArg;
            }
            else if (req.Data[0] == 0)
            {
                // requested service cannot be 0
                err = ErrorCode.InvalidArg;
            }

            return(err);
        }
Esempio n. 3
0
        // start BMW
        public ErrorCode sendRequestBMW(CanMessageSendTool can_tool, byte ecu_id, List <byte> data)
        {
            const byte gateway_id = 0xF1;

            ErrorCode err = ErrorCode.Ok;

            // clean
            cleanData();

            if (data.Count == 0)
            {
                return(ErrorCode.InvalidArg);
            }
            if (ecu_id == 0)
            {
                return(ErrorCode.InvalidArg);
            }

            // set specific configs for BMW
            tx_add_extra_bytes = false;
            m_req_prefix       = new List <byte> {
                ecu_id
            };
            m_resp_prefix = new List <byte> {
                gateway_id
            };

            // prepare the request and response
            canMessage2  req     = new canMessage2(createEcuAddressBmw(gateway_id), false, data.ToArray());
            canMessageId resp_id = new canMessageId(createEcuAddressBmw(ecu_id), 1, false);

            // check the arguments
            err = checkStartArgs(can_tool, req, resp_id);

            // apply
            m_can_tool = can_tool;
            m_req_msg  = req;
            m_resp_id  = resp_id;

            // send the message
            if (err == ErrorCode.Ok)
            {
                m_expected_service = createExpectedService(data[0]);

                var uds_req = createRequestMessage();
                if (uds_req == null)
                {
                    err = ErrorCode.InvalidArg;
                }
                else
                {
                    if (!sendRequest(uds_req))
                    {
                        err = ErrorCode.TxFailed;
                    }
                }
            }

            return(err);
        }
Esempio n. 4
0
        // send a flow control frame
        private bool sendFlow()
        {
            List <byte> data_flow = new List <byte> {
                0x30, 0x00, 0x00
            };
            List <byte> data = new List <byte>();

            // add the prefix if required
            if (m_req_prefix != null)
            {
                data.AddRange(m_req_prefix);
            }

            // add the message itself
            data.AddRange(data_flow);

            // add extra bytes if required
            while (tx_add_extra_bytes && data.Count < tx_message_len_max)
            {
                data.Add(tx_add_extra_byte_value);
            }

            // create the flow control message
            canMessage2 flow = new canMessage2(m_req_msg.Id.Id, m_req_msg.Id.Is29bit, data.ToArray());

            // send it
            return(m_self_test ? true : m_can_tool.SendCanMessage(flow));
        }
Esempio n. 5
0
        //-----------------------------------------------------------------------

        // convert row to message
        private canMessage2 row2message(DataGridViewRow row)
        {
            canMessageId id  = new canMessageId(getMsgIdFromRow(row), getMsgDlcFromRow(row));
            canMessage2  msg = new canMessage2(id, getMsgDataFromRow(row));

            return(msg);
        }
        private void modifyMessage()
        {
            canMessage2 m = Params.Message;

            // id
            int newId = m.Id.Id;

            if (Params.Modifiers.modId)
            {
                newId = newId < m.Id.GetMaxId() ? newId + 1 : 0;
            }

            // data
            byte[] data = m.Data;
            for (int i = 0; i < data.Length; i++)
            {
                if (Params.Modifiers.modB[i])
                {
                    data[i]++;
                }
            }


            msgBeforeMod   = m;
            Params.Message = new canMessage2(newId, m.Id.Is29bit, data);
            sender.messageUpdated(this);
        }
Esempio n. 7
0
        // create a request message
        private canMessage2 createRequestMessage()
        {
            // we do not support TX multiftame messages
            if (m_req_msg == null || (m_req_msg.Data.Count() + 1) > tx_message_len_max)
            {
                return(null);
            }

            List <byte> data = new List <byte>();

            // add the prefix if required
            if (m_req_prefix != null)
            {
                data.AddRange(m_req_prefix);
            }

            // the len of the payload and the payload itself
            data.Add((byte)(m_req_msg.Data.Count()));
            data.AddRange(m_req_msg.Data);

            // dummy bytes
            while (data.Count < tx_message_len_max && tx_add_extra_bytes)
            {
                data.Add(tx_add_extra_byte_value);
            }

            canMessage2 uds_req = new canMessage2(m_req_msg.Id.Id, m_req_msg.Id.Is29bit, data.ToArray());

            return(uds_req);
        }
Esempio n. 8
0
        public void updateItem(canSendWorker item)
        {
            canMessage2 m   = item.Params.Message;
            var         row = getRow(item, true);

            row.Cells[m_colId.Index].Value   = m.Id.GetIdAsString();
            row.Cells[m_colData.Index].Value = m.GetDataString(" ");
        }
Esempio n. 9
0
        // update period
        public void UpdatePeriod(canMessage2 item)
        {
            long key = item.GetHashCodeUnique();

            if (dict.ContainsKey(key))
            {
                dict[key].updatePeriod(item);
            }
        }
Esempio n. 10
0
        // handle a single message
        private void handleMessage(canMessage2 msg)
        {
            const int min_allowed_payload = 2;  // msg len + service

            // check id and mode
            if (msg.Id.Id != m_resp_id.Id)
            {
                return;
            }
            if (msg.Id.Is29bit != m_resp_id.Is29bit)
            {
                return;
            }
            // check the payload
            if (msg.Data == null || msg.Data.Count() < min_allowed_payload)
            {
                return;
            }
            // check the prefix
            if (m_resp_prefix != null)
            {
                if ((msg.Data.Count() + min_allowed_payload) < m_resp_prefix.Count())
                {
                    return;
                }
                for (int i = 0; i < m_resp_prefix.Count(); i++)
                {
                    if (m_resp_prefix[i] != msg.Data[i])
                    {
                        return;
                    }
                }
            }
            // we've finished -> do nothing
            if (m_finished)
            {
                return;
            }

            if (!m_gotAtLeastOneResponse)
            {
                // try to parse the 1st message
                m_gotAtLeastOneResponse = parseFirstMessage(msg);
            }
            else
            {
                // multiframe message
                parseMultiMessage(msg);
            }

            if (!m_finished)
            {
                m_finished = m_expected_len > 0 &&
                             m_response_data.Count() >= m_expected_len;
            }
        }
        private void btnStartStop_Click(object sender, EventArgs e)
        {
            if (!CanTool.IsCommunication)
            {
                return;
            }

            if (stage == scanStage.pause)
            {
                stage = scanStage.waitingForCanSleep;

                // id range
                idStart   = numIdFrom.Value;
                idStop    = numIdTo.Value;
                idCurrent = idStart;
                byte[] d = Tools.hexStringToByteArray(tbData.Text);

                if (d == null || d.Length == 0 || d.Length > canMessage.maxDataBytesNum())
                {
                    return;
                }

                // int only
                messageCountToSend = Convert.ToInt32(tbCount.Text, 10);
                butSleepTmo        = Convert.ToInt32(tbBusSleep.Text, 10);
                idCheckTmo         = Convert.ToInt32(tbIdCheck.Text, 10);

                message = new canMessage2((int)idCurrent, rb29BitId.Checked, d, 0);

                // trace
                if (!string.IsNullOrEmpty(tbTrace.Text))
                {
                    trace(Environment.NewLine);
                }

                trace(Environment.NewLine + string.Format("Scan from {0} to {1}",
                                                          canMessage.getCanIdString((int)idStart, rb29BitId.Checked),
                                                          canMessage.getCanIdString((int)idStop, rb29BitId.Checked)));
                trace(string.Format("DLC = {0}, Data = {1}",
                                    message.Id.GetDlcAsString(),
                                    message.GetDataString(" ")));
                trace("Waiting until the CAN bus is sleeping");

                worker      = new Thread(onWorker);
                worker.Name = "Wrk";
                worker.Start();
            }
            else
            {
                // stop
                stage = scanStage.pause;
                trace("Aborted");
            }

            guiStartStop();
        }
Esempio n. 12
0
        // get a grid message
        public gridMessage getGridMessage(canMessage2 item)
        {
            long key = item.GetHashCodeUnique();

            if (dict.ContainsKey(key))
            {
                return(dict[key]);
            }
            return(null);
        }
Esempio n. 13
0
        private void clearRxer()
        {
            // clean the queue, the message counter and the parser
            canMessage2 msg = new canMessage2();

            while (true == m_queueMsgs.TryTake(out msg))
            {
            }
            MessageCounter = 0;
            m_parser.reset();
        }
Esempio n. 14
0
        //-----------------------------------------------------------------------

        // get an interval value for a message
        public int getMessageInterval(canMessage2 msg)
        {
            gridList list = Parser.GetList();
            var      item = list.getGridMessage(msg);

            if (item == null)
            {
                return(-1);
            }
            return(item.Period);
        }
Esempio n. 15
0
        //-----------------------------------------------------------------------

        // get an counter value for a message
        public int getMessageCounter(canMessage2 msg)
        {
            gridList list = Parser.GetList();
            var      item = list.getGridMessage(msg);

            if (item == null)
            {
                return(-1);
            }
            return(item.Count);
        }
Esempio n. 16
0
 private void setDefaults()
 {
     TriggerStart  = canTriggerStart.timer;
     TriggerStop   = canTriggerStop.doNotStop;
     PostCondition = paramActAfterStop.stop;
     MessageType   = canMessageType.data;
     Message       = new canMessage2();
     Modifiers     = new paramModifiers();
     TimerPeriod   = 1000;
     MessageCount  = 1;
 }
Esempio n. 17
0
 public void updatePeriod(canMessage2 msg)
 {
     if (null == CanPeriod)
     {
         CanPeriod = new canPeriod(msg.TimeStamp);
     }
     else
     {
         CanPeriod.Update(msg.TimeStamp);
     }
 }
Esempio n. 18
0
        //-----------------------------------------------------------------------
        #endregion

        // the region contains add and update methods
        #region Modifiers

        public void updateCheckboxesWithFilter()
        {
            foreach (DataGridViewRow row in m_grid.Rows)
            {
                canMessage2 m    = row2message(row);
                bool        show = !CanFilter.Contains(m.Id);
                hideShowRow(row, show);
            }

            doSort();
        }
Esempio n. 19
0
        public override bool Equals(object obj)
        {
            // Check for null values and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            canMessage2 p = (canMessage2)obj;

            return(p.Id.Equals(Id));
        }
Esempio n. 20
0
 // constructor
 public gridMessage(canMessage2 msg)
 {
     // id
     Data = msg.GetDataString(" ");
     Id   = msg.Id;
     // data
     DataListBuff = new List <byte[]>();
     DataListBuff.Add(msg.Data);
     // period
     CanPeriod = null;
     // counter
     counter = 1;
 }
Esempio n. 21
0
        public void add(canMessage2 msg)
        {
            long key = msg.GetHashCodeUnique();

            if (list.ContainsKey(key))
            {
                list[key] = msg;        // update
            }
            else
            {
                list.Add(key, msg);     // add
            }
        }
Esempio n. 22
0
        // add a new item or update an existing one
        public void Add(canMessage2 item)
        {
            long key = item.GetHashCodeUnique();

            if (dict.ContainsKey(key))
            {
                dict[key].update(item);
            }
            else
            {
                dict.Add(key, new gridMessage(item));
            }
        }
Esempio n. 23
0
            // returns true if the message has at least one new data bit
            // othrewise returns false
            public bool update(canMessage2 msg)
            {
                bool res = false;

                for (int i = 0; i < Mask.Length; i++)
                {
                    int tmp = msg.Data[i] | Mask[i];
                    if (tmp != Mask[i])
                    {
                        res     = true;
                        Mask[i] = (byte)tmp;
                    }
                }
                return(res);
            }
Esempio n. 24
0
        // get can message
        private canMessage2 getMessage()
        {
            int  id        = (int)numId.Value;
            int  dlc       = (int)numDlc.Value;
            bool is29bitId = rbId29b.Checked;

            byte[] data = new byte[dlc];

            int i = 0;

            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD0.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD1.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD2.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD3.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD4.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD5.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD6.Text, 16);
            }
            if (dlc >= i + 1)
            {
                data[i++] = Convert.ToByte(tbD7.Text, 16);
            }

            canMessage2 msg = new canMessage2(id, is29bitId, data, 0);

            return(msg);
        }
Esempio n. 25
0
        // parse message to string before send it to the device
        public static string parseCanMessageForSend(canMessage2 msg, bool remote)
        {
            // format
            // tiiiLDDDDDDDDDDDDDDDD
            string res = string.Empty;

            // header
            if (remote)
            {
                res += msg.Id.Is29bit ? "R" : "r";
            }
            else
            {
                res += msg.Id.Is29bit ? "T" : "t";
            }

            // id
            int  idLen = msg.Id.Is29bit ? 8 : 3;
            uint id    = (uint)msg.Id.Id;

            for (int i = idLen - 1; i >= 0; i--)
            {
                // the oldest byte should be first
                uint tmp = (id >> (4 * i)) & (uint)0x0F;
                res += int2char((byte)tmp);
            }

            // dlc
            res += int2char(msg.Id.Dlc);

            // data (std mode only)
            for (int i = 0; i < msg.Id.Dlc && !remote; i++)
            {
                int b  = msg.Data[i];
                int b1 = b & 0x0F;
                int b2 = b >> 4;

                char ch1 = int2char(b1);
                char ch2 = int2char(b2);

                res += ch2;
                res += ch1;
            }

            return(res);
        }
Esempio n. 26
0
        // send a message
        public bool sendMessge(canMessage2 msg, bool rtr = false)
        {
            // it is not allowed to send messages in the listen only mode
            if (m_silentMode)
            {
                return(false);
            }

            // convert message to raw data string
            string s = canParser.parseCanMessageForSend(msg, rtr);

            if (txQueue.Count > 100)
            {
                return(false);
            }

            txQueue.Add(s);
            return(true);
        }
Esempio n. 27
0
            // 0x77 ,~0x88
            // 0x01 - not new
            // 0x08 - new

            // returns false if it should be filtered
            // returns true if it has at least one new bit
            public bool checkFreshness(canMessage2 msg)
            {
                for (int i = 0; i < Mask.Length; i++)
                {
                    int t1   = 0xFF & msg.Data[i];
                    int t2   = 0xFF & (~Mask[i]);
                    int tmp2 = t1 & t2;
                    int tmp  = msg.Data[i] & (~Mask[i]);
                    if (tmp != tmp2)
                    {
                        break;
                    }
                    if (tmp != 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
Esempio n. 28
0
        // message parser: multiframe message
        private void parseMultiMessage(canMessage2 msg)
        {
            int nibble_pos = 0;

            if (m_resp_prefix != null)
            {
                nibble_pos = m_resp_prefix.Count();
            }
            int data_pos = nibble_pos + 1;

            if (msg.Data.Count() <= data_pos)
            {
                return;
            }
            if ((msg.Data[nibble_pos] & 0x20) != 0x20)
            {
                return;
            }

            int nibble = msg.Data[nibble_pos] & 0x0F;

            if (nibble != m_next_nibble)
            {
                return;
            }

            // copy data
            for (int i = data_pos; i < msg.Data.Count() && m_response_data.Count() < m_expected_len; i++)
            {
                m_response_data.Add(msg.Data[i]);
            }

            // update the nibble
            m_next_nibble = nibble + 1;
            if (m_next_nibble > 0x0F)
            {
                m_next_nibble = 0;
            }

            // update timeout value
            m_rx_timeout += rx_timeout_2_multi;
        }
Esempio n. 29
0
        // returns true if the message can be printed
        // returns false if the message should be filtered
        public bool update(canMessage2 msg)
        {
            long key = msg.GetHashCodeUnique();

            // exits?
            if (list.ContainsKey(key))
            {
                return(Enabled ? list[key].update(msg) : list[key].checkFreshness(msg));
            }
            else
            {
                // create it and return 'true' cuz the message is a new one
                if (Enabled)
                {
                    list.Add(key, new maskedMessage(msg));
                    list[key].update(msg);
                }
                return(true);
            }
        }
Esempio n. 30
0
        // update
        public void update(canMessage2 msg)
        {
            // debug
            // if ( msg.Id.GetHashCodeUnique() != Id.GetHashCodeUnique() )
            // {
            //     int err = 0;
            // }

            // data
            if (DataListBuff.Count < GridTipTool.MaxValues)
            {
                DataListBuff.Add(msg.Data);
            }

            // data string
            if (string.IsNullOrEmpty(Data))
            {
                Data = msg.GetDataString(" ");
            }

            counter++;
        }