This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.
Dependencies: mbed DebugLibrary
NetServices/if/ppp/PPPNetIf.h@0:f30e2135b0db, 2011-02-09 (annotated)
- Committer:
- Yann
- Date:
- Wed Feb 09 13:57:49 2011 +0000
- Revision:
- 0:f30e2135b0db
V0.0.0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yann | 0:f30e2135b0db | 1 | |
Yann | 0:f30e2135b0db | 2 | /* |
Yann | 0:f30e2135b0db | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
Yann | 0:f30e2135b0db | 4 | |
Yann | 0:f30e2135b0db | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Yann | 0:f30e2135b0db | 6 | of this software and associated documentation files (the "Software"), to deal |
Yann | 0:f30e2135b0db | 7 | in the Software without restriction, including without limitation the rights |
Yann | 0:f30e2135b0db | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Yann | 0:f30e2135b0db | 9 | copies of the Software, and to permit persons to whom the Software is |
Yann | 0:f30e2135b0db | 10 | furnished to do so, subject to the following conditions: |
Yann | 0:f30e2135b0db | 11 | |
Yann | 0:f30e2135b0db | 12 | The above copyright notice and this permission notice shall be included in |
Yann | 0:f30e2135b0db | 13 | all copies or substantial portions of the Software. |
Yann | 0:f30e2135b0db | 14 | |
Yann | 0:f30e2135b0db | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Yann | 0:f30e2135b0db | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Yann | 0:f30e2135b0db | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Yann | 0:f30e2135b0db | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Yann | 0:f30e2135b0db | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Yann | 0:f30e2135b0db | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Yann | 0:f30e2135b0db | 21 | THE SOFTWARE. |
Yann | 0:f30e2135b0db | 22 | */ |
Yann | 0:f30e2135b0db | 23 | |
Yann | 0:f30e2135b0db | 24 | /** \file |
Yann | 0:f30e2135b0db | 25 | PPP Generic network interface header file |
Yann | 0:f30e2135b0db | 26 | */ |
Yann | 0:f30e2135b0db | 27 | |
Yann | 0:f30e2135b0db | 28 | //This is a backend for PPP, using lwIP |
Yann | 0:f30e2135b0db | 29 | |
Yann | 0:f30e2135b0db | 30 | #ifndef PPPNETIF_H |
Yann | 0:f30e2135b0db | 31 | #define PPPNETIF_H |
Yann | 0:f30e2135b0db | 32 | |
Yann | 0:f30e2135b0db | 33 | #include "mbed.h" |
Yann | 0:f30e2135b0db | 34 | |
Yann | 0:f30e2135b0db | 35 | //For now, only a GPRS Modem is supported, |
Yann | 0:f30e2135b0db | 36 | //but we could easily split this class into a base class + two derived classes |
Yann | 0:f30e2135b0db | 37 | // (PPP over GPRS + PPP over Serial Modem) |
Yann | 0:f30e2135b0db | 38 | #include "drv/gprs/GPRSModem.h" |
Yann | 0:f30e2135b0db | 39 | #include "if/lwip/LwipNetIf.h" |
Yann | 0:f30e2135b0db | 40 | |
Yann | 0:f30e2135b0db | 41 | ///PPP connection error codes |
Yann | 0:f30e2135b0db | 42 | enum PPPErr |
Yann | 0:f30e2135b0db | 43 | { |
Yann | 0:f30e2135b0db | 44 | __PPP_MIN = -0xFFFF, |
Yann | 0:f30e2135b0db | 45 | PPP_MODEM, ///<AT error returned |
Yann | 0:f30e2135b0db | 46 | PPP_NETWORK, ///<Network is down |
Yann | 0:f30e2135b0db | 47 | PPP_PROTOCOL, ///<PPP Protocol error |
Yann | 0:f30e2135b0db | 48 | PPP_CLOSED, ///<Connection is closed |
Yann | 0:f30e2135b0db | 49 | PPP_OK = 0 ///<Success |
Yann | 0:f30e2135b0db | 50 | }; |
Yann | 0:f30e2135b0db | 51 | |
Yann | 0:f30e2135b0db | 52 | enum PPPStatus |
Yann | 0:f30e2135b0db | 53 | { |
Yann | 0:f30e2135b0db | 54 | PPP_CONNECTING, |
Yann | 0:f30e2135b0db | 55 | PPP_CONNECTED, |
Yann | 0:f30e2135b0db | 56 | PPP_DISCONNECTED, |
Yann | 0:f30e2135b0db | 57 | }; |
Yann | 0:f30e2135b0db | 58 | |
Yann | 0:f30e2135b0db | 59 | class PPPNetIf : public LwipNetIf |
Yann | 0:f30e2135b0db | 60 | { |
Yann | 0:f30e2135b0db | 61 | public: |
Yann | 0:f30e2135b0db | 62 | PPPNetIf(GPRSModem* pIf); |
Yann | 0:f30e2135b0db | 63 | virtual ~PPPNetIf(); |
Yann | 0:f30e2135b0db | 64 | |
Yann | 0:f30e2135b0db | 65 | #if 0 |
Yann | 0:f30e2135b0db | 66 | PPPErr open(Serial* pSerial); |
Yann | 0:f30e2135b0db | 67 | #endif |
Yann | 0:f30e2135b0db | 68 | |
Yann | 0:f30e2135b0db | 69 | PPPErr GPRSConnect(const char* apn, const char* userId, const char* password); //Connect using GPRS |
Yann | 0:f30e2135b0db | 70 | PPPErr ATConnect(const char* number); //Connect using a "classic" voice modem or GSM |
Yann | 0:f30e2135b0db | 71 | |
Yann | 0:f30e2135b0db | 72 | virtual void poll(); |
Yann | 0:f30e2135b0db | 73 | |
Yann | 0:f30e2135b0db | 74 | PPPErr disconnect(); |
Yann | 0:f30e2135b0db | 75 | |
Yann | 0:f30e2135b0db | 76 | #if 0 |
Yann | 0:f30e2135b0db | 77 | PPPErr close(); |
Yann | 0:f30e2135b0db | 78 | #endif |
Yann | 0:f30e2135b0db | 79 | |
Yann | 0:f30e2135b0db | 80 | protected: |
Yann | 0:f30e2135b0db | 81 | GPRSModem* m_pIf; |
Yann | 0:f30e2135b0db | 82 | |
Yann | 0:f30e2135b0db | 83 | private: |
Yann | 0:f30e2135b0db | 84 | void pppCallback(int errCode, void *arg); |
Yann | 0:f30e2135b0db | 85 | |
Yann | 0:f30e2135b0db | 86 | static void sPppCallback(void *ctx, int errCode, void *arg) //Callback from ppp.c |
Yann | 0:f30e2135b0db | 87 | { return ((PPPNetIf*)ctx)->pppCallback(errCode, arg); } |
Yann | 0:f30e2135b0db | 88 | |
Yann | 0:f30e2135b0db | 89 | bool m_connected; |
Yann | 0:f30e2135b0db | 90 | /*bool m_open;*/ |
Yann | 0:f30e2135b0db | 91 | volatile PPPStatus m_status; |
Yann | 0:f30e2135b0db | 92 | volatile int m_fd; //PPP Session descriptor |
Yann | 0:f30e2135b0db | 93 | |
Yann | 0:f30e2135b0db | 94 | //int m_id; |
Yann | 0:f30e2135b0db | 95 | |
Yann | 0:f30e2135b0db | 96 | uint8_t* m_buf; |
Yann | 0:f30e2135b0db | 97 | |
Yann | 0:f30e2135b0db | 98 | }; |
Yann | 0:f30e2135b0db | 99 | |
Yann | 0:f30e2135b0db | 100 | #endif |