Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb authored and root committed Nov 30, 2024
1 parent 6d85c4c commit f9e5bdb
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions mos.yml
Original file line number Diff line number Diff line change
@@ -700,6 +700,7 @@ conds:
name: Plus1PMMini
sources:
- src/ShellyMini1PMGen3
- src/BL0942
libs:
- location: https://github.com/mongoose-os-libs/mongoose
build_vars:
6 changes: 4 additions & 2 deletions src/BL0942/shelly_pm_bl0942.cpp
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ StatusOr<float> BL0942PowerMeter::GetEnergyWH() {

bool BL0942PowerMeter::ReadReg(uint8_t reg, uint8_t *rx_buf, size_t len) {
uint8_t tx_buf[2] = {BL_READ | BL_ADDR, reg};
mgos_uart_write(uart_no_, tx_buf, 1);
mgos_uart_write(uart_no_, tx_buf, 2);
mgos_uart_flush(uart_no_);

// Delay to allow data to be available
@@ -82,12 +82,14 @@ bool BL0942PowerMeter::ReadReg(uint8_t reg, uint8_t *rx_buf, size_t len) {
int read_len = mgos_uart_read(uart_no_, rx_buf, len);

uint8_t chksum = tx_buf[0] + tx_buf[1];
for (int i = 0; i < len; i++) {
for (int i = 0; i < len - 1; i++) {
chksum += rx_buf[i];
LOG(LL_ERROR, "%08X", rx_buf[i]);
}
chksum ^= 0xFF;

if (read_len != len || rx_buf[len - 1] != chksum) {
LOG(LL_ERROR, "wrong checksum");
return false;
}
return true;

0 comments on commit f9e5bdb

Please sign in to comment.