Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:11526ba25edb, committed 2020-02-13
- Comitter:
- martyn gilbertson
- Date:
- Thu Feb 13 13:42:16 2020 +0000
- Parent:
- 3:5ebf4b2c51a1
- Commit message:
- v1.0.2 - 13 February 2020
[+] Made all char arrays const
Changed in this revision
M24SR.cpp | Show annotated file Show diff for this revision Revisions of this file |
M24SR.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5ebf4b2c51a1 -r 11526ba25edb M24SR.cpp --- a/M24SR.cpp Thu Aug 29 12:38:46 2019 +0100 +++ b/M24SR.cpp Thu Feb 13 13:42:16 2020 +0000 @@ -95,7 +95,7 @@ #define M24SR_DEFAULT_FREQUENCY (uint32_t)500000 -M24SR::M24SR(PinName sda, PinName scl, uint8_t address, uint8_t *pass) : _i2c(sda,scl), _addr(address), +M24SR::M24SR(PinName sda, PinName scl, uint8_t address, const uint8_t *pass) : _i2c(sda,scl), _addr(address), _session_open(false), _ndef_size(0), _ndef_hdr_size(0), _write_bytes(0) { frequency(M24SR_DEFAULT_FREQUENCY); @@ -109,7 +109,7 @@ } -void M24SR::password(uint8_t *pass) +void M24SR::password(const uint8_t *pass) { memcpy(_password, pass, 16); } @@ -715,7 +715,7 @@ } -M24SR::status_t M24SR::select_type(uint8_t *cmd, uint8_t size, uint16_t P1_P2, uint16_t mask) +M24SR::status_t M24SR::select_type(const uint8_t *cmd, uint8_t size, uint16_t P1_P2, uint16_t mask) { status_t status; uint16_t length; @@ -751,7 +751,7 @@ const uint8_t M24SR_OPENSESSION_COMMAND = 0x26; const uint8_t M24SR_KILLSESSION_COMMAND = 0x52; - status_t ret; + status_t ret = M24SR_SUCCESS; // if there is an RF session on-going then retry a few times to KILL, once an actual session is started RF is disabled uint8_t retry = 3; @@ -859,7 +859,7 @@ } -M24SR::status_t M24SR::is_S_block(uint8_t *buffer) +M24SR::status_t M24SR::is_S_block(const uint8_t *buffer) { if ((buffer[OFFSET_PCB] & MASK_BLOCK) == MASK_S_BLOCK) { @@ -870,7 +870,7 @@ } -void M24SR::build_I_block_command(uint16_t command_mask, C_APDU *command, uint8_t did, uint16_t *length, uint8_t *command_buffer) +void M24SR::build_I_block_command(uint16_t command_mask, const C_APDU *command, uint8_t did, uint16_t *length, uint8_t *command_buffer) { uint16_t crc16; static uint8_t _block_number; @@ -952,7 +952,7 @@ } -M24SR::status_t M24SR::is_correct_crc_residue(uint8_t *data, uint8_t length) +M24SR::status_t M24SR::is_correct_crc_residue(const uint8_t *data, uint8_t length) { uint16_t res_crc = 0x0000; status_t status; @@ -989,15 +989,16 @@ } -uint16_t M24SR::compute_crc(uint8_t *data, uint8_t length) +uint16_t M24SR::compute_crc(const uint8_t *data, uint8_t length) { uint8_t block; uint16_t crc16 = 0x6363; /* ITU-V.41 */ + uint8_t len = length; do { block = *data++; update_crc(block, &crc16); - } while (--length); + } while (--len); return crc16; }
diff -r 5ebf4b2c51a1 -r 11526ba25edb M24SR.h --- a/M24SR.h Thu Aug 29 12:38:46 2019 +0100 +++ b/M24SR.h Thu Feb 13 13:42:16 2020 +0000 @@ -3,16 +3,19 @@ * * <b> M24SR.h</b> * <p> M24SR NFC Driver </p> - * @version 1.0.1 + * @version 1.0.2 * @since 10 July 2019 * @author Martyn Gilbertson * <p> * v1.0.0 - 10 July 2019 * [+] Initial release * - * v1.0.1 - 29 August 2019 + * v1.0.1 - 29 August 2019 * [+] Disable RF during Session * [+] Fixed writing NDEF at specific location + * + * v1.0.2 - 13 February 2020 + * [+] Made all char arrays const * </p> */ #ifndef _M24SR_H_ @@ -174,7 +177,7 @@ * @param scl - I2C Clock pin * @param addr - Hardware address of device (defaults to 0x56) */ - M24SR(PinName sda, PinName scl, uint8_t address = M24SR_DEFAULT_ADDRESS, uint8_t *pass = M24SR_DEFAULT_PASSWORD); + M24SR(PinName sda, PinName scl, uint8_t address = M24SR_DEFAULT_ADDRESS, const uint8_t *pass = M24SR_DEFAULT_PASSWORD); /** Destructor @@ -265,7 +268,7 @@ * @param pass - 128 bit password array * @pre - password must be 16 bytes */ - void password(uint8_t *pass); + void password(const uint8_t *pass); /** Set write bytes @@ -376,7 +379,7 @@ status_t update_binary(uint16_t offset, uint8_t size, const uint8_t *buffer); - status_t select_type(uint8_t *cmd, uint8_t size, uint16_t P1_P2, uint16_t mask); + status_t select_type(const uint8_t *cmd, uint8_t size, uint16_t P1_P2, uint16_t mask); status_t get_session(bool force); @@ -384,13 +387,13 @@ status_t deselect(); - status_t is_S_block(uint8_t *buffer); + status_t is_S_block(const uint8_t *buffer); - void build_I_block_command(uint16_t command_mask, C_APDU *command, uint8_t did, uint16_t *length, uint8_t *command_buffer); + void build_I_block_command(uint16_t command_mask, const C_APDU *command, uint8_t did, uint16_t *length, uint8_t *command_buffer); - status_t is_correct_crc_residue(uint8_t *data, uint8_t length); + status_t is_correct_crc_residue(const uint8_t *data, uint8_t length); - uint16_t compute_crc(uint8_t *data, uint8_t length); + uint16_t compute_crc(const uint8_t *data, uint8_t length); uint16_t update_crc(uint8_t ch, uint16_t *lpw_crc);