* improved serial console

* repaired /save
* removed yields (not allowed with async-web)
This commit is contained in:
lumapu 2022-09-08 22:52:51 +02:00
parent c32927a94e
commit 4561655d9d
9 changed files with 88 additions and 60 deletions

View file

@ -5,34 +5,31 @@
#include "crc.h"
namespace Hoymiles {
uint8_t crc8(uint8_t buf[], uint8_t len) {
uint8_t crc = CRC8_INIT;
for(uint8_t i = 0; i < len; i++) {
crc ^= buf[i];
for(uint8_t b = 0; b < 8; b ++) {
crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00);
namespace Ahoy {
uint8_t crc8(uint8_t buf[], uint8_t len) {
uint8_t crc = CRC8_INIT;
for(uint8_t i = 0; i < len; i++) {
crc ^= buf[i];
for(uint8_t b = 0; b < 8; b ++) {
crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00);
}
}
yield();
return crc;
}
return crc;
}
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
uint16_t crc = start;
uint8_t shift = 0;
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) {
uint16_t crc = start;
uint8_t shift = 0;
for(uint8_t i = 0; i < len; i ++) {
crc = crc ^ buf[i];
for(uint8_t bit = 0; bit < 8; bit ++) {
shift = (crc & 0x0001);
crc = crc >> 1;
if(shift != 0)
crc = crc ^ CRC16_MODBUS_POLYNOM;
for(uint8_t i = 0; i < len; i ++) {
crc = crc ^ buf[i];
for(uint8_t bit = 0; bit < 8; bit ++) {
shift = (crc & 0x0001);
crc = crc >> 1;
if(shift != 0)
crc = crc ^ CRC16_MODBUS_POLYNOM;
}
}
yield();
return crc;
}
return crc;
}
} // namespace Hoymiles