📄 cathandler_sonyericsson.java
字号:
// jSMSEngine API.
// An open-source API package for sending and receiving SMS via a GSM device.
// Copyright (C) 2002-2006, Thanasis Delenikas, Athens/GREECE
// Web Site: http://www.jsmsengine.org
//
// jSMSEngine is distributed under the GPL license.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
package org.jsmsengine;
import java.util.logging.*;
/**
AT handler for SonyEricsson 2003, 2004 and 2005 series devices.
*/
public class CATHandler_SonyEricsson extends CATHandler
{
public CATHandler_SonyEricsson(CSerialDriver serialDriver, Logger log)
{
super(serialDriver, log);
}
public synchronized boolean disableIndications() throws Exception
{
/* work out what command to send to disable indications, the phone
* itself will tell us what it supports */
String atDisableIndications = "AT\r";
// check for valid AT+CNMI values
serialDriver.send("AT+CNMI=?\r");
// what comes back?
String cnmiTestResponse = serialDriver.getResponse();
if (cnmiTestResponse.toUpperCase().indexOf("+CNMI: (2)") >= 0)
{
atDisableIndications = "AT+CNMI=2,0,0,0\r";
}
else if (cnmiTestResponse.toUpperCase().indexOf("+CNMI: (3)") >= 0)
{
atDisableIndications = "AT+CNMI=3,0,0,0\r";
}
else
{
// we don't know what to send
return false;
}
serialDriver.send(atDisableIndications);
return (serialDriver.getResponse().matches("\\s+OK\\s+"));
}
/*
20/03/2006 by Thanasis Delenikas.
Removed the reset() code for Ericssons - it seems it creates many problems.
// SonyEricsson's documentation on which phones support which
// variant of AT+CFUN is inaccurate, so the safest thing is
// to ask the phone what it supports.
public synchronized void reset() throws Exception
{
String atCFUN = "AT+CFUN=1\r";
// check what is supported
serialDriver.send("AT+CFUN=?\r");
String cfunTestResponse = serialDriver.getResponse();
if (cfunTestResponse.indexOf("+CFUN: (0)") == -1)
{
if (cfunTestResponse.matches("\\+CFUN: \\([^)]+\\),\\([^)]+\\)")) atCFUN = "AT+CFUN=1,1\r";
serialDriver.send(atCFUN);
try { Thread.sleep(10000); } catch (Exception e) {}
serialDriver.clearBuffer();
}
}
*/
// SonyEricssons require an additional <CR> after the <26> that indicates the end of the PDU
public synchronized int sendMessage(int size, String pdu) throws Exception
{
int responseRetries, errorRetries;
String response;
int refNo;
errorRetries = 0;
while (true)
{
responseRetries = 0;
serialDriver.send(CUtils.substituteSymbol("AT+CMGS=\"{1}\"\r", "\"{1}\"", "" + size));
Thread.sleep(300);
while (!serialDriver.dataAvailable())
{
responseRetries ++;
if (responseRetries == 4) throw new NoResponseException();
log.log(Level.INFO, "CATHandler_SonyEricsson().SendMessage(): Still waiting for response (I) (" + responseRetries + ")...");
Thread.sleep(5000);
}
responseRetries = 0;
serialDriver.clearBuffer();
serialDriver.send(pdu);
serialDriver.send((char) 26);
serialDriver.send((char) 13); // special for SonyEricsson
response = serialDriver.getResponse();
while (response.length() == 0)
{
responseRetries ++;
if (responseRetries == 4) throw new NoResponseException();
log.log(Level.INFO, "CATHandler_SonyEricsson().SendMessage(): Still waiting for response (II) (" + responseRetries + ")...");
response = serialDriver.getResponse();
}
if (response.indexOf("OK\r") >= 0)
{
int i;
String tmp = "";;
i = response.indexOf(":");
while (!Character.isDigit(response.charAt(i))) i ++;
while (Character.isDigit(response.charAt(i)))
{
tmp += response.charAt(i);
i ++;
}
refNo = Integer.parseInt(tmp);
break;
}
else if (response.indexOf("CMS ERROR:") >= 0)
{
errorRetries ++;
if (errorRetries == 4)
{
log.log(Level.SEVERE, "GSM CMS Errors: Quit retrying, message lost...");
refNo = -1;
break;
}
else log.log(Level.SEVERE, "GSM CMS Errors: Possible collision, retrying...");
}
else refNo = -1;
}
return refNo;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -