mirror of
https://github.com/RfidResearchGroup/ChameleonMini.git
synced 2026-05-12 11:20:37 -07:00
employ a macro to compute element counts in arrays
This commit is contained in:
@@ -96,7 +96,7 @@ static const CardIdentificationType PROGMEM CardIdentificationList[] = {
|
||||
[CardType_Nokia_MIFARE_Classic_4k_emulated_6131] = { .ATQA=0x0008, .ATQARelevant=true, .SAK=0x38, .SAKRelevant=true, .ATSRelevant=false, .Manufacturer="Nokia", .Type="MIFARE Classic 4k - emulated (6131 NFC)" }
|
||||
};
|
||||
|
||||
static CardType CardCandidates[sizeof(CardIdentificationList) / sizeof(CardIdentificationType)];
|
||||
static CardType CardCandidates[ARRAY_COUNT(CardIdentificationList)];
|
||||
static uint8_t CardCandidatesIdx = 0;
|
||||
|
||||
uint16_t addParityBits(uint8_t * Buffer, uint16_t BitCount)
|
||||
@@ -549,7 +549,7 @@ uint16_t Reader14443AAppProcess(uint8_t* Buffer, uint16_t BitCount)
|
||||
bool ISO14443_4A_compliant = IS_ISO14443A_4_COMPLIANT(Buffer);
|
||||
|
||||
uint8_t i;
|
||||
for (i = 0; i < sizeof(CardIdentificationList)/sizeof(CardIdentificationType); i++)
|
||||
for (i = 0; i < ARRAY_COUNT(CardIdentificationList); i++)
|
||||
{
|
||||
CardIdentificationType card;
|
||||
memcpy_P(&card, &CardIdentificationList[i], sizeof(CardIdentificationType));
|
||||
|
||||
@@ -239,7 +239,7 @@ void ButtonTick(void)
|
||||
|
||||
void ButtonGetActionList(char* List, uint16_t BufferSize)
|
||||
{
|
||||
MapToString(ButtonActionMap, sizeof(ButtonActionMap)/sizeof(*ButtonActionMap), List, BufferSize);
|
||||
MapToString(ButtonActionMap, ARRAY_COUNT(ButtonActionMap), List, BufferSize);
|
||||
}
|
||||
|
||||
void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action)
|
||||
@@ -256,7 +256,7 @@ void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action)
|
||||
|
||||
void ButtonGetActionByName(ButtonTypeEnum Type, char* Action, uint16_t BufferSize)
|
||||
{
|
||||
MapIdToText(ButtonActionMap, sizeof(ButtonActionMap)/sizeof(*ButtonActionMap),
|
||||
MapIdToText(ButtonActionMap, ARRAY_COUNT(ButtonActionMap),
|
||||
GlobalSettings.ActiveSettingPtr->ButtonActions[Type], Action, BufferSize);
|
||||
}
|
||||
|
||||
@@ -264,8 +264,7 @@ bool ButtonSetActionByName(ButtonTypeEnum Type, const char* Action)
|
||||
{
|
||||
MapIdType Id;
|
||||
|
||||
if (MapTextToId(ButtonActionMap, sizeof(ButtonActionMap)/sizeof(*ButtonActionMap),
|
||||
Action, &Id)) {
|
||||
if (MapTextToId(ButtonActionMap, ARRAY_COUNT(ButtonActionMap), Action, &Id)) {
|
||||
ButtonSetActionById(Type, Id);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#define INLINE \
|
||||
static inline __attribute__((always_inline))
|
||||
|
||||
#define ARRAY_COUNT(x) \
|
||||
(sizeof(x) / sizeof(x[0]))
|
||||
|
||||
#define NIBBLE_TO_HEXCHAR(x) ( (x) < 0x0A ? (x) + '0' : (x) + 'A' - 0x0A )
|
||||
#define HEXCHAR_TO_NIBBLE(x) ( (x) < 'A' ? (x) - '0' : (x) - 'A' + 0x0A )
|
||||
#define VALID_HEXCHAR(x) ( ( (x) >= '0' && (x) <= '9' ) || ( (x) >= 'A' && (x) <= 'F' ) )
|
||||
|
||||
@@ -218,14 +218,14 @@ void ConfigurationSetById( ConfigurationEnum Configuration )
|
||||
|
||||
void ConfigurationGetByName(char* Configuration, uint16_t BufferSize)
|
||||
{
|
||||
MapIdToText(ConfigurationMap, sizeof(ConfigurationMap)/sizeof(*ConfigurationMap), GlobalSettings.ActiveSettingPtr->Configuration, Configuration, BufferSize);
|
||||
MapIdToText(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), GlobalSettings.ActiveSettingPtr->Configuration, Configuration, BufferSize);
|
||||
}
|
||||
|
||||
bool ConfigurationSetByName(const char* Configuration)
|
||||
{
|
||||
MapIdType Id;
|
||||
|
||||
if (MapTextToId(ConfigurationMap, sizeof(ConfigurationMap)/sizeof(*ConfigurationMap), Configuration, &Id)) {
|
||||
if (MapTextToId(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), Configuration, &Id)) {
|
||||
ConfigurationSetById(Id);
|
||||
LogEntry(LOG_INFO_CONFIG_SET, Configuration, StringLength(Configuration, CONFIGURATION_NAME_LENGTH_MAX-1));
|
||||
return true;
|
||||
@@ -236,6 +236,6 @@ bool ConfigurationSetByName(const char* Configuration)
|
||||
|
||||
void ConfigurationGetList(char* List, uint16_t BufferSize)
|
||||
{
|
||||
MapToString(ConfigurationMap, sizeof(ConfigurationMap)/sizeof(*ConfigurationMap), List, BufferSize);
|
||||
MapToString(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), List, BufferSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ void LEDTick(void)
|
||||
|
||||
void LEDGetFuncList(char* List, uint16_t BufferSize)
|
||||
{
|
||||
MapToString(LEDFunctionMap, sizeof(LEDFunctionMap)/sizeof(*LEDFunctionMap), List, BufferSize);
|
||||
MapToString(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap), List, BufferSize);
|
||||
}
|
||||
|
||||
void LEDSetFuncById(uint8_t Mask, LEDHookEnum Function)
|
||||
@@ -146,10 +146,10 @@ void LEDSetFuncById(uint8_t Mask, LEDHookEnum Function)
|
||||
void LEDGetFuncByName(uint8_t Mask, char* Function, uint16_t BufferSize)
|
||||
{
|
||||
if (Mask == LED_GREEN) {
|
||||
MapIdToText(LEDFunctionMap, sizeof(LEDFunctionMap)/sizeof(*LEDFunctionMap),
|
||||
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
|
||||
GlobalSettings.ActiveSettingPtr->LEDGreenFunction, Function, BufferSize);
|
||||
} else if (Mask == LED_RED) {
|
||||
MapIdToText(LEDFunctionMap, sizeof(LEDFunctionMap)/sizeof(*LEDFunctionMap),
|
||||
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
|
||||
GlobalSettings.ActiveSettingPtr->LEDRedFunction, Function, BufferSize);
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ bool LEDSetFuncByName(uint8_t Mask, const char* Function)
|
||||
{
|
||||
MapIdType Id;
|
||||
|
||||
if (MapTextToId(LEDFunctionMap, sizeof(LEDFunctionMap)/sizeof(*LEDFunctionMap), Function, &Id)) {
|
||||
if (MapTextToId(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap), Function, &Id)) {
|
||||
LEDSetFuncById(Mask, Id);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -172,8 +172,7 @@ bool LogSetModeByName(const char* Mode)
|
||||
{
|
||||
MapIdType Id;
|
||||
|
||||
if (MapTextToId(LogModeMap, sizeof(LogModeMap)/sizeof(*LogModeMap),
|
||||
Mode, &Id)) {
|
||||
if (MapTextToId(LogModeMap, ARRAY_COUNT(LogModeMap), Mode, &Id)) {
|
||||
LogSetModeById(Id);
|
||||
return true;
|
||||
}
|
||||
@@ -183,13 +182,13 @@ bool LogSetModeByName(const char* Mode)
|
||||
|
||||
void LogGetModeByName(char* Mode, uint16_t BufferSize)
|
||||
{
|
||||
MapIdToText(LogModeMap, sizeof(LogModeMap)/sizeof(*LogModeMap),
|
||||
MapIdToText(LogModeMap, ARRAY_COUNT(LogModeMap),
|
||||
GlobalSettings.ActiveSettingPtr->LogMode, Mode, BufferSize);
|
||||
}
|
||||
|
||||
void LogGetModeList(char* List, uint16_t BufferSize)
|
||||
{
|
||||
MapToString(LogModeMap, sizeof(LogModeMap)/sizeof(*LogModeMap), List, BufferSize);
|
||||
MapToString(LogModeMap, ARRAY_COUNT(LogModeMap), List, BufferSize);
|
||||
}
|
||||
|
||||
void LogSRAMToFRAM(void)
|
||||
|
||||
@@ -341,7 +341,7 @@ static const char* GetStatusMessageP(CommandStatusIdType StatusId)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i=0; i<(sizeof(StatusTable)/sizeof(*StatusTable)); i++) {
|
||||
for (i = 0; i < ARRAY_COUNT(StatusTable); i++) {
|
||||
if (pgm_read_byte(&StatusTable[i].Id) == StatusId)
|
||||
return StatusTable[i].Message;
|
||||
}
|
||||
@@ -409,7 +409,7 @@ static void DecodeCommand(void)
|
||||
*pCommandDelimiter = '\0';
|
||||
|
||||
/* Search in command table */
|
||||
for (i=0; i<(sizeof(CommandTable) / sizeof(*CommandTable)); i++) {
|
||||
for (i = 0; i < ARRAY_COUNT(CommandTable); i++) {
|
||||
if (strcmp_P(pTerminalBuffer, CommandTable[i].Command) == 0) {
|
||||
/* Command found. Clear buffer, and call appropriate function */
|
||||
char* pParam = ++pCommandDelimiter;
|
||||
@@ -451,8 +451,7 @@ bool CommandLineProcessByte(uint8_t Byte) {
|
||||
}
|
||||
|
||||
/* Prevent buffer overflow and account for '\0' */
|
||||
if (BufferIdx
|
||||
< (sizeof(TerminalBuffer) / sizeof(*TerminalBuffer) - 1)) {
|
||||
if (BufferIdx < TERMINAL_BUFFER_SIZE - 1) {
|
||||
TerminalBuffer[BufferIdx++] = Byte;
|
||||
}
|
||||
} else if (Byte == '\r') {
|
||||
@@ -529,25 +528,25 @@ void CommandLineAppendData(void const * const Buffer, uint16_t Bytes)
|
||||
char* pTerminalBuffer = (char*) TerminalBuffer;
|
||||
|
||||
uint16_t tmpBytes = Bytes;
|
||||
if (Bytes > (sizeof(TerminalBuffer) / 2))
|
||||
tmpBytes = sizeof(TerminalBuffer) / 2;
|
||||
if (Bytes > (TERMINAL_BUFFER_SIZE / 2))
|
||||
tmpBytes = TERMINAL_BUFFER_SIZE / 2;
|
||||
Bytes -= tmpBytes;
|
||||
|
||||
BufferToHexString(pTerminalBuffer, sizeof(TerminalBuffer), Buffer, tmpBytes);
|
||||
BufferToHexString(pTerminalBuffer, TERMINAL_BUFFER_SIZE, Buffer, tmpBytes);
|
||||
TerminalSendString(pTerminalBuffer);
|
||||
|
||||
uint8_t i = 1;
|
||||
while (Bytes > (sizeof(TerminalBuffer) / 2))
|
||||
while (Bytes > (TERMINAL_BUFFER_SIZE / 2))
|
||||
{
|
||||
Bytes -= sizeof(TerminalBuffer) / 2;
|
||||
BufferToHexString(pTerminalBuffer, sizeof(TerminalBuffer), Buffer + i * sizeof(TerminalBuffer) / 2, sizeof(TerminalBuffer));
|
||||
Bytes -= TERMINAL_BUFFER_SIZE / 2;
|
||||
BufferToHexString(pTerminalBuffer, TERMINAL_BUFFER_SIZE, Buffer + i * TERMINAL_BUFFER_SIZE / 2, TERMINAL_BUFFER_SIZE);
|
||||
TerminalSendString(pTerminalBuffer);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (Bytes > 0)
|
||||
{
|
||||
BufferToHexString(pTerminalBuffer, sizeof(TerminalBuffer), Buffer + i * sizeof(TerminalBuffer) / 2, Bytes);
|
||||
BufferToHexString(pTerminalBuffer, TERMINAL_BUFFER_SIZE, Buffer + i * TERMINAL_BUFFER_SIZE / 2, Bytes);
|
||||
TerminalSendString(pTerminalBuffer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user