| /* Copyright (c) 2000-2019 Ericsson Telecom AB AB |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Michael Josenhans |
| ******************************************************************************/ |
| // |
| // File: Isobustest.ttcn |
| // Description: Encoder / Decoder for Isobus message frames |
| // |
| // Revision R1A |
| |
| module Isobustest { |
| |
| import from General_Types all |
| import from CanError all |
| import from SocketCANtest all |
| import from SocketCAN_Types all |
| import from SocketCAN_PortType all |
| import from SocketCAN_Templates all |
| import from Can all |
| import from Isobus all |
| import from IsobusMessageTypes all |
| import from Isobus_Templates all |
| import from J1939 all |
| |
| import from IsobusNMMessageTypes all |
| |
| type union CAN_ID { |
| OCT4 can_eff, // 29-bit can address |
| OCT2 can_sff, // 11-bit can address |
| RTR can_rtr, |
| BIT29 can_err // up to 29 can error bits |
| } |
| |
| type bitstring BIT29 length(29) |
| type enumerated RTR { RTRNULL } |
| |
| type union Can_IDs { |
| BIT29 can_eff, // CAN extended format |
| BIT11 can_sff, // CAN basic format |
| RTR can_rtr, // Remote Transmission Request (RTR), seldom used |
| BIT29 can_err // CAN Error |
| } |
| with { variant "" } |
| |
| type record Can_IDwithType { |
| INT1 cantype, // can_id >> 29 bit |
| Can_IDs can_ids // can_id and4b '1FFFFFFF'O |
| } |
| with { |
| variant (can_ids) "CROSSTAG( |
| can_eff, cantype = 4; |
| can_rtr, cantype = 2; |
| can_err, cantype = 1; |
| can_sff, cantype = 0)" |
| } |
| |
| //component declarations |
| type component MTC_CT |
| { |
| } |
| |
| type component PTC_isobus_CT |
| { |
| port SocketCAN_PT pt_socketCAN |
| port Isobus_PT pt_isobus |
| //variables |
| //timers |
| timer T0:= 0.2 |
| } |
| |
| const integer MAX_CONNECTIONS := 65535 |
| |
| type record length (0..MAX_CONNECTIONS) of PTC2_CT OpenConnections |
| type record length (0..MAX_CONNECTIONS) of boolean OpenConnectionsFlags |
| |
| type component PTC1_CT |
| { |
| port Isobus_PT pt_isobus |
| //variables |
| var OpenConnections openConnections |
| var OpenConnectionsFlags openConnectionsFlags |
| //timers |
| timer T1:= 0.2 |
| |
| } |
| type component PTC2_CT |
| { |
| port Isobus_PT pt_isobus |
| //variables |
| var octetstring receivedUnacknowledgedData |
| var INT2 msgSizeInBytes |
| var INT2 receivedUnacknowledgedMsgSizeInBytes |
| var INT1 nextExpectedPacketNumber |
| var PGN pgnOfMultiPacketMessage |
| var OCT1 ps, sa |
| var CAN_id tp_dt_can_id |
| //timers |
| timer T2:= 0.2 |
| } |
| |
| type port Isobus_PT message { |
| out CAN_frame_j1939 |
| in CAN_frame_j1939 |
| } with { extension "internal" } |
| |
| type port SyncMasterPort message { |
| out PhaseStartReq |
| in PhaseEndInd |
| } with { extension "internal" } |
| |
| type port SyncSlavePort message { |
| in PhaseStartReq |
| out PhaseEndInd |
| } with { extension "internal" } |
| |
| type record of PTC PTCSet |
| |
| |
| type component PTC { |
| port SyncSlavePort pt_sync |
| port SocketCAN_PT pt_socketCAN |
| var e_Phase v_phase := c_firstPhase |
| } |
| |
| |
| function f_open_socket2(in SocketCAN_open_socket_type v_socket_type) |
| runs on PTC_isobus_CT |
| return SocketCAN_socket_result { |
| |
| var SocketCAN_socket_result v_result |
| timer t_guard |
| t_guard.start(c_guard) |
| |
| var SocketCAN_socket socket |
| |
| if(v_socket_type==OPEN_CAN_RAW) { |
| socket := {domain:=PF_CAN, ptype := SOCK_RAW, protocol:= CAN_RAW}; |
| } else if (v_socket_type == OPEN_CAN_BCM) { |
| socket := {domain:=PF_CAN, ptype := SOCK_DGRAM, protocol:= CAN_BCM}; |
| } |
| pt_socketCAN.send(socket) |
| |
| // receive response |
| alt { |
| [] pt_socketCAN.receive( |
| a_SocketCAN_socket_result(a_result(SocketCAN_SUCCESS))) -> value v_result |
| {log("SocketCan:Socket opened: ", v_result.id)} |
| [] pt_socketCAN.receive(a_SocketCAN_socket_result(a_result(SocketCAN_ERROR))) |
| {log("Received Opening Socket failed"); setverdict(fail)} |
| [] t_guard.timeout { |
| log("timeout!") |
| setverdict(fail)} |
| [] t_guard.timeout { |
| log("timeout!") |
| setverdict(fail)} |
| } |
| t_guard.stop |
| return v_result |
| } |
| |
| function f_open_raw2() |
| runs on PTC_isobus_CT |
| return SocketCAN_open_raw_result { |
| var SocketCAN_socketid v_socket_id |
| v_socket_id := f_open_socket2(OPEN_CAN_RAW).id |
| var SocketCAN_ifr v_ifr |
| v_ifr := f_ioctl_get_if_index2(v_socket_id).ifr |
| var SocketCAN_bind_result v_bind_result |
| v_bind_result := f_bind2(v_socket_id, v_ifr.if_index) |
| |
| var SocketCAN_open_raw_result v_result |
| v_result := {ifr := v_ifr, socket_id := v_socket_id} |
| |
| return v_result |
| } |
| |
| function f_ioctl_get_if_index2(in SocketCAN_socketid p_socket_id) |
| runs on PTC_isobus_CT |
| return SocketCAN_ioctl_result { |
| var SocketCAN_ioctl_result v_result |
| timer t_guard |
| t_guard.start(c_guard) |
| |
| pt_socketCAN.send(SocketCAN_ioctl:{id:= p_socket_id, ifu := omit}); |
| // receive response |
| alt { |
| [] pt_socketCAN.receive(a_SocketCAN_ioctl_result(a_result(SocketCAN_SUCCESS))) -> value v_result |
| {log("Retrieved interface index", v_result.ifr.if_index)} |
| [] pt_socketCAN.receive(a_SocketCAN_ioctl_result(a_result(SocketCAN_ERROR))) |
| {log("Retrieving interface index failed", p_socket_id); setverdict(fail)} |
| [] t_guard.timeout { |
| log("timeout!") |
| setverdict(fail) |
| } |
| } |
| return v_result |
| } |
| |
| function f_bind2(in SocketCAN_socketid p_socket_id, |
| in SocketCAN_if_index p_if_index) |
| runs on PTC_isobus_CT |
| return SocketCAN_bind_result { |
| var SocketCAN_bind_result v_result |
| timer t_guard |
| t_guard.start(c_guard) |
| |
| pt_socketCAN.send(SocketCAN_bind:{id:= p_socket_id, bindu := {raw := {if_index:= p_if_index}}}); |
| alt { |
| [] pt_socketCAN.receive(a_SocketCAN_bind_result(a_result(SocketCAN_SUCCESS))) -> value v_result |
| {log("Binding socket", p_socket_id)} |
| [] pt_socketCAN.receive(a_SocketCAN_bind_result(a_result(SocketCAN_ERROR))) {} |
| [] t_guard.timeout { |
| log("timeout!") |
| setverdict(fail) |
| } |
| } |
| return v_result |
| } |
| |
| function f_close_socket2 (in SocketCAN_socketid p_socket_id) |
| runs on PTC_isobus_CT { |
| pt_socketCAN.send(SocketCAN_close:{id:= p_socket_id}); |
| } |
| |
| function f_behaviour_isobus(in PTC1_CT v_ptc1) runs on PTC_isobus_CT |
| { |
| |
| map(self:pt_socketCAN, system:pt_socketCAN) |
| connect(v_ptc1:pt_isobus, self:pt_isobus) |
| |
| var SocketCAN_socketid v_socket_id |
| var SocketCAN_ifr v_ifr |
| var SocketCAN_send_data_ifu v_ifu |
| |
| var SocketCAN_open_raw_result res |
| res := f_open_raw2(); |
| v_socket_id := res.socket_id |
| v_ifr := res.ifr |
| v_ifu.if_name := v_ifr.if_name |
| |
| log("socket open(): ", res) |
| |
| var boolean condition3 := true |
| //periodic reception |
| |
| while (condition3) |
| { |
| //var SocketCAN_socket_result v_result_socketcan |
| var SocketCAN_receive_CAN_or_CAN_FD_frame v_result_socketcan |
| //T0.start; |
| |
| alt |
| { |
| [] pt_socketCAN.receive(a_SocketCAN_receive_CAN_frame(v_socket_id, t_CAN_EFF_FLAG, ?)) -> value v_result_socketcan |
| { |
| //log("SocketCan:Expected frame received", v_result_socketcan) |
| // it is assumed that no can fd frames are received here |
| if(ischosen(v_result_socketcan.frame.can_frame)){ |
| var CAN_frame_j1939 v_CAN_frame_j1939 := can2j1939frame(v_result_socketcan.frame.can_frame) |
| pt_isobus.send(v_CAN_frame_j1939) to v_ptc1 |
| } else { |
| setverdict(inconc, "reception of canfd frame not expected") |
| } |
| } |
| }//endalt |
| } |
| f_close_socket2(v_socket_id) |
| disconnect(self:pt_isobus, v_ptc1:pt_isobus) |
| unmap(self:pt_socketCAN, system:pt_socketCAN) |
| setverdict(pass) |
| }//endfunction |
| |
| |
| function f_behaviour1_sync() runs on PTC1_CT |
| { |
| |
| var boolean condition1 := true |
| var CAN_frame_j1939 v_can_frame_j1939 |
| //periodic reception |
| |
| while (condition1) |
| { |
| //T1.start; |
| |
| alt |
| { |
| |
| /* []syncport.receive("halt") { |
| condition1:=false } */ |
| |
| []pt_isobus.receive(CAN_frame_j1939:?) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received: ", v_can_frame_j1939); |
| } |
| |
| //[]T1.timeout; |
| |
| }//endalt |
| } |
| }//endfunction var boolean condition1 |
| |
| function f_get_component (in OCT1 connectioninitiator, in OCT1 connectionresponder) runs on PTC1_CT return PTC2_CT { |
| |
| var PTC2_CT v_PTC2 |
| |
| var integer index |
| index:= oct2int(connectioninitiator) + 256 * oct2int(connectionresponder) |
| |
| if (openConnectionsFlags[index] == false){ |
| |
| v_PTC2 := PTC2_CT.create |
| v_PTC2.start(f_behaviour_connections()); |
| openConnectionsFlags[index] := true |
| openConnections[index] := v_PTC2 |
| connect(v_PTC2:pt_isobus, self:pt_isobus) |
| } else { |
| v_PTC2 := openConnections[index] |
| } |
| return v_PTC2 |
| } |
| |
| |
| |
| function f_behaviour2_sync() runs on PTC1_CT |
| { |
| |
| var boolean condition1 := true |
| var CAN_frame_j1939 v_can_frame_j1939 |
| |
| // initialization |
| |
| var integer i |
| for(i:=1;i<=MAX_CONNECTIONS; i:= i+1){ |
| openConnectionsFlags[i] := false |
| } |
| |
| //periodic reception |
| |
| |
| |
| |
| while (condition1) |
| { |
| //T1.start; |
| |
| alt |
| { |
| |
| /* []syncport.receive("halt") { |
| condition1:=false } */ |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { requestToSend := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received requestToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| |
| var PTC2_CT v_PTC2 |
| v_PTC2 := f_get_component(v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps) |
| pt_isobus.send(v_can_frame_j1939) to v_PTC2 |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { clearToSend := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received requestToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.ps, v_can_frame_j1939.can_j1939.sa); |
| |
| var PTC2_CT v_PTC2 |
| v_PTC2 := f_get_component(v_can_frame_j1939.can_j1939.ps, v_can_frame_j1939.can_j1939.sa) |
| pt_isobus.send(v_can_frame_j1939) to v_PTC2 |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { endOfMessageAcknowledgement := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received requestToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.ps, v_can_frame_j1939.can_j1939.sa); |
| |
| var PTC2_CT v_PTC2 |
| v_PTC2 := f_get_component(v_can_frame_j1939.can_j1939.ps, v_can_frame_j1939.can_j1939.sa) |
| pt_isobus.send(v_can_frame_j1939) to v_PTC2 |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { connectionAbort := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received requestToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.ps, v_can_frame_j1939.can_j1939.sa); |
| |
| var PTC2_CT v_PTC2 |
| v_PTC2 := f_get_component(v_can_frame_j1939.can_j1939.ps, v_can_frame_j1939.can_j1939.sa) |
| pt_isobus.send(v_can_frame_j1939) to v_PTC2 |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { broadcastAnnounce := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received requestToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| |
| var PTC2_CT v_PTC2 |
| v_PTC2 := f_get_component(v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps) |
| pt_isobus.send(v_can_frame_j1939) to v_PTC2 |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_dt := ?}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received tp_ct: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| |
| var PTC2_CT v_PTC2 |
| v_PTC2 := f_get_component(v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps) |
| pt_isobus.send(v_can_frame_j1939) to v_PTC2 |
| } |
| []pt_isobus.receive(CAN_frame_j1939:?) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received: ", v_can_frame_j1939); |
| } |
| |
| //[]T1.timeout; |
| |
| }//endalt |
| } |
| }//endfunction var boolean condition1 |
| function f_behaviour_connections() runs on PTC2_CT |
| { |
| |
| var boolean condition1 := true |
| var CAN_frame_j1939 v_can_frame_j1939 |
| |
| // initialization |
| |
| //periodic reception |
| |
| |
| |
| |
| while (condition1) |
| { |
| //T1.start; |
| |
| alt |
| { |
| |
| /* []syncport.receive("halt") { |
| condition1:=false } */ |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { requestToSend := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| msgSizeInBytes := v_can_frame_j1939.can_pdu.tp_cm.requestToSend.msgSizeInBytes |
| receivedUnacknowledgedData := ''O |
| receivedUnacknowledgedMsgSizeInBytes := 0 |
| pgnOfMultiPacketMessage := v_can_frame_j1939.can_pdu.tp_cm.requestToSend.pgnOfMultiPacketMessage |
| ps := v_can_frame_j1939.can_j1939.ps |
| sa := v_can_frame_j1939.can_j1939.sa |
| //log incoming message |
| log ("received requestToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| alt // connection open requested |
| { |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { clearToSend := {ctrl := '11'O, |
| totalNumberOfPackets := ?, |
| nextPacketNumber :=1, |
| reserved4 := ?, |
| reserved5 := ?, |
| pgnOfMultiPacketMessage := ?}}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| nextExpectedPacketNumber := v_can_frame_j1939.can_pdu.tp_cm.clearToSend.nextPacketNumber |
| //log incoming message |
| log ("received clearToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| alt // connection open - receivig data |
| { |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_dt := ?}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| if ((msgSizeInBytes - receivedUnacknowledgedMsgSizeInBytes) > 7) { |
| tp_dt_can_id := j1939id2canid(v_can_frame_j1939.can_j1939) // actuallay it is only necessary to store it once |
| receivedUnacknowledgedData := receivedUnacknowledgedData & v_can_frame_j1939.can_pdu.tp_dt.data |
| receivedUnacknowledgedMsgSizeInBytes := receivedUnacknowledgedMsgSizeInBytes + 7 |
| nextExpectedPacketNumber := nextExpectedPacketNumber + 1 } |
| else { |
| log("v_can_frame_j1939.can_j1939: ", v_can_frame_j1939.can_j1939) |
| tp_dt_can_id := j1939id2canid(v_can_frame_j1939.can_j1939) // actuallay it is only necessary to store it once |
| receivedUnacknowledgedData := receivedUnacknowledgedData & substr(v_can_frame_j1939.can_pdu.tp_dt.data |
| ,0 , (msgSizeInBytes - receivedUnacknowledgedMsgSizeInBytes)) |
| nextExpectedPacketNumber := 0 |
| receivedUnacknowledgedMsgSizeInBytes := msgSizeInBytes |
| } |
| //log incoming message |
| log ("received tp_dt: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| repeat |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { clearToSend := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| log ("received clearToSend: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| repeat |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { endOfMessageAcknowledgement := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| log ("received endOfMessageAcknowledgement: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| if (receivedUnacknowledgedMsgSizeInBytes == msgSizeInBytes) { |
| var octetstring receivedData |
| //var PGN pgn := v_can_frame_j1939.can_pdu.tp_cm.endOfMessageAcknowledgement.pgnOfMultiPacketMessage |
| if (oct2int((int2oct(pgnOfMultiPacketMessage, 3) and4b '00FF00'O)>> 1 ) < 240) { |
| log ("pgnOfMultiPacketMessage: ", pgnOfMultiPacketMessage, ", ", int2oct(pgnOfMultiPacketMessage, 3)) |
| log ("ps: ", ps) |
| log ("sa: ", sa) |
| receivedData := int2oct(oct2int((int2oct(pgnOfMultiPacketMessage, 3) and4b '03FFFF'O)>> 1 ), 2) & ps & sa & receivedUnacknowledgedData |
| } |
| else |
| { |
| log ("pgnOfMultiPacketMessage: ", pgnOfMultiPacketMessage, ", ", int2oct(pgnOfMultiPacketMessage, 3)) |
| log ("sa: ", sa) |
| receivedData := (int2oct(pgnOfMultiPacketMessage, 3) and4b '03FFFF'O) & sa & receivedUnacknowledgedData |
| } |
| //var octetstring receivedData := (tp_dt_can_id and4b '0003FFFF'O) & receivedUnacknowledgedData |
| log("tp_dt_can_id: ", tp_dt_can_id) |
| //var octetstring receivedData := tp_dt_can_id & receivedUnacknowledgedData |
| //var octetstring receivedData := receivedUnacknowledgedData |
| //log ("received tp_dt frame with PGN: ", receivedData); |
| // changed by MJ |
| |
| //receivedData := receivedUnacknowledgedData |
| log ("received multipart frame", receivedData); |
| v_can_frame_j1939:=f_decode_CAN_frame_j1939(receivedData) |
| log ("received tp_dt frame j1939: ", v_can_frame_j1939); |
| } |
| else { |
| log ("received incomplete message frame: ", receivedUnacknowledgedData); |
| } |
| } |
| } |
| } |
| []pt_isobus.receive(CAN_frame_j1939:{can_j1939 := ?, can_pdu := {tp_cm := { connectionAbort := ?}}}) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| log ("received connectionAbort: ", v_can_frame_j1939, v_can_frame_j1939.can_j1939.sa, v_can_frame_j1939.can_j1939.ps); |
| } |
| } |
| |
| |
| } |
| []pt_isobus.receive(CAN_frame_j1939:?) -> value v_can_frame_j1939 { |
| //T1.stop; |
| //log incoming message |
| //log ("received: ", v_can_frame_j1939); |
| } |
| |
| //[]T1.timeout; |
| |
| }//endalt |
| } |
| }//endfunction var boolean condition1 |
| |
| |
| testcase tc_encdec() runs on MTC_CT |
| |
| { |
| |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 6, res := '0'B, dp := '1'B, pf := 'E9'O, ps := 'FD'O, sa := 'E6'O }, |
| can_pdu := { addressClaimed := { name := { selfConfigurableAddressValue := '0'B, industryGroupValue := '011'B, deviceClassInstanceValue := '0001'B, deviceClassValue := '0000001'B, reserveValued := '0'B, functionValue := '00000011'B, functionInstanceValue := '00101'B, ecuInstancceValue := '110'B, manufacturerCodeValue := '10000000000'B, identityNumberBits := '101000010000101000000'B } }}} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log("--------------------------------------------") |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| log("--------------------------------------------") |
| |
| template CAN_frame_j1939 t_CAN_frame_j1939_2 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := 'FD'O, sa := 'C0'O }, can_pdu := { requestForAddressClaimed := {pgn := 123}} } |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939_2))) |
| log("--------------------------------------------") |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939_2)))) |
| log("--------------------------------------------") |
| |
| template CAN_frame_j1939 t_CAN_frame_j1939_3 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := 'FD'O, sa := 'C0'O }, can_pdu := { cannotClaimSourceAddress := { name := { selfConfigurableAddressValue := '0'B, industryGroupValue := '011'B, deviceClassInstanceValue := '0001'B, deviceClassValue := '0000001'B, reserveValued := '0'B, functionValue := '00000011'B, functionInstanceValue := '00101'B, ecuInstancceValue := '110'B, manufacturerCodeValue := '10000000000'B, identityNumberBits := '101000010000101000000'B } }}} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939_3))) |
| log("--------------------------------------------") |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939_3)))) |
| log("--------------------------------------------") |
| |
| template CAN_frame_j1939 t_CAN_frame_j1939_6 := { can_j1939 := { prio := 6, res := '0'B, dp := '1'B, pf := 'E6'O , ps := 'FD'O, sa := '00'O }, can_pdu := { commandedAddress := { |
| name := { selfConfigurableAddressValue := '0'B, industryGroupValue := '011'B, deviceClassInstanceValue := '0001'B, deviceClassValue := '0000001'B, reserveValued := '0'B, functionValue := '00000011'B, functionInstanceValue := '00101'B, ecuInstancceValue := '110'B, manufacturerCodeValue := '10000000000'B, identityNumberBits := '101000010000101000000'B }, |
| newSourceAddress:='AA'O |
| } } } |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939_6))) |
| log("--------------------------------------------") |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939_6)))) |
| log("--------------------------------------------") |
| } |
| |
| testcase tc_encdec_vt2ecu_vtStatusReq() runs on MTC_CT |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := '00'O, sa := '00'O }, can_pdu := |
| {vt2ecu := {vtStatusReq := |
| { vtfunction := 254, |
| sourceAddressOfActiveWorkingSetMaster := '11'O, |
| objectIDOfTheVisibleDataAlarmMaskOfTheActiveWorkingSet := '2233'O, |
| objectIDOfTheVisibleSoftKeyMaskOfTheActiveWorkingSet := '4455'O, |
| vtBusyCodes := vtIsBusyExecutingACommand, |
| vtFunctionCode := '66'O}}}} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_ecu2vt_getMemoryReq() runs on MTC_CT |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := '00'O, sa := '00'O }, can_pdu := |
| {ecu2vt := {getMemoryReq := |
| { vtfunction := 194, |
| reserved2 := 'FF'O, |
| memoryRequired := 1234567, |
| reserved7 := 'FF'O, |
| reserved8 := 'FF'O}}}} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_ecu2vt_getMemoryReq_with_templateI() runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := '00'O, sa := '00'O }, can_pdu := |
| {ecu2vt := {getMemoryReq := t_GetMemoryReq(1234567)}}} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_ecu2vt_getMemoryReq_with_template_II() runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := '00'O, sa := '00'O }, can_pdu := |
| t_GetMemoryReq_pdu(1234567)} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_networkMessage_N_SP_Response_pdu_with_template() runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := t_message ( 1, '1'B, '0'B, '0A'O, '0B'O, '0C'O , |
| t_N_SP_Response_pdu(port_3, port_4, {'01'O,'02'O,'03'O,'04'O,'05'O,'06'O,'07'O})) |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_networkMessage_N_SP_Response_with_template() runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := t_network_message ( 1, '1'B, '0'B, '0A'O, '0B'O, '0C'O , |
| {n_SP_Response := t_N_SP_Response(port_3, port_4, {'01'O,'02'O,'03'O,'04'O,'05'O,'06'O,'07'O})}) |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_N_SP_Response_with_template() runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := t_message ( 1, '1'B, '0'B, '0A'O, '0B'O, '0C'O , |
| {networkMessage := {n_SP_Response := t_N_SP_Response(port_3, port_4, {'01'O,'02'O,'03'O,'04'O,'05'O,'06'O,'07'O})}}) |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| testcase tc_encdec_ecu2vt_workingSetMaintenanceReq() runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 0, res := '0'B, dp := '0'B, pf := '00'O, ps := '00'O, sa := '00'O }, can_pdu := |
| t_WorkingSetMaintenanceReq_pdu({ |
| initiatingWorkingSetMaintenance := true, |
| reserved1 := false, |
| reserved2 := false, |
| reserved3 := false, |
| reserved4 := false, |
| reserved5 := false, |
| reserved6 := false, |
| reserved7 := false}, compliantWithVTVersion4)} |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| |
| testcase tc_encdec_etp_dt () runs on MTC_CT // using a template |
| { |
| template CAN_frame_j1939 t_CAN_frame_j1939 := { can_j1939 := { prio := 0, res := '1'B, dp := '1'B, pf := 'FE'O, ps := '00'O, sa := 'F8'O }, |
| can_pdu := { etp_dt := { seq_no := 105, data := '6C652073657276'O } } } |
| log(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939))) |
| log(f_decode_CAN_frame_j1939(f_encode_CAN_frame_j1939(valueof(t_CAN_frame_j1939)))) |
| } |
| |
| |
| testcase tc_dec_requestForAddressClaimed() runs on MTC_CT |
| { |
| |
| var octetstring j1939_pdu |
| j1939_pdu := '98EAFFFE00EE00'O |
| |
| log(j1939_pdu) |
| log("--------------------------------------------") |
| log(f_decode_CAN_frame_j1939(j1939_pdu)) |
| log("--------------------------------------------") |
| } |
| |
| |
| testcase tc_dec_largemessage() runs on MTC_CT |
| { |
| |
| var octetstring j1939_pdu |
| //j1939_pdu := '18EAFFFE00EE00'O |
| //j1939_pdu := '18EEFFF83102032E003D0080'O |
| //j1939_pdu := '18EEFFF73102032E008200A0'O |
| //j1939_pdu := '18EAF8F8EBFE00'O |
| j1939_pdu := '18ECF8F810160004FFEBFE00'O |
| |
| // j1939_pdu := '00E726F8B3DA590B0066696C6520736572766572'O |
| // j1939_pdu := '03FE00F8FE2A66696C65207365727665722A3139373136392A2D2A'O |
| // j1939_pdu := '03FE00F82A66696C65207365727665722A3139373136392A2D2A'O |
| // j1939_pdu := '03FE00262A6661726D20646973706C61792A3139373136392A2D2A'O |
| // j1939_pdu := '03FE00F72A7461736B20636F6E74726F6C6C65722A3139373136392A2D2A'O |
| // j1939_pdu := '03FE00FD2A6661726D20646973706C61792A3139373136392A2D2A'O |
| // j1939_pdu := '01FD00F82D2A3139373136392A2D2A2D2A6E696E67757065782A2D2A'O |
| // j1939_pdu := '01FD00262D2A3139373136392A2D2A2D2A6E696E67757065782A2D2A'O |
| // j1939_pdu := '01FD00F72D2A3139373136392A2D2A2D2A6E696E67757065782A2D2A'O |
| // j1939_pdu := '01FD00262D2A3139373136392A2D2A2D2A6E696E67757065782A2D2A'O |
| // j1939_pdu := '01FD00FD2D2A3139373136392A2D2A2D2A6E696E67757065782A2D2A'O |
| // j1939_pdu := '02FE00FD016661726D20646973706C617920312E33372E31362E3733352A'O |
| // j1939_pdu := '02FE0026026661726D20646973706C617920312E33372E31362E3733352A69736F627573206C69627261727920312E32362E332E3932382A'O |
| // j1939_pdu := '02FE00F8096E696E67757065782066696C6520736572766572207573657220696E74657266616365204E5820322E322E342E3237302A746F6F6C206C69627261727920322E34322E382E3834302A6C6F67206C69627261727920322E302E31312E3136342A636F6E66696775726174696F6E206C69627261727920312E31322E322E3139332A43414E20627573206861726477617265206C69627261727920312E31392E352E3139382A7365637572697479206C69627261727920312E31312E302E3332312A69736F627573206C69627261727920312E32362E332E3932382A69736F62757320636F6D6D6F6E206C69627261727920322E31322E302E3139332A66696C652073657276657220312E342E352E3235382A'O |
| // j1939_pdu := '9CFE0DF8FE01FFFFFFFFFFFFFF'O |
| |
| log(j1939_pdu) |
| log("--------------------------------------------") |
| log(f_decode_CAN_frame_j1939(j1939_pdu)) |
| log("--------------------------------------------") |
| } |
| |
| |
| import from IsobusVTMessageTypes all |
| |
| testcase tc_decode_VT2ECU() runs on MTC_CT |
| { |
| |
| var octetstring j1939_vt_pdu |
| j1939_vt_pdu := 'c7ff02cde001e001'O |
| j1939_vt_pdu := 'c200ffff7d48400c'O |
| j1939_vt_pdu := 'c3ffffffff7f7fff'O |
| j1939_vt_pdu := 'c00400ffffffffff'O |
| j1939_vt_pdu := 'e00130303034333030'O |
| j1939_vt_pdu := 'd1ffffffff00ffff'O |
| j1939_vt_pdu := '09d00701ffff01ff'O |
| j1939_vt_pdu := 'b3ffffda5900ffff'O |
| j1939_vt_pdu := 'a82bd300bc0b0000'O |
| j1939_vt_pdu := 'a82cd300bb0b0000'O |
| j1939_vt_pdu := 'a82dd300bb0b0000'O |
| j1939_vt_pdu := 'b3ffff02d700ffff'O |
| j1939_vt_pdu := 'a875d600c4da0000'O |
| j1939_vt_pdu := 'a876d600c2da0000'O |
| j1939_vt_pdu := 'a877d600ffff0000'O |
| j1939_vt_pdu := 'a878d600ffff0000'O |
| j1939_vt_pdu := 'a879d600ffff0000'O |
| j1939_vt_pdu := 'a87ad600ffff0000'O |
| j1939_vt_pdu := 'a87bd600ffff0000'O |
| j1939_vt_pdu := 'a87cd600ffff0000'O |
| j1939_vt_pdu := 'a87dd600ffff0000'O |
| j1939_vt_pdu := 'a87ed600ffff0000'O |
| //j1939_vt_pdu := 'ade90300ffffffff'O |
| //j1939_vt_pdu := '09d00700ffff00ff'O |
| |
| log(j1939_vt_pdu) |
| log("--------------------------------------------") |
| log(decode_VT2ECU(j1939_vt_pdu)) |
| log("--------------------------------------------") |
| } |
| |
| //test case declarations |
| testcase tc_Example001() runs on MTC_CT |
| { |
| |
| var PTC_isobus_CT v_PTC_isobus |
| var PTC1_CT v_PTC1 |
| |
| //create components |
| v_PTC_isobus:=PTC_isobus_CT.create; |
| v_PTC1:=PTC1_CT.create; |
| |
| //connnect ports |
| //map ports |
| |
| //start components |
| |
| v_PTC1.start(f_behaviour1_sync()); |
| v_PTC_isobus.start(f_behaviour_isobus(v_PTC1)); |
| |
| //wait for termination |
| all component.done |
| |
| |
| //unmap ports |
| //disconnect ports |
| //terminate all parallel test componenets |
| all component.kill |
| |
| } |
| //when the test case terminates, MTC will terminate as well |
| //PTCs terminate (reach the state done) when the function with which they were started terminates |
| |
| |
| //test case declarations |
| testcase tc_Example002() runs on MTC_CT |
| { |
| |
| var PTC_isobus_CT v_PTC_isobus |
| var PTC1_CT v_PTC1 |
| |
| //create components |
| v_PTC_isobus:=PTC_isobus_CT.create; |
| v_PTC1:=PTC1_CT.create; |
| |
| //connnect ports |
| //map ports |
| |
| //start components |
| |
| v_PTC1.start(f_behaviour2_sync()); |
| v_PTC_isobus.start(f_behaviour_isobus(v_PTC1)); |
| |
| //wait for termination |
| all component.done |
| |
| |
| //unmap ports |
| //disconnect ports |
| //terminate all parallel test componenets |
| all component.kill |
| |
| } |
| //when the test case terminates, MTC will terminate as well |
| //PTCs terminate (reach the state done) when the function with which they were started terminates |
| |
| |
| control |
| { |
| |
| |
| execute(tc_Example001()) |
| |
| |
| }//endcontrol |
| |
| } with { encode "RAW" } |
| |