libraries / Mitov / Mitov_GSMShield.hon commit Added link to project report (97a3ba0)
   1////////////////////////////////////////////////////////////////////////////////
   2//                                                                            //
   3//     This software is supplied under the terms of a license agreement or    //
   4//     nondisclosure agreement with Mitov Software and may not be copied      //
   5//     or disclosed except in accordance with the terms of that agreement.    //
   6//         Copyright(c) 2002-2016 Mitov Software. All Rights Reserved.        //
   7//                                                                            //
   8////////////////////////////////////////////////////////////////////////////////
   9
  10#ifndef _MITOV_GSM_SHIELD_h
  11#define _MITOV_GSM_SHIELD_h
  12
  13#include <Mitov.h>
  14
  15namespace Mitov
  16{
  17//---------------------------------------------------------------------------
  18        class GSMModule : public OpenWire::Component
  19        {
  20        public:
  21                virtual void StartModule()
  22                {
  23                }
  24
  25                virtual void StopModule()
  26                {
  27                }
  28        };
  29//---------------------------------------------------------------------------
  30        class GSMShield : public OpenWire::Component
  31        {
  32                typedef OpenWire::Component inherited;
  33
  34        public:
  35                bool    Enabled = true;
  36
  37                String  PIN;
  38                bool    Restart = true;
  39
  40        public:
  41                bool    IsStarted = false;
  42
  43        public:
  44                Mitov::SimpleList<GSMModule*>   Modules;
  45
  46        protected:
  47                GSM     FGsm;
  48
  49        public:
  50                void SetEnabled( bool AValue )
  51                {
  52            if( Enabled == AValue )
  53                return;
  54
  55            Enabled = AValue;
  56                        if( Enabled )
  57                                StartShield();
  58
  59                        else
  60                                StopShield();
  61
  62                }
  63
  64        protected:
  65                virtual void SystemInit()
  66                {
  67                        if( Enabled )
  68                                StartShield();
  69
  70                        inherited::SystemInit();
  71                }
  72
  73                void StopShield()
  74                {
  75                        for( int i = 0; i < Modules.size(); ++i )
  76                                Modules[ i ]->StopModule();
  77
  78                        FGsm.shutdown();
  79                        IsStarted = false;
  80                }
  81
  82/*
  83        void RestartShield()
  84                {
  85                        if( ! Enabled )
  86                                return;
  87
  88                        StartShield();
  89                }
  90*/
  91                void StartShield()
  92                {
  93                        if( PIN == "" )
  94                        {
  95//                              if( ! Restart )
  96                                        IsStarted = ( FGsm.begin( 0, Restart ) == GSM_READY );
  97
  98//                              else
  99//                                      IsStarted = ( FGsm.begin() == GSM_READY );
 100                        }
 101
 102                        else
 103                                IsStarted = ( FGsm.begin( (char *)PIN.c_str(), Restart ) == GSM_READY );
 104
 105                        for( int i = 0; i < Modules.size(); ++i )
 106                                Modules[ i ]->StartModule();
 107                }
 108
 109        };
 110//---------------------------------------------------------------------------
 111}
 112
 113#endif