BayEOS-Arduino  1.8.0_0.0.4
BayTCP.h
1 
10 #ifndef BayTCP_h
11 #define BayTCP_h
12 
13 
14 #ifndef BayTCP_BUFFER
15 #define BayTCP_BUFFER 136
16 #endif
17 
18 #define BayTCP_CONFIG_SERVER 0
19 #define BayTCP_CONFIG_PORT 1
20 #define BayTCP_CONFIG_PATH 2
21 #define BayTCP_CONFIG_USER 3
22 #define BayTCP_CONFIG_PASSWORD 4
23 #define BayTCP_CONFIG_SENDER 5
24 #define BayTCP_CONFIG_APN 6
25 #define BayTCP_CONFIG_PROVPW 7
26 #define BayTCP_CONFIG_PROVUSER 8
27 #define BayTCP_CONFIG_PIN 9
28 #define BayTCP_CONFIG_MAC 6
29 #define BayTCP_CONFIG_IP 7
30 #define BayTCP_CONFIG_MASK 8
31 #define BayTCP_CONFIG_DEFAULT_GW 9
32 
33 #define BayTCP_CONFIG_SIZE 140
34 #define BayTCP_EEPROM_OFFSET 400
35 
36 #define BayTCP_DEBUG_OUTPUT 0
37 #define BayTCP_DEBUG_INPUT 0
38 
39 #define printP(x) printPGM(PSTR(x))
40 #define printlnP(x) printlnPGM(PSTR(x))
41 #define wait_for(x,y) wait_forPGM(PSTR(x),y)
42 #define SerialprintP(x) serialprintPGM(PSTR(x))
43 #define SerialprintlnP(x) serialprintlnPGM(PSTR(x))
44 
45 
46 #include <inttypes.h>
47 #include <BayEOS.h>
48 #include "Base64.h"
49 #include <Arduino.h>
50 #include <EEPROM.h>
51 #include "../BayEOSBuffer/BayEOSBuffer.h"
52 #include "../SdFat/SdFat.h"
53 
54 
55 class BayTCPInterface : public Stream, public BayEOS {
56 protected:
57 // virtual uint8_t i_init() = 0;
58  virtual int i_available() = 0;
59 public:
60  using Print::write; // pull in write(str) and write(buf, size) from Print
68  uint8_t sendPayload(void);
69 
70 
78  virtual uint8_t connect(void)=0;
79 
83  virtual void disconnect(void)=0;
84 
85 
86 
87 
95  uint8_t sendMultiFromBuffer(uint16_t maxsize=5000);
96 
100  void setConfig(const char *str,uint8_t index);
101 
107  void readConfigFromStringPGM(const char* string);
108 
113  void readConfigFromFile(const char* file);
117  void readConfigFromEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET);
121  void writeConfigToEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET);
122 
127  const char* getConfig(void);
128 
129  const uint8_t* parseMAC(const char* str);
130  const uint8_t* parseIP(const char* str);
131  uint8_t hex2int(const char c);
132 
137  char** getConfigPointer(uint8_t index);
138 
142  boolean _urlencode;
143 protected:
144  virtual void flushMTU(void)=0;
145  virtual void finishTransmissionMode(void)=0;
146  void printPostHeader(uint16_t size);
147  void setConfigPointers(void);
148  uint8_t addToConfigBuffer(uint8_t offset,const char* str);
149 
150  void skipChars(void);
151  uint8_t wait_forOK(uint16_t timeout);
152  uint8_t wait_forPGM(const char* str, uint16_t timeout,uint8_t bytes=0, char* buffer=NULL);
153  uint8_t wait_for_available(uint16_t* timeout,int bytes=1);
154  void printPGM(const char *str);
155  void printlnPGM(const char *str);
156  void serialprintPGM(const char *str);
157  void serialprintlnPGM(const char *str);
158 
159  uint8_t _mac_ip[6];
160  char _config_buffer[BayTCP_CONFIG_SIZE];
161  char _pgm_buffer[20];
162  char* _server; //0
163  char* _port; //1
164  char* _path; //2
165  char* _user; //3
166  char* _password; //4
167  char* _sender; //5
168  char* _apn; //6
169  char* _prov_pw; //7
170  char* _prov_user; //8
171  char* _pin; //9
172  char _base64buffer[BayTCP_BUFFER];
173  uint8_t _tx_error_count;
174  uint16_t _mtu;
175  int strlenURLencoded(const char *str);
176  void printURLencoded(const char *str);
177  static const char* const _urlencodedChars;
178 
179 };
180 
181 
182 
183 
184 
185 
186 #endif
void readConfigFromStringPGM(const char *string)
Definition: BayTCP.cpp:312
virtual uint8_t connect(void)=0
void setConfig(const char *str, uint8_t index)
Definition: BayTCP.cpp:398
virtual void disconnect(void)=0
Definition: BayEOS.h:160
void readConfigFromEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET)
Definition: BayTCP.cpp:327
void readConfigFromFile(const char *file)
Definition: BayTCP.cpp:297
boolean _urlencode
Definition: BayTCP.h:142
uint8_t sendMultiFromBuffer(uint16_t maxsize=5000)
Definition: BayTCP.cpp:153
char ** getConfigPointer(uint8_t index)
Definition: BayTCP.cpp:348
uint8_t sendPayload(void)
Definition: BayTCP.cpp:243
const char * getConfig(void)
Definition: BayTCP.cpp:344
void writeConfigToEEPROM(int eeoffset=BayTCP_EEPROM_OFFSET)
Definition: BayTCP.cpp:338