Skip to content

Commit

Permalink
Many sub templates to inherit from!
Browse files Browse the repository at this point in the history
  • Loading branch information
SRGDamia1 committed Feb 11, 2020
1 parent 9ec9111 commit be81985
Show file tree
Hide file tree
Showing 33 changed files with 1,963 additions and 2,278 deletions.
4 changes: 3 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ IncludeCategories:
Priority: 2
- Regex: '.*'
Priority: 3
- Regex: '.*.tpp'
Priority: 4
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
Expand All @@ -80,7 +82,7 @@ PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 60
PenaltyExcessCharacter: 600
PenaltyReturnTypeOnItsOwnLine: 50
PointerAlignment: Left
PointerBindsToType: true
Expand Down
4 changes: 2 additions & 2 deletions examples/AllFunctions/AllFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ void loop() {
stream.print(F("Привіііт! Print number: "));
stream.print(595);
res = modem.sendSMS_UTF8_end();
}
}
DBG("UTF8 SMS:", res ? "OK" : "fail");

#endif

#if TINY_GSM_TEST_CALL && defined(CALL_TARGET)
Expand Down
2 changes: 2 additions & 0 deletions examples/WebClient/WebClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
// Chips without internal buffering (A6/A7, ESP8266, M590)
// need enough space in the buffer for the entire response
// else data will be lost (and the http library will fail).
#if !defined(TINY_GSM_RX_BUFFER)
#define TINY_GSM_RX_BUFFER 650
#endif

// See all AT commands, if wanted
// #define DUMP_AT_COMMANDS
Expand Down
98 changes: 98 additions & 0 deletions src/TinyGsmBattery.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @file TinyGsmBattery.tpp
* @author Volodymyr Shymanskyy
* @license LGPL-3.0
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Nov 2016
*/

#ifndef SRC_TINYGSMBATTERY_H_
#define SRC_TINYGSMBATTERY_H_

#include "TinyGsmCommon.h"

#define TINY_GSM_MODEM_HAS_BATTERY

template <class modemType>
class TinyGsmBattery {
public:
/*
* Battery functions
*/
uint16_t getBattVoltage() {
return thisModem().getBattVoltageImpl();
}
int8_t getBattPercent() {
return thisModem().getBattPercentImpl();
}
uint8_t getBattChargeState() {
return thisModem().getBattChargeStateImpl();
}
bool getBattStats(uint8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) {
return thisModem().getBattStatsImpl(chargeState, percent, milliVolts);
}

/*
* CRTP Helper
*/
protected:
inline const modemType& thisModem() const {
return static_cast<const modemType&>(*this);
}
inline modemType& thisModem() {
return static_cast<modemType&>(*this);
}

/*
* Battery functions
*/
protected:
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
uint16_t getBattVoltageImpl() {
thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return 0; }
thisModem().streamSkipUntil(','); // Skip battery charge status
thisModem().streamSkipUntil(','); // Skip battery charge level
// return voltage in mV
uint16_t res = thisModem().streamGetInt(',');
// Wait for final OK
thisModem().waitResponse();
return res;
}

int8_t getBattPercentImpl() {
thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
thisModem().streamSkipUntil(','); // Skip battery charge status
// Read battery charge level
int res = thisModem().streamGetInt(',');
// Wait for final OK
thisModem().waitResponse();
return res;
}

uint8_t getBattChargeStateImpl() {
thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
// Read battery charge status
int res = thisModem().streamGetInt(',');
// Wait for final OK
thisModem().waitResponse();
return res;
}

bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) {
thisModem().sendAT(GF("+CBC"));
if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; }
chargeState = thisModem().streamGetInt(',');
percent = thisModem().streamGetInt(',');
milliVolts = thisModem().streamGetInt('\n');
// Wait for final OK
thisModem().waitResponse();
return true;
}
};

#endif // SRC_TINYGSMBATTERY_H_
90 changes: 90 additions & 0 deletions src/TinyGsmCalling.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* @file TinyGsmCalling.tpp
* @author Volodymyr Shymanskyy
* @license LGPL-3.0
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
* @date Nov 2016
*/

