Skip to content

Commit

Permalink
Updated dbesm sim in case of no temp sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
mfioren committed Feb 7, 2024
1 parent 9f1b40b commit e9dedd4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
47 changes: 29 additions & 18 deletions simulators/dbesm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class System(ListeningSystem):
def __init__(self):
self.msg = ''

# Status -1 -> board not available
# Status = 1 -> board not available
# Status > 1 -> temp sensor not present (timeout)
self.boards = [
{
'Address': '3',
Expand Down Expand Up @@ -192,7 +193,7 @@ def _set_allmode(self, params):
elif params[1] not in self.obs_mode:
return self._error(params[0], 1003)
for key in self.boards:
if key['Status'] != 0:
if key['Status'] == 1:
retval += f'BOARD {key["Address"]} ERR DBE BOARD unreachable\n'
else:
key["Configuration"] = params[1]
Expand All @@ -212,7 +213,7 @@ def _set_mode(self, params):
return self._error(params[0], 1007, params[2])
elif params[3] not in self.obs_mode:
return self._error(params[0], 1003)
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[2])
else:
selected_board["Configuration"] = params[3]
Expand All @@ -225,7 +226,7 @@ def _store_allmode(self, params):
elif params[1] in self.obs_mode:
return self._error(params[0], 1008)
for key in self.boards:
if key['Status'] != 0:
if key['Status'] == 1:
err.append(key['Address'])
if len(err) > 0:
if len(err) == 1:
Expand Down Expand Up @@ -256,7 +257,7 @@ def _get_status(self, params):

if selected_board is None:
return self._error(params[0], 1007, params[2])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[2])
retval = self.ack + '\n'
retval += f'BOARD {selected_board["Address"]}\n\n'
Expand All @@ -276,7 +277,7 @@ def _set_att(self, params):
return self._error(params[0], 1010, params[1])
elif float(params[5]) not in list(numpy.arange(0, 32, 0.5)):
return self._error(params[0], 1011, selected_board["Address"])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[3])
else:
selected_board["ATT"][int(params[1])] = float(params[5])
Expand All @@ -296,7 +297,7 @@ def _set_amp(self, params):
return self._error(params[0], 1012, params[1])
elif float(params[5]) not in [0, 1]:
return self._error(params[0], 1011, selected_board["Address"])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[3])
else:
selected_board["AMP"][int(params[1]) - 1] = params[5]
Expand All @@ -316,7 +317,7 @@ def _set_eq(self, params):
return self._error(params[0], 1013, params[1])
elif float(params[5]) not in [0, 1]:
return self._error(params[0], 1011, selected_board["Address"])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[3])
else:
selected_board["EQ"][int(params[1]) - 1] = params[5]
Expand Down Expand Up @@ -349,7 +350,7 @@ def _set_bpf(self, params):
return self._error(params[0], 1014, params[1])
elif float(params[5]) not in [0, 1]:
return self._error(params[0], 1011, selected_board["Address"])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[3])
else:
channel = -1
Expand All @@ -371,12 +372,16 @@ def _all_diag(self, params):
else:
for board in self.boards:
retval += f'BOARD {board["Address"]} '
if board['Status'] == 0:
if board["Status"] == 0:
retval += self.ack + '\n'
retval += f'5V {board["5V"]} 3V3 {board["3V3"]}\n'
retval += f'T0 {board["T0"]}\n\n'
else:
elif int(board["Status"]) == 1:
retval += 'ERR DBE BOARD unreachable\n\n'
elif int(board["Status"]) > 1:
retval += self.ack + '\n'
retval += f'5V {board["5V"]} 3V3 {board["3V3"]}\n'
retval += 'temp sensor not present\n\n'
return retval[:-2] + '\x0D\x0A'

def _diag(self, params):
Expand All @@ -390,14 +395,20 @@ def _diag(self, params):

if selected_board is None:
return self._error(params[0], 1007, params[2])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[2])
else:
elif selected_board['Status'] == 0:
retval = self.ack + '\n'
retval += f'BOARD {selected_board["Address"]}\n\n'
retval += f'5V {selected_board["5V"]}'
retval += f' 3V3 {selected_board["3V3"]}\n'
retval += f'T0 {selected_board["T0"]}'
elif selected_board['Status'] > 1:
retval = self.ack + '\n'
retval += f'BOARD {selected_board["Address"]}\n\n'
retval += f'5V {selected_board["5V"]}'
retval += f' 3V3 {selected_board["3V3"]}\n'
retval += 'temp sensor not present'
return retval + '\x0D\x0A'

