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:
Wed Jun 24 14:30:34 2020 +0000
Revision:
0:2fc6fc3b5e15
Child:
1:27f6baabb15e
lib_Transmission

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 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 0:2fc6fc3b5e15 29 #define TCP_SET_DHCP true
YSI 0:2fc6fc3b5e15 30 #define TCP_IP "192.168.1.25"
YSI 0:2fc6fc3b5e15 31 #define TCP_NETMASK "255.255.255.0"
YSI 0:2fc6fc3b5e15 32 #define TCP_GATEWAY "192.168.1.1"
YSI 0:2fc6fc3b5e15 33 #define TCP_PORT 80
YSI 0:2fc6fc3b5e15 34 #define TCP_CLIENT_TIMEOUT 100 // client configue bloquante avec timeout sinon limite de transmission a 1072 octets
YSI 0:2fc6fc3b5e15 35 #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 36
YSI 0:2fc6fc3b5e15 37 enum enumCOM { TCP, SERIAL };
YSI 0:2fc6fc3b5e15 38 enum enumCOLOR { WHITE, CYAN, MAGENTA_ACCEPT, BLUE_CLIENT, YELLOW_CONNECTING, GREEN_GLOBAL_UP, RED_DISCONNECTED, BLACK_INITIALIZE };
YSI 0:2fc6fc3b5e15 39 struct typeTransmission { bool TCP; string buffer[2]; bool HTTP; bool BREAK; };
YSI 0:2fc6fc3b5e15 40
YSI 0:2fc6fc3b5e15 41 /** Transmission class
YSI 0:2fc6fc3b5e15 42 */
YSI 0:2fc6fc3b5e15 43 class Transmission
YSI 0:2fc6fc3b5e15 44 {
YSI 0:2fc6fc3b5e15 45 public:
YSI 0:2fc6fc3b5e15 46 /** make new Transmission instance
YSI 0:2fc6fc3b5e15 47 * connected to
YSI 0:2fc6fc3b5e15 48 *
YSI 0:2fc6fc3b5e15 49 * @param
YSI 0:2fc6fc3b5e15 50 * @param
YSI 0:2fc6fc3b5e15 51 */
YSI 0:2fc6fc3b5e15 52 Transmission(UnbufferedSerial *serial, EthernetInterface *eth, EventQueue *queue, void(*com_init)(void), void(*com_processing)(string, const enumCOM&));
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 0:2fc6fc3b5e15 59 */
YSI 0:2fc6fc3b5e15 60 /* communication */
YSI 0:2fc6fc3b5e15 61 enumCOLOR recv(void);
YSI 0:2fc6fc3b5e15 62 nsapi_error_t send(const string& BUFFER, const enumCOM& TYPE);
YSI 0:2fc6fc3b5e15 63
YSI 0:2fc6fc3b5e15 64 bool sendSMTP(const char* MAIL, const char* FROM, const char* SUBJECT, const char* DATA);
YSI 0:2fc6fc3b5e15 65 bool checkSMTP(const char* MAIL);
YSI 0:2fc6fc3b5e15 66
YSI 0:2fc6fc3b5e15 67 intptr_t eth_status(const string&, const intptr_t&);
YSI 0:2fc6fc3b5e15 68 nsapi_error_t eth_error(const string& SOURCE, const nsapi_error_t& CODE);
YSI 0:2fc6fc3b5e15 69
YSI 0:2fc6fc3b5e15 70 typeTransmission message = { true, {"", ""}, false, false };
YSI 0:2fc6fc3b5e15 71 private:
YSI 0:2fc6fc3b5e15 72 void(*fn_com_init)(void);
YSI 0:2fc6fc3b5e15 73 void(*fn_com_processing)(string, const enumCOM&);
YSI 0:2fc6fc3b5e15 74
YSI 0:2fc6fc3b5e15 75 UnbufferedSerial *_serial;
YSI 0:2fc6fc3b5e15 76 EthernetInterface *_eth;
YSI 0:2fc6fc3b5e15 77 EventQueue *_queue;
YSI 0:2fc6fc3b5e15 78 TCPSocket *clientTCP = NULL;
YSI 0:2fc6fc3b5e15 79 TCPSocket serverTCP;
YSI 0:2fc6fc3b5e15 80
YSI 0:2fc6fc3b5e15 81 enumCOLOR statusCOLOR = RED_DISCONNECTED;
YSI 0:2fc6fc3b5e15 82
YSI 0:2fc6fc3b5e15 83 /* EthernetInterface */
YSI 0:2fc6fc3b5e15 84 bool eth_connect(void);
YSI 0:2fc6fc3b5e15 85 void eth_event(nsapi_event_t, intptr_t);
YSI 0:2fc6fc3b5e15 86
YSI 0:2fc6fc3b5e15 87
YSI 0:2fc6fc3b5e15 88 /* serverTCP */
YSI 0:2fc6fc3b5e15 89 bool serverTCP_connect(void);
YSI 0:2fc6fc3b5e15 90 void serverTCP_accept(void);
YSI 0:2fc6fc3b5e15 91 void serverTCP_event(void);
YSI 0:2fc6fc3b5e15 92 };
YSI 0:2fc6fc3b5e15 93
YSI 0:2fc6fc3b5e15 94 #endif