Skip to content
Snippets Groups Projects
Commit fba042bd authored by Carlo Alessandro Nicolau's avatar Carlo Alessandro Nicolau
Browse files

Added and implemented the following commands: LASTERROR,...

Added and implemented the following commands: LASTERROR, SENSOR_AVERAGE_GETALL, SENSOR_AVERAGE_GETALL, SENSOR_AVERAGE_GETALL, SENSOR_AVERAGING_PRESCALER_GET, SENSOR_AVERAGING_PRESCALER_SET, VERSION, and modified the command SENSOR_GET_SINGLE (now returns the average too)
parent 0e698a93
No related branches found
No related tags found
No related merge requests found
Showing
with 352 additions and 111 deletions
# bps-software
https://git.km3net.de/cnicolau/bps-software.git
Software (both host and embedded) for the BPS board.
......@@ -105,7 +105,7 @@ class VariableAveragingPrescalerEnumField(PayloadFieldEnum):
"""A class to create enum relative to the averaging functionality"""
def __init__(self):
idxs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
idxs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
PayloadFieldEnum.__init__(
self,
name='AVERAGINGPRESCALER',
......@@ -474,6 +474,7 @@ class CommandList:
# if requested fields are not offsets, then append the fields for the digital sensors
if not selection == 'offsets':
for variable in self.digital_variable_list.entries():
if selection != 'means':
fields.append(
FlagStateField(
name=variable.name + '_STATE',
......@@ -492,9 +493,9 @@ class CommandList:
name='SENSOR_GET_SINGLE',
request_code=None,
response_code=None,
description='Get one sensor\'s current value, offset value, and max value',
description='Get one sensor\'s current value, offset value, max value, and mean value',
request_payload=[self.variable_enum_field],
response_payload=[self.variable_enum_field, self.variable_value_field, self.variable_offset_field, self.variable_maxvalue_field]
response_payload=[self.variable_enum_field, self.variable_value_field, self.variable_offset_field, self.variable_maxvalue_field, self.variable_meanvalue_field]
)
)
......@@ -634,6 +635,66 @@ class CommandList:
)
)
# ------------------------------------------------------------------------------------------------------------------
# Append command: Versioning info
self.vars.append(
CommandDescriptor(
firmware_config=fwcfg,
name='VERSION',
request_code=None,
response_code=None,
description='Report embedded code versioning information',
request_payload=[],
response_payload=[
PayloadFieldU16(
name='COMMAND_TABLE_VERSION',
description='Version of the current command table'
),
PayloadFieldU16(
name='TEMPLATE_GENERATION_YEAR',
description='Template generation year'
),
PayloadFieldU8(
name='TEMPLATE_GENERATION_MONTH',
description='Template generation month'
),
PayloadFieldU8(
name='TEMPLATE_GENERATION_DAY',
description='Template generation day'
),
PayloadFieldU8(
name='TEMPLATE_GENERATION_HOUR',
description='Template generation hour'
),
PayloadFieldU8(
name='TEMPLATE_GENERATION_MINUTE',
description='Template generation minute'
),
PayloadFieldU8(
name='TEMPLATE_GENERATION_SECOND',
description='Template generation second'
)]
)
)
# ------------------------------------------------------------------------------------------------------------------
# Append command: Get last error recorded
self.vars.append(
CommandDescriptor(
firmware_config=fwcfg,
name='LASTERROR',
request_code=None,
response_code=None,
description='Return the last occurred error, and reset it to NOERR value',
request_payload=[],
response_payload=[
PayloadFieldU8(
name='ERRCODE',
description='Error code'
)]
)
)
def _create_rescue_control_commands(self):
# ------------------------------------------------------------------------------------------------------------------
......
......
......@@ -5,11 +5,30 @@ from analogvariables import AnalogVariableList
from digitalvariables import DigitalVariableList
from userpins import UserPinList
from utils import mls
import pickle
import datetime
def generate_commandtable_header(_commands):
assert isinstance(_commands, CommandList) # just to help pycharm
# read last command table version from file and update it
command_table_version = 10
now = datetime.datetime.now()
generation_year = now.year
generation_month = now.month
generation_day = now.day
generation_hour = now.hour
generation_minute = now.minute
generation_second = now.second
# comment reading first time you execute this script...
with open('versioning.pkl', 'r') as f:
command_table_version = pickle.load(f)
command_table_version += 1
with open('versioning.pkl', 'w') as f:
pickle.dump(command_table_version, f)
callback_declaration_tpl = """
// [comment]
err_t [callback](void);"""
......@@ -54,6 +73,17 @@ extern command_info_t commands_info_table[COMMANDS_COUNT];
header_contents += '\n'
header_contents += '\n// Callback functions\n'
header_contents += '\n'.join(callback_declaration_list)
# versioning information
header_contents += '\n\n// Versioning data\n'
header_contents += '#define COMMAND_TABLE_VERSION_NUM {}\n'.format(command_table_version)
header_contents += '#define TEMPLATE_GENERATION_YEAR {}\n'.format(generation_year)
header_contents += '#define TEMPLATE_GENERATION_MONTH {}\n'.format(generation_month)
header_contents += '#define TEMPLATE_GENERATION_DAY {}\n'.format(generation_day)
header_contents += '#define TEMPLATE_GENERATION_HOUR {}\n'.format(generation_hour)
header_contents += '#define TEMPLATE_GENERATION_MINUTE {}\n'.format(generation_minute)
header_contents += '#define TEMPLATE_GENERATION_SECOND {}\n'.format(generation_second)
return header_contents
......@@ -183,11 +213,11 @@ typedef enum {
contents = ''
for enum in enums.values():
if enum.name == 'VARIABLE_NUMBER':
print enum.name
print enum.__class__.__name__
print enum.index_list
print enum.value_list
# if enum.name == 'VARIABLE_NUMBER':
# print enum.name
# print enum.__class__.__name__
# print enum.index_list
# print enum.value_list
enum_entries = list()
......
......
I30
.
\ No newline at end of file
......@@ -17,9 +17,9 @@ import serial
ASK_CONFIRM = False
SHOW_SENT_DATA = True
SHOW_SENT_DATA = False
SHOW_RECEIVED_DATA = False
UART_DEV = '/dev/ttyUSB1'
UART_DEV = '/dev/ttyUSB0'
def ask_confirm():
......
......
......@@ -14,6 +14,9 @@
#include "hardware.h"
#include "generated/sources/variables.h"
// variables accessible from elsewhere
enum_averagingprescaler_t adcreader_averaging_prescaler = ADCREADER_AVERAGING_PRESCALER_DEFAULT;
analog_variable_sum_counter_t adcreader_averaging_prescaler_maxcount = (analog_variable_sum_counter_t)(1 << ADCREADER_AVERAGING_PRESCALER_DEFAULT);
// local variables
adcreader_state_t _state; // ADC reader state machine status variable
......@@ -24,6 +27,7 @@ uint8_t _state_timeout; // timeout counter used for state transitions
void _sample_acquired(void);
void _update_alarm(analogalarm_info_t* _p_alarm, analog_value_t _value);
bool _check_alarm_firing(analogalarm_info_t* _p_alarm, alarm_callback_t _callback);
void _update_averaging(analog_variable_t* _p_analog_variable);
void adcreader_reset(void) {
_state = ADCREADER_RESET;
......@@ -100,6 +104,7 @@ void _sample_acquired(void) {
// fast alarm did not fire, check also slow alarm
_check_alarm_firing(&(analog_variable->alarms.slow), analog_variable->alarms.callback);
}
_update_averaging(analog_variable);
}
void _update_alarm(analogalarm_info_t* _p_alarm, analog_value_t _value) {
......@@ -143,3 +148,14 @@ bool _check_alarm_firing(analogalarm_info_t* _p_alarm, alarm_callback_t _callbac
}
return false;
}
void _update_averaging(analog_variable_t* _p_analog_variable) {
_p_analog_variable->sum_curr += _p_analog_variable->value;
_p_analog_variable->sum_counter++;
if(_p_analog_variable->sum_counter >= adcreader_averaging_prescaler_maxcount) {
_p_analog_variable->sum_last = _p_analog_variable->sum_curr;
_p_analog_variable->sum_curr = 0;
_p_analog_variable->sum_counter = 0;
}
}
......@@ -26,5 +26,12 @@ void adcreader_reset(void);
void adcreader_start(void);
void adcreader_tick_irq(void);
// prescaler for counts before saving the sum value
extern enum_averagingprescaler_t adcreader_averaging_prescaler;
// number of counts before saving the sum value (must be equal to 2^adcreader_averaging_prescaler)
extern analog_variable_sum_counter_t adcreader_averaging_prescaler_maxcount;
#endif // __ADCREADER_H
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_ALARM_TIMEOUT_GET.tpl.c
// Generation timestamp: 2019-10-26 17:37:27.388435
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_ALARM_TIMEOUT_SET.tpl.c
// Generation timestamp: 2019-10-26 17:37:27.388435
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_BPSTIME.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_LASTERROR.tpl.c
// Generation timestamp: 2019-11-16 20:55:43.822247
#include "../typedefs.h"
#include "../communication.h"
#include "../hardware.h"
#include "../errors.h"
err_t command_LASTERROR(void) {
// Command: LASTERROR
// Description: Return the last occurred error, and reset it to NOERR value
//
// Request code: CMDCODE_LASTERROR_REQ
// Response code: CMDCODE_LASTERROR_REQ
// Request payload (length in bytes is 0):
// Response payload (length in bytes is 1):
// field #0 (1 byte) [type: uint8_t ] : ERRCODE (Error code)
// Auto-generated section: request payload fields reading
// End of auto-generated section
// USER CODE HERE
uint8_t resp_errcode;
INTERRUPT_GlobalInterruptDisable();
resp_errcode = errors_last_error;
errors_last_error = NOERR;
INTERRUPT_GlobalInterruptEnable();
// Auto-generated section: response payload fields writing
communication_response_payload_appender_reset();
communication_response_payload_append_uint8_t((uint8_t)resp_errcode);
return NOERR;
// End of auto-generated section
}
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_LCTIME.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_RESCUE_ENABLE.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_RESCUE_STATUS_GET.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_RESCUE_STATUS_RESET.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_RESCUE_TIMEOUT_GET.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_RESCUE_TIMEOUT_SET.tpl.c
// Generation timestamp: 2019-10-28 18:01:38.276936
......
......
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_SENSOR_AVERAGE_GETALL.tpl.c
// Generation timestamp: 2019-11-16 17:43:28.678814
#include "../typedefs.h"
#include "../communication.h"
#include "../hardware.h"
#include "../adcreader.h"
err_t command_SENSOR_AVERAGE_GETALL(void) {
// Command: SENSOR_AVERAGE_GETALL
// Description: Get all sensors' mean values
//
// Request code: CMDCODE_SENSOR_AVERAGE_GETALL_REQ
// Response code: CMDCODE_SENSOR_AVERAGE_GETALL_REQ
// Request payload (length in bytes is 0):
// Response payload (length in bytes is 16):
// field #0 (2 bytes) [type: uint16_t ] : MON_5V_I_MEAN (Variable MON_5V_I mean)
// field #1 (2 bytes) [type: uint16_t ] : MON_LBL_I_MEAN (Variable MON_LBL_I mean)
// field #2 (2 bytes) [type: uint16_t ] : MON_DU_I_MEAN (Variable MON_DU_I mean)
// field #3 (2 bytes) [type: uint16_t ] : MON_DU_IRTN_MEAN (Variable MON_DU_IRTN mean)
// field #4 (2 bytes) [type: uint16_t ] : MON_BPS_V_MEAN (Variable MON_BPS_V mean)
// field #5 (2 bytes) [type: uint16_t ] : MON_HYDRO_I_MEAN (Variable MON_HYDRO_I mean)
// field #6 (2 bytes) [type: uint16_t ] : MON_THEATSINK_MEAN (Variable MON_THEATSINK mean)
// field #7 (2 bytes) [type: uint16_t ] : MON_TBOARD_MEAN (Variable MON_TBOARD mean)
// Auto-generated section: request payload fields reading
// End of auto-generated section
// USER CODE HERE
// IMPORTANT: we are assuming that analog enum_variable_number_t indexes are ordered as in the response payload
// we are also assuming to correctly know the number of analog and digital variables
uint16_t analog_value_mean[8];
uint8_t analog_variable_index = 0;
for(uint8_t variable_index = enum_variable_number_t_min; variable_index <= enum_variable_number_t_max; variable_index++) {
if(variable_is_analog_by_enum(variable_index)) {
analog_variable_t* p_variable = analog_variable_get_pointer_by_enum(variable_index);
INTERRUPT_GlobalInterruptDisable();
// the mean value is obtained as a sum, properly shifted to the right factor
analog_value_mean[analog_variable_index] = (uint16_t)((p_variable->sum_last >> adcreader_averaging_prescaler) & 0x0000ffff);
INTERRUPT_GlobalInterruptEnable();
analog_variable_index++;
}
}
// analog variables means
for(uint8_t analog_variable_index_tmp = 0; analog_variable_index_tmp < analog_variable_index; analog_variable_index_tmp++) {
communication_response_payload_append_uint16_t((uint16_t)analog_value_mean[analog_variable_index_tmp]);
}
return NOERR;
}
// Auto-generated template file: command_SENSOR_AVERAGE_GETALL.tpl.c
// Generation timestamp: 2019-11-15 15:26:27.506025
#include "../typedefs.h"
#include "../communication.h"
#include "../hardware.h"
err_t command_SENSOR_AVERAGE_GETALL(void) {
// Command: SENSOR_AVERAGE_GETALL
// Description: Get all sensors' mean values
//
// Request code: CMDCODE_SENSOR_AVERAGE_GETALL_REQ
// Response code: CMDCODE_SENSOR_AVERAGE_GETALL_REQ
// Request payload (length in bytes is 0):
// Response payload (length in bytes is 20):
// field #0 (2 bytes) [type: uint16_t ] : MON_5V_I_MEAN (Variable MON_5V_I mean)
// field #1 (2 bytes) [type: uint16_t ] : MON_LBL_I_MEAN (Variable MON_LBL_I mean)
// field #2 (2 bytes) [type: uint16_t ] : MON_DU_I_MEAN (Variable MON_DU_I mean)
// field #3 (2 bytes) [type: uint16_t ] : MON_DU_IRTN_MEAN (Variable MON_DU_IRTN mean)
// field #4 (2 bytes) [type: uint16_t ] : MON_BPS_V_MEAN (Variable MON_BPS_V mean)
// field #5 (2 bytes) [type: uint16_t ] : MON_HYDRO_I_MEAN (Variable MON_HYDRO_I mean)
// field #6 (2 bytes) [type: uint16_t ] : MON_THEATSINK_MEAN (Variable MON_THEATSINK mean)
// field #7 (2 bytes) [type: uint16_t ] : MON_TBOARD_MEAN (Variable MON_TBOARD mean)
// field #8 (1 byte) [type: enum_mon_alrmpos1_state_t] : MON_ALRMPOS1_STATE (MON_ALRMPOS1 status)
// field #9 (1 byte) [type: enum_mon_alrmpos2_state_t] : MON_ALRMPOS2_STATE (MON_ALRMPOS2 status)
// field #10 (1 byte) [type: enum_mon_alrmneg1_state_t] : MON_ALRMNEG1_STATE (MON_ALRMNEG1 status)
// field #11 (1 byte) [type: enum_mon_alrmneg2_state_t] : MON_ALRMNEG2_STATE (MON_ALRMNEG2 status)
// Auto-generated section: request payload fields reading
// End of auto-generated section
// USER CODE HERE
// TODO implement command callback function command_SENSOR_AVERAGE_GETALL
// TODO: assign response field MON_5V_I_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_5v_i_mean = -1;
// TODO: assign response field MON_LBL_I_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_lbl_i_mean = -1;
// TODO: assign response field MON_DU_I_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_du_i_mean = -1;
// TODO: assign response field MON_DU_IRTN_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_du_irtn_mean = -1;
// TODO: assign response field MON_BPS_V_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_bps_v_mean = -1;
// TODO: assign response field MON_HYDRO_I_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_hydro_i_mean = -1;
// TODO: assign response field MON_THEATSINK_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_theatsink_mean = -1;
// TODO: assign response field MON_TBOARD_MEAN in command SENSOR_AVERAGE_GETALL callback
uint16_t resp_mon_tboard_mean = -1;
// TODO: assign response field MON_ALRMPOS1_STATE in command SENSOR_AVERAGE_GETALL callback
enum_mon_alrmpos1_state_t resp_mon_alrmpos1_state = -1;
// TODO: assign response field MON_ALRMPOS2_STATE in command SENSOR_AVERAGE_GETALL callback
enum_mon_alrmpos2_state_t resp_mon_alrmpos2_state = -1;
// TODO: assign response field MON_ALRMNEG1_STATE in command SENSOR_AVERAGE_GETALL callback
enum_mon_alrmneg1_state_t resp_mon_alrmneg1_state = -1;
// TODO: assign response field MON_ALRMNEG2_STATE in command SENSOR_AVERAGE_GETALL callback
enum_mon_alrmneg2_state_t resp_mon_alrmneg2_state = -1;
// Auto-generated section: response payload fields writing
communication_response_payload_appender_reset();
communication_response_payload_append_uint16_t((uint16_t)resp_mon_5v_i_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_lbl_i_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_du_i_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_du_irtn_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_bps_v_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_hydro_i_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_theatsink_mean);
communication_response_payload_append_uint16_t((uint16_t)resp_mon_tboard_mean);
communication_response_payload_append_uint8_t((uint8_t)resp_mon_alrmpos1_state);
communication_response_payload_append_uint8_t((uint8_t)resp_mon_alrmpos2_state);
communication_response_payload_append_uint8_t((uint8_t)resp_mon_alrmneg1_state);
communication_response_payload_append_uint8_t((uint8_t)resp_mon_alrmneg2_state);
return NOERR;
// End of auto-generated section
}
/*
* File: see template info
* Author: Carlo Alessandro Nicolau @ INFN
*
* Created on: see template info
*
* Firmware for BPSV03-R1 board.
*
*/
// Auto-generated template file: command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c
// Generation timestamp: 2019-11-15 15:26:27.506025
// Generation timestamp: 2019-11-16 17:43:28.678814
#include "../typedefs.h"
#include "../communication.h"
#include "../hardware.h"
#include "../adcreader.h"
err_t command_SENSOR_AVERAGING_PRESCALER_GET(void) {
// Command: SENSOR_AVERAGING_PRESCALER_GET
......@@ -20,10 +31,10 @@ err_t command_SENSOR_AVERAGING_PRESCALER_GET(void) {
// End of auto-generated section
// USER CODE HERE
// TODO implement command callback function command_SENSOR_AVERAGING_PRESCALER_GET
// TODO: assign response field AVERAGINGPRESCALER in command SENSOR_AVERAGING_PRESCALER_GET callback
enum_averagingprescaler_t resp_averagingprescaler = -1;
enum_averagingprescaler_t resp_averagingprescaler;
INTERRUPT_GlobalInterruptDisable();
resp_averagingprescaler = adcreader_averaging_prescaler;
INTERRUPT_GlobalInterruptEnable();
// Auto-generated section: response payload fields writing
communication_response_payload_appender_reset();
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment