-
Notifications
You must be signed in to change notification settings - Fork 1
/
DLinkDsl2750Reader.java
86 lines (65 loc) · 2.73 KB
/
DLinkDsl2750Reader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package it.albertus.routerlogger.reader;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import it.albertus.routerlogger.resources.Messages;
import it.albertus.util.logging.LoggerFactory;
/**
* <b>D-Link DSL-2750B</b>. Comandi Telnet disponibili (case sensitive):
* <ul>
* <li><tt><b>adsl status</b></tt></li>
* <li><tt><b>adsl snr</b></tt></li>
* </ul>
*/
public class DLinkDsl2750Reader extends Reader {
private static final Logger logger = LoggerFactory.getLogger(DLinkDsl2750Reader.class);
public static class Defaults {
public static final String COMMAND_INFO_ADSL_STATUS = "adsl status";
public static final String COMMAND_INFO_ADSL_SNR = "adsl snr";
private Defaults() {
throw new IllegalAccessError("Constants class");
}
}
public static final String DEVICE_MODEL_KEY = "lbl.device.model.dlink.2750b";
protected static final String COMMAND_PROMPT = "TBS>>";
protected static final String LOGIN_PROMPT = ":";
@Override
public boolean login(final String username, final char[] password) throws IOException {
final StringBuilder received = new StringBuilder();
// Username...
received.append(readFromTelnet(LOGIN_PROMPT, true).trim());
writeToTelnet(username);
// Password...
received.append(readFromTelnet(LOGIN_PROMPT, true).trim());
writeToTelnet(password);
logger.log(Level.INFO, LOG_MASK_TELNET, received);
received.setLength(0);
// Avanzamento fino al prompt...
received.append(readFromTelnet(COMMAND_PROMPT, true));
logger.log(Level.INFO, LOG_MASK_TELNET, received);
return true;
}
@Override
public LinkedHashMap<String, String> readInfo() throws IOException {
final LinkedHashMap<String, String> info = new LinkedHashMap<String, String>();
// Informazioni sulla portante ADSL...
writeToTelnet(configuration.getString("dlink.2750.command.info.adsl.status", Defaults.COMMAND_INFO_ADSL_STATUS));
readFromTelnet("-----\r", true); // Avanzamento del reader fino all'inizio dei dati di interesse.
info.put("ADSL status", readFromTelnet(COMMAND_PROMPT, false).trim());
writeToTelnet(configuration.getString("dlink.2750.command.info.adsl.snr", Defaults.COMMAND_INFO_ADSL_SNR));
readFromTelnet("Upstream", true); // Avanzamento del reader fino all'inizio dei dati di interesse.
String[] snrs = readFromTelnet(COMMAND_PROMPT, false).trim().split("(\\s\\s)+");
info.put("ADSL SNR Downstream", snrs[0]);
info.put("ADSL SNR Upstream", snrs[1]);
return info;
}
@Override
public String getDeviceModel() {
return Messages.get(DEVICE_MODEL_KEY);
}
@Override
public String getImageFileName() {
return "dlink_dsl_2750b.png";
}
}