]> git.basschouten.com Git - openhab-addons.git/blob
29524c489697b32df438c16040751f58366e8367
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.freeboxos.internal.api.rest;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
20 import org.openhab.binding.freeboxos.internal.api.Response;
21
22 import inet.ipaddr.IPAddress;
23
24 /**
25  * The {@link ConnectionManager} is the Java class used to handle api requests related to connection
26  *
27  * https://dev.freebox.fr/sdk/os/system/#
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 @NonNullByDefault
32 public class ConnectionManager extends ConfigurableRest<ConnectionManager.Status, ConnectionManager.StatusResponse> {
33     private static final String PATH = "connection";
34
35     protected static class StatusResponse extends Response<Status> {
36     }
37
38     private class FtthStatusResponse extends Response<FtthStatus> {
39     }
40
41     private class XdslStatusResponse extends Response<XdslInfos> {
42     }
43
44     private enum State {
45         GOING_UP,
46         UP,
47         GOING_DOWN,
48         DOWN,
49         UNKNOWN
50     }
51
52     private enum Type {
53         ETHERNET,
54         RFC2684,
55         PPPOATM,
56         UNKNOWN
57     }
58
59     public enum Media {
60         FTTH,
61         ETHERNET,
62         XDSL,
63         BACKUP_4G,
64         UNKNOWN
65     }
66
67     public static record Status(State state, Type type, Media media, @Nullable List<Integer> ipv4PortRange,
68             @Nullable IPAddress ipv4, // This can be null if state is not up
69             @Nullable IPAddress ipv6, // This can be null if state is not up
70             long rateUp, // current upload rate in byte/s
71             long rateDown, // current download rate in byte/s
72             long bandwidthUp, // available upload bandwidth in bit/s
73             long bandwidthDown, // available download bandwidth in bit/s
74             long bytesUp, // total uploaded bytes since last connection
75             long bytesDown // total downloaded bytes since last connection
76     ) {
77     }
78
79     public static record FtthStatus(boolean sfpPresent, boolean sfpAlimOk, boolean sfpHasPowerReport,
80             boolean sfpHasSignal, boolean link, String sfpSerial, String sfpModel, String sfpVendor, //
81             int sfpPwrTx, // scaled by 100 (in dBm)
82             int sfpPwrRx // scaled by 100 (in dBm)
83     ) {
84         public double getReceivedDBM() {
85             return 1d * sfpPwrRx / 100;
86         }
87
88         public double getTransmitDBM() {
89             return 1d * sfpPwrTx / 100;
90         }
91     }
92
93     public static record XdslStats( //
94             int maxrate, // ATM max rate in kbit/s
95             int rate, // ATM rate in kbit/s
96             int snr, // in dB
97             int attn, // in dB
98             int snr10, // in dB/10
99             int attn10, // in dB/10
100             int fec, int crc, int hec, int es, int ses, boolean phyr, boolean ginp, boolean nitro, //
101             int rxmt, // only available when phyr is on
102             int rxmtCorr, // only available when phyr is on
103             int rxmtUncorr, // only available when phyr is on
104             int rtxTx, // only available when ginp is on
105             int rtxC, // only available when ginp is on
106             int rtxUc// only available when ginp is on
107     ) {
108     }
109
110     private enum SynchroState {
111         DOWN, // unsynchronized
112         TRAINING, // synchronizing step 1/4
113         STARTED, // synchronizing step 2/4
114         CHAN_ANALYSIS, // synchronizing step 3/4
115         MSG_EXCHANGE, // synchronizing step 4/4
116         SHOWTIME, // Ready
117         DISABLED, // Disabled
118         UNKNOWN
119     }
120
121     private enum Modulation {
122         ADSL,
123         VDSL,
124         UNKNOWN
125     }
126
127     public static record XdslStatus(SynchroState status, String protocol, Modulation modulation, long uptime) {
128
129     }
130
131     public static record XdslInfos(XdslStatus status, XdslStats down, XdslStats up) {
132
133     }
134
135     public ConnectionManager(FreeboxOsSession session) throws FreeboxException {
136         super(session, LoginManager.Permission.NONE, StatusResponse.class, session.getUriBuilder().path(PATH), null);
137     }
138
139     public FtthStatus getFtthStatus() throws FreeboxException {
140         return super.getSingle(FtthStatusResponse.class, "ftth");
141     }
142
143     public XdslInfos getXdslStatus() throws FreeboxException {
144         return super.getSingle(XdslStatusResponse.class, "xdsl");
145     }
146 }