diff --git a/.bumpversion.cfg b/.bumpversion.cfg index daaa391..6fd0f75 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.3.6 +current_version = 1.4.0 [bumpversion:file:CITATION.cff] search = software version diff --git a/CITATION.cff b/CITATION.cff index e340c3f..83713a0 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b9b47a..8d40b3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/device/PowerSensor/PowerSensor.ino b/device/PowerSensor/PowerSensor.ino index 3145875..97780b7 100644 --- a/device/PowerSensor/PowerSensor.ino +++ b/device/PowerSensor/PowerSensor.ino @@ -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 diff --git a/docs/conf.py b/docs/conf.py index 139ba9a..26a27e3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/host/include/PowerSensor.hpp b/host/include/PowerSensor.hpp index 1d8a768..d84a450 100644 --- a/host/include/PowerSensor.hpp +++ b/host/include/PowerSensor.hpp @@ -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 @@ -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); @@ -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; diff --git a/host/src/PowerSensor.cc b/host/src/PowerSensor.cc index ce05055..f3a6bab 100644 --- a/host/src/PowerSensor.cc +++ b/host/src/PowerSensor.cc @@ -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 * diff --git a/host/src/psconfig.cc b/host/src/psconfig.cc index e9d9489..3623ed0 100644 --- a/host/src/psconfig.cc +++ b/host/src/psconfig.cc @@ -127,6 +127,9 @@ void autoCalibrate() { void print() { + // firmware version + std::cout << powerSensor->getVersion() << std::endl; + PowerSensor3::State startState, stopState; measureSensors(&startState, &stopState); @@ -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; @@ -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; @@ -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': @@ -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); diff --git a/python/PyPowerSensor.cc b/python/PyPowerSensor.cc index b392617..a59f7b1 100644 --- a/python/PyPowerSensor.cc +++ b/python/PyPowerSensor.cc @@ -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);