mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-10-27 06:21:26 +00:00
[Cleanup] Simplify removing chars/texts from strings
This commit is contained in:
1 parent
620ec51738
commit
03965a95c7
37 files changed
+151
-34
No files matched your search
+3
-5
@@ -337,8 +337,8 @@ void DeleteNotNeededValues(String& s, uint8_t numberOfValuesWanted)
|
||||
if (i < numberOfValuesWanted)
|
||||
{
|
||||
// yes, so just remove the tokens
|
||||
s.replace(startToken, EMPTY_STRING);
|
||||
s.replace(endToken, EMPTY_STRING);
|
||||
remove(s, startToken);
|
||||
remove(s, endToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -348,10 +348,8 @@ void DeleteNotNeededValues(String& s, uint8_t numberOfValuesWanted)
|
||||
|
||||
while (startIndex != -1 && endIndex != -1 && endIndex > startIndex)
|
||||
{
|
||||
String p = s.substring(startIndex, endIndex + 4);
|
||||
|
||||
// remove the whole string including tokens
|
||||
s.replace(p, EMPTY_STRING);
|
||||
remove(s, s.substring(startIndex, endIndex + 4));
|
||||
|
||||
// find next ones
|
||||
startIndex = s.indexOf(startToken);
|
||||
|
||||
@@ -110,7 +110,7 @@ bool C023_data_struct::txHexBytes(const String& data, uint8_t port) {
|
||||
if (!isInitialized()) { return false; }
|
||||
bool res = true;
|
||||
String sendData = data;
|
||||
sendData.replace(F(" "), F(""));
|
||||
removeSpace(sendData);
|
||||
sendData.trim();
|
||||
|
||||
if (_loraModule == C023_AT_commands::LoRaModule_e::Dragino_LA66) {
|
||||
|
||||
@@ -22,6 +22,7 @@ void FactoryDefault_UnitName_NVS::applyToSettings() const {
|
||||
Settings.Unit = data[0];
|
||||
memcpy(Settings.Name, (char *)(data + 2), sizeof(Settings.Name));
|
||||
|
||||
// TODO TD-er: Settings.UDPPort = getUint16FromBigEndianByteStream(&data[2 + sizeof(Settings.Name)]);
|
||||
Settings.UDPPort = data[2 + sizeof(Settings.Name)] << 8 | data[3 + sizeof(Settings.Name)];
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ NTP_packet::NTP_packet()
|
||||
|
||||
uint32_t NTP_packet::readWord(uint8_t startIndex) const
|
||||
{
|
||||
// TODO TD-er: return getUlFromBigEndianByteStream(&data[startIndex], 4);
|
||||
uint32_t res{};
|
||||
|
||||
res = (uint32_t)data[startIndex] << 24;
|
||||
|
||||
@@ -974,7 +974,7 @@ void substitute_eventvalue(String& line, const String& event) {
|
||||
log += percent_pos;
|
||||
addLog(LOG_LEVEL_ERROR, log);
|
||||
}
|
||||
line.replace(F("%eventvalue"), F(""));
|
||||
remove(line, F("%eventvalue"));
|
||||
} else {
|
||||
// Find the optional part for a default value when the asked for eventvalue does not exist.
|
||||
// Syntax: %eventvalueX|Y%
|
||||
@@ -1010,7 +1010,7 @@ void substitute_eventvalue(String& line, const String& event) {
|
||||
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
|
||||
addLog(LOG_LEVEL_ERROR, concat(F("Rules : Syntax error, invalid variable: "), eventvalue));
|
||||
}
|
||||
line.replace(eventvalue, EMPTY_STRING);
|
||||
remove(line, eventvalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,6 +512,7 @@ Dallas_read_result Dallas_readTemp(const uint8_t ROM[8], float *value, int8_t gp
|
||||
|| (ROM[0] == 0x22) // DS1822
|
||||
|| (ROM[0] == 0x42)) // DS28EA00
|
||||
{
|
||||
// TODO TD-er: Use getUint16FromLittleEndianByteStream
|
||||
DSTemp = (ScratchPad[1] << 8) + ScratchPad[0];
|
||||
|
||||
if (DSTemp == 0x550) { // power-on reset value
|
||||
|
||||
@@ -78,9 +78,8 @@ void Improv_Helper_t::update()
|
||||
{
|
||||
String firmwareName = get_binary_filename();
|
||||
const String buildString = getSystemBuildString();
|
||||
|
||||
firmwareName.replace(F("ESP_Easy_mega_"), F(""));
|
||||
firmwareName.replace(buildString, F(""));
|
||||
remove(firmwareName, F("ESP_Easy_mega_"));
|
||||
remove(firmwareName, buildString);
|
||||
firmwareName.replace('_', ' ');
|
||||
|
||||
// Remove chip variant from the name
|
||||
@@ -90,7 +89,7 @@ void Improv_Helper_t::update()
|
||||
const int endpos = firmwareName.indexOf(' ', pos);
|
||||
|
||||
if (endpos != -1) {
|
||||
firmwareName.replace(firmwareName.substring(pos, endpos), F(""));
|
||||
remove(firmwareName, firmwareName.substring(pos, endpos));
|
||||
}
|
||||
}
|
||||
firmwareName.replace(F(" "), F(" "));
|
||||
|
||||
@@ -21,6 +21,43 @@
|
||||
# include <SD.h>
|
||||
#endif // if FEATURE_SD
|
||||
|
||||
|
||||
// Typical use case: data[i] << 24 | data[i + 1] << 16 | data[i + 2] << 8 | data[i + 3]
|
||||
uint32_t getUlFromBigEndianByteStream(const uint8_t* data, uint8_t nrBytes)
|
||||
{
|
||||
uint32_t res{};
|
||||
if (nrBytes > 4) nrBytes = 4;
|
||||
for (uint8_t i = 0; i < nrBytes; ++i)
|
||||
{
|
||||
res <<= 8;
|
||||
res |= data[i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
uint16_t getUint16FromBigEndianByteStream(const uint8_t* data)
|
||||
{
|
||||
return (data[0] << 8) | data[1];
|
||||
}
|
||||
|
||||
// Typical use case: data[i + 3] << 24 | data[i + 2] << 16 | data[i + 1] << 8 | data[i + 0]
|
||||
uint32_t getUlFromLittleEndianByteStream(const uint8_t* data, uint8_t nrBytes)
|
||||
{
|
||||
uint32_t res{};
|
||||
if (nrBytes > 4) nrBytes = 4;
|
||||
while (nrBytes) {
|
||||
--nrBytes;
|
||||
res <<= 8;
|
||||
res |= data[nrBytes];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
uint16_t getUint16FromLittleEndianByteStream(const uint8_t* data)
|
||||
{
|
||||
return (data[1] << 8) | data[0];
|
||||
}
|
||||
|
||||
bool remoteConfig(struct EventStruct *event, const String& string)
|
||||
{
|
||||
// FIXME TD-er: Why have an event here as argument? It is not used.
|
||||
|
||||
@@ -34,6 +34,13 @@
|
||||
#define get2BitFromUL(number, bitnr) getNBitFromUL(number, bitnr, 0x03UL)
|
||||
|
||||
|
||||
uint32_t getUlFromBigEndianByteStream(const uint8_t* data, uint8_t nrBytes);
|
||||
uint16_t getUint16FromBigEndianByteStream(const uint8_t* data);
|
||||
|
||||
uint32_t getUlFromLittleEndianByteStream(const uint8_t* data, uint8_t nrBytes);
|
||||
uint16_t getUint16FromLittleEndianByteStream(const uint8_t* data);
|
||||
|
||||
|
||||
bool remoteConfig(struct EventStruct *event,
|
||||
const String & string);
|
||||
|
||||
|
||||
@@ -663,6 +663,7 @@ int ModbusRTU_struct::process_16b_register(uint8_t slaveAddress, uint8_t functio
|
||||
errorcode = processCommand();
|
||||
|
||||
if (errorcode == 0) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
return (_recv_buf[3] << 8) | (_recv_buf[4]);
|
||||
}
|
||||
logModbusException(errorcode);
|
||||
@@ -675,6 +676,7 @@ int ModbusRTU_struct::preset_mult16b_register(uint8_t slaveAddress, uint16_t sta
|
||||
const uint8_t process_result = processCommand();
|
||||
|
||||
if (process_result == 0) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
return (_recv_buf[4] << 8) | (_recv_buf[5]);
|
||||
}
|
||||
logModbusException(process_result);
|
||||
|
||||
@@ -76,6 +76,28 @@ String concat(const char& str, const String &val)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool remove(String& str, const String& toRemove)
|
||||
{
|
||||
const size_t origSize = str.length();
|
||||
str.replace(toRemove, EMPTY_STRING);
|
||||
return origSize > str.length();
|
||||
}
|
||||
|
||||
bool remove(String& str, const __FlashStringHelper * toRemove)
|
||||
{
|
||||
return remove(str, String(toRemove));
|
||||
}
|
||||
|
||||
bool remove(String& str, const char& toRemove)
|
||||
{
|
||||
return remove(str, String(toRemove));
|
||||
}
|
||||
|
||||
bool removeSpace(String& str)
|
||||
{
|
||||
return remove(str, ' ');
|
||||
}
|
||||
|
||||
bool equals(const String& str, const __FlashStringHelper * f_str) {
|
||||
return str.equals(String(f_str));
|
||||
}
|
||||
@@ -276,7 +298,7 @@ void removeExtraNewLine(String& line) {
|
||||
}
|
||||
|
||||
void removeChar(String& line, char character) {
|
||||
line.replace(String(character), EMPTY_STRING);
|
||||
line.replace(character, ' ');
|
||||
}
|
||||
|
||||
void addNewLine(String& line) {
|
||||
|
||||
@@ -52,6 +52,11 @@ String concat(const String& str, const T &val) {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool remove(String& str, const String& toRemove);
|
||||
bool remove(String& str, const __FlashStringHelper * toRemove);
|
||||
bool remove(String& str, const char& toRemove);
|
||||
bool removeSpace(String& str);
|
||||
|
||||
bool equals(const String& str, const __FlashStringHelper * f_str);
|
||||
bool equals(const String& str, const char& c);
|
||||
|
||||
|
||||
@@ -425,8 +425,7 @@ String formatToHex_no_prefix(unsigned long value, unsigned int minimal_hex_digit
|
||||
String formatHumanReadable(uint64_t value,
|
||||
uint32_t factor) {
|
||||
String result = formatHumanReadable(value, factor, 2);
|
||||
|
||||
result.replace(F(".00"), EMPTY_STRING);
|
||||
remove(result, F(".00"));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,14 +103,10 @@ String formatGpioName_ADC(int gpio_pin) {
|
||||
if (adc == 0) {
|
||||
return F("Hall Effect");
|
||||
}
|
||||
String res = F("ADC# ch?");
|
||||
res.replace(F("#"), String(adc));
|
||||
res.replace(F("?"), String(ch));
|
||||
String res = strformat(F("ADC%d ch%d"), adc, ch);
|
||||
|
||||
if (t >= 0) {
|
||||
res += F(" (T");
|
||||
res += t;
|
||||
res += ')';
|
||||
res += strformat(F(" (T%d)"), t);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -724,11 +724,11 @@ KeyValueStruct getKeyValue(LabelType::Enum label, bool extendedValue)
|
||||
}
|
||||
case LabelType::CONNECTED:
|
||||
{
|
||||
return KeyValueStruct(F("Connected"), format_msec_duration(ESPEasy::net::NetworkConnectDuration_ms()), KeyValueStruct::Format::PreFormatted);
|
||||
return KeyValueStruct(F("Connected"), format_msec_duration(ESPEasy::net::NetworkConnectDuration_ms()));
|
||||
}
|
||||
case LabelType::CONNECTED_MSEC:
|
||||
{
|
||||
return KeyValueStruct(F("Connected msec"), ESPEasy::net::NetworkConnectDuration_ms(), KeyValueStruct::Format::PreFormatted);
|
||||
return KeyValueStruct(F("Connected msec"), ESPEasy::net::NetworkConnectDuration_ms());
|
||||
}
|
||||
case LabelType::LAST_DISCONNECT_REASON:
|
||||
{
|
||||
@@ -1273,7 +1273,7 @@ String getInternalLabel(const KeyValueStruct& kv,
|
||||
char replaceSpace)
|
||||
{
|
||||
String res = kv.getID();
|
||||
if (replaceSpace != '\0') res.replace(" ", String(replaceSpace));
|
||||
if (replaceSpace != '\0') res.replace(' ', replaceSpace);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ bool ESPEasy_key_value_store::load(
|
||||
const uint8_t version = buffer[0];
|
||||
|
||||
// uint8_t[2]: ID to match, if not matched, then stop loading
|
||||
// TODO TD-er: const uint16_t id = getUint16FromLittleEndianByteStream(&buffer[1]);
|
||||
const uint16_t id = (buffer[2] << 8) | buffer[1];
|
||||
|
||||
if (id != id_to_match) {
|
||||
@@ -78,6 +79,8 @@ bool ESPEasy_key_value_store::load(
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO TD-er: const size_t payloadSize = getUlFromLittleEndianByteStream(&buffer[3], 3);
|
||||
|
||||
const size_t payloadSize = (buffer[5] << 16) | (buffer[4] << 8) | buffer[3];
|
||||
const size_t totalSize = 6 + payloadSize + 16; // header + payload + checksum
|
||||
const size_t startChecksumPos = offset_in_block + 6 + payloadSize;
|
||||
@@ -180,6 +183,7 @@ bool ESPEasy_key_value_store::load(
|
||||
loadNextFromFile = true;
|
||||
} else {
|
||||
bufPos += 4;
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
bytesLeftPartialString = (buffer[bufPos] << 8) | buffer[bufPos + 1];
|
||||
bufPos += 2;
|
||||
|
||||
|
||||
@@ -162,8 +162,8 @@ bool NPlugin_001_send(const NotificationSettingsStruct& notificationsettings, St
|
||||
}
|
||||
|
||||
// Clean up receiver address.
|
||||
tmp_ato.replace(";", ",");
|
||||
tmp_ato.replace(" ", "");
|
||||
tmp_ato.replace(';', ',');
|
||||
removeSpace(tmp_ato);
|
||||
|
||||
|
||||
String mailheader;
|
||||
|
||||
@@ -322,6 +322,7 @@ bool P005_data_struct::readDHT(struct EventStruct *event) {
|
||||
// https://github.com/arendst/Tasmota/blob/0ea36d996c2b8b519ae5aa127f1a5fea354706af/tasmota/tasmota_xsns_sensor/xsns_06_dht_v7.ino#L297
|
||||
|
||||
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
const int16_t voltage = ((dht_dat[0] << 8) | dht_dat[1]);
|
||||
|
||||
// Rough approximate of soil moisture % (based on values observed in the eWeLink app)
|
||||
|
||||
@@ -462,9 +462,9 @@ void P020_Task::rulesEngine(const String& message, struct EventStruct *event) {
|
||||
|
||||
if (_P1EventData) {
|
||||
eventString += '=';
|
||||
eventString += message; // Include entire message, may cause memory overflow!
|
||||
eventString.replace(F("\n"), F(",")); // Make it a single line, comma-separated, as much as possible
|
||||
eventString.replace(F("\r"), F("")); // We don't need no st*n carriage returns :)
|
||||
eventString += message; // Include entire message, may cause memory overflow!
|
||||
eventString.replace('\n', ','); // Make it a single line, comma-separated, as much as possible
|
||||
remove(eventString, '\r'); // We don't need no st*n carriage returns :)
|
||||
}
|
||||
break;
|
||||
} // switch
|
||||
|
||||
@@ -306,6 +306,7 @@ bool P028_data_struct::readUncompensatedData() {
|
||||
uncompensated.temperature = data_msb | data_lsb | data_xlsb;
|
||||
|
||||
/* Store the parsed register values for temperature data */
|
||||
// TODO TD-er: Use getUint16FromLittleEndianByteStream (maybe also the 2 above?)
|
||||
data_lsb = (uint32_t)BME280_data[BME280_DATA_ADDR + 6] << 8;
|
||||
data_msb = (uint32_t)BME280_data[BME280_DATA_ADDR + 7];
|
||||
uncompensated.humidity = data_msb | data_lsb;
|
||||
|
||||
@@ -310,7 +310,7 @@ void P036_data_struct::CleanEscapeCharacters(String& str, const bool ForHeaderOn
|
||||
|
||||
/***** WILL BE DEPRECATED - DO NOT USE *****/
|
||||
if (ForHeaderOnly) {
|
||||
str.replace("$", "%"); // Allow system vars to be passed to header in by using $ instead of %
|
||||
str.replace('$', '%'); // Allow system vars to be passed to header in by using $ instead of %
|
||||
}
|
||||
|
||||
/***** WILL BE DEPRECATED - DO NOT USE *****/
|
||||
|
||||
@@ -343,6 +343,7 @@ float P039_data_struct::readMax6675(struct EventStruct *event)
|
||||
transfer_n_ByteSPI(CS_pin_no, 2, &messageBuffer[0]);
|
||||
|
||||
// merge 16Bit return value from messageBuffer
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
rawvalue = ((messageBuffer[0] << 8) | messageBuffer[1]);
|
||||
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
@@ -390,6 +391,7 @@ float P039_data_struct::readMax31855(struct EventStruct *event)
|
||||
transfer_n_ByteSPI(CS_pin_no, 4, &messageBuffer[0]);
|
||||
|
||||
// merge rawvalue from 4 bytes of messageBuffer
|
||||
// TODO TD-er: Use getUlFromBigEndianByteStream
|
||||
uint32_t rawvalue =
|
||||
((static_cast<uint32_t>(messageBuffer[0]) <<
|
||||
24) |
|
||||
@@ -1137,9 +1139,11 @@ uint16_t P039_data_struct::readLM7xRegisters(int8_t l_CS_pin_no, uint8_t l_LM7xs
|
||||
transfer_n_ByteSPI(l_CS_pin_no, 8, &messageBuffer[4]);
|
||||
|
||||
// read temperature value (16 Bit)
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
l_returnValue = ((messageBuffer[4] << 8) | messageBuffer[5]);
|
||||
|
||||
// read Manufatures/Device ID (16 Bit)
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
*(l_device_id) = ((messageBuffer[8] << 8) | messageBuffer[9]);
|
||||
}
|
||||
else
|
||||
@@ -1150,9 +1154,11 @@ uint16_t P039_data_struct::readLM7xRegisters(int8_t l_CS_pin_no, uint8_t l_LM7xs
|
||||
transfer_n_ByteSPI(l_CS_pin_no, 8, &messageBuffer[0]);
|
||||
|
||||
// read temperature value (16 Bit)
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
l_returnValue = ((messageBuffer[0] << 8) | messageBuffer[1]);
|
||||
|
||||
// read Manufatures/Device ID (16 Bit)
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
*(l_device_id) = ((messageBuffer[4] << 8) | messageBuffer[5]);
|
||||
}
|
||||
|
||||
@@ -1358,6 +1364,7 @@ uint16_t P039_data_struct::read16BitRegister(int8_t l_CS_pin_no, uint8_t l_addre
|
||||
uint16_t l_returnValue;
|
||||
|
||||
transfer_n_ByteSPI(l_CS_pin_no, 3, l_messageBuffer);
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
l_returnValue = ((l_messageBuffer[1] << 8) | l_messageBuffer[2]);
|
||||
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
|
||||
@@ -112,6 +112,7 @@ void P045_data_struct::getRaw6AxisMotion(int16_t *ax, int16_t *ay, int16_t *az,
|
||||
for (; Wire.available(); ++count) {
|
||||
buffer[count] = Wire.read();
|
||||
}
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
*ax = (((int16_t)buffer[0]) << 8) | buffer[1];
|
||||
*ay = (((int16_t)buffer[2]) << 8) | buffer[3];
|
||||
*az = (((int16_t)buffer[4]) << 8) | buffer[5];
|
||||
|
||||
@@ -181,6 +181,7 @@ float P047_data_struct::readTemperature() {
|
||||
buf[b] = Wire.read();
|
||||
}
|
||||
}
|
||||
// TODO TD-er: const int32_t rTemp = getUlFromBigEndianByteStream(buf, 4);
|
||||
const int32_t rTemp = ((uint32_t)buf[0] << 24) | ((uint32_t)buf[1] << 16) |
|
||||
((uint32_t)buf[2] << 8) | (uint32_t)buf[3];
|
||||
|
||||
@@ -254,6 +255,7 @@ uint32_t P047_data_struct::getVersion() {
|
||||
buf[b] = Wire.read();
|
||||
}
|
||||
}
|
||||
// TODO TD-er: uint32_t ret = getUlFromBigEndianByteStream(buf, 4);
|
||||
uint32_t ret = ((uint32_t)buf[0] << 24) | ((uint32_t)buf[1] << 16) |
|
||||
((uint32_t)buf[2] << 8) | (uint32_t)buf[3];
|
||||
return ret;
|
||||
|
||||
@@ -253,6 +253,7 @@ bool P049_data_struct::read_ppm(unsigned int& ppm, signed int& temp, unsigned in
|
||||
|
||||
if ((mhzResp[0] == 0xFF) && (mhzResp[1] == 0x86)) {
|
||||
// calculate CO2 PPM
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
ppm = (static_cast<unsigned int>(mhzResp[2]) << 8) + mhzResp[3];
|
||||
|
||||
// set temperature (offset 40)
|
||||
@@ -267,6 +268,7 @@ bool P049_data_struct::read_ppm(unsigned int& ppm, signed int& temp, unsigned in
|
||||
}
|
||||
|
||||
// calculate 'u' value
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
u = (static_cast<unsigned int>(mhzResp[6]) << 8) + mhzResp[7];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ void P068_SHT3X::readFromSensor()
|
||||
if (calc_CRC8(data[0], data[1], data[2]) &&
|
||||
calc_CRC8(data[3], data[4], data[5]))
|
||||
{
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
tmp = ((((data[0] << 8) | data[1]) * 175.0f) / 65535.0f) - 45.0f;
|
||||
hum = ((((data[3] << 8) | data[4]) * 100.0f) / 65535.0f);
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ uint32_t P077_data_struct::get_24bit_value(uint8_t offset) const {
|
||||
constexpr size_t bufsize = NR_ELEMENTS(serial_in_buffer);
|
||||
|
||||
if ((offset + 2u) < bufsize) {
|
||||
// TODO TD-er: res = getUlFromBigEndianByteStream(&serial_in_buffer[offset], 3);
|
||||
res = serial_in_buffer[offset] << 16 |
|
||||
serial_in_buffer[offset + 1] << 8 |
|
||||
serial_in_buffer[offset + 2];
|
||||
@@ -190,6 +191,7 @@ bool P077_data_struct::processCseReceived(struct EventStruct *event) {
|
||||
const uint32_t cur_millis = millis();
|
||||
|
||||
// Only use CF pulses when a power cycle has completed
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
const uint32_t cur_cf_pulses = serial_in_buffer[21] << 8 | serial_in_buffer[22];
|
||||
|
||||
if (last_cf_pulses == 0) {
|
||||
|
||||
@@ -252,6 +252,7 @@ CCS811Core::status CCS811::readAlgorithmResults(void)
|
||||
// Data ordered:
|
||||
// co2MSB, co2LSB, tvocMSB, tvocLSB
|
||||
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
CO2 = ((uint16_t)data[CSS811_ALG_RESULT_DATA + 0] << 8) | data[CSS811_ALG_RESULT_DATA + 1];
|
||||
tVOC = ((uint16_t)data[CSS811_ALG_RESULT_DATA + 2] << 8) | data[CSS811_ALG_RESULT_DATA + 3];
|
||||
return SENSOR_SUCCESS;
|
||||
@@ -462,10 +463,12 @@ CCS811Core::status CCS811::readNTC(void)
|
||||
return SENSOR_I2C_ERROR;
|
||||
}
|
||||
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
vrefCounts = (static_cast<uint16_t>(data[CSS811_NTC + 0]) << 8) | data[CSS811_NTC + 1];
|
||||
|
||||
// ESPEASY_SERIAL_0.print("vrefCounts: ");
|
||||
// ESPEASY_SERIAL_0.println(vrefCounts);
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
ntcCounts = (static_cast<uint16_t>(data[CSS811_NTC + 2]) << 8) | data[CSS811_NTC + 3];
|
||||
|
||||
// ESPEASY_SERIAL_0.print("ntcCounts: ");
|
||||
|
||||
@@ -782,6 +782,7 @@ boolean P092_data_struct::P092_fetch_sensor(int number, sP092_ReadData *ReadData
|
||||
|
||||
ReadData->mode = -1;
|
||||
number = ReadData->Idx + (number - 1) * 2;
|
||||
// TODO TD-er: Use getUint16FromLittleEndianByteStream
|
||||
int32_t sensorvalue = (DLbus_Data->ByteStream[number + 1] << 8) | DLbus_Data->ByteStream[number];
|
||||
|
||||
if (sensorvalue == 0) {
|
||||
@@ -847,6 +848,7 @@ boolean P092_data_struct::P092_fetch_output(int number, sP092_ReadData *ReadData
|
||||
int32_t outputs;
|
||||
|
||||
if (P092_DataSettings.OutputBytes > 1) {
|
||||
// TODO TD-er: Use getUint16FromLittleEndianByteStream
|
||||
outputs = (DLbus_Data->ByteStream[P092_DataSettings.IdxOutput + 1] << 8) | DLbus_Data->ByteStream[P092_DataSettings.IdxOutput];
|
||||
}
|
||||
else {
|
||||
@@ -981,6 +983,7 @@ boolean P092_data_struct::P092_fetch_heatmeter(int number, sP092_ReadData *ReadD
|
||||
if (HMindex.IndexIsValid == 0) {
|
||||
return false;
|
||||
}
|
||||
// TODO TD-er: Use getUint16FromLittleEndianByteStream
|
||||
heat_meter = (DLbus_Data->ByteStream[HMindex.kwh_index + 1] << 8) | DLbus_Data->ByteStream[HMindex.kwh_index];
|
||||
heat_meter_mwh = (heat_meter * 0.1f) / 1000.0f; // in MWh
|
||||
|
||||
@@ -991,6 +994,7 @@ boolean P092_data_struct::P092_fetch_heatmeter(int number, sP092_ReadData *ReadD
|
||||
}
|
||||
|
||||
// MWh
|
||||
// TODO TD-er: Use getUint16FromLittleEndianByteStream
|
||||
heat_meter = (DLbus_Data->ByteStream[HMindex.mwh_index + 1] << 8) | DLbus_Data->ByteStream[HMindex.mwh_index];
|
||||
ReadData->value = heat_meter_mwh + heat_meter;
|
||||
return true;
|
||||
|
||||
@@ -439,6 +439,7 @@ bool P122_data_struct::readValue(uint16_t& value)
|
||||
|
||||
if (crc8(buffer, 2) == buffer[2])
|
||||
{
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
value = buffer[0] << 8;
|
||||
value += buffer[1];
|
||||
value &= 0xFFFC;
|
||||
|
||||
@@ -210,13 +210,22 @@ bool P129_data_struct::plugin_readData(struct EventStruct *event) {
|
||||
|
||||
void P129_data_struct::checkDiff(struct EventStruct *event) {
|
||||
for (uint8_t i = 0; i < P129_CONFIG_CHIP_COUNT; i += 4) {
|
||||
if (PCONFIG_ULONG(i / 4) != 0) { // Any input event enabled?
|
||||
const uint32_t mask = PCONFIG_ULONG(i / 4);
|
||||
if (mask != 0) { // Any input event enabled?
|
||||
const uint32_t read = readBuffer[i + 3] << 24 | readBuffer[i + 2] << 16 | readBuffer[i + 1] << 8 | readBuffer[i + 0];
|
||||
const uint32_t prev = prevBuffer[i + 3] << 24 | prevBuffer[i + 2] << 16 | prevBuffer[i + 1] << 8 | prevBuffer[i + 0];
|
||||
|
||||
for (uint8_t j = 0; j < 32; ++j) { // Check all 32 bits
|
||||
if (bitRead(PCONFIG_ULONG(i / 4), j) && (bitRead(read, j) != bitRead(prev, j))) { // Event enabled and bit changed?
|
||||
sendInputEvent(event, i, j, bitRead(read, j)); // Send out new state
|
||||
//const uint32_t read = getUlFromLittleEndianByteStream(&readBuffer[i], 4);
|
||||
//const uint32_t prev = getUlFromLittleEndianByteStream(&prevBuffer[i], 4);
|
||||
|
||||
// Use XOR here to only get a '1' when bits have changed.
|
||||
const uint32_t bitsChanged = read ^ prev;
|
||||
|
||||
uint32_t bitsChangedMasked = bitsChanged & mask;
|
||||
for (uint8_t j = 0; j < 32 && bitsChangedMasked; ++j) { // Check all 32 bits
|
||||
if (bitRead(bitsChangedMasked, j)) { // Event enabled and bit changed?
|
||||
sendInputEvent(event, i, j, bitRead(read, j)); // Send out new state
|
||||
bitClear(bitsChangedMasked, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ bool P134_data_struct::plugin_read(struct EventStruct *event) {
|
||||
if (!(((data[0] + data[1] + data[2]) & 0xFF) == data[3])) {
|
||||
measurementStatus = A02YYUW_status_e::STATUS_ERROR_CHECK_SUM;
|
||||
} else {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
measuredDistance = ((data[1] << 8) + data[2]);
|
||||
|
||||
if (measuredDistance < P134_MIN_DISTANCE) {
|
||||
|
||||
@@ -74,6 +74,7 @@ bool P144_data_struct::processSensor() {
|
||||
new_data = processRx(easySerial->read());
|
||||
if (new_data)
|
||||
{
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
pm25Value = float((serialRxBuffer[3] << 8) + serialRxBuffer[4]);
|
||||
#ifdef PLUGIN_144_DEBUG
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO))
|
||||
|
||||
@@ -399,6 +399,7 @@ uint16_t P147_data_struct::readCheckedWord(bool& is_ok, long extraDelay) {
|
||||
}
|
||||
|
||||
if (calc_CRC8(data, 2) == data[2]) { // valid checksum?
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
result = (data[0] << 8) | data[1];
|
||||
is_ok = true;
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ bool P153_data_struct::plugin_read(struct EventStruct *event) {
|
||||
|
||||
// Data valid?
|
||||
if (calc_CRC8(data[0], data[1], data[2]) && calc_CRC8(data[3], data[4], data[5])) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
const float temp = static_cast<float>(((uint16_t)data[0] << 8) | (uint16_t)data[1]);
|
||||
const float hum = static_cast<float>(((uint16_t)data[3] << 8) | (uint16_t)data[4]);
|
||||
temperature = -45.0f + 175.0f * temp / 65535.0f;
|
||||
|
||||
@@ -813,6 +813,8 @@ bool P167_data_struct::readMeasValue() {
|
||||
} else {
|
||||
for (int xx = 0; xx < 8; ++xx) {
|
||||
if ((calc_CRC8(&buffer[xx * 3], 2) == buffer[xx * 3 + 2]) && ((buffer[xx * 3] != 0xFF) || (buffer[xx * 3 + 1] != 0xFF))) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
// TODO TD-er: Why the same operation twice????
|
||||
value = buffer[xx * 3] << 8;
|
||||
value += buffer[xx * 3 + 1];
|
||||
valuesign = buffer[xx * 3] << 8;
|
||||
@@ -919,6 +921,8 @@ bool P167_data_struct::readMeasRawValue() {
|
||||
} else {
|
||||
for (int xx = 0; xx < 4; ++xx) {
|
||||
if ((calc_CRC8(&buffer[xx * 3], 2) == buffer[xx * 3 + 2]) && ((buffer[xx * 3] != 0xFF) || (buffer[xx * 3 + 1] != 0xFF))) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
// TODO TD-er: Why the same operation twice?
|
||||
value = buffer[xx * 3] << 8;
|
||||
value += buffer[xx * 3 + 1];
|
||||
valuesign = buffer[xx * 3] << 8;
|
||||
@@ -1171,6 +1175,7 @@ bool P167_data_struct::readDeviceStatus() {
|
||||
}
|
||||
|
||||
if ((calc_CRC8(&bufferstatus[0], 2) == bufferstatus[2]) && (calc_CRC8(&bufferstatus[3], 2) == bufferstatus[5])) {
|
||||
// TODO TD-er: value = getUlFromBigEndianByteStream(bufferstatus, 4);
|
||||
value = bufferstatus[0] << 24;
|
||||
value += bufferstatus[1] << 16;
|
||||
value += bufferstatus[3] << 8;
|
||||
|
||||
@@ -47,6 +47,7 @@ bool P173_data_struct::plugin_read(struct EventStruct *event) {
|
||||
|
||||
// Read succesful, data valid?
|
||||
if (calc_CRC8(data[0], data[1], data[2]) && calc_CRC8(data[3], data[4], data[5])) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream(&data[0])
|
||||
const float temp = static_cast<float>(((uint16_t)data[0] << 8) | (uint16_t)data[1]);
|
||||
const float hum = static_cast<float>(((uint16_t)data[3] << 8) | (uint16_t)data[4]);
|
||||
temperature = -45.0f + 175.0f * temp / 65535.0f;
|
||||
@@ -117,6 +118,7 @@ bool P173_data_struct::checkDeviceID() {
|
||||
readValue(P173_SHTC3_READ_DEVICEID, 3, idArray);
|
||||
|
||||
if (calc_CRC8(idArray[0], idArray[1], idArray[2])) {
|
||||
// TODO TD-er: Use getUint16FromBigEndianByteStream
|
||||
const uint16_t id = (idArray[0] << 8) | idArray[1];
|
||||
|
||||
if ((id & 0x807) == 0x807) {
|
||||
|
||||
Reference in new issue
Block a user