Skip to content

Commit

Permalink
Merge pull request #87 from makers-for-life/dev
Browse files Browse the repository at this point in the history
Implement EOL on telemetry
  • Loading branch information
valeriansaliou authored Jun 2, 2021
2 parents da57950 + c46135b commit 04aad4c
Show file tree
Hide file tree
Showing 16 changed files with 359 additions and 114 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

## unreleased

_Nothing for now_
- fixed malformatted fatal error telemetry messages
(_existing ones did not pass CRC checks_)
- implemented new fatal error telemetry messages
(_SFM sensor failure, battery deep discharge, calibration errors_)
- sending "end of production line" telemetry snapshots
(_used for the UI to show current EOL step_)
- handling "end of production line" control messages
(_used to continue to next EOL step_)
- if hardware buttons are disabled, then the "end of production line" will skip the buttons test step
- added automation and convenience scripts
(_used to compile and flash to auto-detected serial port_)
- refactored project structure
(_some directories and files have been moved_)

## v4.0.0

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
| V1.2.x | First release version on Hardware V1 | ✅
| V1.3.x | Add Hardware V2 support | ✅
| V1.5.x | Rework ventilation algorithms (pressure control, alarms, code quality) | ✅
| V3.0.x | Support for triggers, add mass flow meter, add Hardware V3 support | ✅
| V3.0.x | Add Hardware V3 support, support for triggers, add mass flow meter | ✅
| V4.0.x | Protocol V2 with ventilation modes, drop Hardware V1 & V2 support | ✅
| V4.1.x | End-of-line test and fatal errors on the UI, store user settings on the EEPROM | ❌
| V4.1.x | End-of-line test and fatal errors on the UI | ❌

For a full history of all minor versions, as well as details of all changes, see [CHANGELOG.md](CHANGELOG.md).

Expand Down Expand Up @@ -68,6 +68,10 @@ A few scripts are available, eg. to automate repeated manual actions:
1. **Compile & Flash**: `./scripts/compile_and_flash.sh` (compiles firmware and flashes it over the plugged STM32 programmer);
2. **Compile Only**: `./scripts/compile_only.sh` (compiles firmware, useful to check for code mistakes);

Some specialized scripts are available, eg. that target older hardwares:

1. **Compile & DFU (HW3)**: `./scripts/compile_and_dfu_hardware_v3.sh` (compiles firmware and flashes it to Hardware V3);

## Configuration

The configuration options can be found in the following files:
Expand Down
4 changes: 2 additions & 2 deletions includes/calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void Calibration_Init(void);
*/
void Calibration_Wait_Measure_Pressure(uint16_t ms);

/// Read keyboard duing calibration process
void Calibration_Read_Keyboard(void);
/// Read keyboard duing calibration process (delayed)
void Calibration_Read_Keyboard_Delayed(void);

/// Restart calibration process
void Calibration_Restart(void);
Expand Down
4 changes: 3 additions & 1 deletion includes/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

/// Defines the current mode
#define MODE MODE_PROD

/**
* Activates debug traces
*
Expand Down Expand Up @@ -54,3 +53,6 @@
/// Disable hardware buttons, used when integrating a motherboard in a touch- \
/// only device.
// #define DISABLE_BUTTONS

// Uncomment when compiling for the simulator
// #define SIMULATOR
62 changes: 62 additions & 0 deletions includes/end_of_line_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#pragma once

// INCLUDES ===================================================================

// Internal

#include "../includes/blower.h"
#include "../includes/pressure_valve.h"

Expand All @@ -17,7 +21,62 @@
*/
#define EOL_TEST_ACTIVE 0xa240183a

// ENUMS =================================================================

