Skip to content

Commit

Permalink
Merge branch 'release/v0.5.6-alpha'
Browse files Browse the repository at this point in the history
  • Loading branch information
frdteknikelektro committed Mar 15, 2017
2 parents 391c90c + cd68a62 commit 22454ae
Show file tree
Hide file tree
Showing 14 changed files with 813 additions and 6 deletions.
6 changes: 6 additions & 0 deletions DTE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ size_t DTE::write(const char str[]) {
return 0;
}

size_t DTE::write(const __FlashStringHelper *str) {
char buffer[strlen_P((const char *)str) + 1];
strcpy_P(buffer, (const char *)str);
return write(buffer);
}

size_t DTE::readBytes(char buffer[], size_t length) {
if (hardwareSerial) return hardwareSerial->readBytes(buffer, length);
if (softwareSerial) return softwareSerial->readBytes(buffer, length);
Expand Down
7 changes: 7 additions & 0 deletions DTE.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ class DTE {
*/
size_t write(const char str[]);

/**
* Send string char array
* @param str String to be sent
* @return Total successfully sent char
*/
size_t write(const __FlashStringHelper *str);

/**
* Read bytes received from Serial buffer, and save it on buffer.
* Warning: buffer size must be equal or smaller then length.
Expand Down
30 changes: 30 additions & 0 deletions GSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ bool GSM::atSelectPhonebookMemoryStorage(const char storage[]) {
return true;
}

bool GSM::atSelectPhonebookMemoryStorage(const __FlashStringHelper *storage) {
char buffer[strlen_P((const char *)storage) + 1];
strcpy_P(buffer, (const char *)storage);
return atSelectPhonebookMemoryStorage(buffer);
}

bool GSM::atEnterPIN(void) {
const __FlashStringHelper *command = F("AT+CPIN?\r");
const __FlashStringHelper *response = F("+CPIN: ");
Expand Down Expand Up @@ -218,6 +224,12 @@ bool GSM::atClock(const char timestamp[]) {
return true;
}

bool GSM::atClock(const __FlashStringHelper *timestamp) {
char buffer[strlen_P((const char *)timestamp) + 1];
strcpy_P(buffer, (const char *)timestamp);
return atClock(buffer);
}

bool GSM::atBatteryCharge(void) {
const __FlashStringHelper *command = F("AT+CBC\r");
const __FlashStringHelper *response = F("+CBC: ");
Expand Down Expand Up @@ -277,6 +289,12 @@ bool GSM::atUnstructuredSupplementaryServiceData(unsigned char n, const char str
return true;
}

bool GSM::atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashStringHelper *str) {
char buffer[strlen_P((const char *)str) + 1];
strcpy_P(buffer, (const char *)str);
return atUnstructuredSupplementaryServiceData(n, buffer);
}

bool GSM::atUnstructuredSupplementaryServiceData(unsigned char n, const char str[], unsigned char dcs) {
char buffer[17 + strlen(str)]; // "AT+CUSD=1,\"{str}\",XX\r"
const __FlashStringHelper *command = F("AT+CUSD=%d,\"%s\",%d\r");
Expand All @@ -288,6 +306,12 @@ bool GSM::atUnstructuredSupplementaryServiceData(unsigned char n, const char str
return true;
}

bool GSM::atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashStringHelper *str, unsigned char dcs) {
char buffer[strlen_P((const char *)str) + 1];
strcpy_P(buffer, (const char *)str);
return atUnstructuredSupplementaryServiceData(n, buffer, dcs);
}

/* GSM Class */
GSM::GSM(DTE &dte) {
this->dte = &dte;
Expand Down Expand Up @@ -370,6 +394,12 @@ bool GSM::sendServiceData(const char serviceNumber[]) {
return true;
}

bool GSM::sendServiceData(const __FlashStringHelper *serviceNumber) {
char buffer[strlen_P((const char *)serviceNumber) + 1];
strcpy_P(buffer, (const char *)serviceNumber);
return sendServiceData(buffer);
}

void GSM::cancelServiceData(void) {
atUnstructuredSupplementaryServiceData(2);
}
138 changes: 137 additions & 1 deletion GSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ class GSM {
*/
bool atSelectPhonebookMemoryStorage(const char storage[]);

/**
* Command AT+CPBS=
* @param storage Storage Name
* @return true: If command successful, false: Otherwise
*/
bool atSelectPhonebookMemoryStorage(const __FlashStringHelper *storage);

/**
* Command AT+CPBW=
* @param index Location number
Expand All @@ -139,6 +146,14 @@ class GSM {
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[]);

/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber);

/**
* Command AT+CPBW=
* @param index Location Number
Expand All @@ -152,6 +167,19 @@ class GSM {
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[], unsigned char type);

/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @param type Type of Number:
* 129: National Number type
* 161: National Number type
* 145: International Number type
* 177: Network Specific Number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber, unsigned char type);

/**
* Command AT+CPBW=
* @param index Location Number
Expand All @@ -166,6 +194,48 @@ class GSM {
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[], unsigned char type, const char text[]);

/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @param type Type of Number:
* 129: National Number type
* 161: National Number type
* 145: International Number type
* 177: Network Specific Number
* @param text Text associated with number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber, unsigned char type, const char text[]);

/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @param type Type of Number:
* 129: National Number type
* 161: National Number type
* 145: International Number type
* 177: Network Specific Number
* @param text Text associated with number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const char phoneNumber[], unsigned char type, const __FlashStringHelper *text);

/**
* Command AT+CPBW=
* @param index Location Number
* @param phoneNumber Phone Number
* @param type Type of Number:
* 129: National Number type
* 161: National Number type
* 145: International Number type
* 177: Network Specific Number
* @param text Text associated with number
* @return true: If command successful, false: Otherwise
*/
bool atWritePhonebookEntry(unsigned char index, const __FlashStringHelper *phoneNumber, unsigned char type, const __FlashStringHelper *text);

/**
* Command AT+CPIN?
* @return true: If command successful, false: Otherwise
Expand All @@ -179,13 +249,44 @@ class GSM {
*/
bool atEnterPIN(const char pin[]);

/**
* Command AT+CPIN=
* @param pin SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const __FlashStringHelper *pin);

/**
* Command AT+CPIN=
* @param pin SIM Pin
* @param newPin New SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const char pin[], const char newPin[]);

/**
* Command AT+CPIN=
* @param pin SIM Pin
* @param newPin New SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const char pin[], const char *newPin);
bool atEnterPIN(const __FlashStringHelper *pin, const char newPin[]);

/**
* Command AT+CPIN=
* @param pin SIM Pin
* @param newPin New SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const char pin[], const __FlashStringHelper *newPin);

/**
* Command AT+CPIN=
* @param pin SIM Pin
* @param newPin New SIM Pin
* @return true: If command successful, false: Otherwise
*/
bool atEnterPIN(const __FlashStringHelper *pin, const __FlashStringHelper *newPin);

/**
* Command AT+CREG?
Expand Down Expand Up @@ -228,6 +329,13 @@ class GSM {
*/
bool atClock(const char timestamp[]);

/**
* Command AT+CCLK=
* @param timestamp Timestamp in format
* @return true: If command successful, false: Otherwise
*/
bool atClock(const __FlashStringHelper *timestamp);

/**
* Command AT+CBC
* @return true: If command successful, false: Otherwise
Expand Down Expand Up @@ -260,6 +368,16 @@ class GSM {
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n, const char str[]);

/**
* Command AT+CUSD=
* @param n Control USSD, Code result presentation
* 0: Disable
* 1: Enable
* @param str USSD Code, ex: *123#
* @return true: If command successful, false: Otherwise
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashStringHelper *str);

/**
* Command AT+CUSD=
* @param n Control USSD, Code result presentation
Expand All @@ -271,6 +389,17 @@ class GSM {
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n, const char str[], unsigned char dcs);

/**
* Command AT+CUSD=
* @param n Control USSD, Code result presentation
* 0: Disable
* 1: Enable
* @param str USSD Code, ex: *123#
* @param dcs Cell Broadcast Data Coding Scheme
* @return true: If command successful, false: Otherwise
*/
bool atUnstructuredSupplementaryServiceData(unsigned char n, const __FlashStringHelper *str, unsigned char dcs);

public:
GSM(DTE &dte);

Expand Down Expand Up @@ -333,6 +462,13 @@ class GSM {
*/
bool sendServiceData(const char serviceNumber[]);

/**
* Send USSD data
* @param serviceNumber String to access USSD, ex: *123#
* @return true: If command successful, false: Otherwise
*/
bool sendServiceData(const __FlashStringHelper *serviceNumber);

/**
* Cancel/close USSD session
*/
Expand Down
Loading

0 comments on commit 22454ae

Please sign in to comment.