support fct

This commit is contained in:
iceman1001 2023-10-15 11:24:48 +02:00
commit a348d58c6d
2 changed files with 31 additions and 0 deletions

View file

@ -1048,6 +1048,36 @@ int binstring2binarray(uint8_t *target, char *source, int length) {
return count; return count;
} }
void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src) {
size_t binlen = strlen(src);
if (binlen == 0) {
*targetlen = 0;
return;
}
// Calculate padding needed
size_t padding = (8 - (binlen % 8)) % 8;
// Determine the size of the hexadecimal array
*targetlen = (binlen + padding) / 8;
uint8_t b = 0;
size_t bit_cnt = padding;
size_t idx = 0;
// Process binary string
for (size_t i = 0; i < binlen; ++i) {
b = (b << 1) | (src[i] == '1');
++bit_cnt;
if (bit_cnt == 8) {
target[idx++] = b;
b = 0;
bit_cnt = 0;
}
}
}
// return parity bit required to match type // return parity bit required to match type
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length) { uint8_t GetParity(const uint8_t *bits, uint8_t type, int length) {
int x; int x;

View file

@ -123,6 +123,7 @@ void binarraytobinstring(char *target, char *source, int length);
int binstring2binarray(uint8_t *target, char *source, int length); int binstring2binarray(uint8_t *target, char *source, int length);
void byte_2_binstr(char *target, const uint8_t *source, size_t sourcelen); void byte_2_binstr(char *target, const uint8_t *source, size_t sourcelen);
void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src);
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length); uint8_t GetParity(const uint8_t *bits, uint8_t type, int length);
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length); void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);