enum TestStep {
START,
SUPPLY_TO_EXPANDER_NOT_CONNECTED,
CHECK_FAN,
TEST_BAT_DEAD,
BATTERY_DEEP_DISCHARGE,
DISCONNECT_MAINS,
CONNECT_MAINS,
CHECK_BUZZER,
// cppcheck-suppress misra-c2012-12.3
CHECK_ALL_BUTTONS,
CHECK_UI_SCREEN,
// cppcheck-suppress misra-c2012-12.3
PLUG_AIR_TEST_SYTEM,
// cppcheck-suppress misra-c2012-12.3
REACH_MAX_PRESSURE,
// cppcheck-suppress misra-c2012-12.3
MAX_PRESSURE_REACHED_OK,
// cppcheck-suppress misra-c2012-12.3
MAX_PRESSURE_NOT_REACHED,
// cppcheck-suppress misra-c2012-12.3
START_LEAK_MESURE,
// cppcheck-suppress misra-c2012-12.3
LEAK_IS_TOO_HIGH,
// cppcheck-suppress misra-c2012-12.3
REACH_NULL_PRESSURE,
// cppcheck-suppress misra-c2012-12.3
MIN_PRESSURE_NOT_REACHED,
USER_CONFIRMATION_BEFORE_O2_TEST,
// cppcheck-suppress misra-c2012-12.3
START_O2_TEST,
// cppcheck-suppress misra-c2012-12.3
O2_PRESSURE_NOT_REACH,
WAIT_USER_BEFORE_LONG_RUN,
// cppcheck-suppress misra-c2012-12.3
START_LONG_RUN_BLOWER,
// cppcheck-suppress misra-c2012-12.3
PRESSURE_NOT_STABLE,
FLOW_NOT_STABLE,
END_SUCCESS,
DISPLAY_PRESSURE,
DISPLAY_FLOW
};

enum TestState {
STATE_IN_PROGRESS,
STATE_ERROR,
STATE_SUCCESS
};

// CLASS ======================================================================

