From d55d52dbb519f047de4c301a248fd5c8033c7ee7 Mon Sep 17 00:00:00 2001 From: Carlo Alessandro Nicolau <cnicolau@km3net.de> Date: Sun, 20 Jun 2021 05:52:49 +0200 Subject: [PATCH] Under Development --- host/python/codegen/analogvariables.py | 12 +- host/python/codegen/digitalvariables.py | 8 +- host/python/codegen/firmwareconfig.py | 4 +- .../output/templates/alarm_callbacks.tpl.c | 2 +- .../commands/command_ALARM_ENABLE.tpl.c | 2 +- .../command_ALARM_FIRECOUNT_GET.tpl.c | 2 +- .../commands/command_ALARM_FIRED_GET.tpl.c | 2 +- .../commands/command_ALARM_FIRED_RESET.tpl.c | 2 +- .../commands/command_ALARM_MAXCOUNT_GET.tpl.c | 2 +- .../command_ALARM_MAXCOUNT_RESET.tpl.c | 2 +- .../command_ALARM_THRESHOLD_GET.tpl.c | 2 +- .../command_ALARM_THRESHOLD_SET.tpl.c | 2 +- .../commands/command_ALARM_TIMEOUT_GET.tpl.c | 2 +- .../commands/command_ALARM_TIMEOUT_SET.tpl.c | 2 +- .../commands/command_BOARDTIME.tpl.c | 2 +- .../templates/commands/command_ECHO1.tpl.c | 2 +- .../templates/commands/command_ECHO32.tpl.c | 2 +- .../templates/commands/command_ECHO4.tpl.c | 2 +- .../commands/command_LASTCOMMANDTIME.tpl.c | 2 +- .../commands/command_LASTERROR.tpl.c | 2 +- .../commands/command_RESCUE_ENABLE.tpl.c | 2 +- .../commands/command_RESCUE_STATUS_GET.tpl.c | 2 +- .../command_RESCUE_STATUS_RESET.tpl.c | 2 +- .../commands/command_RESCUE_TIMEOUT_GET.tpl.c | 2 +- .../commands/command_RESCUE_TIMEOUT_SET.tpl.c | 2 +- .../command_SENSOR_AVERAGE_GETALL.tpl.c | 2 +- ...mmand_SENSOR_AVERAGING_PRESCALER_GET.tpl.c | 2 +- ...mmand_SENSOR_AVERAGING_PRESCALER_SET.tpl.c | 2 +- .../commands/command_SENSOR_GET_SINGLE.tpl.c | 2 +- .../command_SENSOR_MAXVALUES_GETALL.tpl.c | 2 +- .../command_SENSOR_MAXVALUE_RESET.tpl.c | 2 +- .../command_SENSOR_OFFSETS_GETALL.tpl.c | 2 +- .../command_SENSOR_VALUES_GETALL.tpl.c | 2 +- .../commands/command_SWITCH_CONTROL.tpl.c | 2 +- .../commands/command_USER_PIN_CONTROL.tpl.c | 2 +- .../templates/commands/command_VALCHECK.tpl.c | 2 +- .../templates/commands/command_VERSION.tpl.c | 2 +- host/python/console/commutils.py | 83 ++++++ host/python/console/continuousreads.py | 128 +++++++++ host/python/console/help.py | 83 ++++++ host/python/console/jsendcommand.py | 238 +++++++++++++++++ host/python/console/jsendcommand2.py | 246 ++++++++++++++++++ host/python/console/sendcommand.py | 185 +++++++++++++ host/python/console/sendrawpacket.py | 74 ++++++ micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3 | 152 +++++------ .../commands/command_ALARM_ENABLE.c | 2 +- .../commands/command_ALARM_THRESHOLD_GET.c | 16 +- .../commands/command_ALARM_THRESHOLD_SET.c | 10 +- .../commands/command_ALARM_TIMEOUT_GET.c | 2 +- .../commands/command_BOARDTIME.c | 2 +- .../commands/command_ECHO1.c | 2 +- .../commands/command_ECHO32.c | 2 +- .../commands/command_ECHO4.c | 2 +- .../commands/command_SWITCH_CONTROL.c | 2 +- micro/BPD-V01-FIRMWARE.X/communication.c | 1 + micro/BPD-V01-FIRMWARE.X/configuration.h | 4 +- .../generated/sources/commandstable.c | 2 +- .../generated/sources/commandstable.h | 10 +- .../generated/sources/datatypes.h | 2 +- .../generated/sources/variables.c | 30 +-- .../generated/sources/variables.h | 2 +- micro/BPD-V01-FIRMWARE.X/irqs.c | 80 +++--- micro/BPD-V01-FIRMWARE.X/main.c | 47 +++- .../mcc_generated_files/eusart1.c | 4 +- .../mcc_generated_files/mcc.c | 2 +- .../mcc_generated_files/mcc.h | 2 +- .../mcc_generated_files/pin_manager.c | 2 +- .../mcc_generated_files/tmr0.c | 10 +- .../mcc_generated_files/tmr2.c | 8 +- .../nbproject/configurations.xml | 96 ++++++- micro/BPD-V01-FIRMWARE.X/timing.c | 7 +- 71 files changed, 1400 insertions(+), 230 deletions(-) create mode 100644 host/python/console/commutils.py create mode 100644 host/python/console/continuousreads.py create mode 100755 host/python/console/help.py create mode 100755 host/python/console/jsendcommand.py create mode 100755 host/python/console/jsendcommand2.py create mode 100755 host/python/console/sendcommand.py create mode 100755 host/python/console/sendrawpacket.py diff --git a/host/python/codegen/analogvariables.py b/host/python/codegen/analogvariables.py index d50a333..e6bd8a0 100644 --- a/host/python/codegen/analogvariables.py +++ b/host/python/codegen/analogvariables.py @@ -312,13 +312,13 @@ class AnalogVariableList: enum_index=alarm_enum_index, enable_default=True, threshold_default=1.5, # TODO - timeout_default_ms=100. # TODO + timeout_default_ms=150. # TODO ), alarm_fast=AnalogAlarmDescriptor( enum_index=alarm_enum_index+1, enable_default=True, threshold_default=2.5, # TODO - timeout_default_ms=5. # TODO + timeout_default_ms=35. # TODO ) ) ) @@ -343,13 +343,13 @@ class AnalogVariableList: enum_index=alarm_enum_index, enable_default=True, threshold_default=1.4, # TODO - timeout_default_ms=100. # TODO + timeout_default_ms=150. # TODO ), alarm_fast=AnalogAlarmDescriptor( enum_index=alarm_enum_index+1, enable_default=True, threshold_default=2.4, # TODO - timeout_default_ms=5. # TODO + timeout_default_ms=35. # TODO ) ) ) @@ -374,7 +374,7 @@ class AnalogVariableList: enum_index=alarm_enum_index, enable_default=False, threshold_default=0.15, # TODO - timeout_default_ms=100. # TODO + timeout_default_ms=500. # TODO ), alarm_fast=AnalogAlarmDescriptor( enum_index=alarm_enum_index+1, @@ -438,7 +438,7 @@ class AnalogVariableList: enum_index=alarm_enum_index, enable_default=False, threshold_default=0.50, # TODO - timeout_default_ms=100. # TODO + timeout_default_ms=500. # TODO ), alarm_fast=AnalogAlarmDescriptor( enum_index=alarm_enum_index+1, diff --git a/host/python/codegen/digitalvariables.py b/host/python/codegen/digitalvariables.py index 6256f99..d109d31 100644 --- a/host/python/codegen/digitalvariables.py +++ b/host/python/codegen/digitalvariables.py @@ -45,7 +45,7 @@ class DigitalVariableList: alarm=DigitalAlarmDescriptor( enum_index=alarm_enum_index, enable_default=None, # requires a specific #define - timeout_default_ms=1.5 + timeout_default_ms=1.0 ) ) ) @@ -64,7 +64,7 @@ class DigitalVariableList: alarm=DigitalAlarmDescriptor( enum_index=alarm_enum_index, enable_default=None, # requires a specific #define - timeout_default_ms=1.5 + timeout_default_ms=1.0 ) ) ) @@ -83,7 +83,7 @@ class DigitalVariableList: alarm=DigitalAlarmDescriptor( enum_index=alarm_enum_index, enable_default=None, # requires a specific #define - timeout_default_ms=1.5 + timeout_default_ms=1.0 ) ) ) @@ -102,7 +102,7 @@ class DigitalVariableList: alarm=DigitalAlarmDescriptor( enum_index=alarm_enum_index, enable_default=None, # requires a specific #define - timeout_default_ms=1.5 + timeout_default_ms=1.0 ) ) ) diff --git a/host/python/codegen/firmwareconfig.py b/host/python/codegen/firmwareconfig.py index 8e8219c..ff439f9 100644 --- a/host/python/codegen/firmwareconfig.py +++ b/host/python/codegen/firmwareconfig.py @@ -9,10 +9,10 @@ class FirmwareConfig: MAIN_CLOCK = 64. # fast timer period in milliseconds - FAST_TIMER_PERIOD_MS = 0.08 + FAST_TIMER_PERIOD_MS = 0.2 # slow timer period in milliseconds - SLOW_TIMER_PERIOD_MS = 0.3 + SLOW_TIMER_PERIOD_MS = 0.8 # ADC data alignment ADC_ALIGNMENT = 'left' diff --git a/host/python/codegen/output/templates/alarm_callbacks.tpl.c b/host/python/codegen/output/templates/alarm_callbacks.tpl.c index e51b698..fc31d45 100644 --- a/host/python/codegen/output/templates/alarm_callbacks.tpl.c +++ b/host/python/codegen/output/templates/alarm_callbacks.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: alarm_callbacks.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "generated/sources/variables.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c index 5aa7c46..360938e 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_ENABLE.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c index e94dc39..751396e 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_FIRECOUNT_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c index 4478ae0..b92cca9 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_FIRED_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c index 5fc2648..ad41dc3 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_FIRED_RESET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c index 7e8a9c3..3c45e73 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_MAXCOUNT_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c index 8a36d19..f9dbe4e 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_MAXCOUNT_RESET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c index 4894aa1..e4fae8d 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_THRESHOLD_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c index 8c866d5..53ee066 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_THRESHOLD_SET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c index c1ce80c..5598690 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_TIMEOUT_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c index 2446364..79838fd 100644 --- a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ALARM_TIMEOUT_SET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c b/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c index 34abc21..9751cc6 100644 --- a/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c +++ b/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_BOARDTIME.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c b/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c index ebdd2af..c1677ba 100644 --- a/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ECHO1.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c b/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c index 63897c9..bd90820 100644 --- a/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ECHO32.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c b/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c index 91b45a6..76d5139 100644 --- a/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c +++ b/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_ECHO4.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c b/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c index a626966..84db3ed 100644 --- a/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c +++ b/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_LASTCOMMANDTIME.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c b/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c index 9c60584..05efcf1 100644 --- a/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c +++ b/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_LASTERROR.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c index 524d693..70444aa 100644 --- a/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c +++ b/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_RESCUE_ENABLE.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c index 90ec8b1..9aa923f 100644 --- a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_RESCUE_STATUS_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c index 0e48a7a..b8efe25 100644 --- a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_RESCUE_STATUS_RESET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c index 331144d..4c67348 100644 --- a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_RESCUE_TIMEOUT_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c index 9cbcca9..68e3c0a 100644 --- a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_RESCUE_TIMEOUT_SET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c index 0727595..df362e0 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_AVERAGE_GETALL.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c index 8fc5f38..4fdb9db 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c index df09582..ad7a765 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c index ab814b8..5942890 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_GET_SINGLE.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c index 38fe30c..1a88e0c 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_MAXVALUES_GETALL.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c index 75d8876..b7a1c7b 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_MAXVALUE_RESET.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c index ccb1f9b..011cb75 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_OFFSETS_GETALL.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c index 1a2a094..668dde7 100644 --- a/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SENSOR_VALUES_GETALL.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c b/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c index c6de34e..65f0b1a 100644 --- a/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c +++ b/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_SWITCH_CONTROL.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c b/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c index aa6960d..f960e68 100644 --- a/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c +++ b/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_USER_PIN_CONTROL.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c b/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c index e11743f..5c9446e 100644 --- a/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c +++ b/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_VALCHECK.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/codegen/output/templates/commands/command_VERSION.tpl.c b/host/python/codegen/output/templates/commands/command_VERSION.tpl.c index 30391ef..59ef1a9 100644 --- a/host/python/codegen/output/templates/commands/command_VERSION.tpl.c +++ b/host/python/codegen/output/templates/commands/command_VERSION.tpl.c @@ -1,5 +1,5 @@ // Auto-generated template file: command_VERSION.tpl.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "../typedefs.h" diff --git a/host/python/console/commutils.py b/host/python/console/commutils.py new file mode 100644 index 0000000..f8141d0 --- /dev/null +++ b/host/python/console/commutils.py @@ -0,0 +1,83 @@ + +# some defines from microcontroller firmware +# define COMMUNICATION_PACKET_SOF 0x01 // start of frame value +PACKET_SOF = 0x01 +# define COMMUNICATION_PACKET_ADDR 0x30 // address (...yes, only this address is listened to) +PACKET_ADDR = 0x30 +# define COMMUNICATION_PACKET_EOF 0x00 // end of frame value +PACKET_EOF = 0x00 + + +def parse_num(_val): + assert isinstance(_val, basestring) + if _val.startswith('0x'): + return int(_val, 16) + else: + return int(_val, 10) + + +def nibble_to_ascii(_val): + if _val < 10: + r = ord('0') + _val + else: + r = ord('a') + (_val - 10) + return r + + +def uint8_to_nibbles(_byte): + nibble_0 = nibble_to_ascii(_byte & 0x0f) + nibble_1 = nibble_to_ascii((_byte >> 4) & 0x0f) + return nibble_0, nibble_1 + + +def get_checksum(_rawdata): + checksum = 0 + for k in range(1, len(_rawdata)): + checksum = checksum - _rawdata[k] + checksum = checksum % 256 + return checksum + + +def packet_create_rawdata(_command_code, _payload_bytes): + # builds the array of bytes to be sent + rawdata = bytearray() + # start of frame and command code + rawdata.append(PACKET_SOF) + rawdata.append(PACKET_ADDR) + rawdata.append(_command_code) + # append encoded payload data + for val in _payload_bytes: + nibble_0, nibble_1 = uint8_to_nibbles(val) + rawdata.append(nibble_1) + rawdata.append(nibble_0) + # compute the checksum + checksum = get_checksum(rawdata) + rawdata.append(checksum) + # if checksum does NOT equal PACKET_EOF, then add PACKET_EOF + if checksum != PACKET_EOF: + rawdata.append(PACKET_EOF) + return rawdata + + +def packet_extract_data(_rawdata): + # print _rawdata + assert _rawdata[0] == PACKET_SOF + assert _rawdata[1] == PACKET_ADDR + command_code = _rawdata[2] + # decode payload + payload_bytes = list() + for idx in range(3, len(_rawdata), 2): + if _rawdata[idx] == PACKET_EOF or _rawdata[idx+1] == PACKET_EOF: + break + val = int(str(chr(_rawdata[idx])) + str(chr(_rawdata[idx+1])), 16) + payload_bytes.append(val) + # check checksum + checksum = get_checksum(_rawdata[:-1]) + assert _rawdata[idx + 1] == checksum, 'Wrong checksum' + if checksum == PACKET_EOF: + assert (idx + 2) == len(_rawdata) + else: + assert _rawdata[idx + 2] == PACKET_EOF + assert (idx + 2) == len(_rawdata) + return command_code, payload_bytes + diff --git a/host/python/console/continuousreads.py b/host/python/console/continuousreads.py new file mode 100644 index 0000000..02720fa --- /dev/null +++ b/host/python/console/continuousreads.py @@ -0,0 +1,128 @@ +#!/usr/bin/python +""" +A minimal utility to continuously read all sensors +""" + +import sys +import os +sys.path.insert(0, '../codegen') + + +import commands +from utils import mls +from analogvariables import * +from bpsentities.descriptors import PayloadFieldEnum, PayloadFieldU8, PayloadFieldU16, PayloadFieldU32 +from commutils import * +import serial +from time import time + + +ASK_CONFIRM = False +SHOW_SENT_DATA = False +SHOW_RECEIVED_DATA = False +UART_DEV = '/dev/ttyUSB1' + + +def ask_confirm(): + answer = "" + while answer not in ["y", "n"]: + answer = raw_input("Confirm [Y/N]? ").lower() + return answer == "y" + + +if __name__ == '__main__': + # command line options + # example + # python sendcommand.py COMMAND_NAME payload0 payload1 ... + # COMMAND_NAME is the human readable name of the command (e.g.: ) + + # redirect stdout to null in order to avoid the warnings during object creation + stdout = sys.stdout + f = open(os.devnull, 'w') + sys.stdout = f + + switch_list = commands.SwitchList() + analog_variable_list = commands.AnalogVariableList() + digital_variable_list = commands.DigitalVariableList() + user_pin_list = commands.UserPinList() + commands = commands.CommandList(switch_list, analog_variable_list, digital_variable_list, user_pin_list) + + # restore normal stdout + sys.stdout = stdout + + # open the serial port + ser = serial.Serial(UART_DEV, baudrate=19200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.5) + + command_name = 'SENSOR_VALUES_GETALL' + filtered_commands = [command for command in commands.entries() if command.name.startswith(command_name)] + command = filtered_commands[0] + + # expected number of request fields: + req_field_count = len(command.request_payload) + + # prepare the payload + payload_data = list() + payload_field_values = list() + rawdata = packet_create_rawdata(command.request_code, payload_data) + + while True: + # send the message over the serial link + ser.write(rawdata) + print "Packet sent." + if SHOW_SENT_DATA: + print "Sent data are:" + for val in rawdata: + print '\t{}\t(ascii: {})'.format(val, chr(val)) + + # wait for a response (reads up to 1000 bytes, does not parse the packet) + print 'Waiting for response...' + ans = ser.read(1000) + bytes = [ord(c) for c in ans] + print '{} bytes received.'.format(len(ans)) + if SHOW_RECEIVED_DATA: + if len(ans): + print 'Received data:' + for k in range(len(ans)): + print '[byte #{}]\t0x{}\t(dec: {}, ascii: {})'.format(str(k), ans[k].encode('hex'), str(ord(ans[k])), ans[k]) + if not len(ans): + print 'No response...' + continue + # sys.exit(0) + + # parses the response + command_code, payload_bytes = packet_extract_data(bytes) + print "Received raw payolad:", payload_bytes + + print "Received packet:" + print ' Command code: {}'.format(command_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Response payload:' + byte_idx = 0 + for field in command.response_payload: + value = -1 + if isinstance(field, PayloadFieldU8): + value = payload_bytes[byte_idx] + byte_idx += 1 + elif isinstance(field, PayloadFieldU16): + value = payload_bytes[byte_idx] << 8 + value += payload_bytes[byte_idx+1] + byte_idx += 2 + elif isinstance(field, PayloadFieldU32): + value = payload_bytes[byte_idx] << 24 + value += payload_bytes[byte_idx+1] << 16 + value += payload_bytes[byte_idx+2] << 8 + value += payload_bytes[byte_idx+3] + byte_idx += 4 + elif isinstance(field, PayloadFieldEnum): + value = field.get_value_by_index(payload_bytes[byte_idx]) + byte_idx += 1 + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + + print ' {} = {}'.format(field.name, value) + + t = time() + # append read values to a file per sensor, with timestamp + with open('outputs/continuousreads/{}.txt'.format(field.name), 'a') as f: + data = f.write('{}\t{}\n'.format(t, value)) + diff --git a/host/python/console/help.py b/host/python/console/help.py new file mode 100755 index 0000000..00404a4 --- /dev/null +++ b/host/python/console/help.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +""" +Generates a list of the available BPS commands +""" + +import sys +import os +sys.path.insert(0, '../codegen') + +import commands +from entities.descriptors import PayloadFieldEnum +from utils import mls + + +def print_field_description(_field, _field_idx): + print ' FIELD #{} ({}) : {}, {}'.format(mls(str(_field_idx), 2), mls(_field.ctype, 8), _field.name, _field.description) + if isinstance(_field, PayloadFieldEnum): + print ' {} indexing:'.format(_field.name) + for index in _field.index_list: + print ' [{}] --> {}'.format(index, _field.get_value_by_index(index)) + + +if __name__ == '__main__': + + # redirect stdout to null in order to avoid the warnings during object creation + stdout = sys.stdout + f = open(os.devnull, 'w') + sys.stdout = f + + switch_list = commands.SwitchList() + + # analog_variable_list = commands.AnalogVariableList() + # digital_variable_list = commands.DigitalVariableList() + + analog_variable_list = commands.AnalogVariableList( + _var_enum_index_start=1, + _alarm_enum_index_start=1) + + digital_variable_list = commands.DigitalVariableList( + _var_enum_index_start=max(analog_variable_list.get_var_enum_indexes())+1, + _alarm_enum_index_start=max(analog_variable_list.get_alarm_enum_indexes())+1) + + user_pin_list = commands.UserPinList() + commands = commands.CommandList(switch_list, analog_variable_list, digital_variable_list, user_pin_list) + + # restore normal stdout + sys.stdout = stdout + + if len(sys.argv) == 1: + print "List of available commands:" + for command in commands.entries(): + print ' ' + mls(command.name, 32), command.description + print 'Type help.py COMMAND to obtain a detailed description, or help.py ALL to show details for all commands.' + elif len(sys.argv) == 2: + command_name = sys.argv[1].upper() + if command_name == 'ALL': + filtered_commands = commands.entries() + else: + filtered_commands = [command for command in commands.entries() if command.name.startswith(command_name)] + print 'Details of commands starting with "{}":'.format(command_name) + + if not filtered_commands: + print 'List is empty.' + for command in filtered_commands: + print '' + print ' COMMAND NAME : "{}"'.format(command.name) + print ' DESCRIPTION : {}'.format(command.description) + print ' REQUEST CODE : {}'.format(command.request_code) + print ' RESPONSE CODE : {}'.format(command.response_code) + print ' REQUEST PAYLOAD :' + print ' LENGTH : {} fields, {} bytes'.format(len(command.request_payload), command.get_request_payload_len()) + field_idx = 0 + for field in command.request_payload: + print_field_description(field, field_idx) + field_idx += 1 + print ' RESPONSE PAYLOAD :' + print ' LENGTH : {} fields, {} bytes'.format(len(command.response_payload), command.get_response_payload_len()) + field_idx = 0 + for field in command.response_payload: + print_field_description(field, field_idx) + field_idx += 1 + + print '' diff --git a/host/python/console/jsendcommand.py b/host/python/console/jsendcommand.py new file mode 100755 index 0000000..8b7b7d1 --- /dev/null +++ b/host/python/console/jsendcommand.py @@ -0,0 +1,238 @@ +#!/usr/bin/python +""" +A minimal utility to send structured commands to the BPS board using Java BPS network utility +""" + +import sys +import os +sys.path.insert(0, '../codegen') + + +import commands +from utils import mls +from analogvariables import * +from bpsentities.descriptors import PayloadFieldEnum, PayloadFieldU8, PayloadFieldU16, PayloadFieldU32 +from commutils import * +import os + +ASK_CONFIRM = False +SHOW_SENT_DATA = True +SHOW_RECEIVED_DATA = False + +CLB_IPADDR = '172.21.1.221' + +JSCRIPTFMT = './execute.sh BPSCmd {} [REQCODE] [RESPCODE] [RESPLEN] [REQPAYLOAD]'.format(CLB_IPADDR) + + +def ask_confirm(): + answer = "" + while answer not in ["y", "n"]: + answer = raw_input("Confirm [Y/N]? ").lower() + return answer == "y" + + +def mydirtyexec(_cmd): + # like it dirty... + os.system(_cmd + ' > __tmp') + return open('__tmp', 'r').read() + +def getconvertedvals(command, fields): + vals = list() + + # the pork way (with great respect for porks) + if command.name == 'SENSOR_GET_SINGLE': + vn = fields[0] + converter = None + if vn == 'MON_5V_I': + converter = channel2current_MON_5V_I + units = 'A' + elif vn in ['MON_LBL_I', 'MON_HYDRO_I']: + converter = channel2current_12V + units = 'A' + elif vn in ['MON_DU_I', 'MON_DU_IRTN']: + converter = channel2current_MON_DU_I + units = 'A' + elif vn == 'MON_BPS_V': + converter = channel2voltage_MON_BPS_V + units = 'V' + elif vn == 'MON_THEATSINK': + converter = channel2temperature_THEATSINK + units = 'V (A.U.)' + elif vn == 'MON_TBOARD': + converter = channel2temperature_TBOARD + units = 'C' + else: + pass + if converter: + vals.append(['','']) + vals.append([converter(fields[1]), units]) # VALUE + vals.append([converter(fields[2]), units]) # OFFSET + vals.append([converter(fields[3]), units]) # MAXVALUE + vals.append([converter(fields[4]), units]) # MEANVALUE + elif command.name in ['SENSOR_VALUES_GETALL', 'SENSOR_AVERAGE_GETALL', 'SENSOR_OFFSETS_GETALL', 'SENSOR_MAXVALUES_GETALL']: + vals.append([channel2current_MON_5V_I(fields[0]), 'A']) # MON_5V_I_MEAN + vals.append([channel2current_12V(fields[1]), 'A']) # MON_LBL_I_MEAN + vals.append([channel2current_MON_DU_I(fields[2]), 'A']) # MON_DU_I_MEAN + vals.append([channel2current_MON_DU_I(fields[3]), 'A']) # MON_DU_IRTN_MEAN + vals.append([channel2voltage_MON_BPS_V(fields[4]), 'V']) # MON_BPS_V_MEAN + vals.append([channel2current_12V(fields[5]), 'A']) # MON_HYDRO_I_MEAN + vals.append([channel2temperature_THEATSINK(fields[6]), 'V (A.U.)']) # MON_THEATSINK_MEAN + vals.append([channel2temperature_TBOARD(fields[7]), 'C']) # MON_TBOARD_MEAN + + return vals + +if __name__ == '__main__': + # command line options + # example + # python sendcommand.py COMMAND_NAME payload0 payload1 ... + # COMMAND_NAME is the human readable name of the command (e.g.: ) + + # redirect stdout to null in order to avoid the warnings during object creation + stdout = sys.stdout + f = open(os.devnull, 'w') + sys.stdout = f + + switch_list = commands.SwitchList() + analog_variable_list = commands.AnalogVariableList() + digital_variable_list = commands.DigitalVariableList() + user_pin_list = commands.UserPinList() + commands = commands.CommandList(switch_list, analog_variable_list, digital_variable_list, user_pin_list) + + # restore normal stdout + sys.stdout = stdout + + if len(sys.argv) <= 1: + print "Command code missing" + sys.exit(0) + + command_name = sys.argv[1].upper() + + filtered_commands = [command for command in commands.entries() if command.name.startswith(command_name)] + + if len(filtered_commands) == 0: + print 'No command found with name starting with: "{}"'.format(command_name) + elif len(filtered_commands) != 1: + print 'More than one command found with name starting with: "{}":'.format(command_name) + for command in filtered_commands: + print ' {}'.format(command.name) + sys.exit(0) + + # get the wanted command + command = filtered_commands[0] + + # expected number of request fields: + req_field_count = len(command.request_payload) + + if len(sys.argv) != req_field_count + 2: + print 'Number of request payload fields not correct. The {} command expects {} fields; {} where given.'.format(command.name, len(command.request_payload), len(sys.argv) - 2) + sys.exit(0) + + # prepare the payload + payload_data = list() + payload_field_values = list() + idx = 2 + for field in command.request_payload: + val = int(sys.argv[idx]) + payload_field_values.append(val) + if isinstance(field, PayloadFieldU8): + assert val < 2**8, 'Too big value for uint8' + payload_data.append(val) + elif isinstance(field, PayloadFieldU16): + assert val < 2 ** 16, 'Too big value for uint16' + payload_data.append((val >> 8) & 0xff) + payload_data.append(val & 0xff) + elif isinstance(field, PayloadFieldU32): + assert val < 2 ** 32, 'Too big value for uint32' + payload_data.append((val >> 24) & 0xff) + payload_data.append((val >> 16) & 0xff) + payload_data.append((val >> 8) & 0xff) + payload_data.append(val & 0xff) + elif isinstance(field, PayloadFieldEnum): + assert val < 2 ** 8, 'Too big value for enum' + payload_data.append(val) + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + idx += 1 + + print "Sending packet:" + print ' Command code: {} (raw data: {})'.format(command.name, command.request_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Request payload:' + idx = 0 + for field in command.request_payload: + print ' {} = {}'.format(field.name, payload_field_values[idx]) + idx += 1 + + if ASK_CONFIRM: + if not ask_confirm(): + print "Operation aborted by user" + sys.exit() + + jcmd = JSCRIPTFMT + jcmd = jcmd.replace('[REQCODE]', str(command.request_code)) + jcmd = jcmd.replace('[RESPCODE]', str(command.response_code)) + jcmd = jcmd.replace('[RESPLEN]', str(2 * command.get_response_payload_len())) + + if not payload_data: + jcmd = jcmd.replace('[REQPAYLOAD]', 'null') + else: + pl = '' + for b in payload_data: + # print b.__class__ + n0, n1 = uint8_to_nibbles(b) + pl += chr(n1) + pl += chr(n0) + jcmd = jcmd.replace('[REQPAYLOAD]', pl) + + print 'Executing command: "{}"'.format(jcmd) + r = mydirtyexec(jcmd) + print 'Response:"{}"'.format(r.strip()) + + # convert nibbles to bytes + payload_bytes = list() + for k in range(0, len(r)-1, 2): + d = 16 * int(r[k], 16) + int(r[k+1], 16) + payload_bytes.append(d) + + print "Received packet:" + # print ' Command code: {}'.format(command_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Response payload:' + byte_idx = 0 + rawvalues = list(); + for field in command.response_payload: + value = -1 + if isinstance(field, PayloadFieldU8): + value = payload_bytes[byte_idx] + rawvalues.append(value) + byte_idx += 1 + elif isinstance(field, PayloadFieldU16): + value = payload_bytes[byte_idx] << 8 + value += payload_bytes[byte_idx+1] + rawvalues.append(value) + byte_idx += 2 + elif isinstance(field, PayloadFieldU32): + value = payload_bytes[byte_idx] << 24 + value += payload_bytes[byte_idx+1] << 16 + value += payload_bytes[byte_idx+2] << 8 + value += payload_bytes[byte_idx+3] + rawvalues.append(value) + byte_idx += 4 + elif isinstance(field, PayloadFieldEnum): + value = field.get_value_by_index(payload_bytes[byte_idx]) + rawvalues.append(value) + byte_idx += 1 + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + + convertedvals = getconvertedvals(command, rawvalues) + + field_idx = 0 + for field in command.response_payload: + s = ' {} = {} '.format(field.name, rawvalues[field_idx]) + if convertedvals: + if convertedvals[field_idx][0]: + s += '({:0.3} {})'.format(convertedvals[field_idx][0], convertedvals[field_idx][1]) + print s + field_idx += 1 + diff --git a/host/python/console/jsendcommand2.py b/host/python/console/jsendcommand2.py new file mode 100755 index 0000000..9050205 --- /dev/null +++ b/host/python/console/jsendcommand2.py @@ -0,0 +1,246 @@ +#!/usr/bin/python +""" +A minimal utility to send structured commands to the BPS board using Java BPS network utility +""" + +import sys +import os +import re +sys.path.insert(0, '../codegen') + + +import commands +from utils import mls +from analogvariables import * +from bpsentities.descriptors import PayloadFieldEnum, PayloadFieldU8, PayloadFieldU16, PayloadFieldU32 +from commutils import * +import os + +ASK_CONFIRM = False +SHOW_SENT_DATA = True +SHOW_RECEIVED_DATA = False + +# first passed param must be the ip address +CLB_IPADDR = sys.argv[1] +# check it resembles an ip address +if not re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$").match(CLB_IPADDR): + print "IPADDR format error or missing" + sys.exit(0) +# remove it from current list of parameters (historical reasons) +sys.argv.pop(1) + +JSCRIPTFMT = './execute.sh BPSCmd {} [REQCODE] [RESPCODE] [RESPLEN] [REQPAYLOAD]'.format(CLB_IPADDR) + + +def ask_confirm(): + answer = "" + while answer not in ["y", "n"]: + answer = raw_input("Confirm [Y/N]? ").lower() + return answer == "y" + + +def mydirtyexec(_cmd): + # like it dirty... + os.system(_cmd + ' > __tmp') + return open('__tmp', 'r').read() + +def getconvertedvals(command, fields): + vals = list() + + # the pork way (with great respect for porks) + if command.name == 'SENSOR_GET_SINGLE': + vn = fields[0] + converter = None + if vn == 'MON_5V_I': + converter = channel2current_MON_5V_I + units = 'A' + elif vn in ['MON_LBL_I', 'MON_HYDRO_I']: + converter = channel2current_12V + units = 'A' + elif vn in ['MON_DU_I', 'MON_DU_IRTN']: + converter = channel2current_MON_DU_I + units = 'A' + elif vn == 'MON_BPS_V': + converter = channel2voltage_MON_BPS_V + units = 'V' + elif vn == 'MON_THEATSINK': + converter = channel2temperature_THEATSINK + units = 'V (A.U.)' + elif vn == 'MON_TBOARD': + converter = channel2temperature_TBOARD + units = 'C' + else: + pass + if converter: + vals.append(['','']) + vals.append([converter(fields[1]), units]) # VALUE + vals.append([converter(fields[2]), units]) # OFFSET + vals.append([converter(fields[3]), units]) # MAXVALUE + vals.append([converter(fields[4]), units]) # MEANVALUE + elif command.name in ['SENSOR_VALUES_GETALL', 'SENSOR_AVERAGE_GETALL', 'SENSOR_OFFSETS_GETALL', 'SENSOR_MAXVALUES_GETALL']: + vals.append([channel2current_MON_5V_I(fields[0]), 'A']) # MON_5V_I_MEAN + vals.append([channel2current_12V(fields[1]), 'A']) # MON_LBL_I_MEAN + vals.append([channel2current_MON_DU_I(fields[2]), 'A']) # MON_DU_I_MEAN + vals.append([channel2current_MON_DU_I(fields[3]), 'A']) # MON_DU_IRTN_MEAN + vals.append([channel2voltage_MON_BPS_V(fields[4]), 'V']) # MON_BPS_V_MEAN + vals.append([channel2current_12V(fields[5]), 'A']) # MON_HYDRO_I_MEAN + vals.append([channel2temperature_THEATSINK(fields[6]), 'V (A.U.)']) # MON_THEATSINK_MEAN + vals.append([channel2temperature_TBOARD(fields[7]), 'C']) # MON_TBOARD_MEAN + + return vals + +if __name__ == '__main__': + # command line options + # example + # python sendcommand.py COMMAND_NAME payload0 payload1 ... + # COMMAND_NAME is the human readable name of the command (e.g.: ) + + # redirect stdout to null in order to avoid the warnings during object creation + stdout = sys.stdout + f = open(os.devnull, 'w') + sys.stdout = f + + switch_list = commands.SwitchList() + analog_variable_list = commands.AnalogVariableList() + digital_variable_list = commands.DigitalVariableList() + user_pin_list = commands.UserPinList() + commands = commands.CommandList(switch_list, analog_variable_list, digital_variable_list, user_pin_list) + + # restore normal stdout + sys.stdout = stdout + + if len(sys.argv) <= 1: + print "Command code missing" + sys.exit(0) + + command_name = sys.argv[1].upper() + + filtered_commands = [command for command in commands.entries() if command.name.startswith(command_name)] + + if len(filtered_commands) == 0: + print 'No command found with name starting with: "{}"'.format(command_name) + elif len(filtered_commands) != 1: + print 'More than one command found with name starting with: "{}":'.format(command_name) + for command in filtered_commands: + print ' {}'.format(command.name) + sys.exit(0) + + # get the wanted command + command = filtered_commands[0] + + # expected number of request fields: + req_field_count = len(command.request_payload) + + if len(sys.argv) != req_field_count + 2: + print 'Number of request payload fields not correct. The {} command expects {} fields; {} where given.'.format(command.name, len(command.request_payload), len(sys.argv) - 2) + sys.exit(0) + + # prepare the payload + payload_data = list() + payload_field_values = list() + idx = 2 + for field in command.request_payload: + val = int(sys.argv[idx]) + payload_field_values.append(val) + if isinstance(field, PayloadFieldU8): + assert val < 2**8, 'Too big value for uint8' + payload_data.append(val) + elif isinstance(field, PayloadFieldU16): + assert val < 2 ** 16, 'Too big value for uint16' + payload_data.append((val >> 8) & 0xff) + payload_data.append(val & 0xff) + elif isinstance(field, PayloadFieldU32): + assert val < 2 ** 32, 'Too big value for uint32' + payload_data.append((val >> 24) & 0xff) + payload_data.append((val >> 16) & 0xff) + payload_data.append((val >> 8) & 0xff) + payload_data.append(val & 0xff) + elif isinstance(field, PayloadFieldEnum): + assert val < 2 ** 8, 'Too big value for enum' + payload_data.append(val) + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + idx += 1 + + print "Sending packet:" + print ' Command code: {} (raw data: {})'.format(command.name, command.request_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Request payload:' + idx = 0 + for field in command.request_payload: + print ' {} = {}'.format(field.name, payload_field_values[idx]) + idx += 1 + + if ASK_CONFIRM: + if not ask_confirm(): + print "Operation aborted by user" + sys.exit() + + jcmd = JSCRIPTFMT + jcmd = jcmd.replace('[REQCODE]', str(command.request_code)) + jcmd = jcmd.replace('[RESPCODE]', str(command.response_code)) + jcmd = jcmd.replace('[RESPLEN]', str(2 * command.get_response_payload_len())) + + if not payload_data: + jcmd = jcmd.replace('[REQPAYLOAD]', 'null') + else: + pl = '' + for b in payload_data: + # print b.__class__ + n0, n1 = uint8_to_nibbles(b) + pl += chr(n1) + pl += chr(n0) + jcmd = jcmd.replace('[REQPAYLOAD]', pl) + + print 'Executing command: "{}"'.format(jcmd) + r = mydirtyexec(jcmd) + print 'Response:"{}"'.format(r.strip()) + + # convert nibbles to bytes + payload_bytes = list() + for k in range(0, len(r)-1, 2): + d = 16 * int(r[k], 16) + int(r[k+1], 16) + payload_bytes.append(d) + + print "Received packet:" + # print ' Command code: {}'.format(command_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Response payload:' + byte_idx = 0 + rawvalues = list(); + for field in command.response_payload: + value = -1 + if isinstance(field, PayloadFieldU8): + value = payload_bytes[byte_idx] + rawvalues.append(value) + byte_idx += 1 + elif isinstance(field, PayloadFieldU16): + value = payload_bytes[byte_idx] << 8 + value += payload_bytes[byte_idx+1] + rawvalues.append(value) + byte_idx += 2 + elif isinstance(field, PayloadFieldU32): + value = payload_bytes[byte_idx] << 24 + value += payload_bytes[byte_idx+1] << 16 + value += payload_bytes[byte_idx+2] << 8 + value += payload_bytes[byte_idx+3] + rawvalues.append(value) + byte_idx += 4 + elif isinstance(field, PayloadFieldEnum): + value = field.get_value_by_index(payload_bytes[byte_idx]) + rawvalues.append(value) + byte_idx += 1 + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + + convertedvals = getconvertedvals(command, rawvalues) + + field_idx = 0 + for field in command.response_payload: + s = ' {} = {} '.format(field.name, rawvalues[field_idx]) + if convertedvals: + if convertedvals[field_idx][0]: + s += '({:0.3} {})'.format(convertedvals[field_idx][0], convertedvals[field_idx][1]) + print s + field_idx += 1 + diff --git a/host/python/console/sendcommand.py b/host/python/console/sendcommand.py new file mode 100755 index 0000000..2b54e02 --- /dev/null +++ b/host/python/console/sendcommand.py @@ -0,0 +1,185 @@ +#!/usr/bin/python +""" +A minimal utility to send structured commands to the BPS board +""" + +import sys +import os +sys.path.insert(0, '../codegen') + + +import commands +from utils import mls +from analogvariables import * +from entities.descriptors import PayloadFieldEnum, PayloadFieldU8, PayloadFieldU16, PayloadFieldU32 +from commutils import * +import serial + + +ASK_CONFIRM = False +SHOW_SENT_DATA = False +SHOW_RECEIVED_DATA = False +UART_DEV = '/dev/ttyUSB0' + + +def ask_confirm(): + answer = "" + while answer not in ["y", "n"]: + answer = raw_input("Confirm [Y/N]? ").lower() + return answer == "y" + + +if __name__ == '__main__': + # command line options + # example + # python sendcommand.py COMMAND_NAME payload0 payload1 ... + # COMMAND_NAME is the human readable name of the command (e.g.: ) + + # redirect stdout to null in order to avoid the warnings during object creation + stdout = sys.stdout + f = open(os.devnull, 'w') + sys.stdout = f + + switch_list = commands.SwitchList() + + # analog_variable_list = commands.AnalogVariableList() + # digital_variable_list = commands.DigitalVariableList() + + analog_variable_list = commands.AnalogVariableList( + _var_enum_index_start=1, + _alarm_enum_index_start=1) + + digital_variable_list = commands.DigitalVariableList( + _var_enum_index_start=max(analog_variable_list.get_var_enum_indexes())+1, + _alarm_enum_index_start=max(analog_variable_list.get_alarm_enum_indexes())+1) + + user_pin_list = commands.UserPinList() + commands = commands.CommandList(switch_list, analog_variable_list, digital_variable_list, user_pin_list) + + # restore normal stdout + sys.stdout = stdout + + # open the serial port + ser = serial.Serial(UART_DEV, baudrate=19200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.5) + + if len(sys.argv) <= 1: + print "Command code missing" + sys.exit(0) + + command_name = sys.argv[1].upper() + + filtered_commands = [command for command in commands.entries() if command.name.startswith(command_name)] + + if len(filtered_commands) == 0: + print 'No command found with name starting with: "{}"'.format(command_name) + elif len(filtered_commands) != 1: + print 'More than one command found with name starting with: "{}":'.format(command_name) + for command in filtered_commands: + print ' {}'.format(command.name) + sys.exit(0) + + # get the wanted command + command = filtered_commands[0] + + # expected number of request fields: + req_field_count = len(command.request_payload) + + if len(sys.argv) != req_field_count + 2: + print 'Number of request payload fields not correct. The {} command expects {} fields; {} where given.'.format(command.name, len(command.request_payload), len(sys.argv) - 2) + sys.exit(0) + + # prepare the payload + payload_data = list() + payload_field_values = list() + idx = 2 + for field in command.request_payload: + val = int(sys.argv[idx]) + payload_field_values.append(val) + if isinstance(field, PayloadFieldU8): + assert val < 2**8, 'Too big value for uint8' + payload_data.append(val) + elif isinstance(field, PayloadFieldU16): + assert val < 2 ** 16, 'Too big value for uint16' + payload_data.append((val >> 8) & 0xff) + payload_data.append(val & 0xff) + elif isinstance(field, PayloadFieldU32): + assert val < 2 ** 32, 'Too big value for uint32' + payload_data.append((val >> 24) & 0xff) + payload_data.append((val >> 16) & 0xff) + payload_data.append((val >> 8) & 0xff) + payload_data.append(val & 0xff) + elif isinstance(field, PayloadFieldEnum): + assert val < 2 ** 8, 'Too big value for enum' + payload_data.append(val) + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + idx += 1 + + print "Sending packet:" + print ' Command code: {} (raw data: {})'.format(command.name, command.request_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Request payload:' + idx = 0 + for field in command.request_payload: + print ' {} = {}'.format(field.name, payload_field_values[idx]) + idx += 1 + + if ASK_CONFIRM: + if not ask_confirm(): + print "Operation aborted by user" + sys.exit() + + rawdata = packet_create_rawdata(command.request_code, payload_data) + + # send the message over the serial link + print "Packet sent." + if SHOW_SENT_DATA: + print "Sent data are:" + for val in rawdata: + print '\t{}\t(ascii: {})'.format(val, chr(val)) + ser.write(rawdata) + + # wait for a response (reads up to 1000 bytes, does not parse the packet) + print 'Waiting for response...' + ans = ser.read(1000) + bytes = [ord(c) for c in ans] + print '{} bytes received.'.format(len(ans)) + if SHOW_RECEIVED_DATA: + if len(ans): + print 'Received data:' + for k in range(len(ans)): + print '[byte #{}]\t0x{}\t(dec: {}, ascii: {})'.format(str(k), ans[k].encode('hex'), str(ord(ans[k])), ans[k]) + if not len(ans): + sys.exit(0) + + # parses the response + command_code, payload_bytes = packet_extract_data(bytes) + print "Received raw payolad:", payload_bytes + + print "Received packet:" + print ' Command code: {}'.format(command_code) + # print ' Payload data: {} (raw data: {})'.format(payload_field_values, payload_data) + print ' Response payload:' + byte_idx = 0 + for field in command.response_payload: + value = -1 + if isinstance(field, PayloadFieldU8): + value = payload_bytes[byte_idx] + byte_idx += 1 + elif isinstance(field, PayloadFieldU16): + value = payload_bytes[byte_idx] << 8 + value += payload_bytes[byte_idx+1] + byte_idx += 2 + elif isinstance(field, PayloadFieldU32): + value = payload_bytes[byte_idx] << 24 + value += payload_bytes[byte_idx+1] << 16 + value += payload_bytes[byte_idx+2] << 8 + value += payload_bytes[byte_idx+3] + byte_idx += 4 + elif isinstance(field, PayloadFieldEnum): + value = field.get_value_by_index(payload_bytes[byte_idx]) + byte_idx += 1 + else: + assert False, 'Unmanaged type {}'.format(field.__class__.__name__) + + print ' {} = {}'.format(field.name, value) diff --git a/host/python/console/sendrawpacket.py b/host/python/console/sendrawpacket.py new file mode 100755 index 0000000..8590e1b --- /dev/null +++ b/host/python/console/sendrawpacket.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +""" +A minimal utility to send packets to the BPS board +""" + +import serial +import sys +from commutils import * + +ASK_CONFIRM = False +UART_DEV = '/dev/ttyUSB0' + + +def ask_confirm(): + answer = "" + while answer not in ["y", "n"]: + answer = raw_input("Confirm [Y/N]? ").lower() + return answer == "y" + + +if __name__ == '__main__': + # command line options + # example + # python sendrawpacket.py 0x12 0x23 0x34 + # sends the command with code 0x12, and a payload of 2 bytes : [0x23, 0x34] + # numbers can also be given in decimal + + assert len(sys.argv) > 1, "Command code missing" + + # open the serial port + ser = serial.Serial(UART_DEV, baudrate=19200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=0.5) + + # first argument must be command code + command_code = parse_num(sys.argv[1]) + + # payload data are the rest of arguments + payload_data = list() + for k in range(2, len(sys.argv)): + payload_data.append(parse_num(sys.argv[k])) + + print "Command code is: 0x%02x" % command_code, "(", command_code, ")" + print "Payload data is:", ["0x%02x" % d for d in payload_data] + + if ASK_CONFIRM: + if not ask_confirm(): + print "Operation aborted by user" + sys.exit() + + rawdata = packet_create_rawdata(command_code, payload_data) + + # send the message over the serial link + ser.write(rawdata) + print "Packet sent." + print "Sent data are:" + for val in rawdata: + print '\t{}\t(ascii: {})'.format(val, chr(val)) + + # wait for a response (reads up to 1000 bytes, does not parse the packet) + print 'Waiting for response...' + ans = ser.read(1000) + print '{} bytes received.'.format(len(ans)) + if len(ans): + print 'Received data:' + for k in range(len(ans)): + print '[byte #{}]\t0x{}\t(dec: {}, ascii: {})'.format(str(k), ans[k].encode('hex'), str(ord(ans[k])), ans[k]) + + + + + + + + + diff --git a/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3 b/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3 index 167ef70..28c8c9b 100644 --- a/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3 +++ b/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3 @@ -1,5 +1,9 @@ <config configVersion="1.1" device="PIC18F46K22" coreVersion="5.0.2"> <usedClasses class="java.util.HashMap"> + <entry> + <string>ADC</string> + <string>class com.microchip.mcc.mcu8.modules.adc.ADC</string> + </entry> <entry> <string>TMR0</string> <string>class com.microchip.mcc.mcu8.modules.tmr0_v1.TMR0</string> @@ -8,10 +12,6 @@ <string>System Module</string> <string>class com.microchip.mcc.mcu8.systemManager.SystemManager</string> </entry> - <entry> - <string>ADC</string> - <string>class com.microchip.mcc.mcu8.modules.adc.ADC</string> - </entry> <entry> <string>FVR</string> <string>class com.microchip.mcc.mcu8.modules.fvr.FVR</string> @@ -32,14 +32,14 @@ <string>CCP5</string> <string>class com.microchip.mcc.mcu8.modules.ccp_v3.CCP</string> </entry> - <entry> - <string>EUSART1</string> - <string>class com.microchip.mcc.mcu8.modules.eusart.EUSART</string> - </entry> <entry> <string>RESET</string> <string>class com.microchip.mcc.mcu8.systemManager.reset.RESET</string> </entry> + <entry> + <string>EUSART1</string> + <string>class com.microchip.mcc.mcu8.modules.eusart.EUSART</string> + </entry> <entry> <string>Interrupt Module</string> <string>class com.microchip.mcc.mcu8.interruptManager.InterruptManager</string> @@ -55,7 +55,7 @@ <tokenMap class="java.util.HashMap"> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="EUSART1" name="SWTXBufferSize"/> - <value>8</value> + <value>64</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="WPUB" settingAlias="WPUB5"/> @@ -115,7 +115,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="prescaleDivisor"/> - <value>32</value> + <value>64</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="System Module" registerAlias="CONFIG3H" settingAlias="HFOFST"/> @@ -551,7 +551,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="Pin Module" registerAlias="TRISA"/> - <value>127</value> + <value>63</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="INTERNAL OSCILLATOR" registerAlias="OSCCON2" settingAlias="PRISD" alias="enabled"/> @@ -679,7 +679,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="prMatchValue"/> - <value>159</value> + <value>199</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="ANSELA" settingAlias="ANSA3" alias="analog"/> @@ -738,12 +738,12 @@ <value>enabled</value> </entry> <entry> - <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="RCSTA" settingAlias="FERR" alias="error"/> - <value>1</value> + <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="actualPeriod"/> + <value>0.0008</value> </entry> <entry> - <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="actualPeriod"/> - <value>0.0003</value> + <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="RCSTA" settingAlias="FERR" alias="error"/> + <value>1</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="TRISE" settingAlias="TRISE2" alias="output"/> @@ -819,7 +819,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="TRISA" settingAlias="TRISA6"/> - <value>input</value> + <value>output</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="ioc RB2"/> @@ -871,7 +871,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="TMR0" registerAlias="T0CON"/> - <value>212</value> + <value>213</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="TRISB" settingAlias="TRISB5" alias="output"/> @@ -1023,7 +1023,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="prescaledFreq"/> - <value>500000</value> + <value>250000</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATB" settingAlias="LATB7" alias="set"/> @@ -1191,7 +1191,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="TMR2" registerAlias="TCON"/> - <value>13</value> + <value>29</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="TRISA" settingAlias="TRISA7"/> @@ -1339,7 +1339,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="minPeriod"/> - <value>0.000002</value> + <value>0.000004</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG7H" settingAlias="EBTRB" alias="ON"/> @@ -1355,7 +1355,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="maxPeriod"/> - <value>0.000512</value> + <value>0.001024</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="INTERNAL OSCILLATOR" registerAlias="OSCCON" settingAlias="IRCF" alias="16MHz_HFINTOSC"/> @@ -1463,7 +1463,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="requestedPeriod"/> - <value>0.0003</value> + <value>0.0008</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG3H" settingAlias="CCP2MX" alias="PORTC1"/> @@ -1577,14 +1577,14 @@ <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="RESET" registerAlias="RCON" settingAlias="POR" alias="occurred"/> <value>0</value> </entry> - <entry> - <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS"/> - <value>1:2</value> - </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS"/> <value>AN0</value> </entry> + <entry> + <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS"/> + <value>1:4</value> + </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="BRG16"/> <value>16bit_generator</value> @@ -1767,7 +1767,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="TMR0" registerAlias="TMR0L"/> - <value>106</value> + <value>56</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG1H" settingAlias="FCMEN" alias="ON"/> @@ -1949,14 +1949,14 @@ <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="Pin Module" registerAlias="LATC"/> <value>0</value> </entry> - <entry> - <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="TXSTA" settingAlias="SENDB"/> - <value>sync_break_complete</value> - </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="CCP5" name="CCPPinName"/> <value>enabled</value> </entry> + <entry> + <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="TXSTA" settingAlias="SENDB"/> + <value>sync_break_complete</value> + </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="System Module" registerAlias="CONFIG5H"/> <value>192</value> @@ -2031,7 +2031,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerPeriodActual"/> - <value>0.00008</value> + <value>0.0002</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG4L" settingAlias="STVREN" alias="OFF"/> @@ -2079,7 +2079,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.RegisterKey" moduleName="TMR2" registerAlias="PR"/> - <value>159</value> + <value>199</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR0" registerAlias="T0CON" settingAlias="PS" alias="1:32"/> @@ -2293,14 +2293,14 @@ <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="INTERNAL OSCILLATOR" name="CustomFOSC"/> <value>Internal oscillator block</value> </entry> - <entry> - <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="RCSTA" settingAlias="CREN"/> - <value>enabled</value> - </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="CCP5" registerAlias="CCPI" settingAlias="order"/> <value>4</value> </entry> + <entry> + <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="RCSTA" settingAlias="CREN"/> + <value>enabled</value> + </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="TRISD" settingAlias="TRISD4" alias="input"/> <value>1</value> @@ -2471,7 +2471,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerPeriod"/> - <value>0.00008</value> + <value>0.0002</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="Pin Module" registerAlias="LATC" settingAlias="LATC4"/> @@ -2491,7 +2491,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="EUSART1" name="SWRXBufferSize"/> - <value>8</value> + <value>64</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATA" settingAlias="LATA0" alias="set"/> @@ -2743,7 +2743,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR2" registerAlias="PR" settingAlias="PR"/> - <value>159</value> + <value>199</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="CCP5" registerAlias="CCPCON" settingAlias="CCPM"/> @@ -2821,14 +2821,14 @@ <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ADC" registerAlias="ADRESL" settingAlias="ADRESL"/> <value>0</value> </entry> - <entry> - <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="TXSTA" settingAlias="SYNC" alias="asynchronous"/> - <value>0</value> - </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVREN"/> <value>enabled</value> </entry> + <entry> + <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="TXSTA" settingAlias="SYNC" alias="asynchronous"/> + <value>0</value> + </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG2L" settingAlias="BORV" alias="190"/> <value>24</value> @@ -3047,7 +3047,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR0" registerAlias="T0CON" settingAlias="PS"/> - <value>1:32</value> + <value>1:64</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="anselUserSetRD5"/> @@ -3477,14 +3477,14 @@ <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATD" settingAlias="LATD0" alias="clear"/> <value>0</value> </entry> - <entry> - <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerstart"/> - <value>enabled</value> - </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS" alias="AN14"/> <value>14</value> </entry> + <entry> + <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerstart"/> + <value>enabled</value> + </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATA" settingAlias="LATA4" alias="set"/> <value>1</value> @@ -3503,7 +3503,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR0" registerAlias="TMR0L" settingAlias="TMR0L"/> - <value>106</value> + <value>56</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS" alias="AN12"/> @@ -3619,7 +3619,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerPeriodMin"/> - <value>0.0000005</value> + <value>0.000001</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="ANSELD" settingAlias="ANSD1" alias="digital"/> @@ -3842,11 +3842,11 @@ <value>disabled</value> </entry> <entry> - <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="ABDEN"/> + <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVRRDY"/> <value>disabled</value> </entry> <entry> - <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVRRDY"/> + <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="ABDEN"/> <value>disabled</value> </entry> <entry> @@ -4071,7 +4071,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="TimerPeriodkey"/> - <value>12500.000000000002</value> + <value>5000.0</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="ANSELB" settingAlias="ANSB5" alias="digital"/> @@ -4551,7 +4551,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="RA6"/> - <value>input</value> + <value>output</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="RA5"/> @@ -4593,14 +4593,14 @@ <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG7L" settingAlias="EBTR3" alias="OFF"/> <value>8</value> </entry> - <entry> - <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerPeriodMax"/> - <value>0.000128</value> - </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="CCP5" registerAlias="CCPTMRS" settingAlias="CTSEL" alias="CCP5timer3"/> <value>1</value> </entry> + <entry> + <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerPeriodMax"/> + <value>0.000256</value> + </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="INTERNAL OSCILLATOR" name="FOSCClockValue"/> <value>64000000</value> @@ -4967,7 +4967,7 @@ </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="trisUserSetRA6"/> - <value>disabled</value> + <value>enabled</value> </entry> <entry> <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ADC" name="DAC"/> @@ -5073,27 +5073,27 @@ </entry> <entry> <file>mcc_generated_files/tmr0.c</file> - <hash>77631caa3c2b5a163e6a041e9cf6a60dace26d2aa2b81f2bc7277b8d20826612</hash> + <hash>b148174c2c60c29a5406e0754fe9b5623d22f9debe4303ef97ce0e1f4b951033</hash> </entry> <entry> <file>mcc_generated_files/pin_manager.h</file> <hash>63afe0661072367ed7f02048395b49f9b0d2f760e2f246b878b15047d394ba59</hash> </entry> - <entry> - <file>mcc_generated_files/eusart1.h</file> - <hash>adaab835ea05ef3b79b26fd176fb2a8e6d4fbba509dd821f8e01b946f3839d4d</hash> - </entry> <entry> <file>main.c</file> <hash>87bbe9578cf7703cdbfd9af1caeeb4c11efd4c03fde69c03bbc26710a79b1ca5</hash> </entry> + <entry> + <file>mcc_generated_files/eusart1.h</file> + <hash>adaab835ea05ef3b79b26fd176fb2a8e6d4fbba509dd821f8e01b946f3839d4d</hash> + </entry> <entry> <file>mcc_generated_files/tmr2.h</file> <hash>e450ed94162721f5ac2c245378419f8c38f0b9dcc95a4642bb4879b6d61b3312</hash> </entry> <entry> <file>mcc_generated_files/tmr2.c</file> - <hash>ebb169b21ab8afecb20150f9c5cbc326d57004f1fe35f2b1dae82e59c660d136</hash> + <hash>419dcd6904958b08cb0f607f275d2e808d5142f575d2ded71a6a0230d48945ac</hash> </entry> <entry> <file>mcc_generated_files/ccp5.h</file> @@ -5116,12 +5116,12 @@ <hash>198e19c5c6435d1bed824bbdc3f045d3d1a7c313d869a9c8828aaf19e0d08344</hash> </entry> <entry> - <file>mcc_generated_files/eusart1.c</file> - <hash>e4692685821b770cc006efc6342fbb4e0534cec644499a4035f691ecd451d2aa</hash> + <file>mcc_generated_files/mcc.h</file> + <hash>3e9418c8d9f41381e4e09b6614cdc61728125d27e42c7a2af63db4e7512a5ad3</hash> </entry> <entry> - <file>mcc_generated_files/mcc.h</file> - <hash>eeff4ab321ba83391bc922417fe80acf75f67d6c4e49c2740deba77fc3fc5efb</hash> + <file>mcc_generated_files/eusart1.c</file> + <hash>9d090647b9883d331d538804d24b4e47c448761c2681b445c93b49a7368b1915</hash> </entry> <entry> <file>mcc_generated_files/device_config.c</file> @@ -5132,16 +5132,16 @@ <hash>e8b9dffb0d70449ea54caa68ec15f385c88175e6485055d92eac8801a039c407</hash> </entry> <entry> - <file>mcc_generated_files/fvr.h</file> - <hash>9370db448e1f6eadbd24bcd74ccdc505f1bd34051ea9f1be49baf6fdb0669b45</hash> + <file>mcc_generated_files/mcc.c</file> + <hash>184aea097c89a85dca3321db8276433451ea0ff31e35cd95d8a970560cb8caaa</hash> </entry> <entry> - <file>mcc_generated_files/mcc.c</file> - <hash>9c706baea7f5d3f9f01a5516a88090d0159153c0aac4c5026a3d3bed0ae9cefa</hash> + <file>mcc_generated_files/fvr.h</file> + <hash>9370db448e1f6eadbd24bcd74ccdc505f1bd34051ea9f1be49baf6fdb0669b45</hash> </entry> <entry> <file>mcc_generated_files/pin_manager.c</file> - <hash>a5fa123b216f8086f9664a48b9db4d6db74b710f4ccc2b7ab5e99c329a2d0038</hash> + <hash>730784579d6ce17441dd92dd77b86d2c3080580dae5f1dc41a577ba171709bfb</hash> </entry> </generatedFileHashHistoryMap> <mc3libFileHashHistoryMap class="java.util.HashMap"/> diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_ENABLE.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_ENABLE.c index be4b165..dbb0cf7 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_ENABLE.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_ENABLE.c @@ -32,7 +32,7 @@ err_t command_ALARM_ENABLE(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_ALARM_ENABLE + // CHECK : OK enum_alarm_number_t resp_alarm_number = req_alarm_number; enum_enablestate_t resp_enablestate; bool* enable_ptr = alarm_get_enable_ptr_by_enum(req_alarm_number); diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_GET.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_GET.c index 4894aa1..8e85c49 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_GET.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_GET.c @@ -5,6 +5,7 @@ #include "../typedefs.h" #include "../communication.h" #include "../hardware.h" +#include "../spurious.h" // NOT INCLUDED IN GENERATED CODE err_t command_ALARM_THRESHOLD_GET(void) { // Command: ALARM_THRESHOLD_GET @@ -26,13 +27,14 @@ err_t command_ALARM_THRESHOLD_GET(void) { // End of auto-generated section // USER CODE HERE - // TODO implement command callback function command_ALARM_THRESHOLD_GET - - // TODO: assign response field ALARM_NUMBER_ANALOG in command ALARM_THRESHOLD_GET callback - enum_alarm_number_analog_t resp_alarm_number_analog = -1; - - // TODO: assign response field THRESHOLD in command ALARM_THRESHOLD_GET callback - uint16_t resp_threshold = -1; + // TODO CHECK command_ALARM_THRESHOLD_GET + enum_alarm_number_analog_t resp_alarm_number_analog = req_alarm_number_analog; + + // retrieve the pointer to the requested alarm + analogalarm_info_t* p_alarm = alarm_get_analog_alarm_ptr_by_enum((enum_alarm_number_t)req_alarm_number_analog); + + // no need to disable interrupts (just reading, and interrupts don't change thresholds) + uint16_t resp_threshold = p_alarm->threshold; // Auto-generated section: response payload fields writing communication_response_payload_appender_reset(); diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_SET.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_SET.c index 8c866d5..467a3be 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_SET.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_THRESHOLD_SET.c @@ -5,6 +5,7 @@ #include "../typedefs.h" #include "../communication.h" #include "../hardware.h" +#include "../spurious.h" // NOT INCLUDED IN GENERATED CODE err_t command_ALARM_THRESHOLD_SET(void) { // Command: ALARM_THRESHOLD_SET @@ -26,7 +27,14 @@ err_t command_ALARM_THRESHOLD_SET(void) { // End of auto-generated section // USER CODE HERE - // TODO implement command callback function command_ALARM_THRESHOLD_SET + // TODO CHECK command_ALARM_THRESHOLD_SET + + // retrieve the pointer to the requested alarm + analogalarm_info_t* p_alarm = alarm_get_analog_alarm_ptr_by_enum((enum_alarm_number_t)req_alarm_number_analog); + + INTERRUPT_GlobalInterruptDisable(); + p_alarm->threshold = req_threshold; + INTERRUPT_GlobalInterruptEnable(); // Auto-generated section: response payload fields writing communication_response_payload_appender_reset(); diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_TIMEOUT_GET.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_TIMEOUT_GET.c index 71a4bba..dd8852e 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_TIMEOUT_GET.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ALARM_TIMEOUT_GET.c @@ -27,7 +27,7 @@ err_t command_ALARM_TIMEOUT_GET(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_ALARM_TIMEOUT_GET + // CHECK : OK enum_alarm_number_t resp_alarm_number = req_alarm_number; uint16_t resp_timeout; alarm_timeout_t* p_timeout = alarm_get_timeout_ptr_by_enum(req_alarm_number); diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_BOARDTIME.c b/micro/BPD-V01-FIRMWARE.X/commands/command_BOARDTIME.c index 79ce371..fc28d92 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_BOARDTIME.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_BOARDTIME.c @@ -21,7 +21,7 @@ err_t command_BOARDTIME(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_BOARDTIME + // CHECK : OK (tested with an approx 30s interval) uint32_t resp_seconds = timing_get_seconds_since_reset(); // Auto-generated section: response payload fields writing diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO1.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO1.c index e030ac5..17ddff7 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO1.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO1.c @@ -22,7 +22,7 @@ err_t command_ECHO1(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_ECHO1 + // CHECK : OK uint8_t resp_value = req_value; // Auto-generated section: response payload fields writing diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO32.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO32.c index 14d8f62..a3e7423 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO32.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO32.c @@ -84,7 +84,7 @@ err_t command_ECHO32(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_ECHO32 + // CHECK : OK uint8_t req_values[32]; uint8_t idx; for(idx = 0; idx < 32; idx++) { diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO4.c b/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO4.c index 94b895c..0622da5 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO4.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_ECHO4.c @@ -31,7 +31,7 @@ err_t command_ECHO4(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_ECHO4 + // CHECK : OK uint8_t resp_value_0 = req_value_0; uint8_t resp_value_1 = req_value_1; uint8_t resp_value_2 = req_value_2; diff --git a/micro/BPD-V01-FIRMWARE.X/commands/command_SWITCH_CONTROL.c b/micro/BPD-V01-FIRMWARE.X/commands/command_SWITCH_CONTROL.c index d266a50..9d20344 100644 --- a/micro/BPD-V01-FIRMWARE.X/commands/command_SWITCH_CONTROL.c +++ b/micro/BPD-V01-FIRMWARE.X/commands/command_SWITCH_CONTROL.c @@ -32,7 +32,7 @@ err_t command_SWITCH_CONTROL(void) { // End of auto-generated section // USER CODE HERE - // TODO CHECK command_SWITCH_CONTROL + // CHECK : OK enum_switchnum_t resp_switchnum = req_switchnum; enum_switchstate_t resp_switchstate; switch_state_set_func_t switch_state_set_func = switch_get_function_set_by_enum(req_switchnum); diff --git a/micro/BPD-V01-FIRMWARE.X/communication.c b/micro/BPD-V01-FIRMWARE.X/communication.c index 9b304ea..1c1b115 100644 --- a/micro/BPD-V01-FIRMWARE.X/communication.c +++ b/micro/BPD-V01-FIRMWARE.X/communication.c @@ -15,6 +15,7 @@ #include "commands.h" #include "hardware.h" #include "generated/sources/commandstable.h" +#include "generated/sources/variables.h" // TODO remove this include // local ("private") variables communication_parser_state_t _parser_status; // communication parser current status diff --git a/micro/BPD-V01-FIRMWARE.X/configuration.h b/micro/BPD-V01-FIRMWARE.X/configuration.h index bb6059c..a5b1a6c 100644 --- a/micro/BPD-V01-FIRMWARE.X/configuration.h +++ b/micro/BPD-V01-FIRMWARE.X/configuration.h @@ -40,8 +40,8 @@ #define RESCUE_STEP_INTERVAL_SECONDS 60 // period of timers SLOW and FAST in microseconds -#define IRQ_TIMER_SLOW_PERIOD_US 319 // = 300us * 1.06339612032612 from measurements -#define IRQ_TIMER_FAST_PERIOD_US 80 +#define IRQ_TIMER_SLOW_PERIOD_US 800 // from what MCC reports +#define IRQ_TIMER_FAST_PERIOD_US 200 // from what MCC reports // dimension of the buffer for the payload of the packets #define COMMUNICATION_DATABUF_SIZE 240 diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c index d19407f..8b6eb71 100644 --- a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c +++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c @@ -1,5 +1,5 @@ // Auto-generated file: commandstable.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "commandstable.h" diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h index d1caf63..a27cb26 100644 --- a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h +++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h @@ -1,5 +1,5 @@ // Auto-generated file: commandstable.h -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #ifndef _AUTOGENERATED_COMMANDSTABLE_H #define _AUTOGENERATED_COMMANDSTABLE_H @@ -190,10 +190,10 @@ err_t command_INVALID(void); #define COMMAND_TABLE_VERSION_NUM 34 #define TEMPLATE_GENERATION_YEAR 2021 #define TEMPLATE_GENERATION_MONTH 6 -#define TEMPLATE_GENERATION_DAY 17 -#define TEMPLATE_GENERATION_HOUR 18 -#define TEMPLATE_GENERATION_MINUTE 31 -#define TEMPLATE_GENERATION_SECOND 59 +#define TEMPLATE_GENERATION_DAY 20 +#define TEMPLATE_GENERATION_HOUR 5 +#define TEMPLATE_GENERATION_MINUTE 48 +#define TEMPLATE_GENERATION_SECOND 56 #endif // _AUTOGENERATED_COMMANDSTABLE_H diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h b/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h index f356136..246cea6 100644 --- a/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h +++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h @@ -1,5 +1,5 @@ // Auto-generated file: datatypes.h -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #ifndef _AUTOGENERATED_DATATYPES_H #define _AUTOGENERATED_DATATYPES_H diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c index ee8e26c..e24d7bf 100644 --- a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c +++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c @@ -1,5 +1,5 @@ // Auto-generated file: variables.c -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #include "variables.h" #include "../../configuration.h" @@ -110,7 +110,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = true, .threshold = 63760, // 2.5 A - .timeout = 1, // 5.0 ms (6.6 ms real) + .timeout = 2, // 35.0 ms (35.2 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -119,7 +119,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = true, .threshold = 46960, // 1.5 A - .timeout = 15, // 100.0 ms (99.0 ms real) + .timeout = 9, // 150.0 ms (158.4 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -140,7 +140,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = true, .threshold = 62080, // 2.4 A - .timeout = 1, // 5.0 ms (6.6 ms real) + .timeout = 2, // 35.0 ms (35.2 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -149,7 +149,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = true, .threshold = 45280, // 1.4 A - .timeout = 15, // 100.0 ms (99.0 ms real) + .timeout = 9, // 150.0 ms (158.4 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -170,7 +170,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = false, .threshold = 63000, // 0.35 A - .timeout = 8, // 50.0 ms (52.8 ms real) + .timeout = 3, // 50.0 ms (52.8 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -179,7 +179,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = false, .threshold = 27000, // 0.15 A - .timeout = 15, // 100.0 ms (99.0 ms real) + .timeout = 28, // 500.0 ms (492.8 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -230,7 +230,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = false, .threshold = 61714, // 0.6 A - .timeout = 8, // 50.0 ms (52.8 ms real) + .timeout = 3, // 50.0 ms (52.8 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -239,7 +239,7 @@ analog_variable_t analog_variables[ANALOG_VARIABLES_COUNT] = { .implement = true, .enabled = false, .threshold = 51429, // 0.5 A - .timeout = 15, // 100.0 ms (99.0 ms real) + .timeout = 28, // 500.0 ms (492.8 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0 @@ -441,7 +441,7 @@ digital_variable_t digital_variables[DIGITAL_VARIABLES_COUNT] = { .alarm = { .implement = true, .enabled = DEFAULT_FLAG_DUL_ALARMPOS1_ALARM_ENABLED, - .timeout = 19, // 1.5 ms (1.52 ms real) + .timeout = 5, // 1.0 ms (1.0 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0, @@ -455,7 +455,7 @@ digital_variable_t digital_variables[DIGITAL_VARIABLES_COUNT] = { .alarm = { .implement = true, .enabled = DEFAULT_FLAG_DUL_ALARMPOS2_ALARM_ENABLED, - .timeout = 19, // 1.5 ms (1.52 ms real) + .timeout = 5, // 1.0 ms (1.0 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0, @@ -469,7 +469,7 @@ digital_variable_t digital_variables[DIGITAL_VARIABLES_COUNT] = { .alarm = { .implement = true, .enabled = DEFAULT_FLAG_DUL_ALARMNEG1_ALARM_ENABLED, - .timeout = 19, // 1.5 ms (1.52 ms real) + .timeout = 5, // 1.0 ms (1.0 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0, @@ -483,7 +483,7 @@ digital_variable_t digital_variables[DIGITAL_VARIABLES_COUNT] = { .alarm = { .implement = true, .enabled = DEFAULT_FLAG_DUL_ALARMNEG2_ALARM_ENABLED, - .timeout = 19, // 1.5 ms (1.52 ms real) + .timeout = 5, // 1.0 ms (1.0 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0, @@ -497,7 +497,7 @@ digital_variable_t digital_variables[DIGITAL_VARIABLES_COUNT] = { .alarm = { .implement = true, .enabled = true, - .timeout = 19, // 1.5 ms (1.52 ms real) + .timeout = 8, // 1.5 ms (1.6 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0, @@ -511,7 +511,7 @@ digital_variable_t digital_variables[DIGITAL_VARIABLES_COUNT] = { .alarm = { .implement = true, .enabled = true, - .timeout = 19, // 1.5 ms (1.52 ms real) + .timeout = 8, // 1.5 ms (1.6 ms real) .timeout_counter = 0, .timeout_counter_max = 0, .firecount = 0, diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h index 507a119..e556c20 100644 --- a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h +++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h @@ -1,5 +1,5 @@ // Auto-generated file: variables.h -// Generation timestamp: 2021-06-17 18:31:59.933877 +// Generation timestamp: 2021-06-20 05:48:56.170376 #ifndef _AUTOGENERATED_VARIABLES_H #define _AUTOGENERATED_VARIABLES_H diff --git a/micro/BPD-V01-FIRMWARE.X/irqs.c b/micro/BPD-V01-FIRMWARE.X/irqs.c index ce95abe..686d475 100644 --- a/micro/BPD-V01-FIRMWARE.X/irqs.c +++ b/micro/BPD-V01-FIRMWARE.X/irqs.c @@ -17,18 +17,33 @@ void _manage_digital_variables(void); void _manage_digital_variable(digital_variable_t* _p_variable); // "slow" timer interrupt service routine -void irq_timer_slow(void) { +void irq_timer_slow(void) { + + // __TODO LED remove user pin activity + // userpin_SWITCH_LED_D9_set_high(); + // update the adcreader state machine adcreader_tick_irq(); // update timing register timing_tick_irq(); + + // __TODO LED remove user pin activity + // userpin_SWITCH_LED_D9_set_low(); } // "fast" timer interrupt service routine -void irq_timer_fast(void) { +void irq_timer_fast(void) { + + // __TODO LED remove user pin activity + // userpin_SWITCH_LED_D10_set_high(); + // manage digital alarms - _manage_digital_variables(); + _manage_digital_variables(); + + // __TODO LED remove user pin activity + // userpin_SWITCH_LED_D10_set_low(); + } void _manage_digital_variables(void) { @@ -38,6 +53,7 @@ void _manage_digital_variables(void) { } void _manage_digital_variable(digital_variable_t* _p_variable) { + // read digital variables _p_variable->value = _p_variable->readfunc(); @@ -45,37 +61,41 @@ void _manage_digital_variable(digital_variable_t* _p_variable) { if(_p_variable->value > _p_variable->value_max) { _p_variable->value_max = _p_variable->value; } - // check if timout counter has to be incremented - if(_p_variable->value > 0) { - // increment counter - _p_variable->alarm.timeout_counter += 1; - // avoid wrapping on increment (not very elegant...) - if(_p_variable->alarm.timeout_counter == 0) { - _p_variable->alarm.timeout_counter -= 1; - } - // update alarm counter stats - if(_p_variable->alarm.timeout_counter_max < _p_variable->alarm.timeout_counter) { - _p_variable->alarm.timeout_counter_max = _p_variable->alarm.timeout_counter; - } - }else{ - // or reset the counter - _p_variable->alarm.timeout_counter = 0; - } - // check if alarm has fired - if(_p_variable->alarm.enabled) { - // check if timeout was reached - if(_p_variable->alarm.timeout_counter > _p_variable->alarm.timeout) { - // perform the alarm action - _p_variable->alarm.callback(); - // increment the fire counter - _p_variable->alarm.firecount += 1; + + // skip alarm management if alarm not implemented on current variable + if(_p_variable->alarm.implement) { + // check if timout counter has to be incremented + if(_p_variable->value > 0) { + // increment counter + _p_variable->alarm.timeout_counter += 1; // avoid wrapping on increment (not very elegant...) - if(_p_variable->alarm.firecount == 0) { - _p_variable->alarm.firecount -= 1; + if(_p_variable->alarm.timeout_counter == 0) { + _p_variable->alarm.timeout_counter -= 1; + } + // update alarm counter stats + if(_p_variable->alarm.timeout_counter_max < _p_variable->alarm.timeout_counter) { + _p_variable->alarm.timeout_counter_max = _p_variable->alarm.timeout_counter; } - // reset alarm timeout counter + }else{ + // or reset the counter _p_variable->alarm.timeout_counter = 0; } + // check if alarm has fired + if(_p_variable->alarm.enabled) { + // check if timeout was reached + if(_p_variable->alarm.timeout_counter > _p_variable->alarm.timeout) { + // perform the alarm action + _p_variable->alarm.callback(); + // increment the fire counter + _p_variable->alarm.firecount += 1; + // avoid wrapping on increment (not very elegant...) + if(_p_variable->alarm.firecount == 0) { + _p_variable->alarm.firecount -= 1; + } + // reset alarm timeout counter + _p_variable->alarm.timeout_counter = 0; + } + } } } diff --git a/micro/BPD-V01-FIRMWARE.X/main.c b/micro/BPD-V01-FIRMWARE.X/main.c index 697ae84..cd7b6fe 100644 --- a/micro/BPD-V01-FIRMWARE.X/main.c +++ b/micro/BPD-V01-FIRMWARE.X/main.c @@ -30,8 +30,36 @@ void alarms_enable(void); void manage_incoming_data(void); void _delay_seconds(uint8_t _seconds); -void main(void) { - return; +void main(void) { + + // initialize the MCU + init_mcu(); + + // initialize the communication channel + init_comm(); + + // initialize the ADC reader + init_adcreader(); + + // start the interrupt system + start_irqs(); + + // acquire sensor offsets + sensors_acquire_offsets(); + + // enable alarms + alarms_enable(); + + // enter main loop + while(1) { + + // manage auto-rescue + rescue_check(); + // manage incoming communication data + manage_incoming_data(); + + } + } void init_mcu(void) { @@ -76,17 +104,14 @@ void sensors_acquire_offsets(void) { // Note that the ADC is 10 bit, but data are left aligned to 16 bit, we thus // have an headroom of 6 bits = 32 counts. // Note also that stored offset values are initialized to zero. - userpin_SWITCH_LED_D10_set_high(); - userpin_SWITCH_LED_D9_set_high(); - _delay_seconds(5); // wait 5 seconds to make signals steady - userpin_SWITCH_LED_D9_set_low(); + + _delay_seconds(5); // wait 5 seconds to make signals steady for(uint8_t k = 0; k < 32; k++) { __delay_ms(30); // 2.2 * 30 millis are (much) more than sufficient for ADC reader to acquire from all ADC channels for(uint8_t varidx = 0; varidx < ANALOG_VARIABLES_COUNT; varidx++) { analog_variables[varidx].offset += analog_variables[varidx].value/32; } } - userpin_SWITCH_LED_D10_set_low(); } void alarms_enable(void) { @@ -97,12 +122,12 @@ void alarms_enable(void) { void manage_incoming_data(void) { // check if a new byte is present in serial port receive buffer - if(serialport_dataready) { + if(serialport_dataready) { // a byte is present, read it and parse it communication_parser_appendbyte(serialport_read()); } // check if a complete command was received - if(communication_parser_commandready()) { + if(communication_parser_commandready()) { // a new complete command was received // execute the received command and verify result err_t retval = communication_parser_executecommand(); @@ -112,14 +137,14 @@ void manage_incoming_data(void) { // (this function is called after the command was executed to be able to read its value) timing_reset_seconds_since_last_command(); // send the response to the host - // (it was created by the [...]_executecommand function) + // (it was created by the [...]_executecommand function) communication_transmitter_sendresponse(); }else{ // do nothing error_notify(retval); } // reset the parser - communication_parser_reset(); + communication_parser_reset(); } } diff --git a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/eusart1.c b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/eusart1.c index c04e828..84cca18 100644 --- a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/eusart1.c +++ b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/eusart1.c @@ -53,8 +53,8 @@ Section: Macro Declarations */ -#define EUSART1_TX_BUFFER_SIZE 8 -#define EUSART1_RX_BUFFER_SIZE 8 +#define EUSART1_TX_BUFFER_SIZE 64 +#define EUSART1_RX_BUFFER_SIZE 64 /** Section: Global Variables diff --git a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.c b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.c index 1126d71..5e10ce8 100644 --- a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.c +++ b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.c @@ -54,8 +54,8 @@ void SYSTEM_Initialize(void) PIN_MANAGER_Initialize(); OSCILLATOR_Initialize(); FVR_Initialize(); - CCP5_Initialize(); ADC_Initialize(); + CCP5_Initialize(); TMR2_Initialize(); TMR0_Initialize(); EUSART1_Initialize(); diff --git a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.h b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.h index 7fca89b..980078e 100644 --- a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.h +++ b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/mcc.h @@ -56,8 +56,8 @@ #include "fvr.h" #include "ccp5.h" #include "tmr2.h" -#include "tmr0.h" #include "adc.h" +#include "tmr0.h" #include "eusart1.h" diff --git a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/pin_manager.c b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/pin_manager.c index 9d0b816..acee53c 100644 --- a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/pin_manager.c +++ b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/pin_manager.c @@ -67,7 +67,7 @@ void PIN_MANAGER_Initialize(void) TRISx registers */ TRISE = 0x07; - TRISA = 0x7F; + TRISA = 0x3F; TRISB = 0xFF; TRISC = 0xBF; TRISD = 0x00; diff --git a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr0.c b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr0.c index 7b0e922..992cd61 100644 --- a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr0.c +++ b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr0.c @@ -71,12 +71,12 @@ void TMR0_Initialize(void) // TMR0H 0; TMR0H = 0x00; - // TMR0L 106; - TMR0L = 0x6A; + // TMR0L 56; + TMR0L = 0x38; // Load TMR0 value to the 8-bit reload variable - timer0ReloadVal = 106; + timer0ReloadVal = 56; // Clear Interrupt flag before enabling the interrupt INTCONbits.TMR0IF = 0; @@ -87,8 +87,8 @@ void TMR0_Initialize(void) // Set Default Interrupt Handler TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); - // T0PS 1:32; T08BIT 8-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA assigned; - T0CON = 0xD4; + // T0PS 1:64; T08BIT 8-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA assigned; + T0CON = 0xD5; } void TMR0_StartTimer(void) diff --git a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr2.c b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr2.c index d32b0b6..2096517 100644 --- a/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr2.c +++ b/micro/BPD-V01-FIRMWARE.X/mcc_generated_files/tmr2.c @@ -65,8 +65,8 @@ void TMR2_Initialize(void) { // Set TMR2 to the options selected in the User Interface - // PR2 159; - PR2 = 0x9F; + // PR2 199; + PR2 = 0xC7; // TMR2 0; TMR2 = 0x00; @@ -80,8 +80,8 @@ void TMR2_Initialize(void) // Set Default Interrupt Handler TMR2_SetInterruptHandler(TMR2_DefaultInterruptHandler); - // T2CKPS 1:4; T2OUTPS 1:2; TMR2ON on; - T2CON = 0x0D; + // T2CKPS 1:4; T2OUTPS 1:4; TMR2ON on; + T2CON = 0x1D; } void TMR2_StartTimer(void) diff --git a/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml b/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml index 1659101..5cb90fb 100644 --- a/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml +++ b/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml @@ -130,9 +130,9 @@ <targetDevice>PIC18F46K22</targetDevice> <targetHeader></targetHeader> <targetPluginBoard></targetPluginBoard> - <platformTool></platformTool> + <platformTool>noID</platformTool> <languageToolchain>XC8</languageToolchain> - <languageToolchainVersion>2.00</languageToolchainVersion> + <languageToolchainVersion>2.20</languageToolchainVersion> <platform>2</platform> </toolsSet> <packs> @@ -189,9 +189,9 @@ <property key="optimization-level" value="-O0"/> <property key="optimization-speed" value="false"/> <property key="optimization-stable-enable" value="false"/> - <property key="pack-struct" value="true"/> <property key="preprocess-assembler" value="true"/> <property key="short-enums" value="true"/> + <property key="tentative-definitions" value=""/> <property key="undefine-macros" value=""/> <property key="use-cci" value="false"/> <property key="use-iar" value="false"/> @@ -247,6 +247,7 @@ </HI-TECH-LINK> <XC8-CO> <property key="coverage-enable" value=""/> + <property key="stack-guidance" value="false"/> </XC8-CO> <XC8-config-global> <property key="advanced-elf" value="true"/> @@ -261,6 +262,7 @@ <property key="stack-size-main" value="auto"/> <property key="stack-type" value="compiled"/> <property key="user-pack-device-support" value=""/> + <property key="wpo-lto" value="false"/> </XC8-config-global> </conf> <conf name="ARCA" type="2"> @@ -269,7 +271,7 @@ <targetDevice>PIC18F46K22</targetDevice> <targetHeader></targetHeader> <targetPluginBoard></targetPluginBoard> - <platformTool></platformTool> + <platformTool>ICD3PlatformTool</platformTool> <languageToolchain>XC8</languageToolchain> <languageToolchainVersion>2.20</languageToolchainVersion> <platform>2</platform> @@ -318,7 +320,7 @@ <property key="garbage-collect-functions" value="true"/> <property key="identifier-length" value="255"/> <property key="local-generation" value="false"/> - <property key="operation-mode" value="free"/> + <property key="operation-mode" value="pro"/> <property key="opt-xc8-compiler-strict_ansi" value="false"/> <property key="optimization-assembler" value="true"/> <property key="optimization-assembler-files" value="true"/> @@ -326,11 +328,11 @@ <property key="optimization-invariant-enable" value="false"/> <property key="optimization-invariant-value" value="16"/> <property key="optimization-level" value="-O0"/> - <property key="optimization-speed" value="false"/> + <property key="optimization-speed" value="true"/> <property key="optimization-stable-enable" value="false"/> - <property key="pack-struct" value="true"/> <property key="preprocess-assembler" value="true"/> <property key="short-enums" value="true"/> + <property key="tentative-definitions" value=""/> <property key="undefine-macros" value=""/> <property key="use-cci" value="false"/> <property key="use-iar" value="false"/> @@ -384,8 +386,87 @@ <property key="program-the-device-with-default-config-words" value="true"/> <property key="remove-unused-sections" value="true"/> </HI-TECH-LINK> + <ICD3PlatformTool> + <property key="AutoSelectMemRanges" value="auto"/> + <property key="Freeze Peripherals" value="true"/> + <property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/> + <property key="ToolFirmwareFilePath" + value="Press to browse for a specific firmware version"/> + <property key="ToolFirmwareOption.UseLatestFirmware" value="true"/> + <property key="debugoptions.useswbreakpoints" value="false"/> + <property key="hwtoolclock.frcindebug" value="false"/> + <property key="memories.aux" value="false"/> + <property key="memories.bootflash" value="false"/> + <property key="memories.configurationmemory" value="true"/> + <property key="memories.configurationmemory2" value="true"/> + <property key="memories.dataflash" value="true"/> + <property key="memories.eeprom" value="true"/> + <property key="memories.flashdata" value="true"/> + <property key="memories.id" value="true"/> + <property key="memories.instruction.ram" value="true"/> + <property key="memories.instruction.ram.ranges" + value="${memories.instruction.ram.ranges}"/> + <property key="memories.programmemory" value="true"/> + <property key="memories.programmemory.ranges" value="0-ffff"/> + <property key="poweroptions.powerenable" value="false"/> + <property key="programoptions.donoteraseauxmem" value="false"/> + <property key="programoptions.eraseb4program" value="true"/> + <property key="programoptions.preservedataflash" value="false"/> + <property key="programoptions.preservedataflash.ranges" value=""/> + <property key="programoptions.preserveeeprom" value="false"/> + <property key="programoptions.preserveeeprom.ranges" value="0-3ff"/> + <property key="programoptions.preserveprogram.ranges" value=""/> + <property key="programoptions.preserveprogramrange" value="false"/> + <property key="programoptions.preserveuserid" value="false"/> + <property key="programoptions.programcalmem" value="false"/> + <property key="programoptions.programuserotp" value="false"/> + <property key="programoptions.testmodeentrymethod" value="VDDFirst"/> + <property key="programoptions.usehighvoltageonmclr" value="false"/> + <property key="programoptions.uselvpprogramming" value="false"/> + <property key="voltagevalue" value="5.0"/> + </ICD3PlatformTool> + <Tool> + <property key="AutoSelectMemRanges" value="auto"/> + <property key="Freeze Peripherals" value="true"/> + <property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/> + <property key="ToolFirmwareFilePath" + value="Press to browse for a specific firmware version"/> + <property key="ToolFirmwareOption.UseLatestFirmware" value="true"/> + <property key="debugoptions.useswbreakpoints" value="false"/> + <property key="hwtoolclock.frcindebug" value="false"/> + <property key="memories.aux" value="false"/> + <property key="memories.bootflash" value="false"/> + <property key="memories.configurationmemory" value="true"/> + <property key="memories.configurationmemory2" value="true"/> + <property key="memories.dataflash" value="true"/> + <property key="memories.eeprom" value="true"/> + <property key="memories.flashdata" value="true"/> + <property key="memories.id" value="true"/> + <property key="memories.instruction.ram" value="true"/> + <property key="memories.instruction.ram.ranges" + value="${memories.instruction.ram.ranges}"/> + <property key="memories.programmemory" value="true"/> + <property key="memories.programmemory.ranges" value="0-ffff"/> + <property key="poweroptions.powerenable" value="false"/> + <property key="programoptions.donoteraseauxmem" value="false"/> + <property key="programoptions.eraseb4program" value="true"/> + <property key="programoptions.preservedataflash" value="false"/> + <property key="programoptions.preservedataflash.ranges" value=""/> + <property key="programoptions.preserveeeprom" value="false"/> + <property key="programoptions.preserveeeprom.ranges" value="0-3ff"/> + <property key="programoptions.preserveprogram.ranges" value=""/> + <property key="programoptions.preserveprogramrange" value="false"/> + <property key="programoptions.preserveuserid" value="false"/> + <property key="programoptions.programcalmem" value="false"/> + <property key="programoptions.programuserotp" value="false"/> + <property key="programoptions.testmodeentrymethod" value="VDDFirst"/> + <property key="programoptions.usehighvoltageonmclr" value="false"/> + <property key="programoptions.uselvpprogramming" value="false"/> + <property key="voltagevalue" value="5.0"/> + </Tool> <XC8-CO> <property key="coverage-enable" value=""/> + <property key="stack-guidance" value="false"/> </XC8-CO> <XC8-config-global> <property key="advanced-elf" value="true"/> @@ -400,6 +481,7 @@ <property key="stack-size-main" value="auto"/> <property key="stack-type" value="compiled"/> <property key="user-pack-device-support" value=""/> + <property key="wpo-lto" value="false"/> </XC8-config-global> </conf> </confs> diff --git a/micro/BPD-V01-FIRMWARE.X/timing.c b/micro/BPD-V01-FIRMWARE.X/timing.c index 8263114..17e02ea 100644 --- a/micro/BPD-V01-FIRMWARE.X/timing.c +++ b/micro/BPD-V01-FIRMWARE.X/timing.c @@ -68,12 +68,7 @@ void timing_tick_irq(void) { // increment microsecond counter by the number of microseconds per tick _tick_counter_us += IRQ_TIMER_SLOW_PERIOD_US; // check if a second has elapsed - if(_tick_counter_us >= 1000000) { - - // TODO remove user pin activity - if(userpin_SWITCH_LED_D9_get() == PINSTATE_HIGH) userpin_SWITCH_LED_D9_set_low(); - else userpin_SWITCH_LED_D9_set_high(); - + if(_tick_counter_us >= 1000000) { // ONE second elapsed! // increment number of seconds since last received command _timing_seconds_lc += 1; -- GitLab