Skip to content

Commit

Permalink
Reorg nfc (#56)
Browse files Browse the repository at this point in the history
* - wrote release notes

* release 0.3.1

* - organised results and hw based tests
  • Loading branch information
franzhaas authored Dec 18, 2024
1 parent 6a33cdc commit 2f32761
Show file tree
Hide file tree
Showing 10 changed files with 2,234 additions and 572 deletions.
10 changes: 5 additions & 5 deletions atests/hw_dependant_results/nfc/log.html

Large diffs are not rendered by default.

698 changes: 239 additions & 459 deletions atests/hw_dependant_results/nfc/output.xml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions atests/hw_dependant_results/nfc/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -1887,22 +1887,22 @@
window.output = {};
</script>
<script type="text/javascript">
window.output["suite"] = [1,2,3,0,[],[1,0,1479],[[4,5,6,7,[],[1,38,1439],[],[[8,0,9,[10],[1,150,317],[]],[11,0,12,[10],[1,468,300],[]],[13,0,14,[10],[1,769,707],[]]],[],[3,3,0,0]]],[],[],[3,3,0,0]];
window.output["suite"] = [1,2,3,0,[],[1,0,1440],[[4,5,6,7,[],[1,39,1398],[],[[8,0,9,[10],[1,114,306],[]],[11,0,12,[10],[1,421,301],[]],[13,0,14,[10],[1,723,712],[]]],[],[3,3,0,0]]],[],[],[3,3,0,0]];
</script>
<script type="text/javascript">
window.output["strings"] = [];
</script>
<script type="text/javascript">
window.output["strings"] = window.output["strings"].concat(["*","*Nfc Nci","*/home/franz/projects/robotframework-construct/atests/nfc_nci","*../nfc_nci","*Nfc Basic","*/home/franz/projects/robotframework-construct/atests/nfc_nci/nfc_basic.robot","*../nfc_nci/nfc_basic.robot","*<p>This is a simple example for a robot file using robotframework-construct using nfc/nci as an example using UART.\x3c/p>","*Reset NFC Reseting RF configuration","*<p>This test case resets the NFC options using NCI over UART reseting the RF configuration.\x3c/p>","*hardware","*Reset NFC keeping RF configuration","*<p>This test case resets the NFC options using NCI over UART keeping the RF configuration.\x3c/p>","*Actively poll for A cards","*<p>This test case resets the NFC options using NCI over UART.\x3c/p>"]);
window.output["strings"] = window.output["strings"].concat(["*","*Nfc","*/home/franz/projects/robotframework-construct/atests/nfc","*../../nfc","*Nfc Basic","*/home/franz/projects/robotframework-construct/atests/nfc/nfc_basic.robot","*../../nfc/nfc_basic.robot","*<p>This is a simple example for a robot file using robotframework-construct using nfc/nfc as an example using UART.\x3c/p>","*Reset NFC Reseting RF configuration","*<p>This test case resets the NFC options using nfc over UART reseting the RF configuration.\x3c/p>","*hardware","*Reset NFC keeping RF configuration","*<p>This test case resets the NFC options using nfc over UART keeping the RF configuration.\x3c/p>","*Actively poll for A cards","*<p>This test case resets the NFC options using nfc over UART.\x3c/p>"]);
</script>
<script type="text/javascript">
window.output["stats"] = [[{"elapsed":"00:00:01","fail":0,"label":"All Tests","pass":3,"skip":0}],[{"elapsed":"00:00:01","fail":0,"label":"hardware","pass":3,"skip":0}],[{"elapsed":"00:00:01","fail":0,"id":"s1","label":"Nfc Nci","name":"Nfc Nci","pass":3,"skip":0},{"elapsed":"00:00:01","fail":0,"id":"s1-s1","label":"Nfc Nci.Nfc Basic","name":"Nfc Basic","pass":3,"skip":0}]];
window.output["stats"] = [[{"elapsed":"00:00:01","fail":0,"label":"All Tests","pass":3,"skip":0}],[{"elapsed":"00:00:01","fail":0,"label":"hardware","pass":3,"skip":0}],[{"elapsed":"00:00:01","fail":0,"id":"s1","label":"Nfc","name":"Nfc","pass":3,"skip":0},{"elapsed":"00:00:01","fail":0,"id":"s1-s1","label":"Nfc.Nfc Basic","name":"Nfc Basic","pass":3,"skip":0}]];
</script>
<script type="text/javascript">
window.output["baseMillis"] = 1733824849000;
window.output["baseMillis"] = 1734518326106;
</script>
<script type="text/javascript">
window.output["generated"] = 1513;
window.output["generated"] = 1470;
</script>
<script type="text/javascript">
window.output["expand_keywords"] = null;
Expand Down
36 changes: 18 additions & 18 deletions atests/nfc_nci/nci.py → atests/nfc/nfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
NFCEE=2,
Proprietary=0xF)

