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
Diff: lib_Transmission.h
- Revision:
- 4:9a4ab4f406ab
- Parent:
- 3:7e15bf0a71f4
- Child:
- 6:d6a07fd1548a
--- a/lib_Transmission.h Wed Jul 08 12:26:35 2020 +0000 +++ b/lib_Transmission.h Fri Jul 10 15:17:25 2020 +0000 @@ -19,26 +19,24 @@ * @date Jun 2020 * @author Yannic Simon */ -#ifndef COM_H -#define COM_H +#ifndef TRANSMISSION_H +#define TRANSMISSION_H #include "mbed.h" #include "EthernetInterface.h" #include <sstream> -#define TCP_CLIENT_TIMEOUT 100 // configue client bloquante avec timeout sinon limite de transmission a 1072 octets -#define SMTP_SERVER "129.175.212.70" // smtp.u-psud.fr oblige a utiliser DNS avec eth.getHostByName("smtp.u-psud.fr") +#define TCP_CLIENT_TIMEOUT 100 // config client bloquante avec timeout sinon limite de transmission a 1072 octets +#define SMTP_SERVER "129.175.212.70" // IP sinon utilisation du DNS avec eth.getHostByName("smtp.u-psud.fr") -enum enumTRANSMISSION { TCP, SERIAL }; +enum enumTRANSMISSION { TCP, SERIAL, BOTH }; enum enumTRANSTATUS { WHITE, CYAN, MAGENTA_ACCEPT, BLUE_CLIENT, YELLOW_CONNECTING, GREEN_GLOBAL_UP, RED_DISCONNECTED, BLACK_INITIALIZE }; -struct typeTRANSMISSION { string buffer[2]; enumTRANSTATUS status; bool TCP; bool HTTP; bool BREAK; bool DHCP; bool CONNECT; string IP; uint16_t PORT; }; /** Transmission class */ class Transmission { public: - uint16_t _PORT = 80; /** make new Transmission instance * connected to * @@ -52,36 +50,69 @@ * @param * @param * @returns none - */ - /* communication */ - void set(bool TCP, const char* IP="", uint16_t PORT=80); - string get(void); - enumTRANSTATUS recv(void); - nsapi_error_t send(const string& BUFFER, const enumTRANSMISSION& TYPE); - bool smtp(const char* MAIL, const char* FROM="", const char* SUBJECT="", const char* DATA=""); - void http(void); + */ + void set(bool TCP, const char* IP="", uint16_t PORT=80); + /** + * + * @param + * @param + * @returns none + */ + string get(void); + /** + * + * @param + * @param + * @returns none + */ + enumTRANSTATUS recv(void); + /** + * + * @param + * @param + * @returns none + */ + nsapi_error_t send(const string& BUFFER, const enumTRANSMISSION& TYPE); + /** + * + * @param + * @param + * @returns none + */ + bool smtp(const char* MAIL, const char* FROM="", const char* SUBJECT="", const char* DATA=""); + /** + * + * @param + * @param + * @returns none + */ + void http(void); private: - typeTRANSMISSION message = { {"", ""}, RED_DISCONNECTED, false, false, false, false, false, "", 80 }; UnbufferedSerial *_serial; EthernetInterface *_eth; EventQueue *_queue; TCPSocket *_clientTCP = NULL; TCPSocket _serverTCP; - void (*fn_init)(void); - void (*fn_processing)(string, const enumTRANSMISSION&); + /* Transmission */ + void (*fn_init)(void); + void (*fn_processing)(string, const enumTRANSMISSION&); /* EthernetInterface */ - bool eth_connect(void); - void eth_event(nsapi_event_t, intptr_t); - intptr_t eth_status(const string&, const intptr_t&); - nsapi_error_t eth_error(const string& SOURCE, const nsapi_error_t& CODE); + void eth_state(void); + bool eth_connect(void); + void eth_event(nsapi_event_t, intptr_t); + intptr_t eth_status(const string&, const intptr_t&); + nsapi_error_t eth_error(const string& SOURCE, const nsapi_error_t& CODE); /* serverTCP */ - bool serverTCP_connect(void); - void serverTCP_accept(void); - void serverTCP_event(void); + bool serverTCP_connect(void); + void serverTCP_accept(void); + void serverTCP_event(void); + + struct typeTRANSMISSION { string buffer[2]; enumTRANSTATUS status; bool TCP; bool HTTP; bool BREAK; bool DHCP; bool CONNECT; string IP; uint16_t PORT; } + message = { {"", ""}, RED_DISCONNECTED, false, false, false, false, false, "", 80 }; }; #endif \ No newline at end of file