Simplify using of UnbufferedSerial(Serial), USBCDC, TCP, SMTP, NTP Fork : https://github.com/YSI-LPS/lib_Transmission
Dependents: lib_Transmission_Serial_example 2022_TICE_Electrolyse lib_Transmission_TCP_example
lib_Transmission.h@3:7e15bf0a71f4, 2020-07-08 (annotated)
- Committer:
- YSI
- Date:
- Wed Jul 08 12:26:35 2020 +0000
- Revision:
- 3:7e15bf0a71f4
- Parent:
- 2:ec88f3f8b619
- Child:
- 4:9a4ab4f406ab
add get & set ip:port conf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YSI | 0:2fc6fc3b5e15 | 1 | /** Transmission class |
YSI | 0:2fc6fc3b5e15 | 2 | * |
YSI | 0:2fc6fc3b5e15 | 3 | * @purpose library for Transmission |
YSI | 0:2fc6fc3b5e15 | 4 | * |
YSI | 0:2fc6fc3b5e15 | 5 | * Use to Transmission |
YSI | 0:2fc6fc3b5e15 | 6 | * |
YSI | 0:2fc6fc3b5e15 | 7 | * Example: |
YSI | 0:2fc6fc3b5e15 | 8 | * @code |
YSI | 0:2fc6fc3b5e15 | 9 | * #include "mbed.h" |
YSI | 0:2fc6fc3b5e15 | 10 | * |
YSI | 0:2fc6fc3b5e15 | 11 | * int main() |
YSI | 0:2fc6fc3b5e15 | 12 | * { |
YSI | 0:2fc6fc3b5e15 | 13 | * while(1) |
YSI | 0:2fc6fc3b5e15 | 14 | * { |
YSI | 0:2fc6fc3b5e15 | 15 | * } |
YSI | 0:2fc6fc3b5e15 | 16 | * } |
YSI | 0:2fc6fc3b5e15 | 17 | * @endcode |
YSI | 0:2fc6fc3b5e15 | 18 | * @file lib_Transmission.h |
YSI | 0:2fc6fc3b5e15 | 19 | * @date Jun 2020 |
YSI | 0:2fc6fc3b5e15 | 20 | * @author Yannic Simon |
YSI | 0:2fc6fc3b5e15 | 21 | */ |
YSI | 0:2fc6fc3b5e15 | 22 | #ifndef COM_H |
YSI | 0:2fc6fc3b5e15 | 23 | #define COM_H |
YSI | 0:2fc6fc3b5e15 | 24 | |
YSI | 0:2fc6fc3b5e15 | 25 | #include "mbed.h" |
YSI | 0:2fc6fc3b5e15 | 26 | #include "EthernetInterface.h" |
YSI | 0:2fc6fc3b5e15 | 27 | #include <sstream> |
YSI | 0:2fc6fc3b5e15 | 28 | |
YSI | 1:27f6baabb15e | 29 | #define TCP_CLIENT_TIMEOUT 100 // configue client bloquante avec timeout sinon limite de transmission a 1072 octets |
YSI | 2:ec88f3f8b619 | 30 | #define SMTP_SERVER "129.175.212.70" // smtp.u-psud.fr oblige a utiliser DNS avec eth.getHostByName("smtp.u-psud.fr") |
YSI | 0:2fc6fc3b5e15 | 31 | |
YSI | 3:7e15bf0a71f4 | 32 | enum enumTRANSMISSION { TCP, SERIAL }; |
YSI | 3:7e15bf0a71f4 | 33 | enum enumTRANSTATUS { WHITE, CYAN, MAGENTA_ACCEPT, BLUE_CLIENT, YELLOW_CONNECTING, GREEN_GLOBAL_UP, RED_DISCONNECTED, BLACK_INITIALIZE }; |
YSI | 3:7e15bf0a71f4 | 34 | struct typeTRANSMISSION { string buffer[2]; enumTRANSTATUS status; bool TCP; bool HTTP; bool BREAK; bool DHCP; bool CONNECT; string IP; uint16_t PORT; }; |
YSI | 0:2fc6fc3b5e15 | 35 | |
YSI | 0:2fc6fc3b5e15 | 36 | /** Transmission class |
YSI | 0:2fc6fc3b5e15 | 37 | */ |
YSI | 0:2fc6fc3b5e15 | 38 | class Transmission |
YSI | 0:2fc6fc3b5e15 | 39 | { |
YSI | 0:2fc6fc3b5e15 | 40 | public: |
YSI | 3:7e15bf0a71f4 | 41 | uint16_t _PORT = 80; |
YSI | 0:2fc6fc3b5e15 | 42 | /** make new Transmission instance |
YSI | 0:2fc6fc3b5e15 | 43 | * connected to |
YSI | 0:2fc6fc3b5e15 | 44 | * |
YSI | 0:2fc6fc3b5e15 | 45 | * @param |
YSI | 0:2fc6fc3b5e15 | 46 | * @param |
YSI | 0:2fc6fc3b5e15 | 47 | */ |
YSI | 1:27f6baabb15e | 48 | Transmission(UnbufferedSerial *serial, EthernetInterface *eth, EventQueue *queue, void(*_init)(void), void(*_processing)(string, const enumTRANSMISSION&)); |
YSI | 0:2fc6fc3b5e15 | 49 | |
YSI | 0:2fc6fc3b5e15 | 50 | /** |
YSI | 0:2fc6fc3b5e15 | 51 | * |
YSI | 0:2fc6fc3b5e15 | 52 | * @param |
YSI | 0:2fc6fc3b5e15 | 53 | * @param |
YSI | 0:2fc6fc3b5e15 | 54 | * @returns none |
YSI | 0:2fc6fc3b5e15 | 55 | */ |
YSI | 0:2fc6fc3b5e15 | 56 | /* communication */ |
YSI | 3:7e15bf0a71f4 | 57 | void set(bool TCP, const char* IP="", uint16_t PORT=80); |
YSI | 3:7e15bf0a71f4 | 58 | string get(void); |
YSI | 2:ec88f3f8b619 | 59 | enumTRANSTATUS recv(void); |
YSI | 1:27f6baabb15e | 60 | nsapi_error_t send(const string& BUFFER, const enumTRANSMISSION& TYPE); |
YSI | 1:27f6baabb15e | 61 | bool smtp(const char* MAIL, const char* FROM="", const char* SUBJECT="", const char* DATA=""); |
YSI | 3:7e15bf0a71f4 | 62 | void http(void); |
YSI | 0:2fc6fc3b5e15 | 63 | |
YSI | 0:2fc6fc3b5e15 | 64 | private: |
YSI | 3:7e15bf0a71f4 | 65 | typeTRANSMISSION message = { {"", ""}, RED_DISCONNECTED, false, false, false, false, false, "", 80 }; |
YSI | 2:ec88f3f8b619 | 66 | UnbufferedSerial *_serial; |
YSI | 2:ec88f3f8b619 | 67 | EthernetInterface *_eth; |
YSI | 2:ec88f3f8b619 | 68 | EventQueue *_queue; |
YSI | 3:7e15bf0a71f4 | 69 | TCPSocket *_clientTCP = NULL; |
YSI | 3:7e15bf0a71f4 | 70 | TCPSocket _serverTCP; |
YSI | 0:2fc6fc3b5e15 | 71 | |
YSI | 1:27f6baabb15e | 72 | void (*fn_init)(void); |
YSI | 1:27f6baabb15e | 73 | void (*fn_processing)(string, const enumTRANSMISSION&); |
YSI | 0:2fc6fc3b5e15 | 74 | |
YSI | 0:2fc6fc3b5e15 | 75 | /* EthernetInterface */ |
YSI | 0:2fc6fc3b5e15 | 76 | bool eth_connect(void); |
YSI | 0:2fc6fc3b5e15 | 77 | void eth_event(nsapi_event_t, intptr_t); |
YSI | 1:27f6baabb15e | 78 | intptr_t eth_status(const string&, const intptr_t&); |
YSI | 1:27f6baabb15e | 79 | nsapi_error_t eth_error(const string& SOURCE, const nsapi_error_t& CODE); |
YSI | 0:2fc6fc3b5e15 | 80 | |
YSI | 0:2fc6fc3b5e15 | 81 | /* serverTCP */ |
YSI | 0:2fc6fc3b5e15 | 82 | bool serverTCP_connect(void); |
YSI | 0:2fc6fc3b5e15 | 83 | void serverTCP_accept(void); |
YSI | 0:2fc6fc3b5e15 | 84 | void serverTCP_event(void); |
YSI | 0:2fc6fc3b5e15 | 85 | }; |
YSI | 0:2fc6fc3b5e15 | 86 | |
YSI | 0:2fc6fc3b5e15 | 87 | #endif |