mirror of
https://github.com/thelsing/knx.git
synced 2026-03-13 02:22:13 +01:00
astyle
This commit is contained in:
@@ -16,18 +16,21 @@ int FdskCalculator::snprintFdsk(char* str, int strSize, uint8_t* serialNumber, u
|
||||
|
||||
for (int i = 0; i < 36; i++)
|
||||
{
|
||||
if (((i % 6) == 0) && (i!=0))
|
||||
if (((i % 6) == 0) && (i != 0))
|
||||
{
|
||||
*(str+written++) = '-';
|
||||
if (written >= strSize-1)
|
||||
*(str + written++) = '-';
|
||||
|
||||
if (written >= strSize - 1)
|
||||
break;
|
||||
}
|
||||
*(str+written++) = tmpStr[i];
|
||||
if (written >= strSize-1)
|
||||
|
||||
*(str + written++) = tmpStr[i];
|
||||
|
||||
if (written >= strSize - 1)
|
||||
break;
|
||||
}
|
||||
|
||||
*(str+written++) = '\0';
|
||||
*(str + written++) = '\0';
|
||||
|
||||
delete[] tmpStr;
|
||||
|
||||
@@ -39,7 +42,7 @@ char* FdskCalculator::generateFdskString(uint8_t* serialNumber, uint8_t* key)
|
||||
uint8_t buffer[6 + 16 + 1]; // 6 bytes serialnumber + 16 bytes key + 1 byte placeholder for crc-4
|
||||
memcpy(&buffer[0], serialNumber, 6);
|
||||
memcpy(&buffer[6], key, 16);
|
||||
buffer[22] = (crc4Array(buffer, sizeof(buffer)-1)<<4) &0xFF;
|
||||
buffer[22] = (crc4Array(buffer, sizeof(buffer) - 1) << 4) & 0xFF;
|
||||
|
||||
uint8_t* outEncoded = nullptr;
|
||||
toBase32(buffer, sizeof(buffer), outEncoded, false);
|
||||
@@ -50,145 +53,153 @@ char* FdskCalculator::generateFdskString(uint8_t* serialNumber, uint8_t* key)
|
||||
int FdskCalculator::ceil(float num)
|
||||
{
|
||||
int inum = (int)num;
|
||||
if (num == (float)inum) {
|
||||
|
||||
if (num == (float)inum)
|
||||
{
|
||||
return inum;
|
||||
}
|
||||
|
||||
return inum + 1;
|
||||
}
|
||||
|
||||
int FdskCalculator::toBase32(uint8_t* in, long length, uint8_t*& out, bool usePadding)
|
||||
{
|
||||
char base32StandardAlphabet[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"};
|
||||
char standardPaddingChar = '=';
|
||||
char base32StandardAlphabet[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"};
|
||||
char standardPaddingChar = '=';
|
||||
|
||||
int result = 0;
|
||||
int index = 0;
|
||||
int size = 0; // size of temporary array
|
||||
uint8_t* temp = nullptr;
|
||||
int result = 0;
|
||||
int index = 0;
|
||||
int size = 0; // size of temporary array
|
||||
uint8_t* temp = nullptr;
|
||||
|
||||
if (length < 0 || length > 268435456LL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = 8 * ceil(length / 4.0); // Calculating size of temporary array. Not very precise.
|
||||
temp = new uint8_t[size];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
int buffer = in[0];
|
||||
int next = 1;
|
||||
int bitsLeft = 8;
|
||||
|
||||
while (bitsLeft > 0 || next < length)
|
||||
if (length < 0 || length > 268435456LL)
|
||||
{
|
||||
if (bitsLeft < 5)
|
||||
{
|
||||
if (next < length)
|
||||
{
|
||||
buffer <<= 8;
|
||||
buffer |= in[next] & 0xFF;
|
||||
next++;
|
||||
bitsLeft += 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
int pad = 5 - bitsLeft;
|
||||
buffer <<= pad;
|
||||
bitsLeft += pad;
|
||||
}
|
||||
}
|
||||
index = 0x1F & (buffer >> (bitsLeft -5));
|
||||
|
||||
bitsLeft -= 5;
|
||||
temp[result] = (uint8_t)base32StandardAlphabet[index];
|
||||
result++;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (usePadding)
|
||||
{
|
||||
int pads = (result % 8);
|
||||
if (pads > 0)
|
||||
size = 8 * ceil(length / 4.0); // Calculating size of temporary array. Not very precise.
|
||||
temp = new uint8_t[size];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
pads = (8 - pads);
|
||||
for (int i = 0; i < pads; i++)
|
||||
{
|
||||
temp[result] = standardPaddingChar;
|
||||
result++;
|
||||
}
|
||||
int buffer = in[0];
|
||||
int next = 1;
|
||||
int bitsLeft = 8;
|
||||
|
||||
while (bitsLeft > 0 || next < length)
|
||||
{
|
||||
if (bitsLeft < 5)
|
||||
{
|
||||
if (next < length)
|
||||
{
|
||||
buffer <<= 8;
|
||||
buffer |= in[next] & 0xFF;
|
||||
next++;
|
||||
bitsLeft += 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
int pad = 5 - bitsLeft;
|
||||
buffer <<= pad;
|
||||
bitsLeft += pad;
|
||||
}
|
||||
}
|
||||
|
||||
index = 0x1F & (buffer >> (bitsLeft - 5));
|
||||
|
||||
bitsLeft -= 5;
|
||||
temp[result] = (uint8_t)base32StandardAlphabet[index];
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out = new uint8_t[result];
|
||||
if (usePadding)
|
||||
{
|
||||
int pads = (result % 8);
|
||||
|
||||
memcpy(out, temp, result);
|
||||
delete [] temp;
|
||||
if (pads > 0)
|
||||
{
|
||||
pads = (8 - pads);
|
||||
|
||||
return result;
|
||||
for (int i = 0; i < pads; i++)
|
||||
{
|
||||
temp[result] = standardPaddingChar;
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out = new uint8_t[result];
|
||||
|
||||
memcpy(out, temp, result);
|
||||
delete [] temp;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int FdskCalculator::fromBase32(uint8_t* in, long length, uint8_t*& out)
|
||||
{
|
||||
int result = 0; // Length of the array of decoded values.
|
||||
int buffer = 0;
|
||||
int bitsLeft = 0;
|
||||
uint8_t* temp = NULL;
|
||||
int result = 0; // Length of the array of decoded values.
|
||||
int buffer = 0;
|
||||
int bitsLeft = 0;
|
||||
uint8_t* temp = NULL;
|
||||
|
||||
temp = new uint8_t[length]; // Allocating temporary array.
|
||||
temp = new uint8_t[length]; // Allocating temporary array.
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
uint8_t ch = in[i];
|
||||
|
||||
// ignoring some characters: ' ', '\t', '\r', '\n', '='
|
||||
if (ch == 0xA0 || ch == 0x09 || ch == 0x0A || ch == 0x0D || ch == 0x3D)
|
||||
continue;
|
||||
|
||||
// recovering mistyped: '0' -> 'O', '1' -> 'L', '8' -> 'B'
|
||||
if (ch == 0x30)
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
ch = 0x4F;
|
||||
}
|
||||
else if (ch == 0x31)
|
||||
{
|
||||
ch = 0x4C;
|
||||
}
|
||||
else if (ch == 0x38)
|
||||
{
|
||||
ch = 0x42;
|
||||
}
|
||||
uint8_t ch = in[i];
|
||||
|
||||
// ignoring some characters: ' ', '\t', '\r', '\n', '='
|
||||
if (ch == 0xA0 || ch == 0x09 || ch == 0x0A || ch == 0x0D || ch == 0x3D)
|
||||
continue;
|
||||
|
||||
// recovering mistyped: '0' -> 'O', '1' -> 'L', '8' -> 'B'
|
||||
if (ch == 0x30)
|
||||
{
|
||||
ch = 0x4F;
|
||||
}
|
||||
else if (ch == 0x31)
|
||||
{
|
||||
ch = 0x4C;
|
||||
}
|
||||
else if (ch == 0x38)
|
||||
{
|
||||
ch = 0x42;
|
||||
}
|
||||
|
||||
|
||||
// look up one base32 symbols: from 'A' to 'Z' or from 'a' to 'z' or from '2' to '7'
|
||||
if ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))
|
||||
{
|
||||
ch = ((ch & 0x1F) - 1);
|
||||
}
|
||||
else if (ch >= 0x32 && ch <= 0x37)
|
||||
{
|
||||
ch -= (0x32 - 26);
|
||||
}
|
||||
else {
|
||||
delete [] temp;
|
||||
return 0;
|
||||
// look up one base32 symbols: from 'A' to 'Z' or from 'a' to 'z' or from '2' to '7'
|
||||
if ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))
|
||||
{
|
||||
ch = ((ch & 0x1F) - 1);
|
||||
}
|
||||
else if (ch >= 0x32 && ch <= 0x37)
|
||||
{
|
||||
ch -= (0x32 - 26);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete [] temp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer <<= 5;
|
||||
buffer |= ch;
|
||||
bitsLeft += 5;
|
||||
|
||||
if (bitsLeft >= 8)
|
||||
{
|
||||
temp[result] = (unsigned char)((unsigned int)(buffer >> (bitsLeft - 8)) & 0xFF);
|
||||
result++;
|
||||
bitsLeft -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
buffer <<= 5;
|
||||
buffer |= ch;
|
||||
bitsLeft += 5;
|
||||
if (bitsLeft >= 8)
|
||||
{
|
||||
temp[result] = (unsigned char)((unsigned int)(buffer >> (bitsLeft - 8)) & 0xFF);
|
||||
result++;
|
||||
bitsLeft -= 8;
|
||||
}
|
||||
}
|
||||
out = new uint8_t[result];
|
||||
memcpy(out, temp, result);
|
||||
delete [] temp;
|
||||
|
||||
out = new uint8_t[result];
|
||||
memcpy(out, temp, result);
|
||||
delete [] temp;
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,34 +4,38 @@
|
||||
|
||||
class FdskCalculator
|
||||
{
|
||||
public:
|
||||
int snprintFdsk(char* str, int strSize, uint8_t* serialNumber, uint8_t* key);
|
||||
public:
|
||||
int snprintFdsk(char* str, int strSize, uint8_t* serialNumber, uint8_t* key);
|
||||
|
||||
private:
|
||||
char* generateFdskString(uint8_t* serialNumber, uint8_t* key);
|
||||
private:
|
||||
char* generateFdskString(uint8_t* serialNumber, uint8_t* key);
|
||||
|
||||
int toBase32(uint8_t* in, long length, uint8_t*& out, bool usePadding);
|
||||
int fromBase32(uint8_t* in, long length, uint8_t*& out);
|
||||
int toBase32(uint8_t* in, long length, uint8_t*& out, bool usePadding);
|
||||
int fromBase32(uint8_t* in, long length, uint8_t*& out);
|
||||
|
||||
uint8_t crc4Array(uint8_t* data, uint8_t len) {
|
||||
uint8_t start = 0;
|
||||
for (uint8_t i = 0; i <len; i++)
|
||||
uint8_t crc4Array(uint8_t* data, uint8_t len)
|
||||
{
|
||||
start = crc4(start, data[i]);
|
||||
uint8_t start = 0;
|
||||
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
{
|
||||
start = crc4(start, data[i]);
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
uint8_t crc4(uint8_t c, uint8_t x) {
|
||||
uint8_t low4Bits = x & 0x0F;
|
||||
uint8_t high4Bits = x >> 4;
|
||||
c = crc4_tab[c ^ high4Bits];
|
||||
c = crc4_tab[c ^ low4Bits];
|
||||
uint8_t crc4(uint8_t c, uint8_t x)
|
||||
{
|
||||
uint8_t low4Bits = x & 0x0F;
|
||||
uint8_t high4Bits = x >> 4;
|
||||
c = crc4_tab[c ^ high4Bits];
|
||||
c = crc4_tab[c ^ low4Bits];
|
||||
|
||||
return c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int ceil(float num);
|
||||
int ceil(float num);
|
||||
|
||||
static const uint8_t crc4_tab[16];
|
||||
static const uint8_t crc4_tab[16];
|
||||
};
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
volatile sig_atomic_t loopActive = 1;
|
||||
void signalHandler(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
(void)sig;
|
||||
|
||||
// can be called asynchronously
|
||||
loopActive = 0;
|
||||
// can be called asynchronously
|
||||
loopActive = 0;
|
||||
}
|
||||
|
||||
bool sendHidReport(uint8_t* data, uint16_t length)
|
||||
@@ -39,13 +39,13 @@ bool isSendHidReportPossible()
|
||||
}
|
||||
|
||||
#if MASK_VERSION == 0x57B0
|
||||
KnxFacade<LinuxPlatform, Bau57B0> knx;
|
||||
KnxFacade<LinuxPlatform, Bau57B0> knx;
|
||||
#elif MASK_VERSION == 0x27B0
|
||||
KnxFacade<LinuxPlatform, Bau27B0> knx;
|
||||
KnxFacade<LinuxPlatform, Bau27B0> knx;
|
||||
#elif MASK_VERSION == 0x07B0
|
||||
KnxFacade<LinuxPlatform, Bau07B0> knx;
|
||||
KnxFacade<LinuxPlatform, Bau07B0> knx;
|
||||
#else
|
||||
#error Mask version not supported yet!
|
||||
#error Mask version not supported yet!
|
||||
#endif
|
||||
|
||||
long lastsend = 0;
|
||||
@@ -58,6 +58,7 @@ long lastsend = 0;
|
||||
void measureTemp()
|
||||
{
|
||||
long now = millis();
|
||||
|
||||
if ((now - lastsend) < 10000)
|
||||
return;
|
||||
|
||||
@@ -68,10 +69,11 @@ void measureTemp()
|
||||
currentValue -= 50;
|
||||
// currentValue *= (670433.28 + 273);
|
||||
// currentValue -= 273;
|
||||
LOGGER.info("current value: %f",currentValue);
|
||||
LOGGER.info("current value: %f", currentValue);
|
||||
GO_CURR.value<Dpt9>(currentValue);
|
||||
|
||||
float max = GO_MAX.value<Dpt9>();
|
||||
|
||||
if (currentValue > max)
|
||||
GO_MAX.value<Dpt9>(currentValue);
|
||||
|
||||
@@ -92,7 +94,7 @@ void appLoop()
|
||||
{
|
||||
if (!knx.configured())
|
||||
return;
|
||||
|
||||
|
||||
measureTemp();
|
||||
}
|
||||
|
||||
@@ -122,10 +124,11 @@ void setup()
|
||||
}
|
||||
else
|
||||
LOGGER.info("not configured");
|
||||
|
||||
knx.start();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
LOGGER.info("main() start.");
|
||||
|
||||
@@ -151,12 +154,14 @@ int main(int argc, char **argv)
|
||||
knx.platform().cmdLineArgs(argc, argv);
|
||||
|
||||
setup();
|
||||
|
||||
|
||||
while (loopActive)
|
||||
{
|
||||
knx.loop();
|
||||
if(knx.configured())
|
||||
|
||||
if (knx.configured())
|
||||
appLoop();
|
||||
|
||||
delayMicroseconds(100);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user