46 ESP_LOGVV(TAG,
"Decode Tx20");
48 std::string string_buffer;
49 std::string string_buffer_2;
50 std::vector<bool> bit_buffer;
51 bool current_bit =
true;
54 string_buffer_2 += to_string(this->
store_.
buffer[i]) +
", ";
57 string_buffer.append(repeat, current_bit ?
'1' :
'0');
58 bit_buffer.insert(bit_buffer.end(), repeat, current_bit);
59 current_bit = !current_bit;
61 current_bit = !current_bit;
62 if (string_buffer.length() < MAX_BUFFER_SIZE) {
63 uint8_t remain = MAX_BUFFER_SIZE - string_buffer.length();
64 string_buffer_2 += to_string(remain) +
", ";
65 string_buffer.append(remain, current_bit ?
'1' :
'0');
66 bit_buffer.insert(bit_buffer.end(), remain, current_bit);
75 uint8_t tx20_wind_direction = 0;
76 float tx20_wind_speed_kmh = 0;
77 uint8_t bit_count = 0;
79 for (
int i = 41; i > 0; i--) {
80 uint8_t bit = bit_buffer.at(bit_count);
84 tx20_sa = (tx20_sa << 1) | (bit ^ 1);
85 }
else if (i > 41 - 5 - 4) {
87 tx20_sb = tx20_sb >> 1 | ((bit ^ 1) << 3);
88 }
else if (i > 41 - 5 - 4 - 12) {
90 tx20_sc = tx20_sc >> 1 | ((bit ^ 1) << 11);
91 }
else if (i > 41 - 5 - 4 - 12 - 4) {
93 tx20_sd = tx20_sd >> 1 | ((bit ^ 1) << 3);
94 }
else if (i > 41 - 5 - 4 - 12 - 4 - 4) {
96 tx20_se = tx20_se >> 1 | (bit << 3);
99 tx20_sf = tx20_sf >> 1 | (bit << 11);
103 uint8_t chk = (tx20_sb + (tx20_sc & 0xf) + ((tx20_sc >> 4) & 0xf) + ((tx20_sc >> 8) & 0xf));
105 bool value_set =
false;
111 ESP_LOGVV(TAG,
"BUFFER %s", string_buffer_2.c_str());
112 ESP_LOGVV(TAG,
"Decoded bits %s", string_buffer.c_str());
115 if (chk == tx20_sd) {
116 if (tx20_sf == tx20_sc) {
117 tx20_wind_speed_kmh = float(tx20_sc) * 0.36f;
118 ESP_LOGV(TAG,
"WindSpeed %f", tx20_wind_speed_kmh);
123 if (tx20_se == tx20_sb) {
124 tx20_wind_direction = tx20_se;
125 if (tx20_wind_direction >= 0 && tx20_wind_direction < 16) {
128 ESP_LOGV(TAG,
"WindDirection %d", tx20_wind_direction);
134 ESP_LOGW(TAG,
"No value set!");
137 ESP_LOGW(TAG,
"Checksum wrong!");
140 ESP_LOGW(TAG,
"Start wrong!");