Skip to content

Commit e979fec

Browse files
Make all AT command public, and save some memory
1 parent e1adb4f commit e979fec

17 files changed

+134
-713
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
*.app
2929

3030
.gcc-flags.json
31+
.vscode

DTE.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ void DTE::debugPrint(const __FlashStringHelper *message, bool returnChar) {
1414
debugPrint(buffer, returnChar);
1515
}
1616

17+
/* DTE Class */
18+
DTE::DTE(HardwareSerial &hardwareSerial, int powerPin, bool debug) {
19+
this->hardwareSerial = &hardwareSerial;
20+
this->softwareSerial = NULL;
21+
this->powerPin = powerPin;
22+
this->debug = debug;
23+
this->response[0] = '\0';
24+
this->echo = true;
25+
this->flowControl = (struct FlowControl){0, true, 0, true};
26+
this->baudrate = -1;
27+
this->powerDown = true;
28+
29+
pinMode(this->powerPin, OUTPUT);
30+
digitalWrite(this->powerPin, LOW);
31+
}
32+
33+
DTE::DTE(SoftwareSerial &softwareSerial, int powerPin, bool debug) {
34+
this->hardwareSerial = NULL;
35+
this->softwareSerial = &softwareSerial;
36+
this->powerPin = powerPin;
37+
this->debug = debug;
38+
this->response[0] = '\0';
39+
this->echo = true;
40+
this->flowControl = (struct FlowControl){0, true, 0, true};
41+
this->baudrate = -1;
42+
this->powerDown = true;
43+
44+
pinMode(this->powerPin, OUTPUT);
45+
digitalWrite(this->powerPin, LOW);
46+
}
47+
1748
bool DTE::atReIssueLastCommand(void) {
1849
const __FlashStringHelper *command = F("A/\r");
1950

@@ -119,37 +150,6 @@ bool DTE::atSetFixedLocalRate(long baudrate) {
119150
return true;
120151
}
121152

122-
/* DTE Class */
123-
DTE::DTE(HardwareSerial &hardwareSerial, int powerPin, bool debug) {
124-
this->hardwareSerial = &hardwareSerial;
125-
this->softwareSerial = NULL;
126-
this->powerPin = powerPin;
127-
this->debug = debug;
128-
this->response[0] = '\0';
129-
this->echo = true;
130-
this->flowControl = (struct FlowControl){0, true, 0, true};
131-
this->baudrate = -1;
132-
this->powerDown = true;
133-
134-
pinMode(this->powerPin, OUTPUT);
135-
digitalWrite(this->powerPin, LOW);
136-
}
137-
138-
DTE::DTE(SoftwareSerial &softwareSerial, int powerPin, bool debug) {
139-
this->hardwareSerial = NULL;
140-
this->softwareSerial = &softwareSerial;
141-
this->powerPin = powerPin;
142-
this->debug = debug;
143-
this->response[0] = '\0';
144-
this->echo = true;
145-
this->flowControl = (struct FlowControl){0, true, 0, true};
146-
this->baudrate = -1;
147-
this->powerDown = true;
148-
149-
pinMode(this->powerPin, OUTPUT);
150-
digitalWrite(this->powerPin, LOW);
151-
}
152-
153153
int DTE::available(void) {
154154
if (hardwareSerial) return hardwareSerial->available();
155155
if (softwareSerial) return softwareSerial->available();

DTE.h

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ class DTE {
2525
long baudrate;
2626
bool powerDown;
2727

28+
protected:
29+
/**
30+
* Sent debugging message via Serial.
31+
* @param message Debug message
32+
* @param returnChar true: add new line, false: no new line (default)
33+
*/
34+
void debugPrint(const char message[], bool returnChar = false);
35+
void debugPrint(const __FlashStringHelper *message, bool returnChar = false);
36+
37+
public:
38+
DTE(HardwareSerial &hardwareSerial, int pinPower, bool debug = false);
39+
DTE(SoftwareSerial &softwareSerial, int pinPower, bool debug = false);
40+
2841
/**
2942
* Command A/
3043
* @return true: If command successful, false: Otherwise
@@ -75,25 +88,6 @@ class DTE {
7588
*/
7689
bool atSetFixedLocalRate(long baudrate);
7790

78-
protected:
79-
/**
80-
* Sent debugging message via Serial.
81-
* @param message Debug message
82-
* @param returnChar true: add new line, false: no new line (default)
83-
*/
84-
void debugPrint(const char message[], bool returnChar = false);
85-
86-
/**
87-
* Sent debugging message via Serial.
88-
* @param message Debug message
89-
* @param returnChar true: add new line, false: no new line (default)
90-
*/
91-
void debugPrint(const __FlashStringHelper *message, bool returnChar = false);
92-
93-
public:
94-
DTE(HardwareSerial &hardwareSerial, int pinPower, bool debug = false);
95-
DTE(SoftwareSerial &softwareSerial, int pinPower, bool debug = false);
96-
9791
/**
9892
* Check received buffer
9993
* @return Total received char available
@@ -131,12 +125,6 @@ class DTE {
131125
* @return Total successfully sent char
132126
*/
133127
size_t write(const char str[]);
134-
135-
/**
136-
* Send string char array
137-
* @param str String to be sent
138-
* @return Total successfully sent char
139-
*/
140128
size_t write(const __FlashStringHelper *str);
141129

142130
/**
@@ -166,12 +154,6 @@ class DTE {
166154
* @return true: if nothing is wrong, false: otherwise
167155
*/
168156
bool ATCommand(const char at[]);
169-
170-
/**
171-
* Send AT Command
172-
* @param at Command (Flash Memory)
173-
* @return true: if nothing is wrong, false: otherwise
174-
*/
175157
bool ATCommand(const __FlashStringHelper *at);
176158

177159
/**
@@ -200,14 +182,6 @@ class DTE {
200182
* @see ATResponse()
201183
*/
202184
bool ATResponseEqual(const char expected[], unsigned long timeout = 500);
203-
204-
/**
205-
* Get AT Response, and check if response is equal with expected
206-
* @param expected Expected response (Flash Memory)
207-
* @param timeout Timeout in millis, dafault: 500
208-
* @return true: If response as expected, false: Otherwise or timeout
209-
* @see ATResponse()
210-
*/
211185
bool ATResponseEqual(const __FlashStringHelper *expected, unsigned long timeout = 500);
212186

213187
/**
@@ -218,14 +192,6 @@ class DTE {
218192
* @see ATResponse()
219193
*/
220194
bool ATResponseContain(const char expected[], unsigned long timeout = 500);
221-
222-
/**
223-
* Get AT Response, and check if response is contain with expected
224-
* @param expected Expected response (Flash Memory)
225-
* @param timeout Timeout in millis, default: 500
226-
* @return true: If response contain expected, false: Otherwise or timeout
227-
* @see ATResponse()
228-
*/
229195
bool ATResponseContain(const __FlashStringHelper *expected, unsigned long timeout = 500);
230196

231197
/**
@@ -243,12 +209,6 @@ class DTE {
243209
* @return true: If last response as expected, false: Otherwise or timeout
244210
*/
245211
bool isResponseEqual(const char expected[]);
246-
247-
/**
248-
* Check that last response is equal as expected
249-
* @param expected Expected response (Flash Memory)
250-
* @return true: If last response as expected, false: Otherwise or timeout
251-
*/
252212
bool isResponseEqual(const __FlashStringHelper *expected);
253213

254214
/**
@@ -257,12 +217,6 @@ class DTE {
257217
* @return true: If last response contain expected, false: Otherwise or timeout
258218
*/
259219
bool isResponseContain(const char expected[]);
260-
261-
/**
262-
* Check that last response is contain expected
263-
* @param expected Expected response (Flash Memory)
264-
* @return true: If last response contain expected, false: Otherwise or timeout
265-
*/
266220
bool isResponseContain(const __FlashStringHelper *expected);
267221

268222
/**

GPRS.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "GPRS.h"
22
#include "URC.h"
33

4+
/* GPRS Class */
5+
GPRS::GPRS(DTE &dte) {
6+
this->dte = &dte;
7+
}
8+
49
bool GPRS::atAttachGPRSService(void) {
510
const __FlashStringHelper *command = F("AT+CGATT?\r");
611
const __FlashStringHelper *response = F("+CGATT: ");
@@ -28,11 +33,6 @@ bool GPRS::atAttachGPRSService(bool attach) {
2833
return true;
2934
}
3035

31-
/* GPRS Class */
32-
GPRS::GPRS(DTE &dte) {
33-
this->dte = &dte;
34-
}
35-
3636
bool GPRS::isAttached(void) {
3737
if (!atAttachGPRSService()) attached = false;
3838
return attached;

GPRS.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class GPRS {
99
DTE *dte;
1010
bool attached = false;
1111

12+
public:
13+
GPRS(DTE &dte);
14+
1215
/**
1316
* Command AT+CGATT?
1417
* @return true: If command success, false: Otherwise or timeout
@@ -22,9 +25,6 @@ class GPRS {
2225
*/
2326
bool atAttachGPRSService(bool attach);
2427

25-
public:
26-
GPRS(DTE &dte);
27-
2828
/**
2929
* Is GPRS Service attached/available
3030
* @return true: If attached/available, false: Otherwise

GSM.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#include "GSM.h"
22
#include "URC.h"
33

4+
/* GSM Class */
5+
GSM::GSM(DTE &dte) {
6+
this->dte = &dte;
7+
selectedOperator = (struct Operator){0, 0, "", ""};
8+
phonebookMemoryStorage = (struct PhonebookMemoryStorage){"", 0, 0};
9+
networkRegistration = (struct NetworkRegistration){0, 4, "", ""};
10+
signalQuality = (struct SignalQuality){0, 0};
11+
clock = (struct Clock){"", 0, 0, 0, 0, 0, 0, 0};
12+
subscriberNumber = (struct SubscriberNumber){"", "", 0, 0, 0};
13+
batteryStatus = (struct BatteryStatus){false, 0, 0.0f};
14+
}
15+
416
bool GSM::atOperatorSelection(void) {
517
const __FlashStringHelper *command = F("AT+COPS?\r");
618
const __FlashStringHelper *response = F("+COPS: ");
@@ -329,18 +341,6 @@ bool GSM::atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashS
329341
return atUnstructuredSupplementaryServiceData(n, buffer, dcs);
330342
}
331343

332-
/* GSM Class */
333-
GSM::GSM(DTE &dte) {
334-
this->dte = &dte;
335-
selectedOperator = (struct Operator){0, 0, "", ""};
336-
phonebookMemoryStorage = (struct PhonebookMemoryStorage){"", 0, 0};
337-
networkRegistration = (struct NetworkRegistration){0, 4, "", ""};
338-
signalQuality = (struct SignalQuality){0, 0};
339-
clock = (struct Clock){"", 0, 0, 0, 0, 0, 0, 0};
340-
subscriberNumber = (struct SubscriberNumber){"", "", 0, 0, 0};
341-
batteryStatus = (struct BatteryStatus){false, 0, 0.0f};
342-
}
343-
344344
struct Operator GSM::getOperator(unsigned char format) {
345345
if (strlen(selectedOperator.operNumeric) == 0) {
346346
if (getNetworkRegistration().status == 1 || getNetworkRegistration().status == 5) {

0 commit comments

Comments
 (0)