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/services/email/smtp/SMTPClient.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 | #ifndef SMTP_CLIENT_H |
Yann | 0:f30e2135b0db | 25 | #define SMTP_CLIENT_H |
Yann | 0:f30e2135b0db | 26 | |
Yann | 0:f30e2135b0db | 27 | class EmailMessage; |
Yann | 0:f30e2135b0db | 28 | |
Yann | 0:f30e2135b0db | 29 | #include "core/net.h" |
Yann | 0:f30e2135b0db | 30 | #include "api/TCPSocket.h" |
Yann | 0:f30e2135b0db | 31 | #include "../emailMessage.h" |
Yann | 0:f30e2135b0db | 32 | |
Yann | 0:f30e2135b0db | 33 | #include "mbed.h" |
Yann | 0:f30e2135b0db | 34 | |
Yann | 0:f30e2135b0db | 35 | #define SMTP_REQUEST_TIMEOUT 5000 |
Yann | 0:f30e2135b0db | 36 | |
Yann | 0:f30e2135b0db | 37 | enum SMTPResult |
Yann | 0:f30e2135b0db | 38 | { |
Yann | 0:f30e2135b0db | 39 | SMTP_OK, |
Yann | 0:f30e2135b0db | 40 | SMTP_PRTCL, //Protocol error |
Yann | 0:f30e2135b0db | 41 | SMTP_TIMEOUT, //Connection timeout |
Yann | 0:f30e2135b0db | 42 | SMTP_DISC //Disconnected |
Yann | 0:f30e2135b0db | 43 | }; |
Yann | 0:f30e2135b0db | 44 | |
Yann | 0:f30e2135b0db | 45 | class SMTPClient /*: public NetService*/ |
Yann | 0:f30e2135b0db | 46 | { |
Yann | 0:f30e2135b0db | 47 | public: |
Yann | 0:f30e2135b0db | 48 | SMTPClient(); |
Yann | 0:f30e2135b0db | 49 | virtual ~SMTPClient(); |
Yann | 0:f30e2135b0db | 50 | |
Yann | 0:f30e2135b0db | 51 | void setHost(const Host& host); |
Yann | 0:f30e2135b0db | 52 | void send(EmailMessage* pMessage); |
Yann | 0:f30e2135b0db | 53 | |
Yann | 0:f30e2135b0db | 54 | class CDummy; |
Yann | 0:f30e2135b0db | 55 | template<class T> |
Yann | 0:f30e2135b0db | 56 | //Linker bug : Must be defined here :( |
Yann | 0:f30e2135b0db | 57 | void setOnResult( T* pItem, void (T::*pMethod)(SMTPResult) ) |
Yann | 0:f30e2135b0db | 58 | { |
Yann | 0:f30e2135b0db | 59 | m_pCbItem = (CDummy*) pItem; |
Yann | 0:f30e2135b0db | 60 | m_pCbMeth = (void (CDummy::*)(SMTPResult)) pMethod; |
Yann | 0:f30e2135b0db | 61 | } |
Yann | 0:f30e2135b0db | 62 | |
Yann | 0:f30e2135b0db | 63 | void init(); //Create and setup socket if needed |
Yann | 0:f30e2135b0db | 64 | void close(); |
Yann | 0:f30e2135b0db | 65 | |
Yann | 0:f30e2135b0db | 66 | private: |
Yann | 0:f30e2135b0db | 67 | int rc(char* buf); //Return code |
Yann | 0:f30e2135b0db | 68 | void process(bool moreData); //Main state-machine |
Yann | 0:f30e2135b0db | 69 | |
Yann | 0:f30e2135b0db | 70 | void setTimeout(int ms); |
Yann | 0:f30e2135b0db | 71 | void resetTimeout(); |
Yann | 0:f30e2135b0db | 72 | |
Yann | 0:f30e2135b0db | 73 | void onTimeout(); //Connection has timed out |
Yann | 0:f30e2135b0db | 74 | void onTCPSocketEvent(TCPSocketEvent e); |
Yann | 0:f30e2135b0db | 75 | void onResult(SMTPResult r); //Called when exchange completed or on failure |
Yann | 0:f30e2135b0db | 76 | |
Yann | 0:f30e2135b0db | 77 | EmailMessage* m_pMessage; |
Yann | 0:f30e2135b0db | 78 | |
Yann | 0:f30e2135b0db | 79 | TCPSocket* m_pTCPSocket; |
Yann | 0:f30e2135b0db | 80 | |
Yann | 0:f30e2135b0db | 81 | enum SMTPStep |
Yann | 0:f30e2135b0db | 82 | { |
Yann | 0:f30e2135b0db | 83 | SMTP_HELLO, |
Yann | 0:f30e2135b0db | 84 | SMTP_FROM, |
Yann | 0:f30e2135b0db | 85 | SMTP_TO, |
Yann | 0:f30e2135b0db | 86 | SMTP_DATA, |
Yann | 0:f30e2135b0db | 87 | SMTP_BODY, |
Yann | 0:f30e2135b0db | 88 | SMTP_BODYMORE, |
Yann | 0:f30e2135b0db | 89 | SMTP_EOF, |
Yann | 0:f30e2135b0db | 90 | SMTP_BYE |
Yann | 0:f30e2135b0db | 91 | }; |
Yann | 0:f30e2135b0db | 92 | |
Yann | 0:f30e2135b0db | 93 | SMTPStep m_nextState; |
Yann | 0:f30e2135b0db | 94 | |
Yann | 0:f30e2135b0db | 95 | CDummy* m_pCbItem; |
Yann | 0:f30e2135b0db | 96 | void (CDummy::*m_pCbMeth)(SMTPResult); |
Yann | 0:f30e2135b0db | 97 | |
Yann | 0:f30e2135b0db | 98 | Timeout m_watchdog; |
Yann | 0:f30e2135b0db | 99 | int m_timeout; |
Yann | 0:f30e2135b0db | 100 | |
Yann | 0:f30e2135b0db | 101 | int m_posInMsg; |
Yann | 0:f30e2135b0db | 102 | |
Yann | 0:f30e2135b0db | 103 | bool m_closed; |
Yann | 0:f30e2135b0db | 104 | |
Yann | 0:f30e2135b0db | 105 | Host m_host; |
Yann | 0:f30e2135b0db | 106 | |
Yann | 0:f30e2135b0db | 107 | }; |
Yann | 0:f30e2135b0db | 108 | |
Yann | 0:f30e2135b0db | 109 | #endif |