libraries / Mitov / Mitov_LinkIt_GPRS.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_LINKIT_GPRS_h
  11#define _MITOV_LINKIT_GPRS_h
  12
  13#include <Mitov.h>
  14#include <Mitov_BasicEthernet.h>
  15#include <LGPRS.h>
  16#include <LGPRSClient.h>
  17#include <LGPRSServer.h>
  18#include <LGPRSUdp.h>
  19
  20namespace Mitov
  21{
  22//---------------------------------------------------------------------------
  23        class LinkItGPRSModule : public OpenWire::Component
  24        {
  25                typedef OpenWire::Component inherited;
  26
  27        public:
  28                Mitov::SimpleList<BasicEthernetSocket<LinkItGPRSModule>*>       Sockets;
  29
  30        public:
  31                bool    Enabled = true;
  32
  33                Mitov::SimpleObjectList<GPRSAccessPoint *>      AccessPoints;
  34
  35        protected:
  36                bool    FConnected = false;
  37
  38        public:
  39                void SetEnabled( bool AValue )
  40                {
  41            if( Enabled == AValue )
  42                return;
  43
  44            Enabled = AValue;
  45                        if( Enabled )
  46                                StartEthernet();
  47
  48                        else
  49                                StopEthernet();
  50
  51                }
  52
  53        protected:
  54                virtual void SystemInit()
  55                {
  56                        if( Enabled )
  57                                StartEthernet();
  58
  59                        inherited::SystemInit();
  60                }
  61
  62                void StopEthernet()
  63                {
  64                        for( int i = 0; i < Sockets.size(); ++i )
  65                                Sockets[ i ]->StopSocket();
  66
  67//                      LWiFi.end();
  68                }
  69
  70                void StartEthernet()
  71                {
  72                        TryConnect( true, 0 );
  73                }
  74
  75                void TryConnect( bool FromStart, unsigned long currentMicros )
  76                {
  77                        for( int i = 0; i < AccessPoints.size(); i ++ )
  78                                if( AccessPoints[ i ]->Enabled )
  79                                {
  80                                        if( ! FromStart )
  81                                                if( ! AccessPoints[ i ]->CanRetry( currentMicros ) )
  82                                                        continue;
  83
  84                                        if( AccessPoints[ i ]->AccessPoint != "" )
  85                                                FConnected = LGPRS.attachGPRS( AccessPoints[ i ]->AccessPoint.c_str(), AccessPoints[ i ]->UserName.c_str(), AccessPoints[ i ]->Password.c_str() );
  86
  87                                        else
  88                                                FConnected = LGPRS.attachGPRS();
  89
  90                                        if( FConnected )
  91                                                break;
  92                                }
  93
  94                }
  95
  96                virtual void SystemLoopBegin( unsigned long currentMicros )
  97                {
  98                        if( ! FConnected )
  99                                TryConnect( false, currentMicros );
 100
 101                        inherited::SystemLoopBegin( currentMicros );
 102                }
 103
 104        };
 105//---------------------------------------------------------------------------
 106}
 107
 108#endif