/// Controls the running of the embedded auto tests
// cppcheck-suppress misra-c2012-5.2 ; false positive
class EolTest {
public:
/// Default constructor
Expand All @@ -33,6 +92,9 @@ class EolTest {
*/
bool isRunning();

/// Handle EOL confirm control setting from telemetry
void onConfirm();

/// Run test mode
void setupAndStart();

Expand Down
2 changes: 2 additions & 0 deletions includes/serial_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ enum ControlSetting {
PatientGender = 29,
/// Threshold for peak pressure alarm in mmH2O (value bounds must be between 50 and 700)
PeakPressureAlarmThreshold = 30,
/// Confirm end-of-line test step (value bounds must be between 0 and 0)
EolConfirm = 31,
};

/**
Expand Down
11 changes: 10 additions & 1 deletion includes/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
* @file telemetry.h
* @brief Implementation of the telemetry protocol
*****************************************************************************/

#pragma once

#include <stdint.h>

#include "../includes/alarm_controller.h"
#include "../includes/config.h"
#include "../includes/cycle.h"
#ifndef SIMULATOR
#include "../includes/end_of_line_test.h"
#endif

/// Current version of the telemetry protocol
#define PROTOCOL_VERSION 2u
Expand Down Expand Up @@ -144,6 +147,12 @@ void sendMassFlowMeterFatalError(void);
// /// Send a "inconsistent pressure" fatal error
void sendInconsistentPressureFatalError(uint16_t pressureValue);

#ifndef SIMULATOR // Disable the following function when in simulator
/// Send an "end-of-line test" snapshot
void sendEolTestSnapshot(TestStep step, TestState state, char message[]);

#endif

/**
* Convert and round a pressure in mmH2O to a pressure in cmH2O
*
Expand Down
15 changes: 15 additions & 0 deletions scripts/compile_and_dfu_hardware_v3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

##
# compile_and_dfu_hardware_v3.sh
# Compile & DFU HW3 utility
#
# Copyright 2021, Makers For Life
# Author: Makers For Life
##

arduino-cli compile --fqbn STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE ../srcs/respirator.cpp --output-dir ../builds || exit 1

dfu-util -a 0 --dfuse-address 0x08000000 -D builds/srcs.ino.bin || exit 1

exit 0
8 changes: 8 additions & 0 deletions scripts/compile_and_flash.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash

##
# compile_and_flash.sh
# Compile & Flash utility
#
# Copyright 2021, Makers For Life
# Author: Makers For Life
##

ABSPATH=$(cd "$(dirname "$0")"; pwd)
BASE_DIR="$ABSPATH/../"

Expand Down
8 changes: 8 additions & 0 deletions scripts/compile_only.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash

##
# compile_only.sh
# Compile utility
#
# Copyright 2021, Makers For Life
# Author: Makers For Life
##

ABSPATH=$(cd "$(dirname "$0")"; pwd)
BASE_DIR="$ABSPATH/../"

Expand Down
62 changes: 43 additions & 19 deletions srcs/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ int32_t pressureOffsetSum;
uint32_t pressureOffsetCount;
int32_t minOffsetValue = 0;
int32_t maxOffsetValue = 0;
uint32_t restartWaitTimer = 0;
bool startButtonPressed = false;
bool calibationStarted = false;
bool calibrationValid = false;
#define RESTART_READ_KEYBOARD_DELAY 100

void Calibration_Init() {
// Restart calibration process when invalid
Expand Down Expand Up @@ -72,9 +74,21 @@ void Calibration_Init() {
// Invalid calibration
calibrationValid = false;
displayPressureOffsetUnstable(minOffsetValue, maxOffsetValue);
sendInconsistentPressureFatalError(inspiratoryPressureSensorOffset);
Buzzer_High_Prio_Start();
Calibration_Read_Keyboard();

// Wait for user to press start to restart calibration
restartWaitTimer = 0;

while (startButtonPressed == false) {
restartWaitTimer += (uint32_t)RESTART_READ_KEYBOARD_DELAY;

// Heartbeat fatal error periodically
if ((restartWaitTimer % 1000u) == 0u) {
sendInconsistentPressureFatalError(maxOffsetValue - minOffsetValue);
}

Calibration_Read_Keyboard_Delayed();
}
} else {
calibrationValid = true;
inspiratoryPressureSensor.setPressureSensorOffset(inspiratoryPressureSensorOffset);
Expand Down Expand Up @@ -112,19 +126,31 @@ void Calibration_Init() {
calibrationValid = false;
displayFlowMeterFail(flowMeterFlowAtStarting, flowMeterFlowWithBlowerOn);

// MFM reports an out-of-range value, it might not be connected
if (isMassFlowMeterOutOfRange == true) {
// MFM failure (eg. not connected)
sendMassFlowMeterFatalError();
} else {
// Other calibration errors
sendCalibrationFatalError(inspiratoryPressureSensorOffset, minOffsetValue,
maxOffsetValue, flowMeterFlowAtStarting,
flowMeterFlowWithBlowerOn);
}

Buzzer_High_Prio_Start();
Calibration_Read_Keyboard();

// Wait for user to press start to restart calibration
restartWaitTimer = 0;

while (startButtonPressed == false) {
restartWaitTimer += (uint32_t)RESTART_READ_KEYBOARD_DELAY;

// Heartbeat fatal error periodically
if ((restartWaitTimer % 1000u) == 0u) {
// MFM reports an out-of-range value, it might not be connected
if (isMassFlowMeterOutOfRange == true) {
// MFM failure (eg. not connected)
sendMassFlowMeterFatalError();
} else {
// Other calibration errors
sendCalibrationFatalError(inspiratoryPressureSensorOffset,
minOffsetValue, maxOffsetValue,
flowMeterFlowAtStarting,
flowMeterFlowWithBlowerOn);
}
}

Calibration_Read_Keyboard_Delayed();
}
} else {
calibrationValid = true;
}
Expand Down Expand Up @@ -168,11 +194,9 @@ void Calibration_Wait_Measure_Pressure(uint16_t ms) {
}
}

void Calibration_Read_Keyboard() {
while (startButtonPressed == false) {
keyboardLoop();
delay(100);
}
void Calibration_Read_Keyboard_Delayed() {
keyboardLoop();
delay(RESTART_READ_KEYBOARD_DELAY);
}

void Calibration_Restart() { startButtonPressed = true; }
Expand Down
Loading

0 comments on commit 04aad4c

Please sign in to comment.