private static void testPing(bool pingResponse) { using (var scenario = new SerialPortScenario()) { const byte SEND_MESSAGE_FLAGS = Constants.MSG_FLAGS_DIRECT | Constants.MSG_FLAGS_MAX_HOPS; const byte RECV_MESSAGE_FLAGS_ACK = Constants.MSG_FLAGS_DIRECT_ACK; byte[] peerResponse = new byte[] { 0x02, 0x50, PEER_ID_HI, PEER_ID_MI, PEER_ID_LO, PLM_ID_HI, PLM_ID_MI, PLM_ID_LO, RECV_MESSAGE_FLAGS_ACK, 0x0F, 0x00 }; scenario .ShouldSend(0x02, 0x62, PEER_ID_HI, PEER_ID_MI, PEER_ID_LO, SEND_MESSAGE_FLAGS, 0x0F, 0x00) .AndReceive(0x02, 0x62, PEER_ID_HI, PEER_ID_MI, PEER_ID_LO, SEND_MESSAGE_FLAGS, 0x0F, 0x00, 0x06); if (pingResponse) { scenario .WaitsForMessageOfType(0x50) .AndReceives(peerResponse); } else { scenario .WaitsForMessageOfType(0x50) .AndReceives(); } var test = buildObjectForTest(scenario.Playback()); Assert.AreEqual(pingResponse, test.Ping()); } }
public static void SetupSendStandardCommandReceiveAck(this SerialPortScenario scenario, byte command1, byte command2, byte responseCommand1, byte responseCommand2) { const byte SEND_MESSAGE_FLAGS = Constants.MSG_FLAGS_DIRECT | Constants.MSG_FLAGS_MAX_HOPS; const byte RECV_MESSAGE_FLAGS_ACK = Constants.MSG_FLAGS_DIRECT_ACK; scenario .ShouldSend(0x02, 0x62, PEER_ID_HI, PEER_ID_MI, PEER_ID_LO, SEND_MESSAGE_FLAGS, command1, command2) .AndReceive(0x02, 0x62, PEER_ID_HI, PEER_ID_MI, PEER_ID_LO, SEND_MESSAGE_FLAGS, command1, command2, 0x06) // ack from PLM .WaitsForMessageOfType(0x50) .AndReceives(0x02, 0x50, PEER_ID_HI, PEER_ID_MI, PEER_ID_LO, PLM_ID_HI, PLM_ID_MI, PLM_ID_LO, RECV_MESSAGE_FLAGS_ACK, responseCommand1, responseCommand2); // ack from peer device }