first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
261
rus/WEB-INF/lib/abliaSerial_src/com/ablia/sms/SmsClient.java
Normal file
261
rus/WEB-INF/lib/abliaSerial_src/com/ablia/sms/SmsClient.java
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
package com.ablia.sms;
|
||||
|
||||
import com.ablia.serial.SerialClient;
|
||||
import com.ablia.util.StringTokenizer;
|
||||
|
||||
public class SmsClient extends SerialClient {
|
||||
private static char[] hexDigits = new char[] {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
static {
|
||||
char[] gsmiso = {
|
||||
'\000', '@', '\001', '£', '\002', '$', '\016', 'Å', '\017', 'å',
|
||||
'\021', '_',
|
||||
'[', 'Ä', '\\', 'Ö', '^', 'Ü', '_', '§',
|
||||
'{', 'ä', '|', 'ö', '~',
|
||||
'ü', '"', '"', '\005', 'é',
|
||||
'\004', 'è' };
|
||||
char[] gsmisoext = {
|
||||
'\024', '^', '(', '{', ')', '}', '/', '\\', '<',
|
||||
'[',
|
||||
'=', '~', '>', ']', '@', '|' };
|
||||
int lastindex = 255;
|
||||
}
|
||||
|
||||
private static char[] gsmToIsoMap = new char[256];
|
||||
|
||||
private static char[] gsmToIsoExtMap = new char[256];
|
||||
|
||||
private static char[] isoToGsmMap = new char[256];
|
||||
|
||||
private static char[] isoToGsmExtMap = new char[256];
|
||||
|
||||
static {
|
||||
for (int k = 0; k <= 255; k++) {
|
||||
isoToGsmMap[k] = (char)k;
|
||||
gsmToIsoExtMap[k] = (char)k;
|
||||
gsmToIsoMap[k] = (char)k;
|
||||
}
|
||||
int gsmisolen = gsmiso.length;
|
||||
for (int j = 0; j + 1 < gsmisolen; j += 2) {
|
||||
gsmToIsoMap[gsmiso[j]] = gsmiso[j + 1];
|
||||
isoToGsmMap[gsmiso[j + 1]] = gsmiso[j];
|
||||
}
|
||||
int gsmisoextlen = gsmisoext.length;
|
||||
for (int i = 0; i + 1 < gsmisoextlen; i += 2)
|
||||
gsmToIsoExtMap[gsmisoext[i]] = gsmisoext[i + 1];
|
||||
}
|
||||
|
||||
private boolean usePdu = false;
|
||||
|
||||
private static final char EMPTYCHAR = 'Ā';
|
||||
|
||||
private static final char EXTTABLEESCAPE = '\033';
|
||||
|
||||
private String cellulare;
|
||||
|
||||
private String messaggio;
|
||||
|
||||
public SmsClient(String serverHost, int serverPort, boolean isPdu) {
|
||||
super(serverHost, serverPort);
|
||||
this.usePdu = isPdu;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SmsClient cc = new SmsClient("192.168.1.12", 441, false);
|
||||
cc.setCellulare("+393285726937");
|
||||
cc.setMessaggio("hellxxxohello");
|
||||
String res = cc.inviaSms();
|
||||
System.out.println(res);
|
||||
cc.closeConnection();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public String getCellulare() {
|
||||
return (this.cellulare == null) ? "" : this.cellulare;
|
||||
}
|
||||
|
||||
public void setCellulare(String cellulare) {
|
||||
this.cellulare = cellulare;
|
||||
}
|
||||
|
||||
public String getMessaggio() {
|
||||
return (this.messaggio == null) ? "" : this.messaggio;
|
||||
}
|
||||
|
||||
public void setMessaggio(String messaggio) {
|
||||
this.messaggio = messaggio;
|
||||
}
|
||||
|
||||
public String inviaSms() {
|
||||
String temp = getMessaggio();
|
||||
String msgPart = "";
|
||||
boolean flgAncoraTesto = true;
|
||||
StringBuffer resInvio = new StringBuffer();
|
||||
do {
|
||||
if (temp.length() >= 160) {
|
||||
StringTokenizer st = new StringTokenizer(temp, " ");
|
||||
StringBuffer res = new StringBuffer();
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
if (res.length() + token.length() < 160) {
|
||||
res.append(token);
|
||||
res.append(" ");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
msgPart = res.toString();
|
||||
temp = temp.substring(res.length());
|
||||
} else {
|
||||
msgPart = temp;
|
||||
flgAncoraTesto = false;
|
||||
}
|
||||
System.out.println(String.valueOf(flgAncoraTesto) + " l: " + msgPart.length() +
|
||||
" : " + msgPart);
|
||||
if (this.usePdu) {
|
||||
resInvio.append(inviaSmsPDU(msgPart));
|
||||
} else {
|
||||
resInvio.append(inviaSmsStandard(msgPart));
|
||||
}
|
||||
resInvio.append(" - ");
|
||||
} while (flgAncoraTesto);
|
||||
return resInvio.toString();
|
||||
}
|
||||
|
||||
private String inviaSmsPDU(String l_msg) {
|
||||
String temp;
|
||||
resetSerialSendCommand();
|
||||
String fineCmd = "\n";
|
||||
addSerialSendCommand("AT");
|
||||
addSerialSendCommand("AT+CMGF=0" + fineCmd);
|
||||
addSerialSendCommand("AT+CSMS=0" + fineCmd);
|
||||
String ottetto = "001100";
|
||||
ottetto = String.valueOf(ottetto) + toHexString(getCellulare().length());
|
||||
ottetto = String.valueOf(ottetto) + "91";
|
||||
if (getCellulare().length() % 2 == 1) {
|
||||
temp = swapDigits(String.valueOf(getCellulare()) + "F");
|
||||
} else {
|
||||
temp = swapDigits(getCellulare());
|
||||
}
|
||||
ottetto = String.valueOf(ottetto) + temp.toUpperCase();
|
||||
ottetto = String.valueOf(ottetto) + "0000AA";
|
||||
String tempMsg = l_msg.replaceAll("[\n\r]", "\n");
|
||||
ottetto = String.valueOf(ottetto) + toHexString(tempMsg.length());
|
||||
ottetto = String.valueOf(ottetto) + sevenBitEncode(tempMsg).toUpperCase();
|
||||
System.out.println(ottetto.length());
|
||||
int ottettoLen = ottetto.length() / 2 - 1;
|
||||
addSerialSendCommand("AT+CMGS=" + ottettoLen + fineCmd);
|
||||
addSerialSendCommand(ottetto);
|
||||
addSerialSendCommand("\032");
|
||||
System.out.println(getSerialSendCommand());
|
||||
return sendSerialSendCommand();
|
||||
}
|
||||
|
||||
private String inviaSmsStandard(String l_msg) {
|
||||
resetSerialSendCommand();
|
||||
addSerialSendCommand("AT");
|
||||
addSerialSendCommand("AT+CMGF=1");
|
||||
addSerialSendCommand("AT+CMGS=\"" + getCellulare() + "\"");
|
||||
String temp = l_msg.replaceAll("[\n\r]", "\n");
|
||||
addSerialSendCommand(temp);
|
||||
addSerialSendCommand("\032");
|
||||
System.out.println(getSerialSendCommand());
|
||||
return sendSerialSendCommand();
|
||||
}
|
||||
|
||||
public static String sevenBitEncode(String message) {
|
||||
if (message == null)
|
||||
return message;
|
||||
StringBuffer msg = new StringBuffer(message);
|
||||
StringBuffer encmsg = new StringBuffer(320);
|
||||
int bb = 0, bblen = 0;
|
||||
char o = '\000', c = '\000';
|
||||
for (int i = 0; i < msg.length() || bblen >= 8; i++) {
|
||||
if (i < msg.length()) {
|
||||
c = msg.charAt(i);
|
||||
char tc = isoToGsmMap[c];
|
||||
c = tc;
|
||||
c = (char)(c & 0xFFFFFF7F);
|
||||
bb |= c << bblen;
|
||||
bblen += 7;
|
||||
}
|
||||
while (bblen >= 8) {
|
||||
o = (char)(bb & 0xFF);
|
||||
encmsg.append(toHexString(o));
|
||||
bb >>>= 8;
|
||||
bblen -= 8;
|
||||
}
|
||||
}
|
||||
if (bblen > 0)
|
||||
encmsg.append(toHexString(bb));
|
||||
return encmsg.toString();
|
||||
}
|
||||
|
||||
public static String sevenBitDecode(String encmsg) {
|
||||
return sevenBitDecode(encmsg, encmsg.length());
|
||||
}
|
||||
|
||||
public static String sevenBitDecode(String encmsg, int msglen) throws NumberFormatException {
|
||||
int r = 0, rlen = 0, olen = 0, charcnt = 0;
|
||||
StringBuffer msg = new StringBuffer(160);
|
||||
int encmsglen = encmsg.length();
|
||||
boolean exttableescape = false;
|
||||
for (int i = 0; i + 1 < encmsglen && charcnt < msglen; i += 2) {
|
||||
String ostr = encmsg.substring(i, i + 2);
|
||||
int o = Integer.parseInt(ostr, 16);
|
||||
olen = 8;
|
||||
if (rlen >= 7) {
|
||||
char c1 = (char)(r & 0x7F);
|
||||
r >>>= 7;
|
||||
rlen -= 7;
|
||||
msg.append(c1);
|
||||
charcnt++;
|
||||
}
|
||||
o <<= rlen;
|
||||
o |= r;
|
||||
olen += rlen;
|
||||
char c = (char)(o & 0x7F);
|
||||
o >>>= 7;
|
||||
olen -= 7;
|
||||
r = o;
|
||||
rlen = olen;
|
||||
c = gsmToIsoMap[c];
|
||||
if (c == '\033') {
|
||||
exttableescape = true;
|
||||
} else {
|
||||
if (exttableescape) {
|
||||
exttableescape = false;
|
||||
c = gsmToIsoExtMap[c];
|
||||
}
|
||||
msg.append(c);
|
||||
charcnt++;
|
||||
}
|
||||
}
|
||||
if (rlen > 0 && charcnt < msglen)
|
||||
msg.append((char)r);
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
public static String toHexString(int b) {
|
||||
char[] digits = new char[2];
|
||||
b &= 0xFF;
|
||||
digits[0] = hexDigits[b / 16];
|
||||
digits[1] = hexDigits[b % 16];
|
||||
return new String(digits);
|
||||
}
|
||||
|
||||
public static String swapDigits(String str) {
|
||||
if (str == null)
|
||||
return str;
|
||||
int strlen = str.length();
|
||||
StringBuffer sb = new StringBuffer(strlen);
|
||||
for (int i = 0; i + 1 < strlen; i += 2) {
|
||||
sb.append(str.charAt(i + 1));
|
||||
sb.append(str.charAt(i));
|
||||
}
|
||||
return new String(sb);
|
||||
}
|
||||
}
|
||||
21
rus/WEB-INF/lib/abliaSerial_src/com/ablia/sms/SmsServer.java
Normal file
21
rus/WEB-INF/lib/abliaSerial_src/com/ablia/sms/SmsServer.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package com.ablia.sms;
|
||||
|
||||
import com.ablia.serial.SerialPortWriterInterface;
|
||||
import com.ablia.serial.SerialServer;
|
||||
|
||||
public class SmsServer extends SerialServer {
|
||||
protected SerialPortWriterInterface getSerialWriter() {
|
||||
return SmsWriter.getInstance(getResource("SERIAL_COM_PORT"),
|
||||
getResourceLong("COM_DELAY_START"),
|
||||
getResourceLong("COM_DELAY_CMD"),
|
||||
getResourceLong("COM_DELAY_END"));
|
||||
}
|
||||
|
||||
public String getPropertyFileName() {
|
||||
return "sms";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(System.getProperty("java.library.path"));
|
||||
}
|
||||
}
|
||||
84
rus/WEB-INF/lib/abliaSerial_src/com/ablia/sms/SmsWriter.java
Normal file
84
rus/WEB-INF/lib/abliaSerial_src/com/ablia/sms/SmsWriter.java
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
package com.ablia.sms;
|
||||
|
||||
import com.ablia.serial.SerialPortWriter;
|
||||
import com.ablia.serial.SerialPortWriterInterface;
|
||||
import com.ablia.util.StringTokenizer;
|
||||
import gnu.io.UnsupportedCommOperationException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class SmsWriter extends SerialPortWriter implements SerialPortWriterInterface {
|
||||
public static final String RES_FINE_CARTA = "DE2";
|
||||
|
||||
public static final String FINE_SMS_CRTRLZ = "\032";
|
||||
|
||||
public static final String RES_ERRORE_STRING = "DE69";
|
||||
|
||||
public static final String RES_SEQUENZA_ERRATA = "DE6";
|
||||
|
||||
public static final String RES_OK = "";
|
||||
|
||||
public SmsWriter() {}
|
||||
|
||||
public SmsWriter(String portName, long l_comDelayStart, long l_comDelayCmd, long l_comDelayEnd) {
|
||||
super(portName, l_comDelayCmd, l_comDelayCmd, l_comDelayEnd);
|
||||
}
|
||||
|
||||
public String getResponseMessage(String l_res) {
|
||||
return l_res;
|
||||
}
|
||||
|
||||
public String sendToSerial(String theMsg) {
|
||||
String res = "";
|
||||
try {
|
||||
long delayIntestazione = getComDelayStart();
|
||||
long delayFine = getComDelayEnd();
|
||||
long delayComando = getComDelayCmd();
|
||||
OutputStream outputStream = getSerialPort().getOutputStream();
|
||||
getSerialPort().setSerialPortParams(9600, 8,
|
||||
1, 0);
|
||||
getSerialPort().notifyOnOutputEmpty(true);
|
||||
StringTokenizer st = new StringTokenizer(theMsg, "|");
|
||||
boolean firstCmd = true;
|
||||
while (st.hasMoreTokens()) {
|
||||
String theToken = st.nextToken();
|
||||
String theCmd = String.valueOf(theToken) + "\r";
|
||||
System.out.println("sendToSerial: " + theCmd);
|
||||
outputStream.write(theCmd.getBytes());
|
||||
if (firstCmd) {
|
||||
Thread.sleep(delayIntestazione);
|
||||
firstCmd = false;
|
||||
} else {
|
||||
Thread.sleep(delayComando);
|
||||
}
|
||||
res = readFromSerial();
|
||||
}
|
||||
Thread.sleep(delayFine);
|
||||
} catch (UnsupportedCommOperationException e) {
|
||||
e.printStackTrace();
|
||||
res = e.getMessage();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error setting event notification");
|
||||
System.out.println(e.toString());
|
||||
res = "Error setting event notification! " + e.toString();
|
||||
System.exit(-1);
|
||||
}
|
||||
getSerialPort().close();
|
||||
setSerialPort(null);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static synchronized SerialPortWriterInterface getInstance(String portName, long l_comDelayStart, long l_comDelayCmd, long l_comDelayEnd) {
|
||||
String cpKey = portName;
|
||||
if (htSerialPortWriter.containsKey(cpKey))
|
||||
return (SerialPortWriterInterface)htSerialPortWriter.get(cpKey);
|
||||
SerialPortWriterInterface sp = getNewWriterInstance(portName,
|
||||
l_comDelayStart, l_comDelayCmd, l_comDelayEnd);
|
||||
htSerialPortWriter.put(cpKey, sp);
|
||||
return sp;
|
||||
}
|
||||
|
||||
protected static SerialPortWriterInterface getNewWriterInstance(String l_portName, long l_comDelayStart, long l_comDelayCmd, long l_comDelayEnd) {
|
||||
return new SmsWriter(l_portName, l_comDelayStart, l_comDelayCmd,
|
||||
l_comDelayEnd);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue