]> git.basschouten.com Git - openhab-addons.git/blob
ee8268a1f0e0b5058682bd050a7bbacf1461522f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.teleinfo.internal.reader.io.serialport;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link FrameUtil} class defines a utility class for {@link FrameCbetmLong}.
19  *
20  * @author Nicolas SIBERIL - Initial contribution
21  */
22 @NonNullByDefault
23 public class FrameUtil {
24
25     private FrameUtil() {
26         // private constructor (utility class)
27     }
28
29     /**
30      * Compute the checksum of the given group line.
31      *
32      * @param groupLine group line ("etiquette" <SPACE> "valeur"). Note: the SPACE before the checksum of the group line
33      *            must not include in checksum computation.
34      * @return the checksum of the given group line.
35      */
36     public static char computeGroupLineChecksum(final String label, final String value) {
37         final String groupLine = label + " " + value;
38         int sum = 0;
39         for (int i = 0; i < groupLine.length(); i++) {
40             sum = sum + groupLine.codePointAt(i);
41         }
42         sum = (sum & 0x3F) + 0x20;
43
44         return (char) sum;
45     }
46 }