mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Many sub templates to inherit from!
This commit is contained in:
61
src/TinyGsmTime.tpp
Normal file
61
src/TinyGsmTime.tpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file TinyGsmTime.tpp
|
||||
* @author Volodymyr Shymanskyy
|
||||
* @license LGPL-3.0
|
||||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
|
||||
* @date Nov 2016
|
||||
*/
|
||||
|
||||
#ifndef SRC_TINYGSMTIME_H_
|
||||
#define SRC_TINYGSMTIME_H_
|
||||
|
||||
#include "TinyGsmCommon.h"
|
||||
|
||||
#define TINY_GSM_MODEM_HAS_TIME
|
||||
|
||||
enum TinyGSMDateTimeFormat { DATE_FULL = 0, DATE_TIME = 1, DATE_DATE = 2 };
|
||||
|
||||
template <class modemType>
|
||||
class TinyGsmTime {
|
||||
public:
|
||||
/*
|
||||
* Time functions
|
||||
*/
|
||||
String getGSMDateTime(TinyGSMDateTimeFormat format) {
|
||||
return thisModem().getGSMDateTimeImpl(format);
|
||||
}
|
||||
|
||||
/*
|
||||
* CRTP Helper
|
||||
*/
|
||||
protected:
|
||||
inline const modemType& thisModem() const {
|
||||
return static_cast<const modemType&>(*this);
|
||||
}
|
||||
inline modemType& thisModem() {
|
||||
return static_cast<modemType&>(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Time functions
|
||||
*/
|
||||
protected:
|
||||
String getGSMDateTimeImpl(TinyGSMDateTimeFormat format) {
|
||||
thisModem().sendAT(GF("+CCLK?"));
|
||||
if (thisModem().waitResponse(2000L, GF("+CCLK: \"")) != 1) { return ""; }
|
||||
|
||||
String res;
|
||||
|
||||
switch (format) {
|
||||
case DATE_FULL: res = thisModem().stream.readStringUntil('"'); break;
|
||||
case DATE_TIME:
|
||||
thisModem().streamSkipUntil(',');
|
||||
res = thisModem().stream.readStringUntil('"');
|
||||
break;
|
||||
case DATE_DATE: res = thisModem().stream.readStringUntil(','); break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SRC_TINYGSMTIME_H_
|
||||
Reference in New Issue
Block a user