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

Committer:
YSI
Date:
Fri Dec 11 09:12:40 2020 +0000
Revision:
12:e22ff63d237c
Parent:
11:de94dcd67561
Child:
13:1e13e40b03c9
add retrocompatibility with mbed-os-5

Who changed what in which revision?

UserRevisionLine numberNew 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 4:9a4ab4f406ab 22 #ifndef TRANSMISSION_H
YSI 4:9a4ab4f406ab 23 #define TRANSMISSION_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 8:7193327bed34 29 #define NDEBUG
YSI 8:7193327bed34 30 #define REQUEST_TIMEOUT 100 // config client bloquante avec timeout sinon limite de transmission a 1072 octets
YSI 9:abd4a4944399 31 #define SMTP_SERVER "129.175.212.70" // IP sinon utilisation du DNS avec _eth.getHostByName("smtp.u-psud.fr")
YSI 9:abd4a4944399 32 #define NTP_SERVER "129.175.34.43" // IP sinon utilisation du DNS avec _eth.getHostByName("ntp.u-psud.fr")
YSI 0:2fc6fc3b5e15 33
YSI 0:2fc6fc3b5e15 34
YSI 0:2fc6fc3b5e15 35 /** Transmission class
YSI 0:2fc6fc3b5e15 36 */
YSI 0:2fc6fc3b5e15 37 class Transmission
YSI 0:2fc6fc3b5e15 38 {
YSI 0:2fc6fc3b5e15 39 public:
YSI 11:de94dcd67561 40 typedef enum { SERIAL, TCP, HTTP, ANY } enum_trans_to;
YSI 11:de94dcd67561 41 typedef enum { WHITE, CYAN, MAGENTA_ACCEPT, BLUE_CLIENT, YELLOW_CONNECTING, GREEN_GLOBAL_UP, RED_DISCONNECTED, BLACK_INITIALIZE } enum_trans_status;
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 12:e22ff63d237c 48 #if MBED_MAJOR_VERSION > 5
YSI 11:de94dcd67561 49 Transmission(UnbufferedSerial *serial, EthernetInterface *eth, void(*init)(void), void(*processing)(string, Transmission::enum_trans_to));
YSI 12:e22ff63d237c 50 #else
YSI 12:e22ff63d237c 51 Transmission(Serial *serial, EthernetInterface *eth, void(*init)(void), void(*processing)(string, Transmission::enum_trans_to));
YSI 12:e22ff63d237c 52 #endif
YSI 0:2fc6fc3b5e15 53
YSI 0:2fc6fc3b5e15 54 /**
YSI 0:2fc6fc3b5e15 55 *
YSI 0:2fc6fc3b5e15 56 * @param
YSI 0:2fc6fc3b5e15 57 * @param
YSI 0:2fc6fc3b5e15 58 * @returns none
YSI 4:9a4ab4f406ab 59 */
YSI 10:25e049353db5 60 string set(bool SET, const char* IP="", uint16_t PORT=80);
YSI 4:9a4ab4f406ab 61 /**
YSI 4:9a4ab4f406ab 62 *
YSI 4:9a4ab4f406ab 63 * @param
YSI 4:9a4ab4f406ab 64 * @param
YSI 4:9a4ab4f406ab 65 * @returns none
YSI 4:9a4ab4f406ab 66 */
YSI 4:9a4ab4f406ab 67 string get(void);
YSI 4:9a4ab4f406ab 68 /**
YSI 4:9a4ab4f406ab 69 *
YSI 4:9a4ab4f406ab 70 * @param
YSI 4:9a4ab4f406ab 71 * @param
YSI 4:9a4ab4f406ab 72 * @returns none
YSI 4:9a4ab4f406ab 73 */
YSI 11:de94dcd67561 74 enum_trans_status recv(void);
YSI 4:9a4ab4f406ab 75 /**
YSI 4:9a4ab4f406ab 76 *
YSI 4:9a4ab4f406ab 77 * @param
YSI 4:9a4ab4f406ab 78 * @param
YSI 4:9a4ab4f406ab 79 * @returns none
YSI 4:9a4ab4f406ab 80 */
YSI 11:de94dcd67561 81 nsapi_error_t send(const string& BUFFER, const enum_trans_to& TYPE);
YSI 4:9a4ab4f406ab 82 /**
YSI 4:9a4ab4f406ab 83 *
YSI 4:9a4ab4f406ab 84 * @param
YSI 4:9a4ab4f406ab 85 * @param
YSI 4:9a4ab4f406ab 86 * @returns none
YSI 4:9a4ab4f406ab 87 */
YSI 4:9a4ab4f406ab 88 bool smtp(const char* MAIL, const char* FROM="", const char* SUBJECT="", const char* DATA="");
YSI 4:9a4ab4f406ab 89 /**
YSI 4:9a4ab4f406ab 90 *
YSI 4:9a4ab4f406ab 91 * @param
YSI 4:9a4ab4f406ab 92 * @param
YSI 4:9a4ab4f406ab 93 * @returns none
YSI 4:9a4ab4f406ab 94 */
YSI 9:abd4a4944399 95 time_t ntp(const char* ADDRESS="");
YSI 0:2fc6fc3b5e15 96
YSI 0:2fc6fc3b5e15 97 private:
YSI 8:7193327bed34 98 Thread _queueThread;
YSI 8:7193327bed34 99 EventQueue _queue;
YSI 12:e22ff63d237c 100 #if MBED_MAJOR_VERSION > 5
YSI 2:ec88f3f8b619 101 UnbufferedSerial *_serial;
YSI 12:e22ff63d237c 102 #else
YSI 12:e22ff63d237c 103 Serial *_serial;
YSI 12:e22ff63d237c 104 #endif
YSI 2:ec88f3f8b619 105 EthernetInterface *_eth;
YSI 3:7e15bf0a71f4 106 TCPSocket *_clientTCP = NULL;
YSI 3:7e15bf0a71f4 107 TCPSocket _serverTCP;
YSI 0:2fc6fc3b5e15 108
YSI 8:7193327bed34 109 /* EthernetInterface */
YSI 8:7193327bed34 110 void eth_state(void);
YSI 8:7193327bed34 111 bool eth_connect(void);
YSI 8:7193327bed34 112 void eth_event(nsapi_event_t, intptr_t);
YSI 8:7193327bed34 113 intptr_t eth_status(const string&, const intptr_t&);
YSI 8:7193327bed34 114 nsapi_error_t eth_error(const string& SOURCE, const nsapi_error_t& CODE);
YSI 8:7193327bed34 115
YSI 8:7193327bed34 116 /* serverTCP */
YSI 8:7193327bed34 117 bool serverTCP_connect(void);
YSI 8:7193327bed34 118 void serverTCP_accept(void);
YSI 8:7193327bed34 119 void serverTCP_event(void);
YSI 8:7193327bed34 120
YSI 10:25e049353db5 121 /* Transmission */
YSI 10:25e049353db5 122 void (*_init)(void);
YSI 11:de94dcd67561 123 void (*_processing)(string, enum_trans_to);
YSI 11:de94dcd67561 124 struct typeTRANSMISSION { string serial; enum_trans_status status; bool SET; bool BREAK; bool DHCP; bool CONNECT; string IP; uint16_t PORT; } message = { "", RED_DISCONNECTED, false, false, false, false, "", 80 };
YSI 8:7193327bed34 125 };
YSI 0:2fc6fc3b5e15 126 #endif