1 #ifndef pfodSMS_SIM5320_h
2 #define pfodSMS_SIM5320_h
23 #define SMS_MAX_SIZE 160
24 #define SMS_RX_BUFFER_SIZE 267
27 #define SMS_TX_MSG_SIZE 1026
29 #define SMS_TX_BUFFER_SIZE (SMS_TX_MSG_SIZE+8+2)
36 void init(Stream *_gprs,
int resetPin = -1,
int powerOnOffPin = -1,
int powerStatusPin = -1);
54 const static int MAX_PHNO_LEN = 20;
55 const static int MAX_PHNO_CHECK = 6;
66 char returnPhNo[MAX_PHNO_LEN + 1];
69 struct knownConnection {
71 char returnPhNo[MAX_PHNO_LEN + 1];
74 static const int MAX_KNOWN_CONNECTION = 10;
75 struct knownConnection knownConnectionsArray[MAX_KNOWN_CONNECTION];
76 struct knownConnection* knownArrayPtrs[MAX_KNOWN_CONNECTION];
80 int findEmptyKnownConnection();
81 void updateMsgNoForStartNewCommand();
82 void updateMsgNoForStartResend();
84 void stopResponseSends();
87 void clearKnownConnection(knownConnection * kCon);
88 void clearKnownConnection(
int idx);
89 void printKnownConnections();
90 void printKnownConnection(knownConnection * kCon);
91 void swapKnownConnections();
92 void setTopKnownConnectionFromCurrent();
93 void moveKnownConnectionToTop(
int idx);
94 void updateKnownConnectionNo(connection * con);
95 void updateKnownConnectionNoAndMoveToTop(connection * con);
96 void setNextExpectedConnectionMsgNo(connection * con,
boolean foundEndParens);
98 typedef enum decode_sms_return_t {
100 RESEND_LAST_RESPONSE,
103 PROCESS_NEXT_PART_OF_COMMAND,
104 CLOSE_CONNECTION_AND_UPDATE_CONNECTION,
105 NEW_CONNECTION_SAME_PHONE_NO,
107 START_NEW_CONNECTION,
108 START_NEW_CONNECTION_AND_CLOSE
109 } decode_sms_return_t;
111 decode_sms_return_t decodeSMS(connection * current, connection * next,
const char* smsChars,
byte * decodedSMS,
112 size_t* currentDecodedLen);
114 bool havePowerResetPins;
117 void clearResponseSet();
118 boolean decodeSMScmd(
const char*smsChars,
byte * decodedSMS,
size_t* currentDecodedLen);
119 int checkSMSmsgForValidNewConnection(
int connectionNo,
int msgNo,
const char* decodedSMS,
boolean foundCmdClose);
120 size_t encodeSMS(
int connectionNo,
int msgNo,
const byte * msgBytes,
size_t msgBytesIdx,
char* encodedSMS);
123 const char* findStr(
const char* msg,
const __FlashStringHelper * ifsh);
124 const char *findStr(
const char* str,
const char* target);
126 const static size_t MAX_BYTES_TO_CONVERT = 117;
128 const static int MAX_MSG_NO_LEN = 3;
129 const static int MAX_MSG_LEN = 256;
130 char gprsMsg[MAX_MSG_LEN + 1];
132 unsigned char gprsLastChar;
134 const static int MAX_INCOMING_MSG_NOS = 10;
136 uint8_t incomingMsgNos_head;
137 uint8_t incomingMsgNos_tail;
146 char incomingMsgNos[MAX_INCOMING_MSG_NOS + 1][MAX_MSG_NO_LEN + 1];
147 void requestIncomingSmsMsg(
const char *msgNo);
156 static const int SMS_RAWDATA_TX_BUFFER_SIZE = MAX_BYTES_TO_CONVERT - 1;
157 byte rawdataTxBuffer[SMS_RAWDATA_TX_BUFFER_SIZE + 1];
158 size_t rawdataTxBufferLen;
159 size_t rawdataTxBufferIdx;
162 void clearRawdataTxBuffer();
163 boolean isSendingResponse();
164 boolean haveRequestedIncomingMsg;
165 void requestNextIncomingMsg();
167 boolean expectingMessageLines;
168 boolean sendingRawdata;
169 boolean sendingResponse;
170 boolean sendingResend;
171 boolean resendLastResponse;
174 boolean deleteReadSmsMsgs;
177 struct connection connection_A;
178 struct connection connection_B;
179 struct connection *currentConnection;
180 struct connection *nextConnection;
182 void sendSMSrawData();
184 const char* collectGprsMsgs();
185 void clearGprsLine();
186 void processGprsLine(
const char* line);
189 int decodeInt(
const char*smsChars,
size_t idx);
190 size_t encodeInt(
int number,
char*rtn,
size_t idx);
191 size_t convertThree8Bytes(
long three8Bytes,
char*rtn,
size_t idx);
192 byte decodeSMSChar(
byte encodedChar);
193 byte encodeSMSChar(
byte encodedChar);
196 const static byte invalidSMSCharReturn = 0xff;
197 byte bytesToConvert[MAX_BYTES_TO_CONVERT + 1];
199 void closeConnection(connection * con);
200 void clearConnection(connection * con);
202 boolean newConnectionNumberGreater(
int current,
int next);
203 boolean validSMSmsgLen(
const char* smsChars);
204 void printIgnoreOutOfSequence();
207 int findMatchingKnownPhoneNo(
const char *phNo);
208 boolean phoneNoMatchesCurrent(
const char*newPhNo);
209 boolean phoneNoMatches(
const char*oldPhNo,
const char*newPhNo);
210 boolean phoneNoHas6Digits(
const char *phNo);
211 void checkGPRSpoweredUp();
212 int powerCycleGPRS();
215 boolean powerUpGPRS();
216 void clearTxBuffer();
218 void printConnection(connection * con);
219 void swapConnections();
220 void setPhoneNo(connection * con,
const char* phNo);
222 void printCurrentConnection();
223 void printNextConnection();
226 void startSMS(
const char* phoneNo);
228 void clearReadSmsMsgs();
229 void clearAllSmsMsgs();
230 bool clearAllSmsMsgsOnInit();
231 void emptyIncomingMsgNo();
233 void gprsPrint(
const char* str);
234 void gprsPrint(
char c);
235 void gprsPrint(
const __FlashStringHelper * ifsh);
237 boolean haveIncomingMsgNo();
238 boolean addIncomingMsgNo(
const char* msgNo);
239 const char* getIncomingMsgNo();
240 void deleteIncomingMsg(
const char *newMsgNo);
pfod_Base for Arduino Base class for all pfod_Base_xxxx classes The subclasses pfod_Base_xxx must ove...
Print * getRawDataOutput()
Stream * getPfodAppStream()
void init(Stream *_gprs, int resetPin=-1, int powerOnOffPin=-1, int powerStatusPin=-1)
unsigned long getDefaultTimeOut()
size_t writeRawData(uint8_t c)
void setDebugStream(Stream *out)
void _closeCurrentConnection()
#define SMS_TX_BUFFER_SIZE
#define SMS_RX_BUFFER_SIZE