You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/03/15 09:43:37 UTC

[incubator-plc4x] branch master updated: added test which displays a crc table.

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new ff2acf3  added test which displays a crc table.
ff2acf3 is described below

commit ff2acf38382cc2aef95a9b1ca025fb6b3b8dc786
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Mar 15 10:43:33 2018 +0100

    added test which displays a crc table.
---
 .../java/ads/protocol/util/DigestUtilTest.java     | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/util/DigestUtilTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/util/DigestUtilTest.java
new file mode 100644
index 0000000..f2b5917
--- /dev/null
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/util/DigestUtilTest.java
@@ -0,0 +1,47 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.ads.protocol.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
+
+import java.util.stream.IntStream;
+
+public class DigestUtilTest {
+
+    @Test
+    public void displayValue() throws Exception {
+        Object[] crcs = IntStream.range(0, 256)
+            .map(value -> DigestUtil.calculateCrc16(new byte[]{(byte) value}))
+            .mapToObj(Integer::toHexString)
+            .map(s -> StringUtils.leftPad(s, 4, '0'))
+            .toArray(String[]::new);
+        for (int i = 0; i < 32; i++) {
+            String col1 = "" + (i) + '\t' + crcs[i];
+            String col2 = "" + (i + 32) + '\t' + crcs[i + 32];
+            String col3 = "" + (i + 64) + '\t' + crcs[i + 64];
+            String col4 = "" + (i + 96) + '\t' + crcs[i + 96];
+            String col5 = "" + (i + 128) + '\t' + crcs[i + 128];
+            String col6 = "" + (i + 160) + '\t' + crcs[i + 160];
+            String col7 = "" + (i + 192) + '\t' + crcs[i + 192];
+            String col8 = "" + (i + 224) + '\t' + crcs[i + 224];
+            System.out.println(col1 + "\t\t" + col2 + "\t\t" + col3 + "\t\t" + col4 + "\t\t" + col5 + "\t\t" + col6 + "\t\t" + col7 + "\t\t" + col8);
+        }
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.