def _set_status(self, params):
Expand Down Expand Up @@ -426,7 +437,7 @@ def _get_comp(self, params):

if selected_board is None:
return self._error(params[0], 1007, params[2])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[2])
else:
retval = 'ACK\n'
Expand All @@ -444,7 +455,7 @@ def _get_cfg(self, params):
retval += self.ack + '\n'
for board in self.boards:
retval += f'BOARD {board["Address"]} '
if board['Status'] == 0:
if ((board['Status'] == 0) or (board['Status'] > 1)):
retval += f'{board["Configuration"]}\n\n'
else:
retval += 'ERR DBE BOARD unreachable\n\n'
Expand Down Expand Up @@ -483,7 +494,7 @@ def _set_dbeatt(self, params):
list(numpy.arange(0, 32, 0.5))):
retval += (f'ERR DBE {params[1]} BOARD '
f'{board["Address"]} value out of range\n')
elif ((board["Status"] != 0) or (board["Address"] not in brd)):
elif ((board["Status"] == 1) or (board["Address"] not in brd)):
retval += (f'ERR DBE {params[1]} BOARD '
f'{board["Address"]} unreachable\n')
else:
Expand Down Expand Up @@ -518,7 +529,7 @@ def _get_dbeatt(self, params):
# print(board["ATT"])
# print(board["ATT"][a[out_idx[b_idx]]])

if ((board["Status"] != 0) or (board["Address"] not in brd)):
if ((board["Status"] == 1) or (board["Address"] not in brd)):
retval += (f'ERR DBE {params[1]} BOARD '
f'{board["Address"]} unreachable\n')
else:
Expand All @@ -538,7 +549,7 @@ def _get_firm(self, params):

if selected_board is None:
return self._error(params[0], 1007, params[2])
elif selected_board["Status"] != 0:
elif selected_board["Status"] == 1:
return self._error(params[0], 1005, params[2])
else:
retval = self.ack + '\n'
Expand Down
25 changes: 25 additions & 0 deletions tests/test_dbesm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def _disable_board(self, err_board=3):
disable_msg = f'DBE SETSTATUS BOARD {err_board} VALUE 1\x0D\x0A'
self._send(disable_msg)

def _noTemp_board(self, err_board=3):
noTemp_msg = f'DBE SETSTATUS BOARD {err_board} VALUE 2\x0D\x0A'
self._send(noTemp_msg)

def _test_all_boards(self, response, err_board=999, diag=False):
for board in range(0, 4):
if diag:
Expand Down Expand Up @@ -151,6 +155,19 @@ def test_all_diag_boardErr(self, err_board=3):
print(response)
self._test_all_boards(response, err_board, True)

def test_all_diag_noTemp(self, err_board=3):
message = "DBE ReadALLDIAG\x0D\x0A"
self._noTemp_board(err_board)
response = self._send(message)
print(response)
for board in range(0, 4):
if board != err_board:
self.assertRegex(response, f'BOARD {board} ACK\n5V '
'[0-9][.][0-9]+ 3V3 [0-9][.][0-9]+\nT0 [0-9]+[.][0-9]+')
else:
self.assertRegex(response, f'BOARD {board} ACK\n5V '
'[0-9][.][0-9]+ 3V3 [0-9][.][0-9]+\ntemp sensor not present')

def test_nak_alldiag(self):
message = "DBE ReadALLDIAG ?????\x0D\x0A"
response = self._send(message)
Expand Down Expand Up @@ -360,6 +377,14 @@ def test_diag_noBoard(self, board=999):
self.assertEqual(response, f'ERR DBE BOARD {board} '
'not existing\x0D\x0A')

def test_diag_noTemp(self, board=0):
message = f"DBE ReadDIAG BOARD {board}\x0D\x0A"
self._noTemp_board(board)
response = self._send(message)
print(response)
self.assertRegex(response, f'ACK\nBOARD {board}\n\n5V [0-9][.][0-9]+ '
'3V3 [0-9][.][0-9]+\ntemp sensor not present\r\n')

def test_nak_diag_missing(self):
message = "DBE ReadDIAG BOARD\x0D\x0A"
response = self._send(message)
Expand Down

0 comments on commit e9dedd4

Please sign in to comment.