⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsporter.java

📁 排课系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                              buffer.toString().indexOf("CPIN")) >
                           -1)))) {
                        break;
                    }
                }
                retry = RETRIES;
            } catch (Exception e) {
                if (retry < RETRIES) {
                    Thread.sleep(WAIT_TO_RETRY);
                    retry++;
                } else {
                    throw e;
                }
            }
        }

        // Following line is to skip the remaining "\n" char...
        if (dataAvailable()) {
            skipBytes(1);
        }
        //while ((buffer.charAt(0) == 13) || (buffer.charAt(0) == 10)) buffer.delete(0, 1);
        return buffer.toString();
    }

    public boolean CMD_setPDUMode() {
        try {
            synchronized (_SYNC_) {
                send(SMSATCmds.AT_PDU_MODE);
                String response = getResponse();
                if ("OK".equalsIgnoreCase(response)) {
                    return true;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }

    public boolean CMD_setStorageToMT(){
        try {
            synchronized (_SYNC_) {
                send(SMSATCmds.AT_SIEMENS_SMS_STORAGE);
                String response = getResponse();
                if ("OK".equalsIgnoreCase(response)) {
                    return true;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }

    public void CMD_getUnReadRecvMsg() {
        try {
            synchronized (_SYNC_) {
                send(
                        _CharacterUtil.replaceSymbol(
                                SMSATCmds.AT_LIST,
                                "{1}",
                                "0"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void CMD_getAllRecvMsg() {
        try {
            send(
                    _CharacterUtil.replaceSymbol(
                            SMSATCmds.AT_LIST,
                            "{1}",
                            "4"));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void CMD_getReadedRecvMsg() {
        try {
            synchronized (_SYNC_) {
                send(
                        _CharacterUtil.replaceSymbol(
                                SMSATCmds.AT_LIST,
                                "{1}",
                                "1"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void CMD_getSendedRecvMsg() {
        try {
            synchronized (_SYNC_) {
                send(
                        _CharacterUtil.replaceSymbol(
                                SMSATCmds.AT_LIST,
                                "{1}",
                                "3"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


    public boolean CMD_delMsg(int memIndex) {
        String response;

        synchronized (_SYNC_) {
            if (memIndex > 0) {
                try {
                    send(
                            _CharacterUtil.replaceSymbol(
                                    SMSATCmds.AT_DELETE_MESSAGE,
                                    "{1}",
                                    "" + memIndex));
                    response = getResponse();
                    if (response.indexOf(SMSATCmds.AT_OK) > -1) {
                        return true;
                    } else {
                        return false;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }
            } else {
                return false;
            }
        }
    }

    public void CMD_delAllMsg() {
        CMD_getReadedRecvMsg();
        LinkedList ll = readPDUMsg();
        if (ll != null) {
            for (int i = 0; i < ll.size(); i++) {
                CMD_delMsg(((SMSMsg) ll.get(i)).memIndex);
            }
        }
        CMD_getSendedRecvMsg();
        ll = readPDUMsg();
        if (ll != null) {
            for (int i = 0; i < ll.size(); i++) {
                CMD_delMsg(((SMSMsg) ll.get(i)).memIndex);
            }
        }
    }


    public LinkedList readPDUMsg() {
        int i, j, memIndex;
        LinkedList ll = new LinkedList();
        try {
            String response = "";
            synchronized (_SYNC_) {
                response = getResponse();
            }
            BufferedReader reader =
                    new BufferedReader(new StringReader(
                            response));
            String line = reader.readLine();
            if (line != null) {
                line = line.trim();
            }
            //处理命名行被置入输出的问题
            while (line != null &&
                   (line.toLowerCase().startsWith("at+cmgl") ||
                   line.length() == 0)) {
                line = reader.readLine();
                if (line != null) {
                    line = line.trim();
                }
            }
            while ((line != null)
                     && (line.length() > 0)
                     && (!line.equalsIgnoreCase("OK"))
                     && (!line.equalsIgnoreCase("ERROR"))) {
                i = line.indexOf(':');
                j = line.indexOf(',');
                if(i>0&&j>0){
                    memIndex =
                            Integer.parseInt(
                                    line.substring(i + 1, j).trim());
                    String pdu = reader.readLine();
                    if (SmsUtil.isSMSMsgIn(pdu)) {
                        ll.add(
                                new SMSMsgIn(pdu, memIndex));
//                                    deviceInfo.getStatistics().incTotalIn();
                    }
//                                else if (isStatusReportMessage(pdu)) {
//                                    messageList.add(
//                                            new StatusReportMessage(pdu,
//                                            memIndex));
//                                    deviceInfo.getStatistics().incTotalIn();
//                                }
                }
                line = reader.readLine().trim();
            }
            reader.close();
            return ll;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public boolean sendText(String phone, String text) {
        SMSMsgOut m = new SMSMsgOut(phone, text);
        String pdu = m.getPdu();
        return sendPduText(pdu);
    }

    public boolean sendPduText(String pdu) {
        int size = SmsUtil.getSMSSize(pdu);
        try {
            synchronized (_SYNC_) {
                String at_comm_send =
                        _CharacterUtil.replaceSymbol(
                                SMSATCmds.AT_SEND_MESSAGE,
                                "\"{1}\"",
                                "" + size);
                send(at_comm_send);
                while (!dataAvailable()) {
                    Thread.sleep(10);
                } while (dataAvailable()) {
                    skipBytes(1);
                }

                //发送数据
                pdu = pdu + (char) Integer.parseInt("1a",
                        16) ;
//                      + "z";
                send(pdu);
                String response = getResponse();
                int i=0;
                while(response.equals("") && i<3){
                    Thread.sleep(500);
                    i++;
                    response = getResponse();
                }
                if (response.indexOf(SMSATCmds.AT_OK)
                    > -1) {
                    return true;
                } else {
                    return false;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }

    public void setBaud(int baud) {
        this.baud = baud;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -