Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: fi/kvanttisofta/sms/SmsMsgOutgoing.java


1   //
2   // Copyright (c) 2001 Kvanttisofta oy.  All rights reserved.
3   //
4   //
5   // SMS PDU message class for outgoing messages.
6   // (aspa@users.sourceforge.net).
7   //
8   // $Id: SmsMsgOutgoing.java,v 1.1.1.1 2001/04/18 04:19:00 aspa Exp $.
9   //
10  // TODO:
11  // - support for including SMSC info and setting msg validity period
12  // - better handling of recipient address type
13  // - support other data encoding schemes than GSM 7 bit
14  // - message reference support
15  //
16  
17  package fi.kvanttisofta.sms;
18  
19  public class SmsMsgOutgoing {
20      public final int SMS_MSG_ENCODING_7BIT = 0;
21  
22      private int    smscAddressLength = 0;
23      private int    smscAddressType;
24      private String smscAddress;
25      private int    smsSubmitCode = 0x11;
26      private int    tpMsgRef = 0;
27      private int    recipientAddressLength;
28      private int    recipientAddressType = 0x91;
29      private String recipientAddress;
30      private String recipientAddressEnc;
31      private int    tpPid;      // protocol identifier.
32      private int    tpDcs;      // data coding scheme.
33      private int    tpValidity = 0xaa;
34      private int    tpUdl;      // message length.
35      private String tpUd;       // user message (as sent).
36      private String msg;        // user message (unencoded).
37  
38      public SmsMsgOutgoing(String recipientAddress, String msg) {
39    this.recipientAddress = recipientAddress;
40    this.msg = msg;
41      }
42  
43      public String toString() {
44    StringBuffer sb = new StringBuffer(320);
45  
46    if(false) {
47        sb.append(SmsPduCodec.toHexString(smscAddressLength));
48        if( smscAddressLength > 0 ) {
49      // add smscAddressType and smscAddressType to sb.
50        }
51    }
52  
53    sb.append(SmsPduCodec.toHexString(smsSubmitCode));
54    sb.append(SmsPduCodec.toHexString(tpMsgRef));
55  
56    // recipientAddress.
57    recipientAddressLength = recipientAddress.length();
58    if( (recipientAddress.length()%2) == 1 )
59        recipientAddressEnc = SmsPduCodec.swapDigits(recipientAddress+"F");
60    else
61        recipientAddressEnc = SmsPduCodec.swapDigits(recipientAddress);
62    
63    sb.append(SmsPduCodec.toHexString(recipientAddressLength));
64    sb.append(SmsPduCodec.toHexString(recipientAddressType));
65    sb.append(recipientAddressEnc);
66    sb.append(SmsPduCodec.toHexString(tpPid));
67    sb.append(SmsPduCodec.toHexString(tpDcs));
68    sb.append(SmsPduCodec.toHexString(tpValidity));
69  
70    // encode message and calculate message length.
71    tpUd = SmsPduCodec.sevenBitEncode(msg);
72    tpUdl = msg.length();
73  
74    sb.append(SmsPduCodec.toHexString(tpUdl));
75    sb.append(tpUd);
76  
77    return new String(sb);
78      }
79  
80      public void setTarget(String number) {
81      }
82  
83      public void setMessage(String msg) {
84      }
85  
86      public static void main(String[] args) {
87    // phone: 46708251358, msg: hellohello.
88    String smspdu1 = "0011000B916407281553F80000AA0AE8329BFD4697D9EC37";
89  
90    //SmsMsgOutgoing sms1 = new SmsMsgOutgoing("46708251358", "hellohello");
91    //System.err.println("smspdu1: " + smspdu1);
92    //System.err.println("enc:     " + sms1.toString().toUpperCase() );
93  
94    SmsMsgOutgoing sms2 = new SmsMsgOutgoing("358985019963", "hello, world");
95    System.err.println("358985019963: 'hello, world', "+ sms2.toString().length());
96          System.err.println("sms2 enc:     " + sms2.toString().toUpperCase() );
97  
98    SmsMsgOutgoing sms3=new SmsMsgOutgoing("358985019963","testiviesti.");
99    System.err.println("358985019963: 'testiviesti.', " + sms3.toString().length());
100   System.err.println("sms3 enc:     " + sms3.toString().toUpperCase() );
101 
102     }
103 
104 }