#ifndef SRC_TINYGSMCALLING_H_
#define SRC_TINYGSMCALLING_H_

#include "TinyGsmCommon.h"

#define TINY_GSM_MODEM_HAS_CALLING

template <class modemType>
class TinyGsmCalling {
public:
/*
* Phone Call functions
*/
bool callAnswer() {
return thisModem().callAnswerImpl();
}
bool callNumber(const String& number) {
return thisModem().callNumberImpl(number);
}
bool callHangup() {
return thisModem().callHangupImpl();
}
bool dtmfSend(char cmd, int duration_ms = 100) {
return thisModem().dtmfSendImpl(cmd, duration_ms);
}

/*
* CRTP Helper
*/
protected:
inline const modemType& thisModem() const {
return static_cast<const modemType&>(*this);
}
inline modemType& thisModem() {
return static_cast<modemType&>(*this);
}

/*
* Phone Call functions
*/
protected:
bool callAnswerImpl() {
thisModem().sendAT(GF("A"));
return thisModem().waitResponse() == 1;
}

// Returns true on pick-up, false on error/busy
bool callNumberImpl(const String& number) {
if (number == GF("last")) {
thisModem().sendAT(GF("DL"));
} else {
thisModem().sendAT(GF("D"), number, ";");
}
int status = thisModem().waitResponse(60000L, GF("OK"), GF("BUSY"),
GF("NO ANSWER"), GF("NO CARRIER"));
switch (status) {
case 1: return true;
case 2:
case 3: return false;
default: return false;
}
}

bool callHangupImpl() {
thisModem().sendAT(GF("H"));
return thisModem().waitResponse() == 1;
}

// 0-9,*,#,A,B,C,D
bool dtmfSendImpl(char cmd, int duration_ms = 100) {
duration_ms = constrain(duration_ms, 100, 1000);

thisModem().sendAT(GF("+VTD="),
duration_ms / 100); // VTD accepts in 1/10 of a second
thisModem().waitResponse();

thisModem().sendAT(GF("+VTS="), cmd);
return thisModem().waitResponse(10000L) == 1;
}
};

#endif // SRC_TINYGSMCALLING_H_
38 changes: 7 additions & 31 deletions src/TinyGsmClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,128 +6,104 @@
* @date Nov 2016
*/

#ifndef SRC_TINYGSMCLIENT_h
#define SRC_TINYGSMCLIENT_h
#ifndef SRC_TINYGSMCLIENT_H_
#define SRC_TINYGSMCLIENT_H_

#if defined(TINY_GSM_MODEM_SIM800)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_SSL
#include "TinyGsmClientSIM800.h"
typedef TinyGsmSim800 TinyGsm;
typedef TinyGsmSim800::GsmClientSim800 TinyGsmClient;
typedef TinyGsmSim800::GsmClientSecureSim800 TinyGsmClientSecure;

#elif defined(TINY_GSM_MODEM_SIM808) || defined(TINY_GSM_MODEM_SIM868)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_SSL
#define TINY_GSM_MODEM_HAS_GPS
#include "TinyGsmClientSIM808.h"
typedef TinyGsmSim808 TinyGsm;
typedef TinyGsmSim808::GsmClientSim800 TinyGsmClient;
typedef TinyGsmSim808::GsmClientSecureSim800 TinyGsmClientSecure;

#elif defined(TINY_GSM_MODEM_SIM900)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientSIM800.h"
typedef TinyGsmSim800 TinyGsm;
typedef TinyGsmSim800::GsmClientSim800 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_SIM7000)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_GPS
#include "TinyGsmClientSIM7000.h"
typedef TinyGsmSim7000 TinyGsm;
typedef TinyGsmSim7000::GsmClientSim7000 TinyGsmClient;
// typedef TinyGsmSim7000::GsmClientSecureSim7000 TinyGsmClientSecure; TODO!

