2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.teleinfo.internal.reader.io.serialport;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.io.BufferedReader;
18 import java.io.FileInputStream;
19 import java.io.InputStreamReader;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.teleinfo.internal.reader.io.TeleinfoInputStream;
24 import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode;
25 import org.openhab.binding.teleinfo.util.TestUtils;
29 * @author Olivier MARCEAU - Initial contribution
32 public class FrameUtilTest {
35 public void testComputeGroupLineChecksumThreePhaseProd() throws Exception {
36 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
37 new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-three-phase-prod.raw"))));
40 while ((groupLine = bufferedReader.readLine()) != null) {
41 if (i >= 1 && !TeleinfoInputStream.isHeaderFrame(groupLine)) {
42 char expected = groupLine.charAt(groupLine.length() - 1);
43 char actual = FrameUtil.computeGroupLineChecksum(groupLine.substring(0, groupLine.length() - 2),
44 TeleinfoTicMode.STANDARD);
45 assertEquals(expected, actual, i + " " + groupLine + " " + (int) expected + " " + (int) actual);
52 public void testComputeGroupLineChecksumSinglePhaseProd() throws Exception {
53 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
54 new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-single-phase-prod.raw"))));
57 while ((groupLine = bufferedReader.readLine()) != null) {
58 if (i >= 1 && !TeleinfoInputStream.isHeaderFrame(groupLine)) {
59 char expected = groupLine.charAt(groupLine.length() - 1);
60 char actual = FrameUtil.computeGroupLineChecksum(groupLine.substring(0, groupLine.length() - 2),
61 TeleinfoTicMode.STANDARD);
62 assertEquals(expected, actual, i + " " + groupLine + " " + (int) expected + " " + (int) actual);
69 public void testComputeRelaisStates() {
70 assertArrayEquals(new boolean[] { true, false, false, false, false, false, false, false },
71 FrameUtil.parseRelaisStates("001"));
72 assertArrayEquals(new boolean[] { false, false, true, true, false, false, false, true },
73 FrameUtil.parseRelaisStates("140"));