public CommandStationPomMessage prepareTerminatingDataPacket(DecoderInformation.DecoderType decoderType) { LOGGER.info("Prepare terminating data packet for decoder type: {}", decoderType); // prepare the decoder type AddressTypeEnum addressType = AddressTypeEnum.LOCOMOTIVE_FORWARD; if (decoderType == DecoderType.accessoryDecoder) { addressType = AddressTypeEnum.ACCESSORY; } AddressData decoderAddress = new AddressData(ADDR_TERM_PACKET, addressType); CommandStationPom opCode = CommandStationPom.WR_BYTE; int cvNumber = 166; byte[] data = { 0 }; CommandStationPomMessage message = new CommandStationPomMessage(decoderAddress, opCode, cvNumber, data); return message; }
public int getMid() { int opCode = ByteUtils.getInt(getData()[4]); return opCode; }
/** * Create a read command for a loco decoder. * * @param decoderAddress * the decoder address * @param opCode * the operation code * @param cvNumber * the CV number */ public CommandStationPomMessage(AddressData decoderAddress, CommandStationPom opCode, int cvNumber) { super(0, BidibLibrary.MSG_CS_POM, prepareData(decoderAddress, opCode, cvNumber, null)); }
LOGGER.info("Row packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8448); Assert.assertEquals(message.getCvNumber(), 0xF2 + 1); Assert.assertEquals(message.getCvValue(), 0xD0); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 4 /* 0x04 : 8196 */); Assert.assertEquals(message.getCvNumber(), 0x7E + 1); Assert.assertEquals(message.getCvValue(), 0x00); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0 /* 0x00 : 8192 */); Assert.assertEquals(message.getCvNumber(), 0x32 + 1 + 0x0100); Assert.assertEquals(message.getCvValue(), 0x81); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0 /* 0x00 : 8192 */); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0200); Assert.assertEquals(message.getCvValue(), 0x00);
@Test public void prepareNextRowPacketTest() { String line = ":1000000080090020ED000000C1000000C1000000D8"; DecoderPomUpdate decoderPomUpdate = new DecoderPomUpdate(); FirmwarePacket packet = decoderPomUpdate.parseLine(line); Assert.assertNotNull(packet); LOGGER.info("Current packet: {}", packet); CommandStationPomMessage message = decoderPomUpdate.prepareNextRowPacket(packet, DecoderType.locoDecoder); Assert.assertNotNull(message); LOGGER.info("Current message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 0x300 + 1); Assert.assertEquals(message.getCvValue(), 0); line = ":10001000C1000000C1000000C1000000000000009D"; packet = decoderPomUpdate.parseLine(line); Assert.assertNotNull(packet); LOGGER.info("Current packet: {}", packet); message = decoderPomUpdate.prepareNextRowPacket(packet, DecoderType.locoDecoder); Assert.assertNotNull(message); LOGGER.info("Current message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 0x300 + 1); Assert.assertEquals(message.getCvValue(), 16); }
@Test public void prepareDecoderUpdatePomMessagesTest() throws URISyntaxException { DecoderPomUpdate decoderPomUpdate = new DecoderPomUpdate(); File firmwareFile = new File(DecoderPomUpdate.class.getResource("/firmware/LD-G-31-Plus_V2_2.hex").toURI().getPath()); List<String> firmwareContent = decoderPomUpdate.loadFirmwareFile(firmwareFile); Assert.assertNotNull(firmwareContent); DecoderInformation decoderInformation = new DecoderInformation("3E000031020200000305201500000000"); List<CommandStationPomMessage> messages = decoderPomUpdate.prepareDecoderUpdatePomMessages(firmwareContent, decoderInformation); Assert.assertNotNull(messages); CommandStationPomMessage message = messages.get(0); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8705); Assert.assertEquals(message.getCvNumber(), 1); Assert.assertEquals(message.getCvValue(), 0x31); } }
@Test public void prepareDecoderInfoPomMessagesTest() throws URISyntaxException { DecoderPomUpdate decoderPomUpdate = new DecoderPomUpdate(); File firmwareFile = new File(DecoderPomUpdate.class.getResource("/firmware/LD-G-31-Plus_V2_2.hex").toURI().getPath()); List<String> firmwareContent = decoderPomUpdate.loadFirmwareFile(firmwareFile); DecoderInformation information = decoderPomUpdate.findDecoderInformation(firmwareContent); Assert.assertNotNull(information); Assert.assertEquals(information.getVendorId(), 62 /* tams */); Assert.assertEquals(information.getDecoderType(), DecoderType.locoDecoder /* loco */); Assert.assertEquals(information.getDecoderId(), 0x31 /* LD-G-31 */); Assert.assertEquals(information.getFirmwareVersion(), "2.2.0.0"); Assert.assertEquals(information.getFirmwareReleaseDate(), "03.05.2015"); int decoderAddress = 122; List<CommandStationPomMessage> messages = decoderPomUpdate.prepareDecoderInfoPomMessages(information, decoderAddress); Assert.assertNotNull(messages); LOGGER.info("Prepared messages: {}, formatted data: {}", messages); Assert.assertEquals(messages.size(), 12); int cvNumber = 800; for (CommandStationPomMessage message : messages) { Assert.assertEquals(message.getCvNumber(), cvNumber); LOGGER.info("CV{}, message: {}, formatted data: {}", cvNumber, message, ByteUtils.bytesToHex(message.getData())); cvNumber++; } }
@Test public void prepareLine2Test() { String line2 = ":1000000080090020ED000000C1000000C1000000D8"; DecoderPomUpdate decoderPomUpdate = new DecoderPomUpdate(); FirmwarePacket packet = decoderPomUpdate.parseLine(line2); Assert.assertNotNull(packet); LOGGER.info("Current packet: {}", packet); int packetLen = ByteUtils.getInt(packet.getLen()); // 08 F2D0 00 CommandStationPomMessage message = decoderPomUpdate.prepareNextRowPacket(packet, DecoderType.locoDecoder); Assert.assertNotNull(message); LOGGER.info("Row packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8448); Assert.assertEquals(message.getCvNumber(), 0x300 + 1); Assert.assertEquals(message.getCvValue(), 0); for (int index = 0; index < (packetLen / 3 + 1); index++) { message = decoderPomUpdate.prepareNextDataPacket(packet, DecoderType.locoDecoder); Assert.assertNotNull(message); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); } // verify the last message Assert.assertNotNull(message); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0100); Assert.assertEquals(message.getCvValue(), 0x00); }
decoderPomUpdate.prepareDecoderInfoPomMessage(information, decoderAddress, 800); Assert.assertNotNull(message); LOGGER.info("CV800, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 800); Assert.assertEquals(message.getCvValue(), 62); LOGGER.info("CV801, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 801); Assert.assertEquals(message.getCvValue(), DecoderType.locoDecoder.ordinal()); LOGGER.info("CV802, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 802); Assert.assertEquals(message.getCvValue(), 0); LOGGER.info("CV803, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 803); Assert.assertEquals(message.getCvValue(), 0x31); /* LD-G-31 */ LOGGER.info("CV804, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 804); Assert.assertEquals(message.getCvValue(), 2); LOGGER.info("CV805, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 805); Assert.assertEquals(message.getCvValue(), 2); LOGGER.info("CV806, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getCvNumber(), 806); Assert.assertEquals(message.getCvValue(), 0);
LOGGER.info("Row packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8448); Assert.assertEquals(message.getCvNumber(), 0xF2 + 0x100 + 1); Assert.assertEquals(message.getCvValue(), 0xF8); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 16 /* 0x10 : 8208 */); Assert.assertEquals(message.getCvNumber(), 0x27 + 1); Assert.assertEquals(message.getCvValue(), 0x00); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0 /* 0x00 : 8192 */); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0100); Assert.assertEquals(message.getCvValue(), 0x80); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 81 /* 0x51 : 8273 */); Assert.assertEquals(message.getCvNumber(), 0x01 + 1 + 0x0200); Assert.assertEquals(message.getCvValue(), 0x00); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 128 /* 0x80 : 8320 */); Assert.assertEquals(message.getCvNumber(), 0x51 + 1 + 0x0300); Assert.assertEquals(message.getCvValue(), 0x01);
public PomAcknowledge readPom(DecoderIdAddressData locoAddress, CommandStationPom opCode, int cvNumber) throws ProtocolException { byte[] data = { 0 }; BidibMessage response = delegate.send(new CommandStationPomMessage(locoAddress, opCode, cvNumber, data), null, true, CommandStationPomAcknowledgeResponse.TYPE); PomAcknowledge result = null; if (response instanceof CommandStationPomAcknowledgeResponse) { result = ((CommandStationPomAcknowledgeResponse) response).getAcknState(); } LOGGER.debug("Return the pomAcknowledge: {}", result); return result; }
public int getOpCode() { int opCode = ByteUtils.getInt(getData()[5]); return opCode; }
/** * Create the command for a loco decoder. * * @param decoderAddress * the decoder address * @param opCode * the operation code * @param cvNumber * the CV number * @param data * the CV data. For normal POM operation 1 byte but up to 4 bytes for xPOM */ public CommandStationPomMessage(AddressData decoderAddress, CommandStationPom opCode, int cvNumber, byte[] data) { super(0, BidibLibrary.MSG_CS_POM, prepareData(decoderAddress, opCode, cvNumber, data)); }
@Test public void prepareSmallerLine2Test() { String line2 = ":08F2D000047E00003281000001"; DecoderPomUpdate decoderPomUpdate = new DecoderPomUpdate(); FirmwarePacket packet = decoderPomUpdate.parseLine(line2); Assert.assertNotNull(packet); LOGGER.info("Current packet: {}", packet); int packetLen = ByteUtils.getInt(packet.getLen()); // 08 F2D0 00 CommandStationPomMessage message = decoderPomUpdate.prepareNextRowPacket(packet, DecoderType.locoDecoder); Assert.assertNotNull(message); LOGGER.info("Row packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8448); Assert.assertEquals(message.getCvNumber(), 0xF2 + 1); Assert.assertEquals(message.getCvValue(), 0xD0); for (int index = 0; index < (packetLen / 3 + 1); index++) { message = decoderPomUpdate.prepareNextDataPacket(packet, DecoderType.locoDecoder); Assert.assertNotNull(message); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); } // verify the last message Assert.assertNotNull(message); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0 /* 0x00 : 8192 */); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0200); Assert.assertEquals(message.getCvValue(), 0x00); }
public PomAcknowledge readPom(AddressData locoAddress, CommandStationPom opCode, int cvNumber) throws ProtocolException { byte[] data = { 0 }; BidibMessage response = delegate.send(new CommandStationPomMessage(locoAddress, opCode, cvNumber, data), null, true, CommandStationPomAcknowledgeResponse.TYPE); PomAcknowledge result = null; if (response instanceof CommandStationPomAcknowledgeResponse) { result = ((CommandStationPomAcknowledgeResponse) response).getAcknState(); } LOGGER.debug("Return the pomAcknowledge: {}", result); return result; }
public int getCvNumberX() { byte[] data = getData(); return ByteUtils.getInt(data[8]); }
/** * Create the command for a loco decoder. * * @param addressDID * the DID address * @param opCode * the operation code * @param cvNumber * the CV number * @param data * the CV data. For normal POM operation 1 byte but up to 4 bytes for xPOM */ public CommandStationPomMessage(DecoderIdAddressData addressDID, CommandStationPom opCode, int cvNumber, byte[] data) { super(0, BidibLibrary.MSG_CS_POM, prepareData(addressDID, opCode, cvNumber, data)); }
LOGGER.info("Row packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8448); Assert.assertEquals(message.getCvNumber(), 0x300 + 1); Assert.assertEquals(message.getCvValue(), 0); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 128 /* 8320 */); Assert.assertEquals(message.getCvNumber(), 0x09 + 1); Assert.assertEquals(message.getCvValue(), 0x00); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 32 /* 8224 */); Assert.assertEquals(message.getCvNumber(), 0xED + 1 + 0x0100); Assert.assertEquals(message.getCvValue(), 0x00); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0200); Assert.assertEquals(message.getCvValue(), 0xC1); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 0); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0300); Assert.assertEquals(message.getCvValue(), 0x00); LOGGER.info("Data packet, message: {}, formatted data: {}", message, ByteUtils.bytesToHex(message.getData())); Assert.assertEquals(message.getDecoderAddress().getAddress(), 8192 + 193 /* 8385 */); Assert.assertEquals(message.getCvNumber(), 0x00 + 1 + 0x0000); Assert.assertEquals(message.getCvValue(), 0x00);
public List<CommandStationPomMessage> prepareDecoderInfoPomMessages( DecoderInformation decoderInfo, int decoderAddress) { // prepare the decoder type AddressTypeEnum addressType = AddressTypeEnum.LOCOMOTIVE_FORWARD; if (decoderInfo.getDecoderType() == DecoderType.accessoryDecoder) { addressType = AddressTypeEnum.ACCESSORY; } AddressData address = new AddressData(decoderAddress, addressType); CommandStationPom opCode = CommandStationPom.WR_BYTE; List<CommandStationPomMessage> messages = new ArrayList<CommandStationPomMessage>(); for (int cvNumber = 800; cvNumber < 812; cvNumber++) { byte[] data = { decoderInfo.getCvValue(cvNumber) }; CommandStationPomMessage message = new CommandStationPomMessage(address, opCode, cvNumber, data); messages.add(message); } return messages; }
public int getCvValue() { byte[] data = getData(); return ByteUtils.getInt(data[9]); }