2 * Copyright (c) 2010-2023 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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode;
19 * The {@link FrameUtil} class defines a utility class for
20 * {@link org.openhab.binding.teleinfo.internal.data.FrameType#CBETM_LONG_BASE}.
22 * @author Nicolas SIBERIL - Initial contribution
25 public class FrameUtil {
28 // private constructor (utility class)
32 * Compute the checksum of the given group line.
34 * @param groupLine group line ("etiquette" <SPACE> "valeur"). Note: the SPACE before the checksum of the group line
35 * must not include in checksum computation.
36 * @return the checksum of the given group line.
38 public static char computeGroupLineChecksum(final String groupLine, TeleinfoTicMode ticMode) {
40 for (int i = 0; i < groupLine.length(); i++) {
41 sum += groupLine.codePointAt(i);
43 if (ticMode == TeleinfoTicMode.STANDARD) {
46 sum = (sum & 0x3F) + 0x20;
51 * Parse relais states.
53 * @param relais integer string
54 * @return State of each relais
56 public static boolean[] parseRelaisStates(String relais) {
57 boolean[] relaisState = new boolean[8];
58 int value = Integer.parseInt(relais);
59 for (int i = 0; i <= 7; i++) {
60 relaisState[i] = (value & 1) == 1;