forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Lee
committed
Jan 4, 2024
1 parent
50bf4fc
commit 65b7247
Showing
4 changed files
with
96 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "meal_pager_calc.h" | ||
|
||
void customConcat(char* dest, const char* src) { | ||
// Find the end of the destination string | ||
while (*dest != '\0') { | ||
dest++; | ||
} | ||
|
||
// Copy characters from src to dest | ||
while (*src != '\0') { | ||
*dest = *src; | ||
dest++; | ||
src++; | ||
} | ||
|
||
// Null-terminate the concatenated string | ||
*dest = '\0'; | ||
} | ||
|
||
char* encManchester(const char* bits, int mode) { | ||
// Allocate memory for the result string | ||
char* res = (char*)malloc((strlen(bits) * 2 + 1) * sizeof(char)); | ||
|
||
int index = 0; | ||
for (int i = 0; bits[i] != '\0'; i++) { | ||
char c = bits[i]; | ||
if (c == '0') { | ||
if (mode) { | ||
res[index++] = '1'; | ||
res[index++] = '0'; | ||
} else { | ||
res[index++] = '0'; | ||
res[index++] = '1'; | ||
} | ||
} else if (c == '1') { | ||
if (mode) { | ||
res[index++] = '0'; | ||
res[index++] = '1'; | ||
} else { | ||
res[index++] = '1'; | ||
res[index++] = '0'; | ||
} | ||
} else { | ||
// Handle 'EE' case (error) | ||
res[index++] = 'E'; | ||
res[index++] = 'E'; | ||
} | ||
} | ||
|
||
// Null-terminate the result string | ||
res[index] = '\0'; | ||
|
||
return res; | ||
} | ||
|
||
void uint32ToBinaray(uint32_t number, char* str, int8_t length) { | ||
int i = 0; | ||
length--; // count length without 0 | ||
for (i = length; i >= 0; i--) { | ||
// Bitwise AND extration of the i-th bit | ||
int bit = (number >> i) & 1; | ||
// convert the bit to a character of 1 or 0 | ||
str[length - i] = bit + '0'; | ||
} | ||
// Terminate the string | ||
str[length+1] = '\0'; | ||
} | ||
|
||
void reverse(char* str) { | ||
int length = strlen(str); | ||
int start = 0; | ||
int end = length - 1; | ||
while (start < end) { | ||
char temp = str[start]; | ||
str[start] = str[end]; | ||
str[end] = temp; | ||
start++; | ||
end--; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
#pragma once | ||
|
||
#include "../meal_pager_i.h" | ||
|
||
char* encManchester(const char* bits, int mode); | ||
|
||
void uint32ToBinaray(uint32_t number, char* str, int8_t length); | ||
|
||
void reverse(char* str); | ||
|
||
void customConcat(char* dest, const char* src); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters