Warning: Can't synchronize with repository "(default)" (No changeset 96d22ec3fa3ef6de3ea8dc0d7d398adc9aa071cf in the repository). Look in the Trac log for more information.

source: fsogsmd/src/lib/at/atsms.vala @ 2e46854

Revision 2e46854, 4.8 KB checked in by Simon Busch <morphis@…>, 11 months ago (diff)

fsogsmd: lib: drop unneeded parameter id from acknowledgeSmsMessage method

  • Property mode set to 100644
Line 
1/*
2 * Copyright (C) 2009-2011 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17 *
18 */
19
20using Gee;
21
22/**
23 * @class AtSmsHandler
24 **/
25public class FsoGsm.AtSmsHandler : FsoGsm.AbstractSmsHandler
26{
27    private bool ack_supported = true;
28    private bool supported = true;
29
30    //
31    // protected
32    //
33
34    protected override async string retrieveImsiFromSIM()
35    {
36        var cimi = theModem.createAtCommand<PlusCIMI>( "+CIMI" );
37        var response = yield theModem.processAtCommandAsync( cimi, cimi.execute() );
38        if ( cimi.validate( response ) != Constants.AtResponse.VALID )
39        {
40            logger.warning( "Can't retrieve IMSI from SIM to be used as identifier for SMS storage" );
41            return "";
42        }
43        return cimi.value;
44    }
45
46    protected override async void fillStorageWithMessageFromSIM()
47    {
48        var cmgl = theModem.createAtCommand<PlusCMGL>( "+CMGL" );
49        var cmglresponse = yield theModem.processAtCommandAsync( cmgl, cmgl.issue( PlusCMGL.Mode.ALL ) );
50        if ( cmgl.validateMulti( cmglresponse ) != Constants.AtResponse.VALID )
51        {
52            logger.warning( "Can't synchronize SMS storage with SIM" );
53            return;
54        }
55
56        foreach( var sms in cmgl.messagebook )
57        {
58            var ret = storage.addSms( sms.message );
59            // send the incoming_text_message signal if ret == 1 (message is new).
60            if ( ret == 1 )
61            {
62                var msg = storage.message( sms.message.hash() );
63                var obj = theModem.theDevice<FreeSmartphone.GSM.SMS>();
64                obj.incoming_text_message( msg.number, msg.timestamp, msg.contents );
65            }
66        }
67    }
68
69    protected override async bool readSmsMessageFromSIM( uint index, out string hexpdu, out int tpdulen )
70    {
71        hexpdu = "";
72        tpdulen = 0;
73
74        var cmd = theModem.createAtCommand<PlusCMGR>( "+CMGR" );
75        var response = yield theModem.processAtCommandAsync( cmd, cmd.issue( index ) );
76        if ( cmd.validateUrcPdu( response ) != Constants.AtResponse.VALID )
77        {
78            logger.warning( @"Can't read new SMS from SIM storage at index $index." );
79            return false;
80        }
81
82        hexpdu = cmd.hexpdu;
83        tpdulen = cmd.tpdulen;
84
85        return true;
86    }
87
88    protected override async bool acknowledgeSmsMessage()
89    {
90        if ( ! ack_supported )
91        {
92            assert( logger.debug( @"Skipping SMS acknowledgement because it's disabled" ) );
93            return true;
94        }
95
96        var cmd = theModem.createAtCommand<PlusCNMA>( "+CNMA" );
97        var response = yield theModem.processAtCommandAsync( cmd, cmd.issue( 0 ) );
98        if ( cmd.validate( response ) != Constants.AtResponse.VALID )
99        {
100            logger.warning( @"Failed to acknowledge SMS message; further SMS message handling will maybe faulty!" );
101            return false;
102        }
103
104        return true;
105    }
106
107    //
108    // public
109    //
110
111    public AtSmsHandler()
112    {
113        base();
114    }
115
116    public override async void configure()
117    {
118        base.configure();
119
120        // First we're gathing which types of SMS services are supported and select the
121        // one which suites best for our needs.
122        var csms = theModem.createAtCommand<PlusCSMS>( "+CSMS" );
123        // Try to enable GSM phase 2+ commands
124        var response = yield theModem.processAtCommandAsync( csms, csms.issue( 1 ) );
125        if ( csms.validateOk( response ) != Constants.AtResponse.OK )
126        {
127            logger.warning( @"Desired SMS service mode is not available; SMS acknowledgement support will be disabled." );
128            ack_supported = false;
129
130            response = yield theModem.processAtCommandAsync( csms, csms.issue( 0 ) );
131            if ( csms.validateOk( response ) != Constants.AtResponse.OK )
132            {
133                logger.error( @"Could not set minimal SMS service mode; SMS support will be disabled" );
134                supported = false;
135                return;
136            }
137        }
138    }
139
140    public override string repr()
141    {
142        return storage != null ? storage.repr() : "<None>";
143    }
144}
145
146// vim:ts=4:sw=4:expandtab
Note: See TracBrowser for help on using the repository browser.