#elif defined(TINY_GSM_MODEM_SIM5320) || defined(TINY_GSM_MODEM_SIM5360) || \
defined(TINY_GSM_MODEM_SIM5300) || defined(TINY_GSM_MODEM_SIM7100)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientSIM5360.h"
typedef TinyGsmSim5360 TinyGsm;
typedef TinyGsmSim5360::GsmClientSim5360 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_SIM7600) || defined(TINY_GSM_MODEM_SIM7800) || \
defined(TINY_GSM_MODEM_SIM7500)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientSIM7600.h"
typedef TinyGsmSim7600 TinyGsm;
typedef TinyGsmSim7600::GsmClientSim7600 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_UBLOX)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_SSL
#include "TinyGsmClientUBLOX.h"
typedef TinyGsmUBLOX TinyGsm;
typedef TinyGsmUBLOX::GsmClientUBLOX TinyGsmClient;
typedef TinyGsmUBLOX::GsmClientSecureUBLOX TinyGsmClientSecure;

#elif defined(TINY_GSM_MODEM_SARAR4)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_SSL
#include "TinyGsmClientSaraR4.h"
typedef TinyGsmSaraR4 TinyGsm;
typedef TinyGsmSaraR4::GsmClientSaraR4 TinyGsmClient;
typedef TinyGsmSaraR4::GsmClientSecureR4 TinyGsmClientSecure;

#elif defined(TINY_GSM_MODEM_M95)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientM95.h"
typedef TinyGsmM95 TinyGsm;
typedef TinyGsmM95::GsmClientM95 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_BG96)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientBG96.h"
typedef TinyGsmBG96 TinyGsm;
typedef TinyGsmBG96::GsmClientBG96 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_A6) || defined(TINY_GSM_MODEM_A7)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientA6.h"
typedef TinyGsmA6 TinyGsm;
typedef TinyGsmA6::GsmClientA6 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_M590)
#define TINY_GSM_MODEM_HAS_GPRS
#include "TinyGsmClientM590.h"
typedef TinyGsmM590 TinyGsm;
typedef TinyGsmM590::GsmClientM590 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_MC60) || defined(TINY_GSM_MODEM_MC60E)
#include "TinyGsmClientMC60.h"
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_GPS
typedef TinyGsmMC60 TinyGsm;
typedef TinyGsmMC60::GsmClientMC60 TinyGsmClient;

#elif defined(TINY_GSM_MODEM_ESP8266)
#define TINY_GSM_MODEM_HAS_WIFI
#define TINY_GSM_MODEM_HAS_SSL
#include "TinyGsmClientESP8266.h"
typedef TinyGsmESP8266 TinyGsm;
typedef TinyGsmESP8266::GsmClientESP8266 TinyGsmClient;
typedef TinyGsmESP8266::GsmClientSecureESP8266 TinyGsmClientSecure;

#elif defined(TINY_GSM_MODEM_XBEE)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_WIFI
#define TINY_GSM_MODEM_HAS_SSL
#include "TinyGsmClientXBee.h"
typedef TinyGsmXBee TinyGsm;
typedef TinyGsmXBee::GsmClientXBee TinyGsmClient;
typedef TinyGsmXBee::GsmClientSecureXBee TinyGsmClientSecure;

#elif defined(TINY_GSM_MODEM_SEQUANS_MONARCH)
#define TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_MODEM_HAS_SSL
#include "TinyGsmClientSequansMonarch.h"
typedef TinyGsmSequansMonarch TinyGsm;
typedef TinyGsmSequansMonarch::GsmClientSequansMonarch TinyGsmClient;
typedef TinyGsmSequansMonarch::GsmClientSecureSequansMonarch TinyGsmClientSecure;
typedef TinyGsmSequansMonarch TinyGsm;
typedef TinyGsmSequansMonarch::GsmClientSequansMonarch TinyGsmClient;
typedef TinyGsmSequansMonarch::GsmClientSecureSequansMonarch
TinyGsmClientSecure;

#else
#error "Please define GSM modem model"
#endif

#endif
#endif // SRC_TINYGSMCLIENT_H_
Loading

0 comments on commit be81985

Please sign in to comment.