14 return static_cast<int32_t
>(
encode_uint32((uint8_t) input.
h, input.
m, input.
l, 0)) >> 8;
19 return (
address + data->l + data->m + data->h) ^ 0xFF;
34 this->
read_data_(BL0906_TEMPERATURE, BL0906_TREF, this->temperature_sensor_);
36 this->
read_data_(BL0906_I_1_RMS, BL0906_IREF, this->current_1_sensor_);
37 this->
read_data_(BL0906_WATT_1, BL0906_PREF, this->power_1_sensor_);
38 this->
read_data_(BL0906_CF_1_CNT, BL0906_EREF, this->energy_1_sensor_);
40 this->
read_data_(BL0906_I_2_RMS, BL0906_IREF, this->current_2_sensor_);
41 this->
read_data_(BL0906_WATT_2, BL0906_PREF, this->power_2_sensor_);
42 this->
read_data_(BL0906_CF_2_CNT, BL0906_EREF, this->energy_2_sensor_);
44 this->
read_data_(BL0906_I_3_RMS, BL0906_IREF, this->current_3_sensor_);
45 this->
read_data_(BL0906_WATT_3, BL0906_PREF, this->power_3_sensor_);
46 this->
read_data_(BL0906_CF_3_CNT, BL0906_EREF, this->energy_3_sensor_);
48 this->
read_data_(BL0906_I_4_RMS, BL0906_IREF, this->current_4_sensor_);
49 this->
read_data_(BL0906_WATT_4, BL0906_PREF, this->power_4_sensor_);
50 this->
read_data_(BL0906_CF_4_CNT, BL0906_EREF, this->energy_4_sensor_);
52 this->
read_data_(BL0906_I_5_RMS, BL0906_IREF, this->current_5_sensor_);
53 this->
read_data_(BL0906_WATT_5, BL0906_PREF, this->power_5_sensor_);
54 this->
read_data_(BL0906_CF_5_CNT, BL0906_EREF, this->energy_5_sensor_);
56 this->
read_data_(BL0906_I_6_RMS, BL0906_IREF, this->current_6_sensor_);
57 this->
read_data_(BL0906_WATT_6, BL0906_PREF, this->power_6_sensor_);
58 this->
read_data_(BL0906_CF_6_CNT, BL0906_EREF, this->energy_6_sensor_);
61 this->
read_data_(BL0906_FREQUENCY, BL0906_FREF, this->frequency_sensor_);
63 this->
read_data_(BL0906_V_RMS, BL0906_UREF, this->voltage_sensor_);
66 this->
read_data_(BL0906_WATT_SUM, BL0906_WATT, this->total_power_sensor_);
68 this->
read_data_(BL0906_CF_SUM_CNT, BL0906_CF, this->total_energy_sensor_);
95 this->
write_array(USR_WRPROT_WITABLE,
sizeof(USR_WRPROT_WITABLE));
104 this->
write_array(USR_WRPROT_ONLYREAD,
sizeof(USR_WRPROT_ONLYREAD));
110void BL0906::update() {
116 this->action_queue_.push_back(function);
119 return this->action_queue_.size();
123 if (this->action_queue_.empty()) {
127 for (
size_t i = 0; i < this->action_queue_.size(); i++) {
128 ptr_func = this->action_queue_[i];
130 ESP_LOGI(TAG,
"HandleActionCallback[%zu]", i);
137 this->action_queue_.clear();
152 if (sensor ==
nullptr) {
160 bool signed_result = reference == BL0906_TREF || reference == BL0906_WATT || reference == BL0906_PREF;
165 ESP_LOGW(TAG,
"Read failed");
169 ESP_LOGW(TAG,
"Junk on wire. Throwing away partial message");
184 if (reference == BL0906_PREF) {
185 value = (float)
to_int32_t(data_s24) * reference;
189 if (reference == BL0906_WATT) {
190 value = (float)
to_int32_t(data_s24) * reference;
194 if (reference == BL0906_UREF || reference == BL0906_IREF || reference == BL0906_EREF || reference == BL0906_CF) {
199 if (reference == BL0906_FREF) {
203 if (reference == BL0906_TREF) {
205 value = (value - 64) * 12.5f / 59 - 40;
213 float ki = 12875 * 1 * (5.1 + 5.1) * 1000 / 2000 / 1.097;
214 float i_rms0 = measurements * ki;
215 float i_rms = correction * ki;
216 int32_t value = (
i_rms *
i_rms - i_rms0 * i_rms0) / 256;
217 data.l = value & 0xFF;
218 data.m = (value >> 8) & 0xFF;
219 data.h = (value >> 16) & 0xFF;
221 ESP_LOGV(TAG,
"RMSOS:%02X%02X%02X%02X%02X%02X", BL0906_WRITE_COMMAND,
address, data.l, data.m, data.h, data.address);
230void BL0906::dump_config() {
231 ESP_LOGCONFIG(TAG,
"BL0906:");
232 LOG_SENSOR(
" ",
"Voltage", this->voltage_sensor_);
234 LOG_SENSOR(
" ",
"Current1", this->current_1_sensor_);
235 LOG_SENSOR(
" ",
"Current2", this->current_2_sensor_);
236 LOG_SENSOR(
" ",
"Current3", this->current_3_sensor_);
237 LOG_SENSOR(
" ",
"Current4", this->current_4_sensor_);
238 LOG_SENSOR(
" ",
"Current5", this->current_5_sensor_);
239 LOG_SENSOR(
" ",
"Current6", this->current_6_sensor_);
241 LOG_SENSOR(
" ",
"Power1", this->power_1_sensor_);
242 LOG_SENSOR(
" ",
"Power2", this->power_2_sensor_);
243 LOG_SENSOR(
" ",
"Power3", this->power_3_sensor_);
244 LOG_SENSOR(
" ",
"Power4", this->power_4_sensor_);
245 LOG_SENSOR(
" ",
"Power5", this->power_5_sensor_);
246 LOG_SENSOR(
" ",
"Power6", this->power_6_sensor_);
248 LOG_SENSOR(
" ",
"Energy1", this->energy_1_sensor_);
249 LOG_SENSOR(
" ",
"Energy2", this->energy_2_sensor_);
250 LOG_SENSOR(
" ",
"Energy3", this->energy_3_sensor_);
251 LOG_SENSOR(
" ",
"Energy4", this->energy_4_sensor_);
252 LOG_SENSOR(
" ",
"Energy5", this->energy_5_sensor_);
253 LOG_SENSOR(
" ",
"Energy6", this->energy_6_sensor_);
255 LOG_SENSOR(
" ",
"Total Power", this->total_power_sensor_);
256 LOG_SENSOR(
" ",
"Total Energy", this->total_energy_sensor_);
257 LOG_SENSOR(
" ",
"Frequency", this->frequency_sensor_);
258 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);