mirror of
https://github.com/korneliuszo/lumiax-controller.git
synced 2026-03-28 19:22:33 +01:00
Add reading status
This commit is contained in:
15
scripts/status.py
Executable file
15
scripts/status.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tlay2_client
|
||||
import struct
|
||||
|
||||
def get_state():
|
||||
a=tlay2_client.Tlay2_msg(3)
|
||||
keys=("b_soc","b_v","b_a","l_v","l_a","s_v","s_a","on")
|
||||
vals=struct.unpack("<HHhHHHH?",a.msg(b""))
|
||||
ratio = (1,100,100,100,100,100,100,"I")
|
||||
vals = [val/r if r != "I" else val for val,r in zip(vals,ratio)]
|
||||
return dict(zip(keys,vals))
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_state())
|
||||
17
src/uart.cpp
17
src/uart.cpp
@@ -37,6 +37,23 @@ void process_packet(Tlay2<128>* obj, uint8_t*data,size_t len)
|
||||
obj->tx_end();
|
||||
break;
|
||||
}
|
||||
case 3: // read status
|
||||
{
|
||||
k_mutex_lock(®_data.mut, K_FOREVER);
|
||||
Reg_data::Data cached = reg_data.d;
|
||||
k_mutex_unlock(®_data.mut);
|
||||
obj->tx_init_reply();
|
||||
obj->tx_u16(cached.b_soc);
|
||||
obj->tx_u16(cached.b_v);
|
||||
obj->tx_u16(cached.b_a);
|
||||
obj->tx_u16(cached.l_v);
|
||||
obj->tx_u16(cached.l_a);
|
||||
obj->tx_u16(cached.s_v);
|
||||
obj->tx_u16(cached.s_a);
|
||||
obj->tx_byte(cached.on);
|
||||
obj->tx_end();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user