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

Under Development

parent 0e2408fb
No related branches found
No related tags found
No related merge requests found
Showing
with 869 additions and 115 deletions
#!/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
#!/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
#!/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)
#!/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])
This diff is collapsed.
......@@ -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);
......
......@@ -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();
......
......@@ -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();
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
......@@ -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++) {
......
......@@ -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;
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
// 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"
......
// 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
// 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
......
// 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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment