// remove an item public void Remove(canMessageId item) { if (Contains(item)) { set.Remove(GetAKey(item)); } }
// 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); }
//----------------------------------------------------------------------- // 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); }
//----------------------------------------------------------------------- // get a row for an appropiate message private DataGridViewRow getMsgRow(string canId, int dlc) { canMessageId id = new canMessageId(canId, dlc); DataGridViewRow res = RowList.getRow(id); return(res); }
// try to find a gridRow public gridRow find(canMessageId m) { long key = m.GetHashCodeUnique(); if (dict.ContainsKey(key)) { return(dict[key]); } return(null); }
// get a row with the can id // returns null in case the id doesn't exist public DataGridViewRow getRow(canMessageId m) { var gr = find(m); if (gr != null) { return(gr.Row); } return(null); }
// equals public override bool Equals(Object obj) { // Check for null values and compare run-time types. if (obj == null || GetType() != obj.GetType()) { return(false); } canMessageId p = (canMessageId)obj; return(p.GetHashCodeUnique() == GetHashCodeUnique()); }
// add a new item if does not exist yet // returs true if we've added the item public bool Add(canMessageId item) { bool res = false; long key = GetAKey(item); if (!set.Contains(key)) { set.Add(key); res = true; } return(res); }
// constructor public canMessage2(int id, bool is_29bit, byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) { Data = new byte[8]; Data[0] = b0; Data[1] = b1; Data[2] = b2; Data[3] = b3; Data[4] = b4; Data[5] = b5; Data[6] = b6; Data[7] = b7; Id = new canMessageId(id, Data.Length, is_29bit); TimeStamp = new canTimeStamp(0); }
// constructor public canMessage2(int id = 0, bool is29bit = false, byte[] data = null, int ts = 0) { // data if (data != null && data.Length > 0) { Data = new byte[data.Length]; data.CopyTo(Data, 0); } else { Data = null; } // id Id = new canMessageId(id, Data == null ? 0 : data.Length, is29bit); // timestamp TimeStamp = new canTimeStamp(ts); }
// constructor public canMessage2(canMessageId id, byte[] data = null, int ts = 0) { Id = id; // data if (data != null && data.Length > 0) { Data = new byte[data.Length]; data.CopyTo(Data, 0); } else { Data = null; } // todo: compare data len and DLC // ts TimeStamp = new canTimeStamp(ts); }
// start UDS public ErrorCode sendRequest(CanMessageSendTool can_tool, canMessage2 req, canMessageId resp_id) { ErrorCode err = ErrorCode.Ok; // clean and set cleanData(); // 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(req.Data[0]); var uds_req = createRequestMessage(); if (uds_req == null) { err = ErrorCode.InvalidArg; } else { if (!sendRequest(uds_req)) { err = ErrorCode.TxFailed; } } } return(err); }
// returns true if Id is null or empty static bool IsNullOrEmpry(canMessageId id) { return(null == id || id.Equals(Empty)); }
// constructor public gridRow(canMessageId message, DataGridViewRow row) { Msg = message; Row = row; }
// Simple unit tests public void SelfTest() { m_self_test = true; // test: clean { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); Debug.Assert(m_finished == false); Debug.Assert(m_gotAtLeastOneResponse == false); Debug.Assert(m_expected_len == 0); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), new List <byte>())); Debug.Assert(!IsTimeoutExpired()); } // test: parse signle message { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == 6); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test: parse short signle message { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x3E }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x7E }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x01, 0x7E })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test: parse multiframe message { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x22, 0xF1, 0x90 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x62, 0xF1, 0x90 }; for (byte i = 0; i < 17; i++) { expected.Add(i); } List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x10, 17 + 3, 0x62, 0xF1, 0x90, 0, 1, 2 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x21, 3, 4, 5, 6, 7, 8, 9 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x22, 10, 11, 12, 13, 14, 15, 16 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // test: parse a very long multiframe message { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x22, 0xF1, 0x90 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x62, 0xF1, 0x90 }; for (byte i = 0; i < 17; i++) { expected.Add(i); } List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x10, 17 + 3, 0x62, 0xF1, 0x90, 0, 1, 2 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x21, 3, 4, 5, 6, 7, 8, 9 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x22, 10, 11, 12, 13, 14, 15, 16 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // test: parse multiframe messages, the last one is short { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x22, 0xF1, 0x90 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x62, 0xF1, 0x90 }; for (byte i = 0; i < 18; i++) { expected.Add(i); } List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x10, 18 + 3, 0x62, 0xF1, 0x90, 0, 1, 2 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x21, 3, 4, 5, 6, 7, 8, 9 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x22, 10, 11, 12, 13, 14, 15, 16 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x23, 17 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // test: single message with unexpected messages { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x123, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x123, true, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E9, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E9, true, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == 6); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // test: multiframe message with unexpected messages { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x22, 0xF1, 0x90 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x62, 0xF1, 0x90 }; for (byte i = 0; i < 17; i++) { expected.Add(i); } List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x123, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x123, true, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E9, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E9, true, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x10, 17 + 3, 0x62, 0xF1, 0x90, 0, 1, 2 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x21, 3, 4, 5, 6, 7, 8, 9 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x22, 10, 11, 12, 13, 14, 15, 16 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x23, 17, 18, 19, 20, 21, 22, 23 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // test: incorrect service { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41 + 1, 0x00, 0x10, 0x20, 0x30, 0x40 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41 - 1, 0x00, 0x10, 0x20, 0x30, 0x40 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(IsSuccesfullyFinished() == false); Debug.Assert(m_gotAtLeastOneResponse == false); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), new List <byte> { })); } // negative response { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x03, 0x7F, 0x01, 0x13 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(IsSuccesfullyFinished()); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), new List <byte> { 0x7F, 0x01, 0x13 })); } // negative response 0x13 + correct response { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x03, 0x7F, 0x01, 0x13 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(IsSuccesfullyFinished()); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), new List <byte> { 0x7F, 0x01, 0x13 })); } // negative response 0x78 + correct response { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x03, 0x7F, 0x01, 0x78 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(IsSuccesfullyFinished()); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // timeout { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30, 0x40 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); Thread.Sleep((int)rx_timeout_1_single + 1); handleMessages(resp); Debug.Assert(IsTimeoutExpired()); } // test: multiframe message 29b { canMessage2 req = new canMessage2(0x18DAC7F1, true, new byte[] { 0x22, 0xF1, 0xF2 }); canMessageId resp_id = new canMessageId(0x18DAF1C7, 1, true); List <byte> expected = new List <byte> { 0x62, 0xF1, 0xF2, 0, 1, 2, 3, 4, 5, 6 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x18DAF1C7, true, new byte[] { 0x10, 10, 0x62, 0xF1, 0xF2, 0, 1, 2 })); resp.Add(new canMessage2(0x18DAF1C7, true, new byte[] { 0x21, 3, 4, 5, 6, 7, 8, 9 })); resp.Add(new canMessage2(0x18DAF1C7, true, new byte[] { 0x22, 10, 11, 12, 13, 14, 15, 16 })); resp.Add(new canMessage2(0x18DAF1C7, true, new byte[] { 0x23, 17, 18, 19, 20, 21, 22, 23 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } // test BMW: parse signle message { List <byte> request = new List <byte> { 0x22, 0x01, 0x01 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x06, 0x62, 0x01, 0x01, 0x20, 0x30, 0x40 })); List <byte> expected = new List <byte> { 0x62, 0x01, 0x01, 0x20, 0x30, 0x40 }; Debug.Assert(sendRequestBMW(null, 0x60, request) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == 6); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test BMW: parse multi-frame message 1 (the last msg is short) { List <byte> request = new List <byte> { 0x22, 0x01, 0x01 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x10, 20, 0x62, 0x01, 0x01, 0x10, 0x11 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x22, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x23, 0x1E, 0x1F, 0x20 })); List <byte> expected = new List <byte> { 0x62, 0x01, 0x01 }; for (int i = 0; i < (20 - 3); i++) { expected.Add((byte)(0x10 + i)); } Debug.Assert(sendRequestBMW(null, 0x60, request) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test BMW: parse multi-frame message 2 (with flow messages) { List <byte> request = new List <byte> { 0x22, 0x01, 0x01 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x670, false, new byte[] { 0xF1, 0x10, 20, 0x62, 0x01, 0x01, 0, 0 })); resp.Add(new canMessage2(0x777, false, new byte[] { 0x01, 0x02 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x10, 20, 0x62, 0x01, 0x01, 0x10, 0x11 })); resp.Add(new canMessage2(0x670, false, new byte[] { 0xF1, 0x21, 0, 0, 0, 0, 0, 0 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 })); resp.Add(new canMessage2(0x670, false, new byte[] { 0xF1, 0x22, 0, 0, 0, 0, 0, 0 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x22, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D })); resp.Add(new canMessage2(0x670, false, new byte[] { 0xF1, 0x23, 0, 0, 0 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x23, 0x1E, 0x1F, 0x20 })); List <byte> expected = new List <byte> { 0x62, 0x01, 0x01 }; for (int i = 0; i < (20 - 3); i++) { expected.Add((byte)(0x10 + i)); } Debug.Assert(sendRequestBMW(null, 0x60, request) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test BMW: parse multi-frame message 3 (the last msg is long) { List <byte> request = new List <byte> { 0x22, 0x01, 0x01 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x10, 20, 0x62, 0x01, 0x01, 0x10, 0x11 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x22, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D })); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x23, 0x1E, 0x1F, 0x20, 0xFF, 0xFF, 0xFF })); List <byte> expected = new List <byte> { 0x62, 0x01, 0x01 }; for (int i = 0; i < (20 - 3); i++) { expected.Add((byte)(0x10 + i)); } Debug.Assert(sendRequestBMW(null, 0x60, request) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test BMW: negative response { List <byte> request = new List <byte> { 0x22, 0x01, 0x01 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x660, false, new byte[] { 0xF1, 0x03, 0x7F, 0x01, 0x31 })); List <byte> expected = new List <byte> { 0x7F, 0x01, 0x31 }; Debug.Assert(sendRequestBMW(null, 0x60, request) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == expected.Count()); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test: too short single-frame message { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x01, 0x00 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x41, 0x00, 0x10, 0x20, 0x30 }; List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x06, 0x41, 0x00, 0x10, 0x20, 0x30 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(!m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == 6); Debug.Assert(m_flow_sent == false); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); Debug.Assert(!IsTimeoutExpired()); } // test: too short multiframe message { canMessage2 req = new canMessage2(0x7E0, false, new byte[] { 0x22, 0xF1, 0x90 }); canMessageId resp_id = new canMessageId(0x7E8, 1, false); List <byte> expected = new List <byte> { 0x62, 0xF1, 0x90 }; for (byte i = 0; i < 15; i++) { expected.Add(i); } List <canMessage2> resp = new List <canMessage2>(); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x10, 17 + 3, 0x62, 0xF1, 0x90, 0, 1, 2 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x21, 3, 4, 5, 6, 7, 8, 9 })); resp.Add(new canMessage2(0x7E8, false, new byte[] { 0x22, 10, 11, 12, 13, 14 })); Debug.Assert(sendRequest(null, req, resp_id) == ErrorCode.Ok); handleMessages(resp); Debug.Assert(!m_finished); Debug.Assert(m_gotAtLeastOneResponse); Debug.Assert(m_expected_len == 20); Debug.Assert(m_flow_sent == true); Debug.Assert(SelfTestCompareLists(getResponse(), expected)); } m_self_test = false; Debug.WriteLine("UDS unit testing finished"); }
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); }
// add a new id and a row public void add(int id, int dlc, bool is29b, DataGridViewRow row) { canMessageId m = new canMessageId(id, dlc, is29b); add(new gridRow(m, row)); }
public maskedMessage(canMessage2 msg) { Id = msg.Id; Mask = new byte[Id.Dlc]; }
// remove1 public void remove(int canId, int dlc, bool is29bitId) { canMessageId msg = new canMessageId(canId, dlc, is29bitId); remove(msg); }
// add2 public void add(canMessageId canId) { list.Add(canId); }
// add1 public void add(int canId, int dlc, bool is29bitId) { canMessageId msg = new canMessageId(canId, dlc, is29bitId); add(msg); }
// remove2 public void remove(canMessageId canId) { list.Remove(canId); }
//----------------------------------------------------------------------- // get a row for an appropiate message private DataGridViewRow getMsgRow(canMessageId id) { DataGridViewRow res = RowList.getRow(id); return(res); }
// check1 public bool Contains(int canId, int dlc, bool is29bitId) { canMessageId msg = new canMessageId(canId, dlc, is29bitId); return(Contains(msg)); }
// get an unique hash code based key private long GetAKey(canMessageId item) { return(item.GetHashCodeUnique()); }
// is there an item? public bool Contains(canMessageId item) { long key = GetAKey(item); return(set.Contains(key)); }
// check2 public bool Contains(canMessageId canId) { return(list.Contains(canId)); }