📄 abstractathandler.java
字号:
// SMSLib for Java v3
// A Java API library for sending and receiving SMS via a GSM modem
// or other supported gateways.
// Web Site: http://www.smslib.org
//
// SMSLib is distributed under the terms of the Apache License version 2.0
//
// Copyright (C) 2002-2007, Thanasis Delenikas, Athens/GREECE
// Portions Copyright:
// Davide Bettoni, Clusone/ITALY, dbettoni@users.sourceforge.net
// Tomek Cejner, Polland, heretique@users.sourceforge.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.smslib.athandlers;
import org.smslib.*;
import org.smslib.gateway.*;
abstract public class AbstractATHandler
{
protected static final int DELAY_AT = 200;
protected static final int DELAY_RESET = 20000;
protected static final int DELAY_CMD_MODE = 1000;
protected static final int DELAY_CMGS = 100;
protected ModemGateway gateway;
protected String storageLocations;
protected String description;
protected String[] terminators;
protected String asyncEventResponse;
public AbstractATHandler(ModemGateway gateway)
{
this.gateway = gateway;
storageLocations = "";
}
public String getDescription()
{
return description;
}
abstract public void setStorageLocations(String loc);
public String getStorageLocations()
{
return storageLocations;
}
public String[] getTerminators()
{
return terminators;
}
abstract public void sync() throws Exception;
abstract public void reset() throws Exception;
abstract public void echoOff() throws Exception;
abstract public void init() throws Exception;
abstract public boolean isAlive() throws Exception;
abstract public String getSimStatus() throws Exception;
abstract public boolean enterPin(String pin) throws Exception;
abstract public boolean setVerboseErrors() throws Exception;
abstract public boolean setPduProtocol() throws Exception;
abstract public boolean setTextProtocol() throws Exception;
abstract public boolean setIndications() throws Exception;
abstract public String getManufacturer() throws Exception;
abstract public String getModel() throws Exception;
abstract public String getSerialNo() throws Exception;
abstract public String getImsi() throws Exception;
abstract public String getSwVersion() throws Exception;
abstract public String getBatteryLevel() throws Exception;
abstract public String getSignalLevel() throws Exception;
abstract public boolean setMemoryLocation(String mem) throws Exception;
abstract public void switchToCmdMode() throws Exception;
abstract public boolean keepGsmLinkOpen() throws Exception;
abstract public int sendMessage(int size, String pdu, String phone, String text) throws Exception;
abstract public String listMessages(InboundMessage.MessageClass messageClass) throws Exception;
abstract public boolean deleteMessage(int memIndex, String memLocation) throws Exception;
abstract public String getGprsStatus() throws Exception;
abstract public String send(String s) throws Exception;
abstract public String getNetworkRegistration() throws Exception;
abstract public void readStorageLocations() throws Exception;
abstract public org.smslib.gateway.ModemDriver.AsyncEvents processUnsolicitedEvents(String response) throws Exception;
abstract public String getAsyncEventResponse(org.smslib.gateway.ModemDriver.AsyncEvents event) throws Exception;
static public AbstractATHandler load(ModemGateway gateway, String gsmManuf, String gsmModel) throws RuntimeException
{
String BASE_HANDLER = org.smslib.athandlers.ATHandler.class.getName();
String[] handlerClassNames =
{ null, null, BASE_HANDLER };
String[] handlerDescriptions =
{ null, null, "Generic" };
StringBuffer handlerClassName = new StringBuffer(BASE_HANDLER);
if (gsmManuf != null && !gsmManuf.equals(""))
{
handlerClassName.append("_").append(gsmManuf);
handlerClassNames[1] = handlerClassName.toString();
handlerDescriptions[1] = gsmManuf + " (Generic)";
if (gsmModel != null && !gsmModel.equals(""))
{
handlerClassName.append("_").append(gsmModel);
handlerClassNames[0] = handlerClassName.toString();
handlerDescriptions[0] = gsmManuf + " " + gsmModel;
}
}
AbstractATHandler atHandler = null;
for (int i = 0; i < 3; ++i)
{
try
{
if (handlerClassNames[i] != null)
{
Class handlerClass = Class.forName(handlerClassNames[i]);
java.lang.reflect.Constructor handlerConstructor = handlerClass.getConstructor(new Class[] { ModemGateway.class });
atHandler = (AbstractATHandler) handlerConstructor.newInstance(new Object[] { gateway });
atHandler.description = handlerDescriptions[i];
break;
}
}
catch (Exception ex)
{
if (i == 2)
{
ex.printStackTrace();
throw new RuntimeException("Class AbstractATHandler: Cannot initialize handler!");
}
}
}
return atHandler;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -