fixes now compiles

This commit is contained in:
grcasanova 2020-07-06 10:45:55 +02:00
parent d5b8038457
commit 92b30ebec6
29 changed files with 111 additions and 76 deletions

View File

@ -61,5 +61,6 @@
"ocrypto", "ocrypto",
"protobufs", "protobufs",
"wifi" "wifi"
] ],
"C_Cpp.dimInactiveRegions": true
} }

17
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "PlatformIO",
"task": "Build",
"problemMatcher": [
"$platformio"
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "PlatformIO: Build"
}
]
}

View File

@ -8,6 +8,7 @@
#include "screen.h" #include "screen.h"
#include "sleep.h" #include "sleep.h"
#include "target_specific.h" #include "target_specific.h"
#include "timing.h"
static void sdsEnter() static void sdsEnter()
{ {
@ -15,7 +16,7 @@ static void sdsEnter()
// Don't deepsleep if we have USB power or if the user as pressed a button recently // Don't deepsleep if we have USB power or if the user as pressed a button recently
// !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME // !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME
if (millis() - lastPressMs > radioConfig.preferences.mesh_sds_timeout_secs) if (timing::millis() - lastPressMs > radioConfig.preferences.mesh_sds_timeout_secs)
{ {
doDeepSleep(radioConfig.preferences.sds_secs); doDeepSleep(radioConfig.preferences.sds_secs);
} }
@ -130,7 +131,7 @@ static void onEnter()
static uint32_t lastPingMs; static uint32_t lastPingMs;
uint32_t now = millis(); uint32_t now = timing::millis();
if (now - lastPingMs > 30 * 1000) { // if more than a minute since our last press, ask other nodes to update their state if (now - lastPingMs > 30 * 1000) { // if more than a minute since our last press, ask other nodes to update their state
if (displayedNodeNum) if (displayedNodeNum)

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "freertosinc.h" #include "../freertosinc.h"
namespace concurrency { namespace concurrency {

View File

@ -1,7 +1,7 @@
#include "PeriodicScheduler.h" #include "PeriodicScheduler.h"
#include "PeriodicTask.h" #include "PeriodicTask.h"
#include "LockGuard.h" #include "LockGuard.h"
#include "../time.h" #include "../timing.h"
namespace concurrency { namespace concurrency {
@ -10,7 +10,7 @@ void PeriodicScheduler::loop()
{ {
LockGuard lg(&lock); LockGuard lg(&lock);
uint32_t now = time::millis(); uint32_t now = timing::millis();
for (auto t : tasks) { for (auto t : tasks) {
if (t->period && (now - t->lastMsec) >= t->period) { if (t->period && (now - t->lastMsec) >= t->period) {

View File

@ -1,16 +1,16 @@
#pragma once #pragma once
#include "PeriodicScheduler.h" #include "PeriodicScheduler.h"
#include "../time.h" #include "timing.h"
namespace concurrency { namespace concurrency {
/** /**
* A base class for tasks that want their doTask() method invoked periodically * @brief A base class for tasks that want their doTask() method invoked periodically
* *
* FIXME: currently just syntatic sugar for polling in loop (you must call .loop), but eventually * @todo currently just syntatic sugar for polling in loop (you must call .loop), but eventually
* generalize with the freertos scheduler so we can save lots of power by having everything either in * generalize with the freertos scheduler so we can save lots of power by having everything either in
* something like this or triggered off of an irq. * something like this or triggered off of an irq.
*/ */
class PeriodicTask class PeriodicTask
{ {
@ -27,7 +27,8 @@ class PeriodicTask
*/ */
PeriodicTask(uint32_t initialPeriod = 1); PeriodicTask(uint32_t initialPeriod = 1);
/** MUST be be called once at startup (but after threading is running - i.e. not from a constructor) /**
* MUST be be called once at startup (but after threading is running - i.e. not from a constructor)
*/ */
void setup(); void setup();
@ -37,7 +38,7 @@ class PeriodicTask
*/ */
void setPeriod(uint32_t p) void setPeriod(uint32_t p)
{ {
lastMsec = time::millis(); // reset starting from now lastMsec = timing::millis(); // reset starting from now
period = p; period = p;
} }

View File

@ -1,5 +1,5 @@
#include "WorkerThread.h" #include "WorkerThread.h"
#include "debug.h" #include "timing.h"
namespace concurrency { namespace concurrency {
@ -10,8 +10,8 @@ void WorkerThread::doRun()
#ifdef DEBUG_STACK #ifdef DEBUG_STACK
static uint32_t lastPrint = 0; static uint32_t lastPrint = 0;
if (millis() - lastPrint > 10 * 1000L) { if (timing::millis() - lastPrint > 10 * 1000L) {
lastPrint = millis(); lastPrint = timing::millis();
uint32_t taskHandle = reinterpret_cast<uint32_t>(xTaskGetCurrentTaskHandle()); uint32_t taskHandle = reinterpret_cast<uint32_t>(xTaskGetCurrentTaskHandle());
DEBUG_MSG("printThreadInfo(%s) task: %" PRIx32 " core id: %u min free stack: %u\n", "thread", taskHandle, xPortGetCoreID(), DEBUG_MSG("printThreadInfo(%s) task: %" PRIx32 " core id: %u min free stack: %u\n", "thread", taskHandle, xPortGetCoreID(),
uxTaskGetStackHighWaterMark(nullptr)); uxTaskGetStackHighWaterMark(nullptr));

View File

@ -3,21 +3,22 @@
#include "CallbackCharacteristic.h" #include "CallbackCharacteristic.h"
#include "RadioLibInterface.h" #include "RadioLibInterface.h"
#include "configuration.h" #include "configuration.h"
#include "lock.h" #include "../concurrency/LockGuard.h"
#include "../timing.h"
#include <Arduino.h> #include <Arduino.h>
#include <BLE2902.h> #include <BLE2902.h>
#include <CRC32.h> #include <CRC32.h>
#include <Update.h> #include <Update.h>
#include <esp_gatt_defs.h> #include <esp_gatt_defs.h>
using namespace meshtastic; //using namespace meshtastic;
CRC32 crc; CRC32 crc;
uint32_t rebootAtMsec = 0; // If not zero we will reboot at this time (used to reboot shortly after the update completes) uint32_t rebootAtMsec = 0; // If not zero we will reboot at this time (used to reboot shortly after the update completes)
uint32_t updateExpectedSize, updateActualSize; uint32_t updateExpectedSize, updateActualSize;
Lock *updateLock; concurrency::Lock *updateLock;
class TotalSizeCharacteristic : public CallbackCharacteristic class TotalSizeCharacteristic : public CallbackCharacteristic
{ {
@ -30,7 +31,7 @@ class TotalSizeCharacteristic : public CallbackCharacteristic
void onWrite(BLECharacteristic *c) void onWrite(BLECharacteristic *c)
{ {
LockGuard g(updateLock); concurrency::LockGuard g(updateLock);
// Check if there is enough to OTA Update // Check if there is enough to OTA Update
uint32_t len = getValue32(c, 0); uint32_t len = getValue32(c, 0);
updateExpectedSize = len; updateExpectedSize = len;
@ -65,7 +66,7 @@ class DataCharacteristic : public CallbackCharacteristic
void onWrite(BLECharacteristic *c) void onWrite(BLECharacteristic *c)
{ {
LockGuard g(updateLock); concurrency::LockGuard g(updateLock);
std::string value = c->getValue(); std::string value = c->getValue();
uint32_t len = value.length(); uint32_t len = value.length();
assert(len <= MAX_BLOCKSIZE); assert(len <= MAX_BLOCKSIZE);
@ -89,7 +90,7 @@ class CRC32Characteristic : public CallbackCharacteristic
void onWrite(BLECharacteristic *c) void onWrite(BLECharacteristic *c)
{ {
LockGuard g(updateLock); concurrency::LockGuard g(updateLock);
uint32_t expectedCRC = getValue32(c, 0); uint32_t expectedCRC = getValue32(c, 0);
uint32_t actualCRC = crc.finalize(); uint32_t actualCRC = crc.finalize();
DEBUG_MSG("expected CRC %u\n", expectedCRC); DEBUG_MSG("expected CRC %u\n", expectedCRC);
@ -106,7 +107,7 @@ class CRC32Characteristic : public CallbackCharacteristic
} else { } else {
if (Update.end()) { if (Update.end()) {
DEBUG_MSG("OTA done, rebooting in 5 seconds!\n"); DEBUG_MSG("OTA done, rebooting in 5 seconds!\n");
rebootAtMsec = millis() + 5000; rebootAtMsec = timing::millis() + 5000;
} else { } else {
DEBUG_MSG("Error Occurred. Error #: %d\n", Update.getError()); DEBUG_MSG("Error Occurred. Error #: %d\n", Update.getError());
} }
@ -124,7 +125,7 @@ class CRC32Characteristic : public CallbackCharacteristic
void bluetoothRebootCheck() void bluetoothRebootCheck()
{ {
if (rebootAtMsec && millis() > rebootAtMsec) { if (rebootAtMsec && timing::millis() > rebootAtMsec) {
DEBUG_MSG("Rebooting for update\n"); DEBUG_MSG("Rebooting for update\n");
ESP.restart(); ESP.restart();
} }
@ -137,7 +138,7 @@ See bluetooth-api.md
BLEService *createUpdateService(BLEServer *server, std::string hwVendor, std::string swVersion, std::string hwVersion) BLEService *createUpdateService(BLEServer *server, std::string hwVendor, std::string swVersion, std::string hwVersion)
{ {
if (!updateLock) if (!updateLock)
updateLock = new Lock(); updateLock = new concurrency::Lock();
// Create the BLE Service // Create the BLE Service
BLEService *service = server->createService(BLEUUID("cb0b9a0b-a84c-4c0d-bdbb-442e3144ee30"), 25, 0); BLEService *service = server->createService(BLEUUID("cb0b9a0b-a84c-4c0d-bdbb-442e3144ee30"), 25, 0);

View File

@ -1,9 +1,9 @@
#include "GPS.h" #include "GPS.h"
#include "configuration.h" #include "configuration.h"
#include "time.h" #include "timing.h"
#include <assert.h> #include <assert.h>
#include <sys/time.h> #include <time.h>
#ifdef GPS_RX_PIN #ifdef GPS_RX_PIN
HardwareSerial _serial_gps_real(GPS_SERIAL_NUM); HardwareSerial _serial_gps_real(GPS_SERIAL_NUM);
@ -27,7 +27,7 @@ void readFromRTC()
struct timeval tv; /* btw settimeofday() is helpfull here too*/ struct timeval tv; /* btw settimeofday() is helpfull here too*/
if (!gettimeofday(&tv, NULL)) { if (!gettimeofday(&tv, NULL)) {
uint32_t now = millis(); uint32_t now = timing::millis();
DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS); DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS);
timeStartMsec = now; timeStartMsec = now;
@ -68,11 +68,9 @@ void perhapsSetRTC(struct tm &t)
perhapsSetRTC(&tv); perhapsSetRTC(&tv);
} }
#include <time.h>
uint32_t getTime() uint32_t getTime()
{ {
return ((millis() - timeStartMsec) / 1000) + zeroOffsetSecs; return ((timing::millis() - timeStartMsec) / 1000) + zeroOffsetSecs;
} }
uint32_t getValidTime() uint32_t getValidTime()

View File

@ -1,5 +1,6 @@
#include "NEMAGPS.h" #include "NEMAGPS.h"
#include "configuration.h" #include "configuration.h"
#include "timing.h"
static int32_t toDegInt(RawDegrees d) static int32_t toDegInt(RawDegrees d)
{ {
@ -19,7 +20,7 @@ void NEMAGPS::loop()
reader.encode(c); reader.encode(c);
} }
uint32_t now = millis(); uint32_t now = timing::millis();
if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume
// serial chars at whatever rate) // serial chars at whatever rate)
lastUpdateMsec = now; lastUpdateMsec = now;

View File

@ -2,7 +2,7 @@
#include "GPS.h" #include "GPS.h"
#include "Observer.h" #include "Observer.h"
#include "PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "TinyGPS++.h" #include "TinyGPS++.h"
/** /**

View File

@ -2,7 +2,7 @@
#include "sleep.h" #include "sleep.h"
#include <assert.h> #include <assert.h>
UBloxGPS::UBloxGPS() : PeriodicTask() UBloxGPS::UBloxGPS() : concurrency::PeriodicTask()
{ {
notifySleepObserver.observe(&notifySleep); notifySleepObserver.observe(&notifySleep);
} }
@ -55,7 +55,7 @@ bool UBloxGPS::setup()
ok = ublox.saveConfiguration(3000); ok = ublox.saveConfiguration(3000);
assert(ok); assert(ok);
PeriodicTask::setup(); // We don't start our periodic task unless we actually found the device concurrency::PeriodicTask::setup(); // We don't start our periodic task unless we actually found the device
return true; return true;
} else { } else {

View File

@ -2,7 +2,7 @@
#include "GPS.h" #include "GPS.h"
#include "Observer.h" #include "Observer.h"
#include "PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "SparkFun_Ublox_Arduino_Library.h" #include "SparkFun_Ublox_Arduino_Library.h"
/** /**
@ -10,7 +10,7 @@
* *
* When new data is available it will notify observers. * When new data is available it will notify observers.
*/ */
class UBloxGPS : public GPS, public PeriodicTask class UBloxGPS : public GPS, public concurrency::PeriodicTask
{ {
SFE_UBLOX_GPS ublox; SFE_UBLOX_GPS ublox;

View File

@ -37,6 +37,7 @@
#include "main.h" #include "main.h"
#include "screen.h" #include "screen.h"
#include "sleep.h" #include "sleep.h"
#include "timing.h"
#include <Wire.h> #include <Wire.h>
#include <OneButton.h> #include <OneButton.h>
// #include <driver/rtc_io.h> // #include <driver/rtc_io.h>
@ -329,7 +330,7 @@ void loop()
powerFSM.run_machine(); powerFSM.run_machine();
service.loop(); service.loop();
periodicScheduler.loop(); concurrency::periodicScheduler.loop();
// axpDebugOutput.loop(); // axpDebugOutput.loop();
#ifdef DEBUG_PORT #ifdef DEBUG_PORT
@ -351,23 +352,23 @@ void loop()
// Show boot screen for first 3 seconds, then switch to normal operation. // Show boot screen for first 3 seconds, then switch to normal operation.
static bool showingBootScreen = true; static bool showingBootScreen = true;
if (showingBootScreen && (millis() > 3000)) { if (showingBootScreen && (timing::millis() > 3000)) {
screen.stopBootScreen(); screen.stopBootScreen();
showingBootScreen = false; showingBootScreen = false;
} }
#ifdef DEBUG_STACK #ifdef DEBUG_STACK
static uint32_t lastPrint = 0; static uint32_t lastPrint = 0;
if (millis() - lastPrint > 10 * 1000L) { if (timing::millis() - lastPrint > 10 * 1000L) {
lastPrint = millis(); lastPrint = timing::millis();
meshtastic::printThreadInfo("main"); meshtastic::printThreadInfo("main");
} }
#endif #endif
// Update the screen last, after we've figured out what to show. // Update the screen last, after we've figured out what to show.
screen.debug()->setNodeNumbersStatus(nodeDB.getNumOnlineNodes(), nodeDB.getNumNodes()); screen.debug_info()->setNodeNumbersStatus(nodeDB.getNumOnlineNodes(), nodeDB.getNumNodes());
screen.debug()->setChannelNameStatus(channelSettings.name); screen.debug_info()->setChannelNameStatus(channelSettings.name);
screen.debug()->setPowerStatus(powerStatus); screen.debug_info()->setPowerStatus(powerStatus);
// No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in) // No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in)
// i.e. don't just keep spinning in loop as fast as we can. // i.e. don't just keep spinning in loop as fast as we can.

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "PacketHistory.h" #include "PacketHistory.h"
#include "PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "Router.h" #include "Router.h"
/** /**

View File

@ -7,12 +7,13 @@
//#include "MeshBluetoothService.h" //#include "MeshBluetoothService.h"
#include "MeshService.h" #include "MeshService.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "Periodic.h" #include "../concurrency/Periodic.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "power.h" #include "power.h"
#include "BluetoothUtil.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here #include "BluetoothUtil.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here
#include "timing.h"
/* /*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@ -55,7 +56,7 @@ static uint32_t sendOwnerCb()
return radioConfig.preferences.send_owner_interval * radioConfig.preferences.position_broadcast_secs * 1000; return radioConfig.preferences.send_owner_interval * radioConfig.preferences.position_broadcast_secs * 1000;
} }
static Periodic sendOwnerPeriod(sendOwnerCb); static concurrency::Periodic sendOwnerPeriod(sendOwnerCb);
MeshService::MeshService() : toPhoneQueue(MAX_RX_TOPHONE) MeshService::MeshService() : toPhoneQueue(MAX_RX_TOPHONE)
{ {
@ -308,7 +309,7 @@ int MeshService::onGPSChanged(void *unused)
// We limit our GPS broadcasts to a max rate // We limit our GPS broadcasts to a max rate
static uint32_t lastGpsSend; static uint32_t lastGpsSend;
uint32_t now = millis(); uint32_t now = timing::millis();
if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) { if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) {
lastGpsSend = now; lastGpsSend = now;
DEBUG_MSG("Sending position to mesh\n"); DEBUG_MSG("Sending position to mesh\n");

View File

@ -1,6 +1,7 @@
#include "PacketHistory.h" #include "PacketHistory.h"
#include "configuration.h" #include "configuration.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "../timing.h"
PacketHistory::PacketHistory() PacketHistory::PacketHistory()
{ {
@ -18,7 +19,7 @@ bool PacketHistory::wasSeenRecently(const MeshPacket *p, bool withUpdate)
return false; // Not a floodable message ID, so we don't care return false; // Not a floodable message ID, so we don't care
} }
uint32_t now = millis(); uint32_t now = timing::millis();
for (size_t i = 0; i < recentPackets.size();) { for (size_t i = 0; i < recentPackets.size();) {
PacketRecord &r = recentPackets[i]; PacketRecord &r = recentPackets[i];

View File

@ -4,6 +4,7 @@
#include "PowerFSM.h" #include "PowerFSM.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#include "GPS.h" #include "GPS.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
PhoneAPI::PhoneAPI() PhoneAPI::PhoneAPI()
@ -20,7 +21,7 @@ void PhoneAPI::init()
void PhoneAPI::checkConnectionTimeout() void PhoneAPI::checkConnectionTimeout()
{ {
if (isConnected) { if (isConnected) {
bool newConnected = (millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L); bool newConnected = (timing::millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L);
if (!newConnected) { if (!newConnected) {
isConnected = false; isConnected = false;
onConnectionChanged(isConnected); onConnectionChanged(isConnected);
@ -34,7 +35,7 @@ void PhoneAPI::checkConnectionTimeout()
void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
{ {
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // As long as the phone keeps talking to us, don't let the radio go to sleep powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // As long as the phone keeps talking to us, don't let the radio go to sleep
lastContactMsec = millis(); lastContactMsec = timing::millis();
if (!isConnected) { if (!isConnected) {
isConnected = true; isConnected = true;
onConnectionChanged(isConnected); onConnectionChanged(isConnected);

View File

@ -6,6 +6,7 @@
#include "assert.h" #include "assert.h"
#include "configuration.h" #include "configuration.h"
#include "sleep.h" #include "sleep.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
@ -155,7 +156,7 @@ size_t RadioInterface::beginSending(MeshPacket *p)
// DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad()); // DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad());
assert(p->which_payload == MeshPacket_encrypted_tag); // It should have already been encoded by now assert(p->which_payload == MeshPacket_encrypted_tag); // It should have already been encoded by now
lastTxStart = millis(); lastTxStart = timing::millis();
PacketHeader *h = (PacketHeader *)radiobuf; PacketHeader *h = (PacketHeader *)radiobuf;

View File

@ -4,7 +4,7 @@
#include "MeshTypes.h" #include "MeshTypes.h"
#include "Observer.h" #include "Observer.h"
#include "PointerQueue.h" #include "PointerQueue.h"
#include "WorkerThread.h" #include "../concurrency/NotifiedWorkerThread.h"
#include "mesh.pb.h" #include "mesh.pb.h"
#define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission #define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission
@ -43,7 +43,7 @@ typedef enum {
* *
* This defines the SOLE API for talking to radios (because soon we will have alternate radio implementations) * This defines the SOLE API for talking to radios (because soon we will have alternate radio implementations)
*/ */
class RadioInterface : protected NotifiedWorkerThread class RadioInterface : protected concurrency::NotifiedWorkerThread
{ {
friend class MeshRadio; // for debugging we let that class touch pool friend class MeshRadio; // for debugging we let that class touch pool
PointerQueue<MeshPacket> *rxDest = NULL; PointerQueue<MeshPacket> *rxDest = NULL;

View File

@ -10,7 +10,7 @@ static SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0);
RadioLibInterface::RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, RadioLibInterface::RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy,
SPIClass &spi, PhysicalLayer *_iface) SPIClass &spi, PhysicalLayer *_iface)
: PeriodicTask(0), module(cs, irq, rst, busy, spi, spiSettings), iface(_iface) : concurrency::PeriodicTask(0), module(cs, irq, rst, busy, spi, spiSettings), iface(_iface)
{ {
assert(!instance); // We assume only one for now assert(!instance); // We assume only one for now
instance = this; instance = this;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#ifdef CubeCell_BoardPlus #ifdef CubeCell_BoardPlus
@ -16,7 +16,7 @@
#define INTERRUPT_ATTR #define INTERRUPT_ATTR
#endif #endif
class RadioLibInterface : public RadioInterface, private PeriodicTask class RadioLibInterface : public RadioInterface, private concurrency::PeriodicTask
{ {
/// Used as our notification from the ISR /// Used as our notification from the ISR
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED }; enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };

View File

@ -2,6 +2,7 @@
#include "MeshTypes.h" #include "MeshTypes.h"
#include "configuration.h" #include "configuration.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "timing.h"
// ReliableRouter::ReliableRouter() {} // ReliableRouter::ReliableRouter() {}
@ -162,7 +163,7 @@ PendingPacket *ReliableRouter::startRetransmission(MeshPacket *p)
*/ */
void ReliableRouter::doRetransmissions() void ReliableRouter::doRetransmissions()
{ {
uint32_t now = millis(); uint32_t now = timing::millis();
// FIXME, we should use a better datastructure rather than walking through this map. // FIXME, we should use a better datastructure rather than walking through this map.
// for(auto el: pending) { // for(auto el: pending) {

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "FloodingRouter.h" #include "FloodingRouter.h"
#include "PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "../timing.h"
#include <unordered_map> #include <unordered_map>
/** /**
@ -48,7 +49,7 @@ struct PendingPacket {
PendingPacket() {} PendingPacket() {}
PendingPacket(MeshPacket *p); PendingPacket(MeshPacket *p);
void setNextTx() { nextTxMsec = millis() + random(20 * 1000L, 22 * 1000L); } void setNextTx() { nextTxMsec = timing::millis() + random(20 * 1000L, 22 * 1000L); }
}; };
class GlobalPacketIdHashFunction class GlobalPacketIdHashFunction

View File

@ -12,7 +12,7 @@
#include "concurrency/PeriodicTask.h" #include "concurrency/PeriodicTask.h"
#include "TypedQueue.h" #include "TypedQueue.h"
#include "concurrency/Lock.h" #include "concurrency/LockGuard.h"
#include "power.h" #include "power.h"
#include <string> #include <string>
@ -187,7 +187,7 @@ class Screen : public concurrency::PeriodicTask
/// Returns a handle to the DebugInfo screen. /// Returns a handle to the DebugInfo screen.
// //
// Use this handle to set things like battery status, user count, GPS status, etc. // Use this handle to set things like battery status, user count, GPS status, etc.
DebugInfo *debug() { return &debugInfo; } DebugInfo* debug_info() { return &debugInfo; }
protected: protected:
/// Updates the UI. /// Updates the UI.

View File

@ -5,7 +5,7 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "configuration.h" #include "configuration.h"
#include "error.h" #include "error.h"
#include "timing.h"
#include "main.h" #include "main.h"
#include "target_specific.h" #include "target_specific.h"
@ -123,11 +123,11 @@ bool doPreflightSleep()
/// Tell devices we are going to sleep and wait for them to handle things /// Tell devices we are going to sleep and wait for them to handle things
static void waitEnterSleep() static void waitEnterSleep()
{ {
uint32_t now = millis(); uint32_t now = timing::millis();
while (!doPreflightSleep()) { while (!doPreflightSleep()) {
delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives) delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives)
if (millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep if (timing::millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep
recordCriticalError(ErrSleepEnterWait); recordCriticalError(ErrSleepEnterWait);
assert(0); // FIXME - for now we just restart, need to fix bug #167 assert(0); // FIXME - for now we just restart, need to fix bug #167
break; break;

View File

@ -1,11 +0,0 @@
#pragma once
#include "freertos.h"
namespace time {
uint32_t millis() {
return xTaskGetTickCount();
}
} // namespace time

10
src/timing.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "timing.h"
#include "freertosinc.h"
namespace timing {
uint32_t millis() {
return xTaskGetTickCount();
}
} // namespace timing

9
src/timing.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <cstdint>
namespace timing {
uint32_t millis();
} // namespace timing