Skip to content

Commit

Permalink
Merge pull request #163 from nlesc-recruit/162-expand-psconfig
Browse files Browse the repository at this point in the history
Expand psconfig
  • Loading branch information
loostrum authored Feb 9, 2024
2 parents 1023781 + 158e2a1 commit 53c173d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.3.6
current_version = 1.4.0

[bumpversion:file:CITATION.cff]
search = software version
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type: software
repository-code: "https://github.com/nlesc-recruit/PowerSensor3"
license: Apache-2.0
#software version
version: 1.3.6
version: 1.4.0
authors:
- given-names: Leon
family-names: Oostrum
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20.1)

project(PowerSensor3 VERSION 1.3.6)
project(PowerSensor3 VERSION 1.4.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-Wall")
Expand Down
6 changes: 3 additions & 3 deletions device/PowerSensor/PowerSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#define TIMEOUT 2000 // ms

#ifdef STM32F401xC
#define VERSION "F401-1.3.6"
#define VERSION "F401-1.4.0"
#elif defined STM32F411xE
#define VERSION "F411-1.3.6"
#define VERSION "F411-1.4.0"
#elif defined STM32F407xx
#define VERSION "F407-1.3.6"
#define VERSION "F407-1.4.0"
#else
#error "Unsupported device"
#endif
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'PowerSensor 3'
copyright = '2023, Leon Oostrum, John Romein, Ben van Werkhoven, Quinten Twisk, Gijs Schoonderbeek, Steven van der Vlugt'
author = 'Leon Oostrum, John Romein, Ben van Werkhoven, Quinten Twisk, Gijs Schoonderbeek, Steven van der Vlugt'
release = '1.3.6'
release = '1.4.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 3 additions & 1 deletion host/include/PowerSensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const unsigned MAX_SENSORS = 8;
static const unsigned MAX_PAIRS = MAX_SENSORS / 2;
static const float VOLTAGE = 3.3;
static const unsigned MAX_LEVEL = 1023;
static const std::string POWERSENSOR_VERSION = "1.3.6";
static const std::string POWERSENSOR_VERSION = "1.4.0";

/**
* @brief Struct containing values of all active sensors at a single point in time
Expand Down Expand Up @@ -55,6 +55,7 @@ class PowerSensor {
void dump(const std::string dumpFileName); // dumpFileName == 0 --> stop dumping
void mark(char name);
void mark(const State &startState, const State &stopState, const std::string name = 0, unsigned int tag = 0) const;
void reset(bool dfuMode);

void writeSensorsToEEPROM();
void setType(unsigned int sensorID, const std::string type);
Expand All @@ -70,6 +71,7 @@ class PowerSensor {
float getSensitivity(unsigned int sensorID) const;
bool getInUse(unsigned int sensorID) const;
int getPolarity(unsigned int sensorID) const;
std::string getVersion();

private:
static const unsigned MAX_TYPE_LENGTH = 16;
Expand Down
36 changes: 36 additions & 0 deletions host/src/PowerSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,42 @@ namespace PowerSensor3 {
return sensorPairs[pairID].consumedEnergy + energy;
}

/**
* @brief Reset device, either normally or to DFU mode for firmware upload
*
* @param dfuMode
*/
void PowerSensor::reset(bool dfuMode) {
stopIOThread(); // to avoid writing to device _after_ reset
if (dfuMode) {
writeCharToDevice('Y');
} else {
writeCharToDevice('Z');
}
}

/**
* @brief Get the firmware version
*
* @return std::string
*/
std::string PowerSensor::getVersion() {
std::string version;
stopIOThread();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
// drain any remaining incoming data
tcflush(fd, TCIFLUSH);
writeCharToDevice('V');
char c = readCharFromDevice();
version += c;
while (c != '\n') {
c = readCharFromDevice();
version += c;
}
startIOThread();
return version;
}

/**
* @brief Get type of given sensor
*
Expand Down
21 changes: 19 additions & 2 deletions host/src/psconfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ void autoCalibrate() {


void print() {
// firmware version
std::cout << powerSensor->getVersion() << std::endl;

PowerSensor3::State startState, stopState;

measureSensors(&startState, &stopState);
Expand Down Expand Up @@ -173,7 +176,7 @@ void print() {

void usage(char *argv[]) {
std::cerr << "usage: " << argv[0] << " [-h] [-d device] [-s sensor] [-t type] "
"[-m name] [-a | -v volt] [-n sensitivity] [-x polarity] [-o on/off] [-p]" << std::endl;
"[-m name] [-a | -v volt] [-n sensitivity] [-x polarity] [-o on/off] [-p] [-r] [-f]" << std::endl;
std::cerr << "-h prints this help" << std::endl;
std::cerr << "-d selects the device (default: /dev/ttyACM0)" << std::endl;
std::cerr << "-s selects the sensor (0-" << PowerSensor3::MAX_SENSORS << ")" << std::endl;
Expand All @@ -189,6 +192,8 @@ void usage(char *argv[]) {
std::cerr << "-x sets the polarity of a sensor. 1 for normal, -1 for inverted" << std::endl;
std::cerr << "-o turns a sensor on (1) or off (0)" << std::endl;
std::cerr << "-p prints configured values" << std::endl;
std::cerr << "-r reboots the device" << std::endl;
std::cerr << "-f reboots the device to DFU mode" << std::endl;
std::cerr << "example: " << argv[0] << " -d /dev/ttyACM0 -s 0 -t MLX10 -v 1.65 "
"-o 1 -s 1 -t voltage0 -v 0 -n 0.95 -o 1 -p" << std::endl;
std::cerr << "Known current sensor types: MLX10, MLX20, MLX50, MLX75." << std::endl;
Expand All @@ -202,7 +207,7 @@ int main(int argc, char *argv[]) {
bool doPrint = false;

std::cout << "psconfig version " << PowerSensor3::POWERSENSOR_VERSION << std::endl << std::endl;
for (int opt; (opt = getopt(argc, argv, "d:s:i:t:m:av:n:x:o:ph")) >= 0;) {
for (int opt; (opt = getopt(argc, argv, "d:s:i:t:m:av:n:x:o:phrf")) >= 0;) {
switch (opt) {
// device select
case 'd':
Expand Down Expand Up @@ -271,6 +276,18 @@ int main(int argc, char *argv[]) {
doPrint = true;
break;

// reboot device
case 'r':
std::cout << "Rebooting device, ignorning any config changes" << std::endl;
getPowerSensor(device)->reset(false);
exit(0); // disconnect after a reset

// reboot device to DFU mode
case 'f':
std::cout << "Rebooting device to DFU mode, ignoring any config changes" << std::endl;
getPowerSensor(device)->reset(true);
return 0; // disconnect after a reset

// help
case 'h':
usage(argv);
Expand Down
2 changes: 1 addition & 1 deletion python/PyPowerSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace py = pybind11;


PYBIND11_MODULE(powersensor, m) {
m.attr("__version__") = "1.3.6";
m.attr("__version__") = "1.4.0";

m.attr("MAX_PAIRS") = py::int_(PowerSensor3::MAX_PAIRS);

Expand Down

0 comments on commit 53c173d

Please sign in to comment.