Skip to content

Commit 53c173d

Browse files
authored
Merge pull request #163 from nlesc-recruit/162-expand-psconfig
Expand psconfig
2 parents 1023781 + 158e2a1 commit 53c173d

File tree

9 files changed

+66
-11
lines changed

9 files changed

+66
-11
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.3.6
2+
current_version = 1.4.0
33

44
[bumpversion:file:CITATION.cff]
55
search = software version

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type: software
1010
repository-code: "https://github.com/nlesc-recruit/PowerSensor3"
1111
license: Apache-2.0
1212
#software version
13-
version: 1.3.6
13+
version: 1.4.0
1414
authors:
1515
- given-names: Leon
1616
family-names: Oostrum

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20.1)
22

3-
project(PowerSensor3 VERSION 1.3.6)
3+
project(PowerSensor3 VERSION 1.4.0)
44

55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_FLAGS "-Wall")

device/PowerSensor/PowerSensor.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#define TIMEOUT 2000 // ms
1010

1111
#ifdef STM32F401xC
12-
#define VERSION "F401-1.3.6"
12+
#define VERSION "F401-1.4.0"
1313
#elif defined STM32F411xE
14-
#define VERSION "F411-1.3.6"
14+
#define VERSION "F411-1.4.0"
1515
#elif defined STM32F407xx
16-
#define VERSION "F407-1.3.6"
16+
#define VERSION "F407-1.4.0"
1717
#else
1818
#error "Unsupported device"
1919
#endif

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
project = 'PowerSensor 3'
1010
copyright = '2023, Leon Oostrum, John Romein, Ben van Werkhoven, Quinten Twisk, Gijs Schoonderbeek, Steven van der Vlugt'
1111
author = 'Leon Oostrum, John Romein, Ben van Werkhoven, Quinten Twisk, Gijs Schoonderbeek, Steven van der Vlugt'
12-
release = '1.3.6'
12+
release = '1.4.0'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

host/include/PowerSensor.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static const unsigned MAX_SENSORS = 8;
1717
static const unsigned MAX_PAIRS = MAX_SENSORS / 2;
1818
static const float VOLTAGE = 3.3;
1919
static const unsigned MAX_LEVEL = 1023;
20-
static const std::string POWERSENSOR_VERSION = "1.3.6";
20+
static const std::string POWERSENSOR_VERSION = "1.4.0";
2121

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

5960
void writeSensorsToEEPROM();
6061
void setType(unsigned int sensorID, const std::string type);
@@ -70,6 +71,7 @@ class PowerSensor {
7071
float getSensitivity(unsigned int sensorID) const;
7172
bool getInUse(unsigned int sensorID) const;
7273
int getPolarity(unsigned int sensorID) const;
74+
std::string getVersion();
7375

7476
private:
7577
static const unsigned MAX_TYPE_LENGTH = 16;

host/src/PowerSensor.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,42 @@ namespace PowerSensor3 {
551551
return sensorPairs[pairID].consumedEnergy + energy;
552552
}
553553

554+
/**
555+
* @brief Reset device, either normally or to DFU mode for firmware upload
556+
*
557+
* @param dfuMode
558+
*/
559+
void PowerSensor::reset(bool dfuMode) {
560+
stopIOThread(); // to avoid writing to device _after_ reset
561+
if (dfuMode) {
562+
writeCharToDevice('Y');
563+
} else {
564+
writeCharToDevice('Z');
565+
}
566+
}
567+
568+
/**
569+
* @brief Get the firmware version
570+
*
571+
* @return std::string
572+
*/
573+
std::string PowerSensor::getVersion() {
574+
std::string version;
575+
stopIOThread();
576+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
577+
// drain any remaining incoming data
578+
tcflush(fd, TCIFLUSH);
579+
writeCharToDevice('V');
580+
char c = readCharFromDevice();
581+
version += c;
582+
while (c != '\n') {
583+
c = readCharFromDevice();
584+
version += c;
585+
}
586+
startIOThread();
587+
return version;
588+
}
589+
554590
/**
555591
* @brief Get type of given sensor
556592
*

host/src/psconfig.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ void autoCalibrate() {
127127

128128

129129
void print() {
130+
// firmware version
131+
std::cout << powerSensor->getVersion() << std::endl;
132+
130133
PowerSensor3::State startState, stopState;
131134

132135
measureSensors(&startState, &stopState);
@@ -173,7 +176,7 @@ void print() {
173176

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

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

279+
// reboot device
280+
case 'r':
281+
std::cout << "Rebooting device, ignorning any config changes" << std::endl;
282+
getPowerSensor(device)->reset(false);
283+
exit(0); // disconnect after a reset
284+
285+
// reboot device to DFU mode
286+
case 'f':
287+
std::cout << "Rebooting device to DFU mode, ignoring any config changes" << std::endl;
288+
getPowerSensor(device)->reset(true);
289+
return 0; // disconnect after a reset
290+
274291
// help
275292
case 'h':
276293
usage(argv);

python/PyPowerSensor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace py = pybind11;
66

77

88
PYBIND11_MODULE(powersensor, m) {
9-
m.attr("__version__") = "1.3.6";
9+
m.attr("__version__") = "1.4.0";
1010

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

0 commit comments

Comments
 (0)