1 #ifndef pfodSMS_SIM900_h
2 #define pfodSMS_SIM900_h
22 #define SMS_MAX_SIZE 160
23 #define SMS_RX_BUFFER_SIZE 267
26 #define SMS_TX_MSG_SIZE 1026
28 #define SMS_TX_BUFFER_SIZE (SMS_TX_MSG_SIZE+8+2)
35 void init(Stream *_gprs,
int powerOnOffPin);
50 const static int MAX_PHNO_LEN = 20;
51 const static int MAX_PHNO_CHECK = 6;
62 char returnPhNo[MAX_PHNO_LEN + 1];
65 struct knownConnection {
67 char returnPhNo[MAX_PHNO_LEN + 1];
70 static const int MAX_KNOWN_CONNECTION = 10;
71 struct knownConnection knownConnectionsArray[MAX_KNOWN_CONNECTION];
72 struct knownConnection* knownArrayPtrs[MAX_KNOWN_CONNECTION];
75 int findEmptyKnownConnection();
76 void updateMsgNoForStartNewCommand();
77 void updateMsgNoForStartResend();
79 void stopResponseSends();
82 void clearKnownConnection(knownConnection *kCon);
83 void clearKnownConnection(
int idx);
84 void printKnownConnections();
85 void printKnownConnection(knownConnection *kCon);
86 void swapKnownConnections();
87 void setTopKnownConnectionFromCurrent();
88 void moveKnownConnectionToTop(
int idx);
89 void updateKnownConnectionNo(connection *con);
90 void updateKnownConnectionNoAndMoveToTop(connection *con);
91 void setNextExpectedConnectionMsgNo(connection *con,
boolean foundEndParens);
93 typedef enum decode_sms_return_t {
98 PROCESS_NEXT_PART_OF_COMMAND,
99 CLOSE_CONNECTION_AND_UPDATE_CONNECTION,
100 NEW_CONNECTION_SAME_PHONE_NO,
102 START_NEW_CONNECTION,
103 START_NEW_CONNECTION_AND_CLOSE
104 } decode_sms_return_t;
106 decode_sms_return_t decodeSMS(connection *current, connection *next,
const char* smsChars,
byte* decodedSMS,
107 size_t* currentDecodedLen);
111 void clearResponseSet();
112 boolean decodeSMScmd(
const char*smsChars,
byte*decodedSMS,
size_t* currentDecodedLen);
113 int checkSMSmsgForValidNewConnection(
int connectionNo,
int msgNo,
const char* decodedSMS,
boolean foundCmdClose);
114 size_t encodeSMS(
int connectionNo,
int msgNo,
const byte* msgBytes,
size_t msgBytesIdx,
char* encodedSMS);
117 const char* findStr(
const char* msg,
const __FlashStringHelper *ifsh);
118 const char *findStr(
const char* str,
const char* target);
120 const static size_t MAX_BYTES_TO_CONVERT = 117;
122 const static int MAX_MSG_NO_LEN = 3;
123 const static int MAX_MSG_LEN = 256;
124 char gprsMsg[MAX_MSG_LEN + 1];
126 unsigned char gprsLastChar;
128 const static int MAX_INCOMING_MSG_NOS = 10;
130 uint8_t incomingMsgNos_head;
131 uint8_t incomingMsgNos_tail;
140 char incomingMsgNos[MAX_INCOMING_MSG_NOS + 1][MAX_MSG_NO_LEN + 1];
141 void requestIncomingSmsMsg(
const char *msgNo);
150 static const int SMS_RAWDATA_TX_BUFFER_SIZE = MAX_BYTES_TO_CONVERT - 1;
151 byte rawdataTxBuffer[SMS_RAWDATA_TX_BUFFER_SIZE + 1];
152 size_t rawdataTxBufferLen;
153 size_t rawdataTxBufferIdx;
156 void clearRawdataTxBuffer();
157 boolean isSendingResponse();
158 boolean haveRequestedIncomingMsg;
159 void requestNextIncomingMsg();
161 boolean expectingMessageLines;
162 boolean sendingRawdata;
163 boolean sendingResponse;
164 boolean sendingResend;
165 boolean resendLastResponse;
168 boolean deleteReadSmsMsgs;
171 struct connection connection_A;
172 struct connection connection_B;
173 struct connection *currentConnection;
174 struct connection *nextConnection;
176 void sendSMSrawData();
178 const char* collectGprsMsgs();
179 void clearGprsLine();
180 void processGprsLine(
const char* line);
183 int decodeInt(
const char*smsChars,
size_t idx);
184 size_t encodeInt(
int number,
char*rtn,
size_t idx);
185 size_t convertThree8Bytes(
long three8Bytes,
char*rtn,
size_t idx);
186 byte decodeSMSChar(
byte encodedChar);
187 byte encodeSMSChar(
byte encodedChar);
190 const static byte invalidSMSCharReturn = 0xff;
191 byte bytesToConvert[MAX_BYTES_TO_CONVERT + 1];
193 void closeConnection(connection* con);
194 void clearConnection(connection* con);
196 boolean newConnectionNumberGreater(
int current,
int next);
197 boolean validSMSmsgLen(
const char* smsChars);
198 void printIgnoreOutOfSequence();
199 unsigned long timedOutTimer;
200 unsigned long start_mS;
201 int findMatchingKnownPhoneNo(
const char *phNo);
202 boolean phoneNoMatchesCurrent(
const char*newPhNo);
203 boolean phoneNoMatches(
const char*oldPhNo,
const char*newPhNo);
204 boolean phoneNoHas6Digits(
const char *phNo);
205 void checkGPRSpoweredUp();
208 boolean powerUpGPRS();
209 void clearTxBuffer();
211 void printConnection(connection* con);
212 void swapConnections();
213 void setPhoneNo(connection *con,
const char* phNo);
215 void printCurrentConnection();
216 void printNextConnection();
218 void startSMS(
const char* phoneNo);
220 void clearReadSmsMsgs();
221 void clearAllSmsMsgs();
222 void emptyIncomingMsgNo();
224 void gprsPrint(
const char* str);
225 void gprsPrint(
char c);
226 void gprsPrint(
const __FlashStringHelper *ifsh);
228 boolean haveIncomingMsgNo();
229 boolean addIncomingMsgNo(
const char* msgNo);
230 const char* getIncomingMsgNo();
231 void deleteIncomingMsg(
const char *newMsgNo);
pfod_Base for Arduino Base class for all pfod_Base_xxxx classes The subclasses pfod_Base_xxx must ove...
size_t writeRawData(uint8_t c)
unsigned long getDefaultTimeOut()
void init(Stream *_gprs, int powerOnOffPin)
void _closeCurrentConnection()
void setDebugStream(Stream *out)
Stream * getPfodAppStream()
Print * getRawDataOutput()
#define SMS_TX_BUFFER_SIZE
#define SMS_RX_BUFFER_SIZE