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:
Thu Oct 01 11:35:46 2020 +0000
Revision:
7:98b12722e9e2
Parent:
6:d6a07fd1548a
Child:
8:7193327bed34
fix ntp light hour

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 6:d6a07fd1548a 29 #define REQUEST_TIMEOUT 100 // config client bloquante avec timeout sinon limite de transmission a 1072 octets
YSI 4:9a4ab4f406ab 30 #define SMTP_SERVER "129.175.212.70" // IP sinon utilisation du DNS avec eth.getHostByName("smtp.u-psud.fr")
YSI 6:d6a07fd1548a 31 #define NTP_SERVER "129.175.34.43" // IP sinon utilisation du DNS avec eth.getHostByName("ntp.u-psud.fr")
YSI 0:2fc6fc3b5e15 32
YSI 4:9a4ab4f406ab 33 enum enumTRANSMISSION { TCP, SERIAL, BOTH };
YSI 3:7e15bf0a71f4 34 enum enumTRANSTATUS { WHITE, CYAN, MAGENTA_ACCEPT, BLUE_CLIENT, YELLOW_CONNECTING, GREEN_GLOBAL_UP, RED_DISCONNECTED, BLACK_INITIALIZE };
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 0:2fc6fc3b5e15 41 /** make new Transmission instance
YSI 0:2fc6fc3b5e15 42 * connected to
YSI 0:2fc6fc3b5e15 43 *
YSI 0:2fc6fc3b5e15 44 * @param
YSI 0:2fc6fc3b5e15 45 * @param
YSI 0:2fc6fc3b5e15 46 */
YSI 1:27f6baabb15e 47 Transmission(UnbufferedSerial *serial, EthernetInterface *eth, EventQueue *queue, void(*_init)(void), void(*_processing)(string, const enumTRANSMISSION&));
YSI 0:2fc6fc3b5e15 48
YSI 0:2fc6fc3b5e15 49 /**
YSI 0:2fc6fc3b5e15 50 *
YSI 0:2fc6fc3b5e15 51 * @param
YSI 0:2fc6fc3b5e15 52 * @param
YSI 0:2fc6fc3b5e15 53 * @returns none
YSI 4:9a4ab4f406ab 54 */
YSI 4:9a4ab4f406ab 55 void set(bool TCP, const char* IP="", uint16_t PORT=80);
YSI 4:9a4ab4f406ab 56 /**
YSI 4:9a4ab4f406ab 57 *
YSI 4:9a4ab4f406ab 58 * @param
YSI 4:9a4ab4f406ab 59 * @param
YSI 4:9a4ab4f406ab 60 * @returns none
YSI 4:9a4ab4f406ab 61 */
YSI 4:9a4ab4f406ab 62 string get(void);
YSI 4:9a4ab4f406ab 63 /**
YSI 4:9a4ab4f406ab 64 *
YSI 4:9a4ab4f406ab 65 * @param
YSI 4:9a4ab4f406ab 66 * @param
YSI 4:9a4ab4f406ab 67 * @returns none
YSI 4:9a4ab4f406ab 68 */
YSI 4:9a4ab4f406ab 69 enumTRANSTATUS recv(void);
YSI 4:9a4ab4f406ab 70 /**
YSI 4:9a4ab4f406ab 71 *
YSI 4:9a4ab4f406ab 72 * @param
YSI 4:9a4ab4f406ab 73 * @param
YSI 4:9a4ab4f406ab 74 * @returns none
YSI 4:9a4ab4f406ab 75 */
YSI 4:9a4ab4f406ab 76 nsapi_error_t send(const string& BUFFER, const enumTRANSMISSION& TYPE);
YSI 4:9a4ab4f406ab 77 /**
YSI 4:9a4ab4f406ab 78 *
YSI 4:9a4ab4f406ab 79 * @param
YSI 4:9a4ab4f406ab 80 * @param
YSI 4:9a4ab4f406ab 81 * @returns none
YSI 4:9a4ab4f406ab 82 */
YSI 4:9a4ab4f406ab 83 bool smtp(const char* MAIL, const char* FROM="", const char* SUBJECT="", const char* DATA="");
YSI 4:9a4ab4f406ab 84 /**
YSI 4:9a4ab4f406ab 85 *
YSI 4:9a4ab4f406ab 86 * @param
YSI 4:9a4ab4f406ab 87 * @param
YSI 4:9a4ab4f406ab 88 * @returns none
YSI 4:9a4ab4f406ab 89 */
YSI 6:d6a07fd1548a 90 time_t ntp(void);
YSI 6:d6a07fd1548a 91 /**
YSI 6:d6a07fd1548a 92 *
YSI 6:d6a07fd1548a 93 * @param
YSI 6:d6a07fd1548a 94 * @param
YSI 6:d6a07fd1548a 95 * @returns none
YSI 6:d6a07fd1548a 96 */
YSI 4:9a4ab4f406ab 97 void http(void);
YSI 0:2fc6fc3b5e15 98
YSI 0:2fc6fc3b5e15 99 private:
YSI 2:ec88f3f8b619 100 UnbufferedSerial *_serial;
YSI 2:ec88f3f8b619 101 EthernetInterface *_eth;
YSI 2:ec88f3f8b619 102 EventQueue *_queue;
YSI 3:7e15bf0a71f4 103 TCPSocket *_clientTCP = NULL;
YSI 3:7e15bf0a71f4 104 TCPSocket _serverTCP;
YSI 0:2fc6fc3b5e15 105
YSI 4:9a4ab4f406ab 106 /* Transmission */
YSI 4:9a4ab4f406ab 107 void (*fn_init)(void);
YSI 4:9a4ab4f406ab 108 void (*fn_processing)(string, const enumTRANSMISSION&);
YSI 0:2fc6fc3b5e15 109
YSI 0:2fc6fc3b5e15 110 /* EthernetInterface */
YSI 4:9a4ab4f406ab 111 void eth_state(void);
YSI 4:9a4ab4f406ab 112 bool eth_connect(void);
YSI 4:9a4ab4f406ab 113 void eth_event(nsapi_event_t, intptr_t);
YSI 4:9a4ab4f406ab 114 intptr_t eth_status(const string&, const intptr_t&);
YSI 4:9a4ab4f406ab 115 nsapi_error_t eth_error(const string& SOURCE, const nsapi_error_t& CODE);
YSI 0:2fc6fc3b5e15 116
YSI 0:2fc6fc3b5e15 117 /* serverTCP */
YSI 4:9a4ab4f406ab 118 bool serverTCP_connect(void);
YSI 4:9a4ab4f406ab 119 void serverTCP_accept(void);
YSI 4:9a4ab4f406ab 120 void serverTCP_event(void);
YSI 4:9a4ab4f406ab 121
YSI 4:9a4ab4f406ab 122 struct typeTRANSMISSION { string buffer[2]; enumTRANSTATUS status; bool TCP; bool HTTP; bool BREAK; bool DHCP; bool CONNECT; string IP; uint16_t PORT; }
YSI 4:9a4ab4f406ab 123 message = { {"", ""}, RED_DISCONNECTED, false, false, false, false, false, "", 80 };
YSI 0:2fc6fc3b5e15 124 };
YSI 0:2fc6fc3b5e15 125
YSI 0:2fc6fc3b5e15 126 #endif