📄 aathandler.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;
import java.io.*;
abstract class AATHandler
{
static final int DELAY_AT = 200;
static final int DELAY_RESET = 20000;
static final int DELAY_CMD_MODE = 1500;
static final int DELAY_CMGS = 100;
ModemGateway gateway;
String storageLocations;
String description;
String[] terminators;
String asyncEventResponse;
public AATHandler(ModemGateway gateway)
{
this.gateway = gateway;
storageLocations = "";
}
abstract void sync() throws IOException, InterruptedException;
abstract void reset() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract void echoOff() throws IOException, InterruptedException;
abstract void init() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean isAlive() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getSimStatus() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean enterPin(String pin) throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean setVerboseErrors() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean setPduProtocol() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean setTextProtocol() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean setIndications() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getManufacturer() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getModel() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getSerialNo() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getImsi() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getSwVersion() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getBatteryLevel() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getSignalLevel() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean setStorageLocation(String mem) throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract void switchToCmdMode() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean keepGsmLinkOpen() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract int sendMessage(int size, String pdu, String phone, String text) throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String listMessages(MessageClasses messageClass) throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract boolean deleteMessage(int memIndex, String memLocation) throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getGprsStatus() throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String send(String s) throws TimeoutException, GatewayException, IOException, InterruptedException;
abstract String getNetworkRegistration() throws GatewayException, TimeoutException, IOException;
abstract void readStorageLocations() throws Exception;
abstract AsyncEvents processUnsolicitedEvents(String response) throws IOException;
abstract String getAsyncEventResponse(AsyncEvents event) throws TimeoutException, GatewayException, IOException, InterruptedException;
static AATHandler load(ModemGateway gateway, String gsmManuf, String gsmModel) throws RuntimeException
{
String BASE_HANDLER = ATHandler.class.getName();
String[] handlerClassNames = { null, null, BASE_HANDLER };
String[] handlerDescriptions = { null, null, "Generic" };
StringBuffer handlerClassName = new StringBuffer(BASE_HANDLER);
if (gsmManuf != null && gsmManuf.length() != 0)
{
handlerClassName.append("_").append(gsmManuf);
handlerClassNames[1] = handlerClassName.toString();
handlerDescriptions[1] = gsmManuf + " (Generic)";
if (gsmModel != null && gsmModel.length() != 0)
{
handlerClassName.append("_").append(gsmModel);
handlerClassNames[0] = handlerClassName.toString();
handlerDescriptions[0] = gsmManuf + " " + gsmModel;
}
}
AATHandler 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 = (AATHandler) handlerConstructor.newInstance(new Object[] { gateway });
atHandler.description = handlerDescriptions[i];
break;
}
}
catch (Exception ex)
{
if (i == 2)
{
ex.printStackTrace();
throw new RuntimeException("Class AATHandler: Cannot initialize handler!");
}
}
}
return atHandler;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -