Merge pull request #293 from lora-aprs/hw_testing

update hw testing
This commit is contained in:
Peter Buchegger 2023-05-17 19:48:23 +00:00 committed by GitHub
commit f1f42038e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 483 additions and 487 deletions

View file

@ -3,7 +3,6 @@ name: Integration Tests
on: on:
merge_group: merge_group:
pull_request: pull_request:
types: [opened, reopened]
jobs: jobs:
build: build:
@ -45,10 +44,10 @@ jobs:
- 'lib/BoardFinder' - 'lib/BoardFinder'
- 'lib/ConfigurationManagement' - 'lib/ConfigurationManagement'
#- 'lib/Display' #- 'lib/Display'
#- 'lib/NTPClient' - 'lib/NTPClient'
- 'lib/PowerManagement' - 'lib/PowerManagement'
- 'lib/System' - 'lib/System'
#- 'lib/TimeLib' - 'lib/TimeLib'
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -61,38 +60,14 @@ jobs:
cppcheck: cppcheck:
name: Run cppcheck name: Run cppcheck
runs-on: ubuntu-latest runs-on: ubuntu-latest
env:
CPPCHECK_ARGS: --enable=all --std=c++14 --inline-suppr -I lib/BoardFinder -I lib/ConfigurationManagement -I lib/Display -I lib/LoRa -I lib/LoRa_APRS -I lib/NTPClient -I lib/PowerManagement -I lib/System -I lib/TimeLib -i lib/Display -i lib/LoRa -i lib/NTPClient -i lib/TimeLib src lib
steps: steps:
- name: checkout code - uses: actions/cache@v3
uses: actions/checkout@v3
- run: docker pull facthunder/cppcheck:latest
- name: Run cppcheck and print result
run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck $CPPCHECK_ARGS"
- name: Run cppcheck and create html
run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck --xml $CPPCHECK_ARGS 2> report.xml && cppcheck-htmlreport --file=report.xml --report-dir=output"
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: Cppcheck Report
path: output
remote_testing:
name: Remote Testing
runs-on: ubuntu-20.04
env:
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
steps:
- name: Setup Cache
uses: actions/cache@v3
with: with:
path: | path: |
~/.cache/pip ~/.cache/pip
~/.platformio ~/.platformio/.cache
key: remote-cache key: check-cache
- name: Setup Python - uses: actions/setup-python@v4
uses: actions/setup-python@v4
with: with:
python-version: '3.10' python-version: '3.10'
- name: Install PlatformIO - name: Install PlatformIO
@ -101,9 +76,37 @@ jobs:
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install --upgrade platformio pip install --upgrade platformio
- name: Checkout code
uses: actions/checkout@v3
- name: Run PlatformIO Check
run: pio check --fail-on-defect high -e lora_board
hw_testing:
name: Hardware Testing
strategy:
matrix:
usb_port: [ttyUSB0]
runs-on: [self-hosted, "${{ matrix.usb_port }}"]
steps:
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: hw-cache
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install PlatformIO
shell: bash
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: List Devices - name: List Devices
run: pio remote device list run: pio device list
- name: PlatformIO Test - name: PlatformIO Test
run: pio remote test -v -r --upload-port /dev/ttyUSB4 --test-port /dev/ttyUSB4 if: always()
run: flock -w 600 --verbose /locks/pio-${{ matrix.usb_port }} -c "pio test -vvv --upload-port /dev/${{ matrix.usb_port }} --test-port /dev/${{ matrix.usb_port }}"

View file

