Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Sep 24, 2023
1 parent e23ad69 commit 372cfea
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 91 deletions.
32 changes: 16 additions & 16 deletions firmware/application/src/app_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static data_frame_tx_t *cmd_processor_mf1_write_one_block(uint16_t cmd, uint16_t

static data_frame_tx_t *cmd_processor_hf14a_raw(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
// Response Buffer
uint8_t resp[DEF_FIFO_LENGTH] = { 0x00 };
uint8_t resp[DEF_FIFO_LENGTH] = { 0x00 };
uint16_t resp_length = 0;

typedef struct {
Expand Down Expand Up @@ -427,22 +427,22 @@ static data_frame_tx_t *cmd_processor_hf14a_raw(uint16_t cmd, uint16_t status, u
NRF_LOG_INFO("reserved = %d", payload->options.reserved);

status = pcd_14a_reader_raw_cmd(
payload->options.activate_rf_field,
payload->options.wait_response,
payload->options.append_crc,
payload->options.auto_select,
payload->options.keep_rf_field,
payload->options.check_response_crc,
payload->options.activate_rf_field,
payload->options.wait_response,
payload->options.append_crc,
payload->options.auto_select,
payload->options.keep_rf_field,
payload->options.check_response_crc,

U16NTOHS(payload->resp_timeout),
U16NTOHS(payload->resp_timeout),

U16NTOHS(payload->data_bitlength),
payload->data_buffer,
U16NTOHS(payload->data_bitlength),
payload->data_buffer,

resp,
&resp_length,
U8ARR_BIT_LEN(resp)
);
resp,
&resp_length,
U8ARR_BIT_LEN(resp)
);

return data_frame_make(cmd, status, resp_length, resp);
}
Expand Down Expand Up @@ -552,7 +552,7 @@ static data_frame_tx_t *cmd_processor_set_slot_enable(uint16_t cmd, uint16_t sta
uint8_t slot_now = payload->slot_index;
tag_emulation_slot_set_enable(slot_now, payload->sense_type, payload->enabled);
if ((!payload->enabled) &&
(!tag_emulation_slot_is_enabled(slot_now, payload->sense_type == TAG_SENSE_HF ? TAG_SENSE_LF : TAG_SENSE_HF))) {
(!tag_emulation_slot_is_enabled(slot_now, payload->sense_type == TAG_SENSE_HF ? TAG_SENSE_LF : TAG_SENSE_HF))) {
// HF and LF disabled, need to change slot
uint8_t slot_prev = tag_emulation_slot_find_next(slot_now);
NRF_LOG_INFO("slot_now = %d, slot_prev = %d", slot_now, slot_prev);
Expand Down Expand Up @@ -863,7 +863,7 @@ static data_frame_tx_t *cmd_processor_get_enabled_slots(uint16_t cmd, uint16_t s
payload[slot].enabled_hf = tag_emulation_slot_is_enabled(slot, TAG_SENSE_HF);
payload[slot].enabled_lf = tag_emulation_slot_is_enabled(slot, TAG_SENSE_LF);
}
return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, sizeof(payload), (uint8_t*)&payload);
return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, sizeof(payload), (uint8_t *)&payload);
}

static data_frame_tx_t *cmd_processor_get_ble_connect_key(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) {
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/src/rfid/nfctag/tag_base_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ typedef enum {
TAG_TYPE_NTAG_216

typedef struct {
tag_specific_type_t tag_hf;
tag_specific_type_t tag_lf;
tag_specific_type_t tag_hf;
tag_specific_type_t tag_lf;
} tag_slot_specific_type_t;


Expand Down
30 changes: 15 additions & 15 deletions firmware/application/src/rfid/nfctag/tag_emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ static tag_specific_type_t tag_specific_type_hf_values[] = { TAG_SPECIFIC_TYPE_H

bool is_tag_specific_type_valid(tag_specific_type_t tag_type) {
bool valid = false;
for (uint16_t i=0; i < ARRAYLEN(tag_specific_type_lf_values); i++) {
for (uint16_t i = 0; i < ARRAYLEN(tag_specific_type_lf_values); i++) {
valid |= (tag_type == tag_specific_type_lf_values[i]);
}
for (uint16_t i=0; i < ARRAYLEN(tag_specific_type_hf_values); i++) {
for (uint16_t i = 0; i < ARRAYLEN(tag_specific_type_hf_values); i++) {
valid |= (tag_type == tag_specific_type_hf_values[i]);
}
return valid;
Expand Down Expand Up @@ -398,15 +398,15 @@ void tag_emulation_sense_switch(tag_sense_type_t type, bool enable) {
break;
case TAG_SENSE_HF:
if (enable && (slotConfig.slots[slot].enabled_hf) &&
(slotConfig.slots[slot].tag_hf != TAG_TYPE_UNDEFINED)) {
(slotConfig.slots[slot].tag_hf != TAG_TYPE_UNDEFINED)) {
nfc_tag_14a_sense_switch(true);
} else {
nfc_tag_14a_sense_switch(false);
}
break;
case TAG_SENSE_LF:
if (enable && (slotConfig.slots[slot].enabled_lf) &&
(slotConfig.slots[slot].tag_lf != TAG_TYPE_UNDEFINED)) {
(slotConfig.slots[slot].tag_lf != TAG_TYPE_UNDEFINED)) {
lf_tag_125khz_sense_switch(true);
} else {
lf_tag_125khz_sense_switch(false);
Expand All @@ -425,32 +425,32 @@ static void tag_emulation_migrate_slot_config_v0_to_v8(void) {
// Populate new slotConfig struct
slotConfig.version = TAG_SLOT_CONFIG_CURRENT_VERSION;
slotConfig.active_slot = tmpbuf[0];
for (uint8_t i = 0; i< ARRAYLEN(slotConfig.slots); i++) {
bool enabled = tmpbuf[4+(i*4)] & 1;
for (uint8_t i = 0; i < ARRAYLEN(slotConfig.slots); i++) {
bool enabled = tmpbuf[4 + (i * 4)] & 1;

slotConfig.slots[i].tag_hf = tmpbuf[4+(i*4)+2];
for (uint8_t j=0; j < ARRAYLEN(tag_specific_type_old2new_hf_values); j++) {
slotConfig.slots[i].tag_hf = tmpbuf[4 + (i * 4) + 2];
for (uint8_t j = 0; j < ARRAYLEN(tag_specific_type_old2new_hf_values); j++) {
if (slotConfig.slots[i].tag_hf == tag_specific_type_old2new_hf_values[j][0]) {
slotConfig.slots[i].tag_hf = tag_specific_type_old2new_hf_values[j][1];
}
}
slotConfig.slots[i].enabled_hf = slotConfig.slots[i].tag_hf != TAG_TYPE_UNDEFINED ? enabled : false;
NRF_LOG_INFO("Slot %i HF: %02X->%04X enabled:%i", i, tmpbuf[4+(i*4)+2], slotConfig.slots[i].tag_hf, slotConfig.slots[i].enabled_hf);
NRF_LOG_INFO("Slot %i HF: %02X->%04X enabled:%i", i, tmpbuf[4 + (i * 4) + 2], slotConfig.slots[i].tag_hf, slotConfig.slots[i].enabled_hf);

slotConfig.slots[i].tag_lf = tmpbuf[4+(i*4)+3];
for (uint8_t j=0; j < ARRAYLEN(tag_specific_type_old2new_lf_values); j++) {
slotConfig.slots[i].tag_lf = tmpbuf[4 + (i * 4) + 3];
for (uint8_t j = 0; j < ARRAYLEN(tag_specific_type_old2new_lf_values); j++) {
if (slotConfig.slots[i].tag_lf == tag_specific_type_old2new_lf_values[j][0]) {
slotConfig.slots[i].tag_lf = tag_specific_type_old2new_lf_values[j][1];
}
}
slotConfig.slots[i].enabled_lf = slotConfig.slots[i].tag_lf != TAG_TYPE_UNDEFINED ? enabled : false;
NRF_LOG_INFO("Slot %i LF: %02X->%04X enabled:%i", i, tmpbuf[4+(i*4)+3], slotConfig.slots[i].tag_lf, slotConfig.slots[i].enabled_lf);
NRF_LOG_INFO("Slot %i LF: %02X->%04X enabled:%i", i, tmpbuf[4 + (i * 4) + 3], slotConfig.slots[i].tag_lf, slotConfig.slots[i].enabled_lf);
}
}


static void tag_emulation_migrate_slot_config(void) {
switch(slotConfig.version) {
switch (slotConfig.version) {
case 0:
case 1:
case 2:
Expand Down Expand Up @@ -627,7 +627,7 @@ uint8_t tag_emulation_slot_find_next(uint8_t slot_now) {
uint8_t start_slot = (slot_now + 1 == TAG_MAX_SLOT_NUM) ? 0 : slot_now + 1;
for (uint8_t i = start_slot;;) {
if (i == slot_now) return slot_now; // No other activated card slots were found after a loop
if (slotConfig.slots[i].enabled_hf || slotConfig.slots[i].enabled_lf ) return i; // Check whether the card slot that is currently traversed is enabled, so that the capacity determines that the current card slot is the card slot that can effectively enable capacity
if (slotConfig.slots[i].enabled_hf || slotConfig.slots[i].enabled_lf) return i; // Check whether the card slot that is currently traversed is enabled, so that the capacity determines that the current card slot is the card slot that can effectively enable capacity
i++;
if (i == TAG_MAX_SLOT_NUM) { // Continue the next cycle
i = 0;
Expand Down Expand Up @@ -686,7 +686,7 @@ void tag_emulation_change_type(uint8_t slot, tag_specific_type_t tag_type) {
void tag_emulation_factory_init(void) {
fds_slot_record_map_t map_info;

// Initialized a dual -frequency card in the card slot, if there is no historical record, it is a new state of factory.
// Initialized a dual -frequency card in the card slot, if there is no historical record, it is a new state of factory.
if (slotConfig.slots[0].enabled_hf && slotConfig.slots[0].tag_hf == TAG_TYPE_MIFARE_1024) {
// Initialize a high -frequency M1 card in the card slot 1, if it does not exist.
get_fds_map_by_slot_sense_type_for_dump(0, TAG_SENSE_HF, &map_info);
Expand Down
60 changes: 30 additions & 30 deletions firmware/application/src/rfid/reader/hf/rc522.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,20 +1129,20 @@ inline void pcd_14a_reader_crc_computer(uint8_t use522CalcCRC) {
}

/**
* @brief : The hf 14a raw command implementation function can be used to send the 14A command with the specified configuration parameters.
* @param :waitResp : Wait for tag response
* @param :appendCrc : Do you want to add CRC before sending
* @param :autoSelect : Automatically select card before sending data
* @param :keepField : Do you want to keep the RF field on after sending
* @param :checkCrc : Is CRC verified after receiving data? If CRC verification is enabled, CRC bytes will be automatically removed after verification is completed.
* @param :waitRespTimeout : If waitResp is enabled, this parameter will be the timeout value to wait for the tag to respond
* @param :szDataSend : The number of bytes or bits of data to be sent
* @param :pDataSend : Pointer to the buffer of the data to be sent
* @brief : The hf 14a raw command implementation function can be used to send the 14A command with the specified configuration parameters.
* @param :waitResp : Wait for tag response
* @param :appendCrc : Do you want to add CRC before sending
* @param :autoSelect : Automatically select card before sending data
* @param :keepField : Do you want to keep the RF field on after sending
* @param :checkCrc : Is CRC verified after receiving data? If CRC verification is enabled, CRC bytes will be automatically removed after verification is completed.
* @param :waitRespTimeout : If waitResp is enabled, this parameter will be the timeout value to wait for the tag to respond
* @param :szDataSend : The number of bytes or bits of data to be sent
* @param :pDataSend : Pointer to the buffer of the data to be sent
*
* @retval : Execution Status
* @retval : Execution Status
*
*/
uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc, bool autoSelect, bool keepField, bool checkCrc, uint16_t waitRespTimeout,
uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc, bool autoSelect, bool keepField, bool checkCrc, uint16_t waitRespTimeout,
uint16_t szDataSendBits, uint8_t *pDataSend, uint8_t *pDataRecv, uint16_t *pszDataRecv, uint16_t szDataRecvBitMax) {
// Status code, default is OK.
uint8_t status = HF_TAG_OK;
Expand Down Expand Up @@ -1203,32 +1203,32 @@ uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc,
}
if (szDataSendBits % 8) {
status = pcd_14a_reader_bits_transfer(
pDataSend,
szDataSendBits,
NULL,
pDataRecv,
NULL,
pszDataRecv,
szDataRecvBitMax
);
pDataSend,
szDataSendBits,
NULL,
pDataRecv,
NULL,
pszDataRecv,
szDataRecvBitMax
);
} else {
status = pcd_14a_reader_bytes_transfer(
PCD_TRANSCEIVE,
pDataSend,
szDataSendBits / 8,
pDataRecv,
pszDataRecv,
szDataRecvBitMax
);
PCD_TRANSCEIVE,
pDataSend,
szDataSendBits / 8,
pDataRecv,
pszDataRecv,
szDataRecvBitMax
);
}

// If we need to receive data, we need to perform further operations on the data based on the remaining configuration after receiving it
if (waitResp) {
// Number of bits to bytes
uint8_t finalRecvBytes = (*pszDataRecv / 8) + (*pszDataRecv % 8 > 0 ? 1 : 0);
// If CRC verification is required, we need to perform CRC calculation
if (checkCrc) {
if (finalRecvBytes >= 3) { // Ensure at least three bytes (one byte of data+two bytes of CRC)
if (finalRecvBytes >= 3) { // Ensure at least three bytes (one byte of data+two bytes of CRC)
// Calculate and store CRC
uint8_t crc_buff[DEF_CRC_LENGTH] = { 0x00 };
crc_14a_calculate(pDataRecv, finalRecvBytes - DEF_CRC_LENGTH, crc_buff);
Expand All @@ -1238,7 +1238,7 @@ uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc,
*pszDataRecv = 0;
status = HF_ERR_CRC;
} else {
// If the CRC needs to be verified by the device and the device determines that the CRC is normal,
// If the CRC needs to be verified by the device and the device determines that the CRC is normal,
// we will return the data without CRC
*pszDataRecv = finalRecvBytes - DEF_CRC_LENGTH;
}
Expand All @@ -1263,4 +1263,4 @@ uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc,
}

return status;
}
}
4 changes: 2 additions & 2 deletions firmware/application/src/rfid/reader/hf/rc522.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ uint8_t pcd_14a_reader_mf1_read(uint8_t addr, uint8_t *pData);
uint8_t pcd_14a_reader_halt_tag(void);
void pcd_14a_reader_fast_halt_tag(void);

uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc, bool autoSelect, bool keepField, bool checkCrc, uint16_t waitRespTimeout,
uint16_t szDataSendBits, uint8_t* pDataSend, uint8_t* pDataRecv, uint16_t* pszDataRecv, uint16_t szDataRecvBitMax);
uint8_t pcd_14a_reader_raw_cmd(bool openRFField, bool waitResp, bool appendCrc, bool autoSelect, bool keepField, bool checkCrc, uint16_t waitRespTimeout,
uint16_t szDataSendBits, uint8_t *pDataSend, uint8_t *pDataRecv, uint16_t *pszDataRecv, uint16_t szDataRecvBitMax);

// UID & UFUID tag operation
uint8_t pcd_14a_reader_gen1a_unlock(void);
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/src/rgb_marquee.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ void ledblink6(void) {
} else {
ledblink6_step = 0;
//if (++ledblink6_color == RGB_WHITE) ledblink6_color = RGB_RED;
uint8_t new_color=rand()%6;
for (; new_color == ledblink6_color; new_color=rand()%6);
uint8_t new_color = rand() % 6;
for (; new_color == ledblink6_color; new_color = rand() % 6);
ledblink6_color = new_color;
}
}
Expand Down
Loading

0 comments on commit 372cfea

Please sign in to comment.