OID_NCI_Core = Enum(BitsInteger(6),
OID_NFC_Core = Enum(BitsInteger(6),
CORE_RESET=0,
CORE_INIT=1,
CORE_SET_CONFIG=2,
Expand Down Expand Up @@ -129,11 +129,11 @@
RFU_255=255 # RFU (Value 255)
) # Table 53

CONFIGURATION_STATUS = Enum(Byte,NCI_RF_CONFIGURATION_KEPT=0,
NCI_RF_CONFIGURATION_RESET=1) # Table 7
CONFIGURATION_STATUS = Enum(Byte,NFC_RF_CONFIGURATION_KEPT=0,
NFC_RF_CONFIGURATION_RESET=1) # Table 7

NCI_VERSION = Enum(Byte, NCI_VERSION_1_0=0x10,
NCI_VERSION_2_0=0x20) # Table 6
NFC_VERSION = Enum(Byte, NFC_VERSION_1_0=0x10,
NFC_VERSION_2_0=0x20) # Table 6

CORE_RESET_NTF_STATUS_REASON_CODE = Enum(Byte, UNSPECIFIED=0x00,
CORE_RESET_TRIGGERED=0x01)
Expand Down Expand Up @@ -232,15 +232,15 @@
"Manufacturer_specific_info" / Bytes(4))

CORE_RESET_RSP = Struct("Status" / If(this._.payload_length>=1, CORE_RESET_RSP_STATUS),
"NCI_Version" / If(this._.payload_length>=2, NCI_VERSION),
"NFC_Version" / If(this._.payload_length>=2, NFC_VERSION),
"ConfigurationStatus" / If(this._.payload_length>=3, CONFIGURATION_STATUS),
"padding" / If(this._.payload_length> 3, Bytes(this._.payload_length-3)))

CORE_RESET_NTF = Struct("Reason" / CORE_RESET_NTF_STATUS_REASON_CODE,
"ConfigurationStatus" / CONFIGURATION_STATUS,
"padding" / If(this._.payload_length> 2, Bytes(this._.payload_length-2)))

