mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			code review from paul,don addressed:compilers fixed
							parent
							
								
									c509af32ce
								
							
						
					
					
						commit
						dea37cb97e
					
				| 
						 | 
				
			
			@ -1,6 +1,9 @@
 | 
			
		|||
{
 | 
			
		||||
    "config": {
 | 
			
		||||
        "TEST_NDEF_MSG_MAX" : 1024
 | 
			
		||||
        "TEST_NDEF_MSG_MAX": {
 | 
			
		||||
            "help": "NFC-Driver buffer (EEPROM and Controller) maximum MAX Size of NFC message(s) driver buffer",
 | 
			
		||||
            "value": 4096
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    "target_overrides": {
 | 
			
		||||
        "DISCO_L475VG_IOT01A": {
 | 
			
		||||
| 
						 | 
				
			
			@ -8,12 +11,18 @@
 | 
			
		|||
            "MBED_NFC_M24SR.nfceeprom": true
 | 
			
		||||
        },
 | 
			
		||||
        "NUCLEO_F401RE": {
 | 
			
		||||
            "target.extra_labels_add": ["PN512"]
 | 
			
		||||
            "target.extra_labels_add": ["PN512"],
 | 
			
		||||
	    "MBED_NFC_M24SR.nfceeprom": false
 | 
			
		||||
        },
 | 
			
		||||
        "NUCLEO_F746ZG": {
 | 
			
		||||
            "target.extra_labels_add": ["M24SR"],
 | 
			
		||||
	    "MBED_NFC_M24SR.X_NUCLEO_NFC01A1": true,
 | 
			
		||||
	    "MBED_NFC_M24SR.nfceeprom": true
 | 
			
		||||
        },
 | 
			
		||||
        "NUCLEO_F429ZI": {
 | 
			
		||||
            "target.extra_labels_add": ["M24SR"],
 | 
			
		||||
	    "MBED_NFC_M24SR.X_NUCLEO_NFC01A1": true,
 | 
			
		||||
	    "MBED_NFC_M24SR.nfceeprom": true
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#include <vector>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include "mbed_events.h"
 | 
			
		||||
#include "mbed-client-cli/ns_cmdline.h"
 | 
			
		||||
#include "rtos\Thread.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#include <stdarg.h>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "mbed_events.h"
 | 
			
		||||
#include "mbed-client-cli/ns_cmdline.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -98,6 +99,7 @@ void NFCProcessEEPROM::on_ndef_message_written(nfc_err_t result)
 | 
			
		|||
    }
 | 
			
		||||
    // complete the async test method here
 | 
			
		||||
    cmd_ready(CMDLINE_RETCODE_SUCCESS);
 | 
			
		||||
    free(long_string); // free buffer allocated by the command class now
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NFCProcessEEPROM::on_ndef_message_read(nfc_err_t result)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,12 +38,12 @@
 | 
			
		|||
class NFCProcessEEPROM : NFCTestShim, mbed::nfc::NFCEEPROM::Delegate {
 | 
			
		||||
public:
 | 
			
		||||
    NFCProcessEEPROM(events::EventQueue &queue, mbed::nfc::NFCEEPROMDriver &eeprom_driver);
 | 
			
		||||
    nfc_err_t init();
 | 
			
		||||
    virtual nfc_err_t init();
 | 
			
		||||
    void queue_write_call();
 | 
			
		||||
    void queue_write_long_call();
 | 
			
		||||
    void queue_read_call();
 | 
			
		||||
    void queue_erase_call();
 | 
			
		||||
    void cmd_get_max_ndef();
 | 
			
		||||
    virtual void cmd_get_max_ndef();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
#include <stdarg.h>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "mbed-client-cli/ns_cmdline.h"
 | 
			
		||||
#include "nfc/ndef/common/Text.h"
 | 
			
		||||
#include "nfc/ndef/common/URI.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +42,7 @@ using mbed::nfc::nfc_rf_protocols_bitmask_t;
 | 
			
		|||
 | 
			
		||||
// statics
 | 
			
		||||
namespace {
 | 
			
		||||
char long_string[MBED_CONF_APP_TEST_NDEF_MSG_MAX];
 | 
			
		||||
 | 
			
		||||
char const   *uri_prefix_string[] = { "",
 | 
			
		||||
                                      "http://www.",
 | 
			
		||||
                                      "https://www.",
 | 
			
		||||
| 
						 | 
				
			
			@ -278,15 +279,15 @@ void NFCTestShim::cmd_erase()
 | 
			
		|||
 | 
			
		||||
/** \brief Writes a Text T record buffer with really long message - length checks to be done by driver only.
 | 
			
		||||
  * If an NFC controller, no write to the chip happens, we copy the data into a Controller buffer
 | 
			
		||||
  * \param uri This method must free the passed in pointer
 | 
			
		||||
  * \return void An ICETEA error code and NFC error is set asyncronously
 | 
			
		||||
  * \param text_string This method must free the passed in pointer
 | 
			
		||||
  * \return void An ICETEA error code and NFC error is set asynchronously
 | 
			
		||||
  */
 | 
			
		||||
void NFCTestShim::cmd_write_long(char *text_string)
 | 
			
		||||
{
 | 
			
		||||
    MessageBuilder builder(_ndef_poster_message);
 | 
			
		||||
    strcpy(::long_string, text_string); //max_ndef - header - overheads
 | 
			
		||||
    long_string = text_string; // copy the pointer and free it when the write completes
 | 
			
		||||
    Text text(Text::UTF8, span_from_cstr("en-US"),
 | 
			
		||||
              span_from_cstr((const char *)(::long_string)));
 | 
			
		||||
              span_from_cstr((const char *)(long_string)));
 | 
			
		||||
 | 
			
		||||
    text.append_as_record(builder, true);
 | 
			
		||||
    _ndef_write_buffer_used = builder.get_message().size();
 | 
			
		||||
| 
						 | 
				
			
			@ -295,12 +296,12 @@ void NFCTestShim::cmd_write_long(char *text_string)
 | 
			
		|||
#if MBED_CONF_NFCEEPROM
 | 
			
		||||
    ((NFCProcessEEPROM *)this)->queue_write_call();
 | 
			
		||||
#else
 | 
			
		||||
    // not on a wire, so the caller will store the message in a buffer
 | 
			
		||||
    // not on a wire, and we just stored the message in _ndef_write_buffer above
 | 
			
		||||
    set_last_nfc_error(NFC_OK);
 | 
			
		||||
    cmd_ready(CMDLINE_RETCODE_SUCCESS);
 | 
			
		||||
    free(long_string); // free buffer allocated by the command class now
 | 
			
		||||
#endif
 | 
			
		||||
    trace_printf("NFCTestShim::write_long() exit\r\n");
 | 
			
		||||
    free(text_string);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** \brief Write a URI Use case would be to prompt to install an app from the appstore using the tag
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -100,6 +100,7 @@ protected:
 | 
			
		|||
    uint8_t _ndef_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX];       // driver I/O buffer
 | 
			
		||||
    bool _discovery_restart;            // default true, restart discovery loop again on remote disconnect
 | 
			
		||||
    events::EventQueue &_queue;
 | 
			
		||||
    char *long_string;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// forward declare single instance
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,6 +110,7 @@ class NfcTestParsers(PluginBase):
 | 
			
		|||
                if value is not False:
 | 
			
		||||
                    results['lastnfcerror'] = int(value)
 | 
			
		||||
                # {{nfcmessage=([0-9a-f\s]*)}}
 | 
			
		||||
                # message may be split over multiple lines, so we will start a search and wait until we get a }} pair
 | 
			
		||||
                data = PluginBase.find_one(line, "{{nfcmessage=([0-9a-f\s]*).*")
 | 
			
		||||
                if data is not False:
 | 
			
		||||
                    started_read_data = True
 | 
			
		||||
| 
						 | 
				
			
			@ -117,10 +118,9 @@ class NfcTestParsers(PluginBase):
 | 
			
		|||
                    values = self.find_all_hex_data(line, "([0-9a-f\s]*)")
 | 
			
		||||
                    if values is not False:
 | 
			
		||||
                        if "{{nfcmessage" in line:
 | 
			
		||||
                            value = values[0]
 | 
			
		||||
                            value = values[0] # first (and possibly only data line)
 | 
			
		||||
                        else:
 | 
			
		||||
                            value = values[0]
 | 
			
		||||
                        #print ("==%s==" % value)
 | 
			
		||||
                            value += values[0] # concatenate (2nd and possibly last data line)
 | 
			
		||||
                        partial_data += value
 | 
			
		||||
                    if PluginBase.find_one(line, ".*(}})") is not False: # search for end marker
 | 
			
		||||
                        started_read_data = False
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,9 +25,6 @@ import logging
 | 
			
		|||
"""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# def command_is(string, command):
 | 
			
		||||
#     return string.split(' ')[0] == command
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def debug_nfc_data(key, value):
 | 
			
		||||
    """
 | 
			
		||||
| 
						 | 
				
			
			@ -55,25 +52,27 @@ class NfcWrapper:
 | 
			
		|||
            logger.error("The NFC reader was not detected on any USB port!")
 | 
			
		||||
        self.clfResponse = None
 | 
			
		||||
 | 
			
		||||
    def clf_response(self):
 | 
			
		||||
        return self.clfResponse
 | 
			
		||||
 | 
			
		||||
    def connect(self, target_options = ("106A","106B","212F")):
 | 
			
		||||
    def connect(self):
 | 
			
		||||
        # note: only supporting type4
 | 
			
		||||
        time.sleep(0.5)
 | 
			
		||||
        after5s = lambda: time.time() - started > 5
 | 
			
		||||
        started = time.time()
 | 
			
		||||
 | 
			
		||||
        tag = self.clf.connect( rdwr={'on-connect': lambda tag: False},
 | 
			
		||||
            llcp={}, terminate = after5s)
 | 
			
		||||
        self.clfResponse = tag
 | 
			
		||||
            terminate = after5s)
 | 
			
		||||
        if tag: # None if timeout expires
 | 
			
		||||
            logging.info("NFCReader: connected " + str(tag))
 | 
			
		||||
        else:
 | 
			
		||||
            logging.info("NFCReader: warning, no tag detected ")
 | 
			
		||||
        return tag
 | 
			
		||||
 | 
			
		||||
    def mute(self):
 | 
			
		||||
        """turn off the reader radio"""
 | 
			
		||||
        if self.clf.device:
 | 
			
		||||
        if (self.clf.device is not None):
 | 
			
		||||
            logging.info("NFCReader: radio mute" + self.clf.device.product_name)
 | 
			
		||||
            self.clf.device.mute()
 | 
			
		||||
        else:
 | 
			
		||||
            logging.warning("NFCReader: reader not initialized!")
 | 
			
		||||
 | 
			
		||||
    def disconnect(self):
 | 
			
		||||
        logging.info("NFCReader: close frontend.")
 | 
			
		||||
| 
						 | 
				
			
			@ -97,5 +96,3 @@ class ContactlessCommandRunner():
 | 
			
		|||
 | 
			
		||||
    __nfc_wrapper = None
 | 
			
		||||
 | 
			
		||||
    def clf_response(self):
 | 
			
		||||
        return self.nfc.clf_response()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,8 +22,8 @@ from nfc_messages import NfcErrors
 | 
			
		|||
import logging
 | 
			
		||||
import icetea_lib.tools.asserts as asserts
 | 
			
		||||
 | 
			
		||||
# Values > 4 k incur large time costs
 | 
			
		||||
STRESS_BUFFLEN = 4096 # Default value for large buffer tests, this value can be read from the target with a command
 | 
			
		||||
# Values > 1 k incur large time costs
 | 
			
		||||
LARGE_BUFFLEN = 400 # Value for large buffer tests, a maximum value can be read from the target with a command
 | 
			
		||||
 | 
			
		||||
class CliHelper():
 | 
			
		||||
    """
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ from mbed_clitest.tools.tools import test_case
 | 
			
		|||
import icetea_lib.tools.asserts as asserts
 | 
			
		||||
from nfc_messages import NfcErrors
 | 
			
		||||
from nfc_cli_helper import CliHelper
 | 
			
		||||
from nfc_cli_helper import STRESS_BUFFLEN
 | 
			
		||||
from nfc_cli_helper import LARGE_BUFFLEN
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CreamSconeTests(Bench, CliHelper):
 | 
			
		||||
| 
						 | 
				
			
			@ -56,16 +56,31 @@ class CreamSconeTests(Bench, CliHelper):
 | 
			
		|||
        Bench.__init__(self, **testcase_args)
 | 
			
		||||
 | 
			
		||||
    def setup(self):
 | 
			
		||||
        #try:
 | 
			
		||||
        self.logger.info("Test setup: Open Reader and mute...")
 | 
			
		||||
        try:
 | 
			
		||||
            self.clf = ContactlessCommandRunner()
 | 
			
		||||
            self.clf.nfc.mute()
 | 
			
		||||
        #except:
 | 
			
		||||
        #    raise asserts.TestStepFail("Could not find NFC reader")
 | 
			
		||||
            self.clf.nfc.mute() # mute if the last test case did not mute
 | 
			
		||||
        except:
 | 
			
		||||
            raise asserts.TestStepFail("Could not find NFC reader")
 | 
			
		||||
 | 
			
		||||
    def teardown(self):
 | 
			
		||||
        self.logger.info("Test teardown: Reboot target...")
 | 
			
		||||
        self.reset_dut()
 | 
			
		||||
        self.clf.nfc.mute() # mute if the last test case did not mute
 | 
			
		||||
 | 
			
		||||
    def prepare_target(self):
 | 
			
		||||
        """
 | 
			
		||||
        simple set up a clean target device
 | 
			
		||||
        :return: 
 | 
			
		||||
        """
 | 
			
		||||
        response = self.nfc_command("dev1", "iseeprom")
 | 
			
		||||
        eeprom = response.parsed['iseeprom']
 | 
			
		||||
        self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
        self.nfc_command("dev1", "initnfc")
 | 
			
		||||
        if not eeprom:
 | 
			
		||||
            self.nfc_command("dev1", "start")
 | 
			
		||||
 | 
			
		||||
        self.nfc_command("dev1", "erase")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@test_case(CreamSconeTests)
 | 
			
		||||
| 
						 | 
				
			
			@ -83,8 +98,7 @@ def test_nfce2e_target_found(self):
 | 
			
		|||
    if not eeprom:
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -103,8 +117,7 @@ def test_nfce2e_type4_found(self):
 | 
			
		|||
    if not eeprom:
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
 | 
			
		||||
    asserts.assertEqual(tag.type, 'Type4Tag', "Tag of type Type4Tag not found")
 | 
			
		||||
| 
						 | 
				
			
			@ -117,20 +130,12 @@ def test_nfce2e_smartposter(self):
 | 
			
		|||
    """
 | 
			
		||||
    expectedURI = "https://www.mbed.com"    # ensure that these differ per test case
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "initnfc")
 | 
			
		||||
    self.nfc_command("dev1", "erase")
 | 
			
		||||
    response = self.nfc_command("dev1", "iseeprom")
 | 
			
		||||
    eeprom = response.parsed['iseeprom']
 | 
			
		||||
 | 
			
		||||
    self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
    if not eeprom:
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
    self.prepare_target()
 | 
			
		||||
 | 
			
		||||
    # write poster tag to target
 | 
			
		||||
    self.command("dev1", "setsmartposter %s" % expectedURI)
 | 
			
		||||
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
    asserts.assertEqual(1, len(tag.ndef.records), "expected number NDEF records")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -145,27 +150,18 @@ def test_nfce2e_reprogrammed(self):
 | 
			
		|||
    """
 | 
			
		||||
    expectedURI = "https://www.google.com"
 | 
			
		||||
 | 
			
		||||
    response = self.nfc_command("dev1", "iseeprom")
 | 
			
		||||
    eeprom = response.parsed['iseeprom']
 | 
			
		||||
    self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "initnfc")
 | 
			
		||||
    if not eeprom:
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
    self.nfc_command("dev1", "erase")
 | 
			
		||||
    self.prepare_target()
 | 
			
		||||
 | 
			
		||||
    # program a poster tag to target
 | 
			
		||||
    print("Write Smartposter MESSAGE wirelessly")
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    self.logger.info("Write Smartposter MESSAGE wirelessly")
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
    smartposter = nfc_messages.make_smartposter(expectedURI, ["en-US:Other search engines exist"])
 | 
			
		||||
    nfc_messages.program_remote_tag(smartposter, tag)
 | 
			
		||||
    self.logger.info("Remote programmed %d bytes Smartposter" % len(str(smartposter)))
 | 
			
		||||
 | 
			
		||||
    print("Write back Smartposter MESSAGE wirelessly")
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    self.logger.info("Write back Smartposter MESSAGE wirelessly")
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not re-connect to any tag")
 | 
			
		||||
 | 
			
		||||
    asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "SmartposterRecord", "expected SmartposterRecord")
 | 
			
		||||
| 
						 | 
				
			
			@ -185,35 +181,22 @@ def test_nfce2e_read_stress(self):
 | 
			
		|||
    """
 | 
			
		||||
    check - Large record can be programmed in and read via contactless
 | 
			
		||||
    """
 | 
			
		||||
    messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
 | 
			
		||||
 | 
			
		||||
    response = self.nfc_command("dev1", "iseeprom")
 | 
			
		||||
    eeprom = response.parsed['iseeprom']
 | 
			
		||||
    self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
    max_ndef = STRESS_BUFFLEN
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "initnfc")
 | 
			
		||||
    if not eeprom:
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
    else:
 | 
			
		||||
        max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
 | 
			
		||||
    if (max_ndef > 800 ):
 | 
			
		||||
        textLength = 800   # large values slow down test runs and may time out
 | 
			
		||||
    else:
 | 
			
		||||
        textLength = max_ndef
 | 
			
		||||
    self.nfc_command("dev1", "erase")
 | 
			
		||||
    message_to_repeat = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
 | 
			
		||||
    text_length = LARGE_BUFFLEN
 | 
			
		||||
    # calculate actual message to compare to using the library
 | 
			
		||||
    expected_text = nfc_messages.repeat_string_to_length(messageRep, textLength)
 | 
			
		||||
    expected_text = nfc_messages.repeat_string_to_length(message_to_repeat, text_length)
 | 
			
		||||
 | 
			
		||||
    self.prepare_target()
 | 
			
		||||
    # write a large message to the tag via API, then read it wirelessly
 | 
			
		||||
    print("Write/set tag MESSAGE (%d) bytes" % textLength)
 | 
			
		||||
    self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
    self.logger.info("Write/set tag MESSAGE (%d) bytes" % text_length)
 | 
			
		||||
    self.nfc_command("dev1", "writelong %d %s" % (text_length,message_to_repeat))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # assert that read the eeprom contents gives correct data and length
 | 
			
		||||
    print("Read tag MESSAGE wirelessly" )
 | 
			
		||||
    self.logger.info("Read tag MESSAGE wirelessly" )
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
 | 
			
		||||
    asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
 | 
			
		||||
    self.assert_text_equal(tag.ndef.records[0].text, expected_text)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -223,43 +206,27 @@ def test_nfce2e_reprogrammed_stress(self):
 | 
			
		|||
    """
 | 
			
		||||
    check - Large record can be programmed from a remote and read via contactless
 | 
			
		||||
    """
 | 
			
		||||
    messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    response = self.nfc_command("dev1", "iseeprom")
 | 
			
		||||
    eeprom = response.parsed['iseeprom']
 | 
			
		||||
    self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
    max_ndef = STRESS_BUFFLEN
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "initnfc")
 | 
			
		||||
    if not eeprom:
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
    else:
 | 
			
		||||
        max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
 | 
			
		||||
 | 
			
		||||
    if (max_ndef > 800 ):
 | 
			
		||||
        textLength = 800   # large values slow down test runs and may time out
 | 
			
		||||
    else:
 | 
			
		||||
        textLength = max_ndef
 | 
			
		||||
    self.nfc_command("dev1", "erase")
 | 
			
		||||
    message_to_repeat = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
 | 
			
		||||
    text_length = LARGE_BUFFLEN # large values slow down test runs and may time out
 | 
			
		||||
 | 
			
		||||
    # calculate actual message to compare to using the library
 | 
			
		||||
    message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
 | 
			
		||||
    message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(message_to_repeat, text_length))
 | 
			
		||||
    expected_message = str(message)
 | 
			
		||||
 | 
			
		||||
    self.prepare_target()
 | 
			
		||||
    # program a large tag to target remotely
 | 
			
		||||
    print("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message)))
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    self.logger.info("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message)))
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
    nfc_messages.program_remote_tag(message, tag)
 | 
			
		||||
    self.logger.info("%d bytes chunk of data written to tag remotely" %  len(str(message)))
 | 
			
		||||
    self.clf.nfc.mute()
 | 
			
		||||
 | 
			
		||||
    # read device locally
 | 
			
		||||
    print("Read back tag MESSAGE wirelessly")
 | 
			
		||||
    self.clf.nfc.connect()
 | 
			
		||||
    tag = self.clf.clf_response()
 | 
			
		||||
    self.logger.info("Read back tag MESSAGE wirelessly")
 | 
			
		||||
    tag = self.clf.nfc.connect()
 | 
			
		||||
    asserts.assertNotNone(tag, "Could not re-connect to any tag")
 | 
			
		||||
    asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
 | 
			
		||||
    self.clf.nfc.mute() # disable the reader radio, to allow local access
 | 
			
		||||
 | 
			
		||||
    # verify in target
 | 
			
		||||
| 
						 | 
				
			
			@ -285,27 +252,23 @@ def test_nfce2e_discovery_loop(self):
 | 
			
		|||
    # Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" .
 | 
			
		||||
 | 
			
		||||
    if not eeprom:
 | 
			
		||||
        self.clf.nfc.connect()
 | 
			
		||||
        tag = self.clf.clf_response()
 | 
			
		||||
        tag = self.clf.nfc.connect()
 | 
			
		||||
        asserts.assertNone(tag, "post-init: Tag discovery loop should be stopped!")
 | 
			
		||||
        self.nfc_command("dev1", "stop")
 | 
			
		||||
        time.sleep(1)
 | 
			
		||||
 | 
			
		||||
        self.clf.nfc.connect()
 | 
			
		||||
        tag = self.clf.clf_response()
 | 
			
		||||
        tag = self.clf.nfc.connect()
 | 
			
		||||
        asserts.assertNone(tag, "post-stop: Tag discovery loop should be stopped!")
 | 
			
		||||
        self.nfc_command("dev1", "start")
 | 
			
		||||
        time.sleep(1)
 | 
			
		||||
 | 
			
		||||
        self.clf.nfc.connect()
 | 
			
		||||
        tag = self.clf.clf_response()
 | 
			
		||||
        tag = self.clf.nfc.connect()
 | 
			
		||||
        asserts.assertNotNone(tag, "Could not connect to any tag")
 | 
			
		||||
 | 
			
		||||
        self.clf.nfc.mute()
 | 
			
		||||
        self.nfc_command("dev1", "stop")
 | 
			
		||||
        time.sleep(10)
 | 
			
		||||
        self.clf.nfc.connect()
 | 
			
		||||
        tag = self.clf.clf_response()
 | 
			
		||||
        tag = self.clf.nfc.connect()
 | 
			
		||||
        # test blocked by issue raised IOTPAN313 NFC Controller discovery can stop but cannot restart - PN512
 | 
			
		||||
        asserts.assertNone(tag, "post-restart: Tag discovery loop should be stopped!")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ import icetea_lib.tools.asserts as asserts
 | 
			
		|||
import nfc_messages
 | 
			
		||||
from nfc_messages import NfcErrors
 | 
			
		||||
from nfc_cli_helper import CliHelper
 | 
			
		||||
from nfc_cli_helper import STRESS_BUFFLEN
 | 
			
		||||
from nfc_cli_helper import LARGE_BUFFLEN
 | 
			
		||||
import nfc
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +111,7 @@ check - Create a SmartPoster but does not read it back
 | 
			
		|||
def test_nfc_setsmartposter(self):
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "initnfc")
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "setsmartposter https://www.mbed.com")
 | 
			
		||||
 | 
			
		||||
@test_case(CreamSconeSelfTests)
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +121,6 @@ def test_nfc_erase(self):
 | 
			
		|||
    eeprom = response.parsed['iseeprom']
 | 
			
		||||
    if eeprom:
 | 
			
		||||
        self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "erase", timeout=30)
 | 
			
		||||
    response = self.nfc_command("dev1", "readmessage")
 | 
			
		||||
    asserts.assertEqual(response.parsed['nfcmessage'] is None, True)
 | 
			
		||||
| 
						 | 
				
			
			@ -132,7 +132,7 @@ can be read back.
 | 
			
		|||
@test_case(CreamSconeSelfTests)
 | 
			
		||||
def test_nfc_write_long(self):
 | 
			
		||||
    messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
 | 
			
		||||
    textLength = STRESS_BUFFLEN / 2       # 2K < x < 4K
 | 
			
		||||
    textLength = LARGE_BUFFLEN        # large values take longer
 | 
			
		||||
    # calculate actual message to compare to using the library
 | 
			
		||||
    message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
 | 
			
		||||
    expected_message = str(message)
 | 
			
		||||
| 
						 | 
				
			
			@ -142,7 +142,6 @@ def test_nfc_write_long(self):
 | 
			
		|||
    eeprom = response.parsed['iseeprom']
 | 
			
		||||
    if eeprom:
 | 
			
		||||
        self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
 | 
			
		||||
 | 
			
		||||
    self.nfc_command("dev1", "erase")
 | 
			
		||||
    self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
 | 
			
		||||
    response = self.nfc_command("dev1", "readmessage")
 | 
			
		||||
| 
						 | 
				
			
			@ -252,5 +251,5 @@ def test_nfc_get_max_ndef(self):
 | 
			
		|||
    self.nfc_command("dev1", "initnfc")
 | 
			
		||||
    max = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
 | 
			
		||||
    self.logger.info("Target NDEF max buffer size %d" % max)
 | 
			
		||||
    self.logger.info("Teststress size %d" % STRESS_BUFFLEN)
 | 
			
		||||
    self.logger.info("Teststress size %d" % LARGE_BUFFLEN)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue