Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHIM-336 Architecture for in-firmware factory testing #26

Merged
merged 13 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions LogAndStream/.cproject

Large diffs are not rendered by default.

840 changes: 95 additions & 745 deletions LogAndStream/main.c

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions LogAndStream/python_scripts/Bluetooth commands/test_bt_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from Shimmer_common import shimmer_comms_bluetooth, util_shimmer_time, util_shimmer
from Shimmer_common import shimmer_device, shimmer_app_common

from colorama import Fore


def does_response_include_length_byte(get_cmd):
return (get_cmd == shimmer_comms_bluetooth.BtCmds.GET_DAUGHTER_CARD_ID_COMMAND
Expand Down Expand Up @@ -1110,12 +1112,24 @@ def test_95_get_Pressure_Calibration_coefficients(self):
else:
print("Skipping test, command not supported in firmware")

def test_99_reset_config_and_calib_after_testing(self):
def test_96_factory_test_bluetooth(self):
print(Fore.LIGHTMAGENTA_EX + "Factory Test Start")
tx_bytes = 0
self.shimmer.bluetooth_port.send_bluetooth([shimmer_comms_bluetooth.BtCmds.SET_FACTORY_TEST, tx_bytes])
self.shimmer.bluetooth_port.wait_for_ack(2000)
end = "//***************************** TEST END *************************************//\r\n"
while True:
response = self.shimmer.bluetooth_port.ser.readline().decode('utf-8')
print(response, end='')
if response == end:
print(Fore.LIGHTMAGENTA_EX + "Factory Test End")
break

def test_97_reset_config_and_calib_after_testing(self):
print("\r\nResetting Shimmer's config and calibration\r\n")
self.test_02_reset_default_config(True)
self.test_03_reset_default_calib(True)



if __name__ == '__main__':
unittest.main()
15 changes: 15 additions & 0 deletions LogAndStream/python_scripts/Docked commands/test_docked_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from Shimmer_common import util_shimmer, util_shimmer_time, shimmer_device, shimmer_app_common

from colorama import Fore


class TestShimmerDockCommunication(unittest.TestCase):
shimmer = None
Expand Down Expand Up @@ -236,6 +238,19 @@ def test_11_read_write_infomem(self):
# self.assertTrue(False)
# print("")

def test_12_factory_test_dock(self):
print(Fore.LIGHTMAGENTA_EX + "Factory Test Start")
tx_bytes = [0x24, 0x01, 0x02, 0x0B, 0x00, 0xDB, 0x0A]
self.shimmer.dock_port.send_uart(tx_bytes)
end = "//***************************** TEST END *************************************//\r\n"
while True:
# response = data.decode('utf-8')
response = self.shimmer.dock_port.ser.readline().decode('utf-8')
print(response, end='')
if response == end:
print(Fore.LIGHTMAGENTA_EX + "Factory Test End")
break


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class BtCmds:
SET_SD_SYNC_COMMAND = 0xE0
SD_SYNC_RESPONSE = 0xE1
ACK_COMMAND_PROCESSED = 0xFF

SET_FACTORY_TEST = 0xA8

class ShimmerBluetooth:
serial_port_timeout_ms = 500
Expand Down
83 changes: 49 additions & 34 deletions LogAndStream/python_scripts/Shimmer_common/shimmer_comms_docked.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import serial
from serial import SerialException
from enum import Enum

from Shimmer_common import shimmer_crc as shimmerCrc
from Shimmer_common import util_shimmer_time
Expand Down Expand Up @@ -60,6 +61,12 @@ class DaughterCard:
class Bluetooth:
VER = 0x03

class UART_RX_STAGES(Enum):
WAIT_FOR_CMD = 0
WAIT_FOR_LENGTH = 1
WAIT_FOR_CONTENTS = 2
WAIT_FOR_CRC = 3


def assemble_tx_packet(uart_cmd=None, uart_component=None, uart_property=None, uart_args=None):
if uart_args is None:
Expand Down Expand Up @@ -328,52 +335,60 @@ def set_mem_command(self, uart_component, uart_property, address, byte_buf):
def wait_for_response(self):
flag = True

loop_count = 0
wait_interval_ms = 100
loop_count_total = self.serial_port_timeout_ms / wait_interval_ms

rx_buf = []

stage = UART_RX_STAGES.WAIT_FOR_CMD
qty_to_wait_for = 2

while flag:
time.sleep(wait_interval_ms / 1000)
loop_count += 1
if loop_count >= loop_count_total:
if len(rx_buf) > 0:
print("UART RX (incomplete due to timeout): " + util_shimmer.byte_array_to_hex_string(rx_buf))
data_read = self.ser.read(qty_to_wait_for)
if isinstance(data_read, str):
rx_buf += bytearray.fromhex(binascii.hexlify(data_read))
else:
rx_buf += data_read

if len(data_read) != qty_to_wait_for:
print("UART RX (incomplete due to timeout): " + util_shimmer.byte_array_to_hex_string(rx_buf))
return False

buf_len = self.ser.inWaiting()
if buf_len > 0:
data_read = self.ser.read(buf_len)
if isinstance(data_read, str):
rx_buf += bytearray.fromhex(binascii.hexlify(data_read))
# Wait for header and CMD byte
if stage == UART_RX_STAGES.WAIT_FOR_CMD:
if rx_buf[0] == PACKET_HEADER:
if rx_buf[1] == UartPacketCmd.ACK_RESPONSE \
or rx_buf[1] == UartPacketCmd.BAD_CMD_RESPONSE \
or rx_buf[1] == UartPacketCmd.BAD_ARG_RESPONSE \
or rx_buf[1] == UartPacketCmd.BAD_CRC_RESPONSE:
qty_to_wait_for = 2
stage = UART_RX_STAGES.WAIT_FOR_CRC
else:
qty_to_wait_for = 1
stage = UART_RX_STAGES.WAIT_FOR_LENGTH
else:
rx_buf += data_read
qty_to_wait_for = 1
stage = UART_RX_STAGES.WAIT_FOR_CMD
elif stage == UART_RX_STAGES.WAIT_FOR_LENGTH:
qty_to_wait_for = rx_buf[2]
stage = UART_RX_STAGES.WAIT_FOR_CONTENTS

elif stage == UART_RX_STAGES.WAIT_FOR_CONTENTS:
qty_to_wait_for = 2
stage = UART_RX_STAGES.WAIT_FOR_CRC

elif stage == UART_RX_STAGES.WAIT_FOR_CRC:
if shimmerCrc.crc_check(len(rx_buf), rx_buf) is not True:
print("CRC fail")
else:
if self.debug_tx_rx_packets:
print("UART RX: " + util_shimmer.byte_array_to_hex_string(rx_buf))

if rx_buf[0] == PACKET_HEADER:
if rx_buf[1] == UartPacketCmd.ACK_RESPONSE \
or rx_buf[1] == UartPacketCmd.BAD_CMD_RESPONSE \
or rx_buf[1] == UartPacketCmd.BAD_ARG_RESPONSE \
or rx_buf[1] == UartPacketCmd.BAD_CRC_RESPONSE:
if self.debug_tx_rx_packets:
print("UART RX: " + util_shimmer.byte_array_to_hex_string(rx_buf))
rx_buf = rx_buf[1]
break

if buf_len > 3:
if len(rx_buf) == rx_buf[2] + 5:
if shimmerCrc.crc_check(len(rx_buf), rx_buf) is not True:
print("CRC fail")
else:
if self.debug_tx_rx_packets:
print("UART RX: " + util_shimmer.byte_array_to_hex_string(rx_buf))

rx_buf = rx_buf[5:len(rx_buf) - 2]
break
else:
# TODO
print("RX: Invalid Response")
return
else:
rx_buf = rx_buf[5:len(rx_buf) - 2]
break

return rx_buf

Expand Down
Loading