NCI_DATA_PACKET = Struct(
NFC_DATA_PACKET = Struct(
"header" / BitStruct(
"MT" / MT,
"PBF" / PBF,
Expand All @@ -254,30 +254,30 @@

CORE_RESET_CMD_PAYLOAD = Struct("ResetType" / CORE_RESET_CMD)

NCI_CONTROL_PACKET = Struct(
NFC_CONTROL_PACKET = Struct(
"header" / BitStruct("MT" / MT,
"PBF" / PBF,
"GID" / GID,
"RFU" / BitsInteger(2),
"OID" / Switch(this.GID, {GID.CORE: OID_NCI_Core, GID.RF: OID_RF_Management, GID.NFCEE: OID_NFCEE_Management})),
"OID" / Switch(this.GID, {GID.CORE: OID_NFC_Core, GID.RF: OID_RF_Management, GID.NFCEE: OID_NFCEE_Management})),
"payload_length" / Int8ub,
"payload" / Switch((this.header.MT, this.header.GID, this.header.OID,), {(MT.ControlPacketCommand, GID.CORE, OID_NCI_Core.CORE_RESET,): CORE_RESET_CMD_PAYLOAD,
(MT.ControlPacketResponse, GID.CORE, OID_NCI_Core.CORE_RESET,): CORE_RESET_RSP,
(MT.ControlPacketNotification, GID.CORE, OID_NCI_Core.CORE_RESET,): CORE_RESET_NTF,
(MT.ControlPacketCommand, GID.CORE, OID_NCI_Core.CORE_INIT,): CORE_INIT_CMD_PAYLOAD,
(MT.ControlPacketResponse, GID.CORE, OID_NCI_Core.CORE_INIT,): CORE_INIT_RSP_PAYLOAD,
"payload" / Switch((this.header.MT, this.header.GID, this.header.OID,), {(MT.ControlPacketCommand, GID.CORE, OID_NFC_Core.CORE_RESET,): CORE_RESET_CMD_PAYLOAD,
(MT.ControlPacketResponse, GID.CORE, OID_NFC_Core.CORE_RESET,): CORE_RESET_RSP,
(MT.ControlPacketNotification, GID.CORE, OID_NFC_Core.CORE_RESET,): CORE_RESET_NTF,
(MT.ControlPacketCommand, GID.CORE, OID_NFC_Core.CORE_INIT,): CORE_INIT_CMD_PAYLOAD,
(MT.ControlPacketResponse, GID.CORE, OID_NFC_Core.CORE_INIT,): CORE_INIT_RSP_PAYLOAD,
(MT.ControlPacketCommand, GID.RF, OID_RF_Management.RF_DISCOVER,): RF_DISCOVER_CMD_PAYLOAD,
(MT.ControlPacketResponse, GID.RF, OID_RF_Management.RF_DISCOVER,): RF_DISCOVER_RSP_PAYLOAD,
(MT.ControlPacketNotification, GID.RF, OID_RF_Management.RF_DISCOVER,): RF_DISCOVER_NTF_PAYLOAD,
})).compile()
NCI_CONTROL_PACKET.name = "NCI_CONTROL_PACKET"
NFC_CONTROL_PACKET.name = "NFC_CONTROL_PACKET"


NFC_RST_CMD= {"header": {"MT": MT.ControlPacketCommand,
"PBF": 0,
"GID": GID.CORE,
"RFU": 0,
"OID": OID_NCI_Core.CORE_RESET},
"OID": OID_NFC_Core.CORE_RESET},
"payload_length": 1,
"payload": {"ResetType": CORE_RESET_CMD.RESET_CONFIGURATION},
"padding": b""}
Expand All @@ -286,14 +286,14 @@
"PBF": 0,
"GID": GID.CORE,
"RFU": 0,
"OID": OID_NCI_Core.CORE_INIT},
"OID": OID_NFC_Core.CORE_INIT},
"payload_length": 2,
"payload": {"ConstValue": b"\x00\x00"},
"padding": b""}



NCI_DISCVER_CMD = {"header": {"MT": MT.ControlPacketCommand,
NFC_DISCVER_CMD = {"header": {"MT": MT.ControlPacketCommand,
"PBF": 0,
"GID": GID.RF,
"RFU": 0,
Expand Down
70 changes: 70 additions & 0 deletions atests/nfc/nfc_basic.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
*** Settings ***
Documentation This is a simple example for a robot file using robotframework-construct using nfc/nfc as an example using UART.
Variables nfc.py
Library nfc_interface
Library robotframework_construct
Test Teardown Close nfc Connection
Default Tags hardware
*** Variables ***
${NFC_INTERFACE} /dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_066EFF3031454D3043225321-if02
${BAUD_RATE} 115200

*** Test Cases ***
Reset NFC Reseting RF configuration
[Documentation] This test case resets the NFC options using nfc over UART reseting the RF configuration.
${NFC_INTERFACE}= Open nfc Connection Via UART ${NFC_INTERFACE} ${BAUD_RATE}
Sleep 0.25
Empty nfc Connection Receive Buffer
Modify the element located at 'payload.ResetType' of '${NFC_RST_CMD}' to '${CORE_RESET_CMD.RESET_CONFIGURATION}'
Write Binary Data Generated From '${NFC_RST_CMD}' Using Construct '${nfcControlPacket}' To '${NFC_INTERFACE}'
Expect Response from ${NFC_INTERFACE} of type ${MT.ControlPacketResponse}
${RESET_NOTIFICATION}= Expect Response from ${NFC_INTERFACE} of type ${MT.ControlPacketNotification}
Element 'payload.ConfigurationStatus' in '${RESET_NOTIFICATION}' should be equal to '${CONFIGURATION_STATUS.NFC_RF_CONFIGURATION_RESET}'
NFC Connection Receive Buffer Should Be Empty

Reset NFC keeping RF configuration
[Documentation] This test case resets the NFC options using nfc over UART keeping the RF configuration.
${NFC_INTERFACE} = Open nfc Connection Via UART ${NFC_INTERFACE} ${BAUD_RATE}
Sleep 0.25
Empty NFC Connection Receive Buffer
Modify the element located at 'payload.ResetType' of '${NFC_RST_CMD}' to '${CORE_RESET_CMD.KEEP_CONFIGURATION}'
Write Binary Data Generated From '${NFC_RST_CMD}' Using Construct '${nfcControlPacket}' To '${NFC_INTERFACE}'
Expect Response from ${NFC_INTERFACE} of type ${MT.ControlPacketResponse}
${RESET_NOTIFICATION}= Expect Response from ${NFC_INTERFACE} of type ${MT.ControlPacketNotification}
Element 'payload.ConfigurationStatus' in '${RESET_NOTIFICATION}' should be equal to '${CONFIGURATION_STATUS.NFC_RF_CONFIGURATION_KEPT}'
NFC Connection Receive Buffer Should Be Empty

Actively poll for A cards
[Documentation] This test case resets the NFC options using nfc over UART.
${NFC_INTERFACE}= Open NFC Connection Via UART ${NFC_INTERFACE} ${BAUD_RATE}
Sleep 0.25
Empty NFC Connection Receive Buffer
Write Binary Data Generated From '${NFC_RST_CMD}' Using Construct '${nfcControlPacket}' To '${NFC_INTERFACE}'
Expect Response from ${NFC_INTERFACE} of type ${MT.ControlPacketResponse}
Expect Response from ${NFC_INTERFACE} of type ${MT.ControlPacketNotification}
Write Binary Data Generated From '${NFC_INIT_CMD}' Using Construct '${nfcControlPacket}' To '${NFC_INTERFACE}'
Expect Status OK response from ${NFC_INTERFACE}
Write Binary Data Generated From '${NFC_DISCVER_CMD}' Using Construct '${NFCControlPacket}' To '${NFC_INTERFACE}'
Expect Status OK response from ${NFC_INTERFACE}
Log to console please place a card on the reader
Wait For Data From NFC timeout=1
${RESPONSE}= Parse '${NFC_INTERFACE}' Using Construct '${NFCControlPacket}'
Wait For Data From NFC timeout=1
${RESPONSE}= Parse '${NFC_INTERFACE}' Using Construct '${nfcControlPacket}'

*** Keywords ***
Receive message from nfc from ${nfc_INTERFACE}
Wait For Data From nfc
${RESPONSE}= Parse '${nfc_INTERFACE}' Using Construct '${nfcControlPacket}'
RETURN ${RESPONSE}

Expect Status OK response from ${nfc_INTERFACE}
${RESPONSE}= Receive message from nfc from ${nfc_INTERFACE}
Element 'payload.Status' in '${RESPONSE}' should be equal to '${GENERIC_STATUS_CODE.STATUS_OK}'
RETURN ${RESPONSE}

Expect Response from ${nfc_INTERFACE} of type ${EXPECTED_MT}
${RESPONSE}= Receive message from nfc from ${nfc_INTERFACE}
Element 'header.MT' in '${RESPONSE}' should be equal to '${EXPECTED_MT}'
RETURN ${RESPONSE}

26 changes: 13 additions & 13 deletions atests/nfc_nci/nci_interface.py → atests/nfc/nfc_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import time


class nci_interface():
class nfc_interface():
def __init__(self):
self._serial_connection = None

def open_nci_connection_via_uart(self, device: str, baudrate: int, timeout=1.0):
def open_nfc_connection_via_uart(self, device: str, baudrate: int, timeout=1.0):
"""
Opens a connection to a NCI device via UART.
Opens a connection to a NFC device via UART.
Returns a tuple of two file objects, first one for reading and second one for writing.
"""
Expand All @@ -26,11 +26,11 @@ def read(self, size=1):
return self._serial_connection # Alternatively, on linux we can use self._serial_connection.fileno() + select instead of the timeout read...


def wait_for_data_from_nci(self, timeout: float = 1.0):
def wait_for_data_from_nfc(self, timeout: float = 1.0):
"""
Waits for data from the NCI device.
Waits for data from the NFC device.
Raises an exception if the NCI connection is not open.
Raises an exception if the NFC connection is not open.
"""
if self._serial_connection and self._serial_connection.is_open:
try:
Expand All @@ -40,26 +40,26 @@ def wait_for_data_from_nci(self, timeout: float = 1.0):
endTime = time.time() + timeout
while time.time() < endTime and not self._serial_connection.in_waiting:
time.sleep(0.001)
assert self._serial_connection.in_waiting, "Timeout while waiting for data from NCI device"
assert self._serial_connection.in_waiting, "Timeout while waiting for data from NFC device"
else:
raise Exception("NCI connection is not open")
raise Exception("NFC connection is not open")

def close_nci_connection(self):
def close_nfc_connection(self):
"""
Closes the NCI connection by closing the serial connection.
Closes the NFC connection by closing the serial connection.
"""
if self._serial_connection and self._serial_connection.is_open:
self._serial_connection.close()
else:
raise Exception("NCI connection is not open")
raise Exception("NFC connection is not open")

def nci_connection_receive_buffer_should_be_empty(self):
def nfc_connection_receive_buffer_should_be_empty(self):
"""
Verifies that the receive buffer is empty.
"""
assert 0 == self._serial_connection.in_waiting

def empty_nci_connection_receive_buffer(self):
def empty_nfc_connection_receive_buffer(self):
"""
Empties the receive buffer.
Expand Down
Loading

0 comments on commit 2f32761

Please sign in to comment.