Skip to content

Commit

Permalink
adding anya actuator branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jdh committed Sep 26, 2023
1 parent b11d7d4 commit d425d6f
Show file tree
Hide file tree
Showing 26 changed files with 1,384 additions and 105 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

* upgraded to maple 14.0.0 ([23a4d48](https://github.com/WaterBearSondes/waterbear-firmware/commit/23a4d48ed5a4cde8f87365d09ca46ac12acf1145))
* upgraded to maple v14.0.0 ([bea4157](https://github.com/WaterBearSondes/waterbear-firmware/commit/bea4157acd4f2feaba3784daeb0e8326a756bda9))

# [1.1.0](https://github.com/WaterBearSondes/waterbear-firmware/compare/v1.0.10...v1.1.0) (2021-05-22)
#
[1.1.0](https://github.com/WaterBearSondes/waterbear-firmware/compare/v1.0.10...v1.1.0) (2021-05-22)


### Bug Fixes
Expand Down
6 changes: 4 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ build_unflags = -O2
#build_unflags = -std=gnu++11
board_build.f_cpu = 64000000L
lib_deps =
https://github.com/ZavenArra/ModularSensors#stm32f1
; [email protected]:ZavenArra/ModularSensors.git#stm32f1
https://github.com/ZavenArra/ModularSensors.git#stm32f1
; https://github.com/deepwinter/Adafruit_BluefruitLE_nRF51.git
https://github.com/WaterBearSondes/DS3231.git
https://github.com/WaterBearSondes/atlas_OEM.git
https://github.com/greiman/SdFat.git#1.1.4
https://github.com/DaveGamble/cJSON.git
https://github.com/ZavenArra/CmdArduino.git
https://github.com/adafruit/DHT-sensor-library.git
https://github.com/adafruit/Adafruit_AHTX0.git
https://github.com/adafruit/Adafruit_BME280_Library.git
;adafruit/DHT sensor library
monitor_speed = 115200
debug_port = /dev/ttyACM0
check_tool = cppcheck
check_flags = --enable=all

91 changes: 57 additions & 34 deletions src/datalogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#include "utilities/STM32-UID.h"
#include "scratch/dbgmcu.h"
#include "system/logs.h"
#include "sensors/drivers/air_pump.h"
#include "sensors/drivers/generic_actuator.h"

// #include "sensors/drivers/air_pump.h"
// #include "sensors/drivers/generic_actuator.h"

void Datalogger::sleepMCU(uint32 milliseconds)
{
Expand Down Expand Up @@ -96,12 +101,15 @@ Datalogger::Datalogger(datalogger_settings_type *settings)
{
powerCycle = true;

// defaults
//defaults
if (settings->interval < 1)
{
settings->interval = 1;
}




memcpy(&this->settings, settings, sizeof(datalogger_settings_type));

switch (settings->mode)
Expand Down Expand Up @@ -165,15 +173,19 @@ bool Datalogger::processReadingsCycle()
{
writeRawMeasurementToLogFile();
}


if (shouldContinueBursting())
{

// sleep for maximum time before next reading
// ask all drivers for maximum time until next burst reading
// ask all drivers for maximum time until next available reading
// sleep for whichever is less

notify(minMillisecondsUntilNextReading());
sleepMCU(minMillisecondsUntilNextReading());

return true;
}

Expand All @@ -189,8 +201,7 @@ bool Datalogger::processReadingsCycle()

if (settings.interBurstDelay > 0)
{
notify(F("burst delay"));
int interBurstDelay = settings.interBurstDelay;
int interBurstDelay = settings.interBurstDelay * 60; // convert to seconds
// todo: we should sleep any sensors that can be slept without re-warming
// this could be called 'standby' mode
// placeSensorsInStandbyMode();
Expand All @@ -199,9 +210,9 @@ bool Datalogger::processReadingsCycle()
}

initializeBurst();

return true;
}

return false;
}

Expand All @@ -210,6 +221,7 @@ void Datalogger::testMeasurementCycle()
initializeMeasurementCycle();
fileSystemWriteCache->setOutputToSerial(true); // another way to do this would be to set a special write cache
while(processReadingsCycle()){

fileSystemWriteCache->flushCache();
outputLastMeasurement();
}
Expand All @@ -227,7 +239,8 @@ void Datalogger::loop()
}

if (inMode(logging))
{
{
//AE actuate hook before measurement could go here

if (powerCycle)
{
Expand All @@ -248,18 +261,20 @@ void Datalogger::loop()

if (shouldExitLoggingMode())
{
notify("Should exit logging mode");
changeMode(interactive);
return;
}

if(processReadingsCycle())
if(processReadingsCycle() == true) // nothing changes if this true/false
{
return;
}

// otherwise go to sleep
fileSystemWriteCache->flushCache();

//AE actuator hook could go here: is this before or after measurement?

SLEEP:
stopAndAwaitTrigger();
initializeMeasurementCycle();
Expand Down Expand Up @@ -335,13 +350,13 @@ void Datalogger::loadSensorConfigurations()
}
if (sensorCount == 0)
{
notify("no sensor configurations found");
notify("no sensor config");
}
notify("FREE MEM");
printFreeMemory();

// construct the drivers
notify("construct drivers");
// notify("construct drivers");
drivers = (SensorDriver **)malloc(sizeof(SensorDriver *) * sensorCount);
int j = 0;
for (int i = 0; i < EEPROM_TOTAL_SENSOR_SLOTS; i++)
Expand Down Expand Up @@ -458,6 +473,8 @@ void Datalogger::initializeBurst()

void Datalogger::initializeMeasurementCycle()
{
//AE actuate hook before measurement could go here

// notify(F("setting base time"));
currentEpoch = timestamp();
offsetMillis = millis();
Expand All @@ -473,10 +490,9 @@ void Datalogger::initializeMeasurementCycle()
// delay(20000);
// startCustomWatchDog();

notify(F("wait for start up delay"));
int startUpDelay = settings.startUpDelay*60; // convert to seconds and print
// startUpDelay = 2;
notify(startUpDelay);
// notify(startUpDelay);
sleepMCU(startUpDelay * 1000); // convert seconds to milliseconds
notify("sleep done");
}
Expand All @@ -487,7 +503,7 @@ void Datalogger::initializeMeasurementCycle()
sensorsWarmedUp = true;
for (unsigned short i = 0; i < sensorCount; i++)
{
notify("check isWarmed");
// notify("check isWarmed");
if (!drivers[i]->isWarmedUp())
{
// TODO: enhancement, ask the sensor driver if we should sleep MCU for a while
Expand All @@ -496,11 +512,15 @@ void Datalogger::initializeMeasurementCycle()
}
}
}
//AE actuator call could go here


}

void Datalogger::measureSensorValues(bool performingBurst)
{
// notify("in measure senosr values\n");

if (settings.externalADCEnabled)
{
// get readings from the external ADC
Expand All @@ -511,11 +531,14 @@ void Datalogger::measureSensorValues(bool performingBurst)

for (unsigned int i = 0; i < sensorCount; i++)
{

if (drivers[i]->takeMeasurement())
{

if (performingBurst)
{
drivers[i]->incrementBurst(); // burst bookkeeping

}
}
}
Expand Down Expand Up @@ -677,7 +700,7 @@ void Datalogger::setConfiguration(cJSON *config)
{
strcpy(settings.deploymentIdentifier, deploymentIdentifierJSON->valuestring);
} else {
notify("Invalid deployment identifier");
notify("Invalid deployment ID");
}

const cJSON * intervalJson = cJSON_GetObjectItemCaseSensitive(config, "interval");
Expand Down Expand Up @@ -745,6 +768,7 @@ void Datalogger::setSensorConfiguration(char *type, cJSON *json)
{
return;
}

if (driver->getProtocol() == i2c)
{
((I2CProtocolSensorDriver *)driver)->setWire(&WireTwo);
Expand Down Expand Up @@ -788,8 +812,10 @@ void Datalogger::setSensorConfiguration(char *type, cJSON *json)
}
free(drivers);
drivers = updatedDrivers;

}
}

}

void Datalogger::clearSlot(unsigned short slot)
Expand Down Expand Up @@ -910,7 +936,7 @@ void Datalogger::calibrate(unsigned short slot, char *subcommand, int arg_cnt, c

if (strcmp(subcommand, "init") == 0)
{
notify("calling init");
// notify("calling init");
driver->initCalibration();
}
else
Expand Down Expand Up @@ -958,8 +984,9 @@ bool Datalogger::deploy()
notifyDebugStatus();
if (checkDebugSystemDisabled() == false)
{
notify("**** ABORTING DEPLOYMENT *****");
notify("**** PLEASE POWER CYCLE THIS UNIT AND TRY AGAIN *****");
// notify("**** ABORTING DEPLOYMENT *****");
// notify("**** PLEASE POWER CYCLE THIS UNIT AND TRY AGAIN *****");
notify("ABORT TRY AGAIN");
return false;
}

Expand Down Expand Up @@ -1248,31 +1275,27 @@ const char *Datalogger::getUUIDString()
}


int Datalogger::minMillisecondsUntilNextReading()
unsigned int Datalogger::minMillisecondsUntilNextReading()
{
unsigned int minimumNextRequestedReading = MAX_REQUESTED_READING_DELAY;
unsigned int minimumDelayUntilNextRequestedReading = MAX_REQUESTED_READING_DELAY;
unsigned int maxDelayUntilNextAvailableReading = 0;
for(int i=0; i<sensorCount; i++)
{
minimumNextRequestedReading = min(minimumNextRequestedReading, drivers[i]->millisecondsUntilNextRequestedReading());
}
// retrieve the fastest time requested for sampling
minimumDelayUntilNextRequestedReading = min(minimumDelayUntilNextRequestedReading, drivers[i]->millisecondsUntilNextRequestedReading());

unsigned int maxDelayUntilNextAvailableReading = 0;
for(int i=0; i<sensorCount; i++)
{
// retrieve the slowest response time for sampling
maxDelayUntilNextAvailableReading = max(maxDelayUntilNextAvailableReading, drivers[i]->millisecondsUntilNextReadingAvailable());
}

// we want to read as fast the speed requested by the fastest sensor
// or as slow as the slowest sensor has a new reading available
if(maxDelayUntilNextAvailableReading == 0)
{
return minimumNextRequestedReading;
}
else
{
return min(minimumNextRequestedReading, maxDelayUntilNextAvailableReading);
}

// return max to prioritize sampling as soon as ALL sensors are ready to sample
return max(minimumDelayUntilNextRequestedReading, maxDelayUntilNextAvailableReading);
// return min to prioritize sampling at desired speed for ONE specific sensor
// if (maxDelayUntilNextAvailableReading == 0) // meaning all sensors have no delay between readings available
// {
// return minimumDelayUntilNextRequestedReading;
// }
// return min(minimumDelayUntilNextRequestedReading, maxDelayUntilNextAvailableReading);
}


Expand Down
4 changes: 2 additions & 2 deletions src/datalogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct datalogger_settings {
char loggerName[8]; // 8 bytes
unsigned long deploymentTimestamp; // 8 bytes
unsigned short interval; // 2 bytes minutes
unsigned short burstNumber; // 2 bytes
unsigned short burstNumber; // 2 bytes
unsigned short startUpDelay; // 2 bytes minutes
unsigned short interBurstDelay; // 2 bytes minutes
char mode; // 1 byte i(interactive), d(debug), l(logging), t(deploy on trigger)
Expand Down Expand Up @@ -178,7 +178,7 @@ class Datalogger
void storeSensorConfiguration(SensorDriver * driver);

void sleepMCU(uint32 milliseconds);
int minMillisecondsUntilNextReading();
unsigned int minMillisecondsUntilNextReading();

// run loop
void initializeFilesystem();
Expand Down
14 changes: 13 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "system/eeprom.h"
#include "system/logs.h"


// Setup and Loop
Datalogger *datalogger;
void printWelcomeMessage(datalogger_settings_type *dataloggerSettings);
Expand Down Expand Up @@ -56,6 +57,16 @@ void setup(void)
enableI2C1();
delay(500);











debug("creating datalogger");
datalogger_settings_type *dataloggerSettings = (datalogger_settings_type *)malloc(sizeof(datalogger_settings_type));
Datalogger::readConfiguration(dataloggerSettings);
Expand All @@ -77,6 +88,7 @@ void setup(void)
{
notify("Device will enter logging mode in 5 seconds");
notify("Type 'i' to exit to interactive mode");

Serial2.print("CMD >> ");
int start = timestamp();
int now = start;
Expand Down Expand Up @@ -153,7 +165,7 @@ Type 'help' for command list.
// space to work our development details


void workspace()
void workspace()
{
// notify(sizeof(long long));
// notify(sizeof(sone));
Expand Down
Loading

0 comments on commit d425d6f

Please sign in to comment.