@ -28,7 +28,7 @@ NTPClient::NTPClient(long timeOffset) {
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
} }
NTPClient::NTPClient(const char* poolServerName) { NTPClient::NTPClient(const char *poolServerName) {
this->_poolServerName = poolServerName; this->_poolServerName = poolServerName;
} }
@ -37,18 +37,18 @@ NTPClient::NTPClient(IPAddress poolServerIP) {
this->_poolServerName = NULL; this->_poolServerName = NULL;
} }
NTPClient::NTPClient(const char* poolServerName, long timeOffset) { NTPClient::NTPClient(const char *poolServerName, long timeOffset) {
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
this->_poolServerName = poolServerName; this->_poolServerName = poolServerName;
} }
NTPClient::NTPClient(IPAddress poolServerIP, long timeOffset){ NTPClient::NTPClient(IPAddress poolServerIP, long timeOffset) {
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
this->_poolServerIP = poolServerIP; this->_poolServerIP = poolServerIP;
this->_poolServerName = NULL; this->_poolServerName = NULL;
} }
NTPClient::NTPClient(const char* poolServerName, long timeOffset, unsigned long updateInterval) { NTPClient::NTPClient(const char *poolServerName, long timeOffset, unsigned long updateInterval) {
this->_timeOffset = timeOffset; this->_timeOffset = timeOffset;
this->_poolServerName = poolServerName; this->_poolServerName = poolServerName;
this->_updateInterval = updateInterval; this->_updateInterval = updateInterval;
@ -74,12 +74,12 @@ void NTPClient::begin(unsigned int port) {
} }
bool NTPClient::forceUpdate() { bool NTPClient::forceUpdate() {
#ifdef DEBUG_NTPClient #ifdef DEBUG_NTPClient
Serial.println("Update from NTP Server"); Serial.println("Update from NTP Server");
#endif #endif
// flush any existing packets // flush any existing packets
while(this->_udp.parsePacket() != 0) while (this->_udp.parsePacket() != 0)
this->_udp.flush(); this->_udp.flush();
this->sendNTPPacket(); this->sendNTPPacket();
@ -88,9 +88,10 @@ bool NTPClient::forceUpdate() {
byte timeout = 0; byte timeout = 0;
int cb = 0; int cb = 0;
do { do {
delay ( 10 ); delay(10);
cb = this->_udp.parsePacket(); cb = this->_udp.parsePacket();
if (timeout > 100) return false; // timeout after 1000 ms if (timeout > 100)
return false; // timeout after 1000 ms
timeout++; timeout++;
} while (cb == 0); } while (cb == 0);
@ -112,7 +113,8 @@ bool NTPClient::forceUpdate() {
bool NTPClient::update() { bool NTPClient::update() {
if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval if ((millis() - this->_lastUpdate >= this->_updateInterval) // Update after _updateInterval
|| this->_lastUpdate == 0) { // Update if there was no update yet. || this->_lastUpdate == 0) { // Update if there was no update yet.
if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT) this->begin(this->_port); // setup the UDP client if needed if (!this->_udpSetup || this->_port != NTP_DEFAULT_LOCAL_PORT)
this->begin(this->_port); // setup the UDP client if needed
return this->forceUpdate(); return this->forceUpdate();
} }
return false; // return false if update does not occur return false; // return false if update does not occur
@ -125,7 +127,7 @@ unsigned long NTPClient::getEpochTime() const {
} }
int NTPClient::getDay() const { int NTPClient::getDay() const {
return (((this->getEpochTime() / 86400L) + 4 ) % 7); //0 is Sunday return (((this->getEpochTime() / 86400L) + 4) % 7); // 0 is Sunday
} }
int NTPClient::getHours() const { int NTPClient::getHours() const {
return ((this->getEpochTime() % 86400L) / 3600); return ((this->getEpochTime() % 86400L) / 3600);
@ -165,7 +167,7 @@ void NTPClient::setUpdateInterval(unsigned long updateInterval) {
this->_updateInterval = updateInterval; this->_updateInterval = updateInterval;
} }
void NTPClient::setPoolServerName(const char* poolServerName) { void NTPClient::setPoolServerName(const char *poolServerName) {
this->_poolServerName = poolServerName; this->_poolServerName = poolServerName;
} }

View file

@ -8,11 +8,11 @@
#define NTP_DEFAULT_LOCAL_PORT 1337 #define NTP_DEFAULT_LOCAL_PORT 1337
class NTPClient { class NTPClient {
private: private:
WiFiUDP _udp; WiFiUDP _udp;
bool _udpSetup = false; bool _udpSetup = false;
const char* _poolServerName = "pool.ntp.org"; // Default time server const char *_poolServerName = "pool.ntp.org"; // Default time server
IPAddress _poolServerIP; IPAddress _poolServerIP;
unsigned int _port = NTP_DEFAULT_LOCAL_PORT; unsigned int _port = NTP_DEFAULT_LOCAL_PORT;
long _timeOffset = 0; long _timeOffset = 0;
@ -26,12 +26,12 @@ class NTPClient {
void sendNTPPacket(); void sendNTPPacket();
public: public:
NTPClient(); NTPClient();
explicit NTPClient(long timeOffset); explicit NTPClient(long timeOffset);
explicit NTPClient(const char* poolServerName); explicit NTPClient(const char *poolServerName);
NTPClient(const char* poolServerName, long timeOffset); NTPClient(const char *poolServerName, long timeOffset);
NTPClient(const char* poolServerName, long timeOffset, unsigned long updateInterval); NTPClient(const char *poolServerName, long timeOffset, unsigned long updateInterval);
explicit NTPClient(IPAddress poolServerIP); explicit NTPClient(IPAddress poolServerIP);
NTPClient(IPAddress poolServerIP, long timeOffset); NTPClient(IPAddress poolServerIP, long timeOffset);
NTPClient(IPAddress poolServerIP, long timeOffset, unsigned long updateInterval); NTPClient(IPAddress poolServerIP, long timeOffset, unsigned long updateInterval);
@ -41,7 +41,7 @@ class NTPClient {
* *
* @param poolServerName * @param poolServerName
*/ */
void setPoolServerName(const char* poolServerName); void setPoolServerName(const char *poolServerName);
/** /**
* Set random local port * Set random local port

View file

@ -57,12 +57,12 @@ int hourFormat12() { // the hour now in 12 hour format
int hourFormat12(time_t t) { // the hour for the given time in 12 hour format int hourFormat12(time_t t) { // the hour for the given time in 12 hour format
refreshCache(t); refreshCache(t);
if( tm.Hour == 0 ) if (tm.Hour == 0)
return 12; // 12 midnight return 12; // 12 midnight
else if( tm.Hour > 12) else if (tm.Hour > 12)
return tm.Hour - 12 ; return tm.Hour - 12;
else else
return tm.Hour ; return tm.Hour;
} }
uint8_t isAM() { // returns true if time now is AM uint8_t isAM() { // returns true if time now is AM
@ -99,8 +99,8 @@ int second(time_t t) { // the second for the given time
return tm.Second; return tm.Second;
} }
int day(){ int day() {
return(day(now())); return (day(now()));
} }
int day(time_t t) { // the day for the given time (0-6) int day(time_t t) { // the day for the given time (0-6)
@ -117,7 +117,7 @@ int weekday(time_t t) {
return tm.Wday; return tm.Wday;
} }
int month(){ int month() {
return month(now()); return month(now());
} }
@ -135,13 +135,11 @@ int year(time_t t) { // the year for the given time
return tmYearToCalendar(tm.Year); return tmYearToCalendar(tm.Year);
} }
const String timeString() const String timeString() {
{
return timeString(now()); return timeString(now());
} }
const String timeString(time_t t) const String timeString(time_t t) {
{
char line[30]; char line[30];
sprintf(line, "%02d:%02d:%02d", hour(t), minute(t), second(t)); sprintf(line, "%02d:%02d:%02d", hour(t), minute(t), second(t));
return String(line); return String(line);
@ -152,14 +150,14 @@ const String timeString(time_t t)
/* These are for interfacing with time services and are not normally needed in a sketch */ /* These are for interfacing with time services and are not normally needed in a sketch */
// leap year calculator expects year argument as years offset from 1970 // leap year calculator expects year argument as years offset from 1970
#define LEAP_YEAR(Y) ( ((1970+(Y))>0) && !((1970+(Y))%4) && ( ((1970+(Y))%100) || !((1970+(Y))%400) ) ) #define LEAP_YEAR(Y) (((1970 + (Y)) > 0) && !((1970 + (Y)) % 4) && (((1970 + (Y)) % 100) || !((1970 + (Y)) % 400)))
static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0 static const uint8_t monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // API starts months from 1, this array starts from 0
void breakTime(time_t timeInput, tmElements_t &tm){ void breakTime(time_t timeInput, tmElements_t &tm) {
// break the given time_t into time components // break the given time_t into time components
// this is a more compact version of the C library localtime function // this is a more compact version of the C library localtime function
// note that year is offset from 1970 !!! // note that year is offset from 1970 !!!
uint8_t year; uint8_t year;
uint8_t month, monthLength; uint8_t month, monthLength;
@ -177,7 +175,7 @@ void breakTime(time_t timeInput, tmElements_t &tm){
year = 0; year = 0;
days = 0; days = 0;
while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) { while ((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) {
year++; year++;
} }
tm.Year = year; // year is offset from 1970 tm.Year = year; // year is offset from 1970
@ -185,15 +183,15 @@ void breakTime(time_t timeInput, tmElements_t &tm){
days -= LEAP_YEAR(year) ? 366 : 365; days -= LEAP_YEAR(year) ? 366 : 365;
time -= days; // now it is days in this year, starting at 0 time -= days; // now it is days in this year, starting at 0
days=0; days = 0;
month=0; month = 0;
monthLength=0; monthLength = 0;
for (month=0; month<12; month++) { for (month = 0; month < 12; month++) {
if (month==1) { // february if (month == 1) { // february
if (LEAP_YEAR(year)) { if (LEAP_YEAR(year)) {
monthLength=29; monthLength = 29;
} else { } else {
monthLength=28; monthLength = 28;
} }
} else { } else {
monthLength = monthDays[month]; monthLength = monthDays[month];
@ -209,16 +207,16 @@ void breakTime(time_t timeInput, tmElements_t &tm){
tm.Day = time + 1; // day of month tm.Day = time + 1; // day of month
} }
time_t makeTime(const tmElements_t &tm){ time_t makeTime(const tmElements_t &tm) {
// assemble time elements into time_t // assemble time elements into time_t
// note year argument is offset from 1970 (see macros in time.h to convert to other formats) // note year argument is offset from 1970 (see macros in time.h to convert to other formats)
// previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9 // previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9
int i; int i;
uint32_t seconds; uint32_t seconds;
// seconds from 1970 till 1 jan 00:00:00 of the given year // seconds from 1970 till 1 jan 00:00:00 of the given year
seconds= tm.Year*(SECS_PER_DAY * 365); seconds = tm.Year * (SECS_PER_DAY * 365);
for (i = 0; i < tm.Year; i++) { for (i = 0; i < tm.Year; i++) {
if (LEAP_YEAR(i)) { if (LEAP_YEAR(i)) {
seconds += SECS_PER_DAY; // add extra days for leap years seconds += SECS_PER_DAY; // add extra days for leap years
@ -227,16 +225,16 @@ time_t makeTime(const tmElements_t &tm){
// add days for this year, months start from 1 // add days for this year, months start from 1
for (i = 1; i < tm.Month; i++) { for (i = 1; i < tm.Month; i++) {
if ( (i == 2) && LEAP_YEAR(tm.Year)) { if ((i == 2) && LEAP_YEAR(tm.Year)) {
seconds += SECS_PER_DAY * 29; seconds += SECS_PER_DAY * 29;
} else { } else {
seconds += SECS_PER_DAY * monthDays[i-1]; //monthDay array starts from 0 seconds += SECS_PER_DAY * monthDays[i - 1]; // monthDay array starts from 0
} }
} }
seconds+= (tm.Day-1) * SECS_PER_DAY; seconds += (tm.Day - 1) * SECS_PER_DAY;
seconds+= tm.Hour * SECS_PER_HOUR; seconds += tm.Hour * SECS_PER_HOUR;
seconds+= tm.Minute * SECS_PER_MIN; seconds += tm.Minute * SECS_PER_MIN;
seconds+= tm.Second; seconds += tm.Second;
return (time_t)seconds; return (time_t)seconds;
} }
/*=====================================================*/ /*=====================================================*/
@ -248,13 +246,12 @@ static uint32_t nextSyncTime = 0;
static timeStatus_t Status = timeNotSet; static timeStatus_t Status = timeNotSet;
getExternalTime getTimePtr; // pointer to external sync function getExternalTime getTimePtr; // pointer to external sync function
//setExternalTime setTimePtr; // not used in this version // setExternalTime setTimePtr; // not used in this version
#ifdef TIME_DRIFT_INFO // define this to get drift data #ifdef TIME_DRIFT_INFO // define this to get drift data
time_t sysUnsyncedTime = 0; // the time sysTime unadjusted by sync time_t sysUnsyncedTime = 0; // the time sysTime unadjusted by sync
#endif #endif
time_t now() { time_t now() {
// calculate number of seconds passed since last call to now() // calculate number of seconds passed since last call to now()
while (millis() - prevMillis >= 1000) { while (millis() - prevMillis >= 1000) {
@ -281,7 +278,7 @@ time_t now() {
void setTime(time_t t) { void setTime(time_t t) {
#ifdef TIME_DRIFT_INFO #ifdef TIME_DRIFT_INFO
if(sysUnsyncedTime == 0) if (sysUnsyncedTime == 0)
sysUnsyncedTime = t; // store the time of the first call to set a valid Time sysUnsyncedTime = t; // store the time of the first call to set a valid Time
#endif #endif
@ -291,10 +288,10 @@ void setTime(time_t t) {
prevMillis = millis(); // restart counting from now (thanks to Korman for this fix) prevMillis = millis(); // restart counting from now (thanks to Korman for this fix)
} }
void setTime(int hr,int min,int sec,int dy, int mnth, int yr){ void setTime(int hr, int min, int sec, int dy, int mnth, int yr) {
// year can be given as full four digit year or two digts (2010 or 10 for 2010); // year can be given as full four digit year or two digts (2010 or 10 for 2010);
//it is converted to years since 1970 // it is converted to years since 1970
if( yr > 99) if (yr > 99)
yr = yr - 1970; yr = yr - 1970;
else else
yr += 30; yr += 30;
@ -317,13 +314,13 @@ timeStatus_t timeStatus() {
return Status; return Status;
} }
void setSyncProvider( getExternalTime getTimeFunction){ void setSyncProvider(getExternalTime getTimeFunction) {
getTimePtr = getTimeFunction; getTimePtr = getTimeFunction;
nextSyncTime = sysTime; nextSyncTime = sysTime;
now(); // this will sync the clock now(); // this will sync the clock
} }
void setSyncInterval(time_t interval){ // set the number of seconds between re-sync void setSyncInterval(time_t interval) { // set the number of seconds between re-sync
syncInterval = (uint32_t)interval; syncInterval = (uint32_t)interval;
nextSyncTime = sysTime + syncInterval; nextSyncTime = sysTime + syncInterval;
} }

View file

@ -10,18 +10,35 @@
#ifndef _Time_h #ifndef _Time_h
#define _Time_h #define _Time_h
#include <inttypes.h>
#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h>
typedef enum {timeNotSet, timeNeedsSync, timeSet
} timeStatus_t ;
typedef enum { typedef enum {
dowInvalid, dowSunday, dowMonday, dowTuesday, dowWednesday, dowThursday, dowFriday, dowSaturday timeNotSet,
timeNeedsSync,
timeSet
} timeStatus_t;
typedef enum {
dowInvalid,
dowSunday,
dowMonday,
dowTuesday,
dowWednesday,
dowThursday,
dowFriday,
dowSaturday
} timeDayOfWeek_t; } timeDayOfWeek_t;
typedef enum { typedef enum {
tmSecond, tmMinute, tmHour, tmWday, tmDay,tmMonth, tmYear, tmNbrFields tmSecond,
tmMinute,
tmHour,
tmWday,
tmDay,
tmMonth,
tmYear,
tmNbrFields
} tmByteFields; } tmByteFields;
typedef struct { typedef struct {
@ -34,15 +51,14 @@ typedef struct {
uint8_t Year; // offset from 1970; uint8_t Year; // offset from 1970;
} tmElements_t, TimeElements, *tmElementsPtr_t; } tmElements_t, TimeElements, *tmElementsPtr_t;
//convenience macros to convert to and from tm years // convenience macros to convert to and from tm years
#define tmYearToCalendar(Y) ((Y) + 1970) // full four digit year #define tmYearToCalendar(Y) ((Y) + 1970) // full four digit year
#define CalendarYrToTm(Y) ((Y) - 1970) #define CalendarYrToTm(Y) ((Y)-1970)
#define tmYearToY2k(Y) ((Y) - 30) // offset is from 2000 #define tmYearToY2k(Y) ((Y)-30) // offset is from 2000
#define y2kYearToTm(Y) ((Y) + 30) #define y2kYearToTm(Y) ((Y) + 30)
typedef time_t(*getExternalTime)(); typedef time_t (*getExternalTime)();
//typedef void (*setExternalTime)(const time_t); // not used in this version // typedef void (*setExternalTime)(const time_t); // not used in this version
/*==============================================================================*/ /*==============================================================================*/
/* Useful Constants */ /* Useful Constants */
@ -58,23 +74,22 @@ typedef time_t(*getExternalTime)();
#define numberOfSeconds(_time_) ((_time_) % SECS_PER_MIN) #define numberOfSeconds(_time_) ((_time_) % SECS_PER_MIN)
#define numberOfMinutes(_time_) (((_time_) / SECS_PER_MIN) % SECS_PER_MIN) #define numberOfMinutes(_time_) (((_time_) / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (((_time_) % SECS_PER_DAY) / SECS_PER_HOUR) #define numberOfHours(_time_) (((_time_) % SECS_PER_DAY) / SECS_PER_HOUR)
#define dayOfWeek(_time_) ((((_time_) / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday #define dayOfWeek(_time_) ((((_time_) / SECS_PER_DAY + 4) % DAYS_PER_WEEK) + 1) // 1 = Sunday
#define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970 #define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970
#define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight #define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971 // The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
// Always set the correct time before setting alarms // Always set the correct time before setting alarms
#define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day #define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
#define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day #define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day
#define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY)) // note that week starts on day 1 #define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_) - 1) * SECS_PER_DAY)) // note that week starts on day 1
#define previousSunday(_time_) ((_time_) - elapsedSecsThisWeek(_time_)) // time at the start of the week for the given time #define previousSunday(_time_) ((_time_)-elapsedSecsThisWeek(_time_)) // time at the start of the week for the given time
#define nextSunday(_time_) (previousSunday(_time_)+SECS_PER_WEEK) // time at the end of the week for the given time #define nextSunday(_time_) (previousSunday(_time_) + SECS_PER_WEEK) // time at the end of the week for the given time
/* Useful Macros for converting elapsed time to a time_t */ /* Useful Macros for converting elapsed time to a time_t */
#define minutesToTime_t(M) ((M) * SECS_PER_MIN) #define minutesToTime_t(M) ((M)*SECS_PER_MIN)
#define hoursToTime_t(H) ((H) * SECS_PER_HOUR) #define hoursToTime_t(H) ((H)*SECS_PER_HOUR)
#define daysToTime_t(D) ((D) * SECS_PER_DAY) // fixed on Jul 22 2011 #define daysToTime_t(D) ((D)*SECS_PER_DAY) // fixed on Jul 22 2011
#define weeksToTime_t(W) ((W) * SECS_PER_WEEK) #define weeksToTime_t(W) ((W)*SECS_PER_WEEK)
/*============================================================================*/ /*============================================================================*/
/* time and date functions */ /* time and date functions */
@ -104,7 +119,7 @@ const String timeString(time_t t);
time_t now(); // return the current time as seconds since Jan 1 1970 time_t now(); // return the current time as seconds since Jan 1 1970
void setTime(time_t t); void setTime(time_t t);
void setTime(int hr,int min,int sec,int day, int month, int yr); void setTime(int hr, int min, int sec, int day, int month, int yr);
void adjustTime(long adjustment); void adjustTime(long adjustment);
/* date strings */ /* date strings */
@ -116,7 +131,7 @@ const String dayShortStr(uint8_t day);
/* time sync functions */ /* time sync functions */
timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized
void setSyncProvider( getExternalTime getTimeFunction); // identify the external time provider void setSyncProvider(getExternalTime getTimeFunction); // identify the external time provider
void setSyncInterval(time_t interval); // set the number of seconds between re-sync void setSyncInterval(time_t interval); // set the number of seconds between re-sync
/* low level functions to convert to and from system time */ /* low level functions to convert to and from system time */
@ -124,4 +139,3 @@ void breakTime(time_t time, tmElements_t &tm); // break time_t into elements
time_t makeTime(const tmElements_t &tm); // convert time elements into time_t time_t makeTime(const tmElements_t &tm); // convert time elements into time_t
#endif /* _Time_h */ #endif /* _Time_h */

View file

@ -9,48 +9,29 @@
* *
*/ */
#include <Arduino.h>
#include "TimeLib.h" #include "TimeLib.h"
#include <Arduino.h>
const String monthNames[] = const String monthNames[] = {"Error", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
{
"Error", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
};
const String monthStr(uint8_t month) const String monthStr(uint8_t month) {
{
return monthNames[month]; return monthNames[month];
} }
const String monthShortNames[] = {"Err", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
const String monthShortNames[] = const String monthShortStr(uint8_t month) {
{
"Err", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
const String monthShortStr(uint8_t month)
{
return monthShortNames[month]; return monthShortNames[month];
} }
const String dayNames[] = {"Err", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const String dayNames[] = const String dayStr(uint8_t day) {
{
"Err", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
const String dayStr(uint8_t day)
{
return dayNames[day]; return dayNames[day];
} }
const String dayShortNames[] = {"Err", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
const String dayShortNames[] = const String dayShortStr(uint8_t day) {
{
"Err", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
const String dayShortStr(uint8_t day)
{
return dayShortNames[day]; return dayShortNames[day];
} }

View file

@ -19,10 +19,9 @@ lib_deps =
jgromes/RadioLib @ 5.7.0 jgromes/RadioLib @ 5.7.0
check_tool = cppcheck check_tool = cppcheck
check_flags = check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient cppcheck: --std=c++14 --suppress=*:*.pio\* --inline-suppr --suppress=unusedFunction -DCPPCHECK --force lib -ilib/TimeLib
check_skip_packages = yes check_skip_packages = yes
test_build_src = yes test_build_src = yes
#monitor_flags = --raw
# activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port: # activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port:
#upload_protocol = espota #upload_protocol = espota
#upload_port = <CALLSIGN>.local #upload_port = <CALLSIGN>.local
@ -35,4 +34,4 @@ build_flags = -Werror -Wall -DUNITY_INCLUDE_PRINT_FORMATTED
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
build_flags = -Werror -Wall -DCORE_DEBUG_LEVEL=5 -DUNITY_INCLUDE_PRINT_FORMATTED build_flags = -Werror -Wall -DCORE_DEBUG_LEVEL=5 -DUNITY_INCLUDE_PRINT_FORMATTED
build_type = debug build_type = debug
monitor_filters = esp32_exception_decoder #monitor_filters = esp32_exception_decoder