Rework Cmd exposed API, use more static and fix [-Wmissing-prototypes], ongoing...

This commit is contained in:
Philippe Teuwen 2019-04-12 00:38:54 +02:00
commit 7d48ad19f9
42 changed files with 865 additions and 872 deletions

View file

@ -37,38 +37,6 @@ static int usage_lf_viking_sim(void) {
return 0;
}
// calc checksum
static uint64_t getVikingBits(uint32_t id) {
uint8_t checksum = ((id >> 24) & 0xFF) ^ ((id >> 16) & 0xFF) ^ ((id >> 8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
uint64_t ret = (uint64_t)0xF2 << 56;
ret |= (uint64_t)id << 8;
ret |= checksum;
return ret;
}
// by marshmellow
// find viking preamble 0xF200 in already demoded data
int detectViking(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 64 * 2) return -2;
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
uint32_t checkCalc = bytebits_to_byte(dest + startIdx, 8) ^
bytebits_to_byte(dest + startIdx + 8, 8) ^
bytebits_to_byte(dest + startIdx + 16, 8) ^
bytebits_to_byte(dest + startIdx + 24, 8) ^
bytebits_to_byte(dest + startIdx + 32, 8) ^
bytebits_to_byte(dest + startIdx + 40, 8) ^
bytebits_to_byte(dest + startIdx + 48, 8) ^
bytebits_to_byte(dest + startIdx + 56, 8);
if (checkCalc != 0xA8) return -5;
if (*size != 64) return -6;
//return start position
return (int)startIdx;
}
//by marshmellow
//see ASKDemod for what args are accepted
int CmdVikingDemod(const char *Cmd) {
@ -178,3 +146,40 @@ int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
// calc checksum
uint64_t getVikingBits(uint32_t id) {
uint8_t checksum = ((id >> 24) & 0xFF) ^ ((id >> 16) & 0xFF) ^ ((id >> 8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
uint64_t ret = (uint64_t)0xF2 << 56;
ret |= (uint64_t)id << 8;
ret |= checksum;
return ret;
}
// by marshmellow
// find viking preamble 0xF200 in already demoded data
int detectViking(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 64 * 2) return -2;
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
return -4; //preamble not found
uint32_t checkCalc = bytebits_to_byte(dest + startIdx, 8) ^
bytebits_to_byte(dest + startIdx + 8, 8) ^
bytebits_to_byte(dest + startIdx + 16, 8) ^
bytebits_to_byte(dest + startIdx + 24, 8) ^
bytebits_to_byte(dest + startIdx + 32, 8) ^
bytebits_to_byte(dest + startIdx + 40, 8) ^
bytebits_to_byte(dest + startIdx + 48, 8) ^
bytebits_to_byte(dest + startIdx + 56, 8);
if (checkCalc != 0xA8) return -5;
if (*size != 64) return -6;
//return start position
return (int)startIdx;
}
int demodViking(void) {
return CmdVikingDemod("");
}