public static SoftwareVersion build(int firstVersion, int secondVersion, int thirdVersion) { return new SoftwareVersion(firstVersion, secondVersion, thirdVersion); }
@Override public int compareTo(SoftwareVersion other) { LOGGER.info("Compare sw version, other: {}, this: {}", other, this); int myVersion = toInt(); int otherVersion = other.toInt(); if (secondVersion == -1) { // skip compare second and third version SoftwareVersion myVersion2 = new SoftwareVersion(firstVersion, 255, 255); myVersion = myVersion2.toInt(); LOGGER .info("Skip compare the micro version, otherVersion: {}, myVersion: {}", otherVersion, myVersion); } else if (thirdVersion == -1) { // skip compare third version SoftwareVersion myVersion2 = new SoftwareVersion(firstVersion, secondVersion, 255); myVersion = myVersion2.toInt(); LOGGER .info("Skip compare the micro version, otherVersion: {}, myVersion: {}", otherVersion, myVersion); } return (otherVersion - myVersion); } };
@Override public void setSoftwareVersion(String version) { LOGGER.info("Set the software version: {}", version); try { softwareVersion = SoftwareVersion.parse(version); } catch (Exception ex) { LOGGER.warn("Parse software version failed, fall back to default.", ex); softwareVersion = new SoftwareVersion(1, 0, 0); } }
public SoftwareVersion getVersion() { byte[] data = getData(); SoftwareVersion softwareVersion = new SoftwareVersion(ByteUtils.getInt(data[2]), ByteUtils.getInt(data[1]), ByteUtils.getInt(data[0])); if (data.length > 3) { // add the children versions int totalChildren = (data.length - 3) / 3; LOGGER.info("Total number of children: {}", totalChildren); int index = 3; while (index < data.length) { SoftwareVersion childVersion = new SoftwareVersion(ByteUtils.getInt(data[index+2]), ByteUtils.getInt(data[index+1]), ByteUtils.getInt(data[index])); softwareVersion.addChildVersion(childVersion); index += 3; } } return softwareVersion; } }
public static PortModelEnum getPortModel(final Node node) { // TODO add support for flat_extended // this is a hack to support wrong implementation on OneControl and OneDriveTurn if (ProductUtils.isOneControl(node.getUniqueId()) && node.getSoftwareVersion().compareTo(SoftwareVersion.build(2, 0, 6)) < 1) { return type; } // special processing for OneDriveTurn < 1.01.07 else if (ProductUtils.isOneDriveTurn(node.getUniqueId()) && node.getSoftwareVersion().compareTo(SoftwareVersion.build(1, 1, 7)) < 1) { return type; } if (node.isPortFlatModelAvailable()) { return flat; } return type; }
@Override public int hashCode() { return toInt(); }
int difference = current.compareTo(softwareVersion); LOGGER.info("The comparison difference: {}", difference); weightedMap.put(difference, file);
@Test public void toNodeType() { final SimulationFactory factory = new SimulationFactory(); factory.initialize(); Node masterNode = new Node(1, NodeUtils.ROOT_ADDRESS, MASTER_UNIQUE); masterNode.setProtocolVersion(ProtocolVersion.VERSION_0_7); masterNode.setSoftwareVersion(SoftwareVersion.build(1, 3, 7)); NodeType masterNodeType = factory.toNodeType(masterNode); Assertions.assertThat(masterNodeType).isNotNull().isInstanceOf(MasterType.class); } }
protected byte[] processSysGetSwVersionRequest(BidibCommand bidibMessage) { LOGGER.info("Process the SysGetSwVersion request: {}", bidibMessage); byte[] response = null; try { LOGGER.info("Current softwareVersion: {}", softwareVersion); SysSwVersionResponse sysSwVersionResponse = new SysSwVersionResponse(bidibMessage.getAddr(), getNextSendNum(), softwareVersion.asByteArray()); response = sysSwVersionResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create sysSwVersion response failed.", ex); } return response; }
public static SoftwareVersion parse(String version) { try { String[] splited = version.split("\\."); return new SoftwareVersion(Integer.parseInt(splited[0]), Integer.parseInt(splited[1]), Integer.parseInt(splited[2])); } catch (Exception ex) { LOGGER.warn("Parse software version failed: {}", version, ex); throw new IllegalArgumentException("The provided version string is not a valid SoftwareVersion: " + version); } } }
@Test public void findMatchingVendorCVClosestMatching2() { Collection<File> files = new LinkedList<File>(); File expected = new File("BiDiBCV-13-117-1.03.25.xml"); files.add(expected); files.add(new File("BiDiBCV-13-117.xml")); files.add(new File("BiDiBCV-13-117-1.03.xml")); String defaultFilename = "BiDiBCV-13-117.xml"; SoftwareVersion softwareVersion = new SoftwareVersion(1, 0, 0); VendorCvFactory vendorCvFactory = new VendorCvFactory(); File matchingFile = vendorCvFactory.findMatchingVendorCV(files, defaultFilename, softwareVersion); Assert.assertNotNull(matchingFile); LOGGER.info("Found matching file: {}", matchingFile); Assert.assertEquals(matchingFile, expected); }
@Test public void findMatchingVendorCV() { Collection<File> files = new LinkedList<File>(); File expected = new File("BiDiBCV-13-117-1.03.24.xml"); files.add(expected); files.add(new File("BiDiBCV-13-117.xml")); String defaultFilename = "BiDiBCV-13-117.xml"; SoftwareVersion softwareVersion = new SoftwareVersion(1, 3, 24); VendorCvFactory vendorCvFactory = new VendorCvFactory(); File matchingFile = vendorCvFactory.findMatchingVendorCV(files, defaultFilename, softwareVersion); Assert.assertNotNull(matchingFile); LOGGER.info("Found matching file: {}", matchingFile); Assert.assertEquals(matchingFile, expected); }
@Test public void findMatchingVendorCVClosestMatching() { Collection<File> files = new LinkedList<File>(); // must accept 1.03 as closest matching because it is expanded to 1.03.99 File expected = new File("BiDiBCV-13-117-1.03.xml"); files.add(expected); files.add(new File("BiDiBCV-13-117-1.03.22.xml")); files.add(new File("BiDiBCV-13-117-1.03.23.xml")); files.add(new File("BiDiBCV-13-117.xml")); String defaultFilename = "BiDiBCV-13-117.xml"; SoftwareVersion softwareVersion = new SoftwareVersion(1, 3, 24); VendorCvFactory vendorCvFactory = new VendorCvFactory(); File matchingFile = vendorCvFactory.findMatchingVendorCV(files, defaultFilename, softwareVersion); Assert.assertNotNull(matchingFile); LOGGER.info("Found matching file: {}", matchingFile); Assert.assertEquals(matchingFile, expected); }
@Test public void findMatchingVendorCV2() { Collection<File> files = new LinkedList<File>(); File expected = new File("BiDiBCV-13-117-11.03.24.xml"); files.add(expected); files.add(new File("BiDiBCV-13-117-1.03.22.xml")); files.add(new File("BiDiBCV-13-117.xml")); String defaultFilename = "BiDiBCV-13-117.xml"; SoftwareVersion softwareVersion = new SoftwareVersion(11, 3, 24); VendorCvFactory vendorCvFactory = new VendorCvFactory(); File matchingFile = vendorCvFactory.findMatchingVendorCV(files, defaultFilename, softwareVersion); Assert.assertNotNull(matchingFile); LOGGER.info("Found matching file: {}", matchingFile); Assert.assertEquals(matchingFile, expected); }
@Test public void findMatchingVendorCVClosestMatching4() { Collection<File> files = new LinkedList<File>(); File expected = new File("BiDiBCV-13-104.xml"); files.add(expected); files.add(new File("BiDiBCV-13-104-2.02.00.xml")); files.add(new File("BiDiBCV-13-104-2.02.02.xml")); String defaultFilename = "BiDiBCV-13-104.xml"; SoftwareVersion softwareVersion = new SoftwareVersion(2, 2, 5); VendorCvFactory vendorCvFactory = new VendorCvFactory(); File matchingFile = vendorCvFactory.findMatchingVendorCV(files, defaultFilename, softwareVersion); Assert.assertNotNull(matchingFile); LOGGER.info("Found matching file: {}", matchingFile); Assert.assertEquals(matchingFile, expected); }
@Test public void findMatchingVendorCVClosestMatching5() { Collection<File> files = new LinkedList<File>(); File expected = new File("BiDiBCV-13-104.xml"); files.add(expected); files.add(new File("BiDiBCV-13-104-2.02.00.xml")); files.add(new File("BiDiBCV-13-104-2.02.02.xml")); String defaultFilename = "BiDiBCV-13-104.xml"; SoftwareVersion softwareVersion = new SoftwareVersion(2, 3, 0); VendorCvFactory vendorCvFactory = new VendorCvFactory(); File matchingFile = vendorCvFactory.findMatchingVendorCV(files, defaultFilename, softwareVersion); Assert.assertNotNull(matchingFile); LOGGER.info("Found matching file: {}", matchingFile); Assert.assertEquals(matchingFile, expected); } }