1
2
3
4
5
6 package net.sf.atmodem4j.core.gsm;
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 import java.io.IOException;
37 import net.sf.atmodem4j.core.Modem;
38
39
40
41
42
43 public class DefaultGsmExtention implements GsmExtention {
44
45 Modem modem;
46
47 public void sendSms(String phonenumber, String text) {
48 throw new UnsupportedOperationException("Not supported yet.");
49 }
50
51 public void sendPdu(int pduLength, String pdu) throws IOException, InterruptedException {
52 modem.sendCommandLineWithPrompt("AT+CMGS=" + pduLength, pdu);
53 }
54
55 public Modem getModem() {
56 return modem;
57 }
58
59 public void setModem(Modem modem) {
60 this.modem = modem;
61 }
62
63 public String getSimPin() throws IOException, InterruptedException {
64 return getModem().extractData(getModem().sendAndEctractData("AT+CPIN?")[0]);
65 }
66
67 public boolean isSimPin() throws IOException, InterruptedException {
68 return "READY".equals(getSimPin());
69 }
70
71 public void setSimPin(String simPin) throws IOException,
72 InterruptedException {
73 getModem().sendAndEctractData("AT+CPIN="+ simPin, 1, getModem().getDefaultWaitTime() * 2);
74 }
75
76 public String getNetworkProvider() throws IOException, InterruptedException {
77 return getModem().extractData(getModem().sendAndEctractData("AT+COPS?")[0]);
78 }
79
80 public String getSignalQuality(boolean raw) throws IOException, InterruptedException {
81 String data = getModem().extractData(getModem().sendAndEctractData("AT+CSQ")[0]);
82 if (raw) {
83 return data;
84 } else {
85 int sQ = Integer.parseInt(data.substring(0, data.indexOf(',')));
86 if (sQ == 0) {
87 return "<-113dBm";
88 } else if (sQ < 31) {
89 return Integer.toString(-111 + (sQ - 1) * 2) + "dBm";
90 } else if (sQ == 31) {
91 return ">-51dBm";
92 } else if (sQ == 99) {
93 return "unknown";
94 } else {
95 return "unknown value sQ == " + sQ;
96 }
97 }
98 }
99
100 }