Browse Source

some toole refinery

master
root 5 years ago
parent
commit
d6f9989379
  1. 9
      tools/can2coil.py
  2. 15
      tools/coil2can.py
  3. 2
      tools/shutter2can.py

9
tools/can2coil.py

@ -28,10 +28,10 @@ coil_map = {
'SCH': [ 0x01, 0x08 ],
'B1': [ 0x01, 0x01 ],
'B2': [ 0x01, 0x02 ],
'ROL_EZ_G_DOWN': [0x03, 0x05, -1],
'ROL_EZ_G_UP': [0x03,0x04, -1],
'ROL_EZ_N_DOWN': [0x03, 0x06, -2],
'ROL_EZ_N_UP': [0x03,0x08, -2],
'ROL_EZ_G_DOWN': [0x03, 0x05],
'ROL_EZ_G_UP': [0x03,0x04],
'ROL_EZ_N_DOWN': [0x03, 0x06],
'ROL_EZ_N_UP': [0x03,0x08],
'EG1': [ 0x02, 0x09 ],
'EG2': [ 0x03, 0x09 ],
'OG': [ 0x01, 0x09 ],
@ -86,6 +86,7 @@ def main():
mcp_mqtt.user_data_set(canbus)
mcp_mqtt.connect("mcp", 1883, 60)
mcp_mqtt.publish("coil/welcome", "1" , retain=0)
try:
while True:
msg = canbus.recv(1)

15
tools/coil2can.py

@ -139,10 +139,21 @@ def main():
mcp_mqtt.on_message = on_message
mcp_mqtt.user_data_set(bus)
mcp_mqtt.connect("mcp", 1883, 60)
# mcp_mqtt.loop_start()
mcp_mqtt.loop_start()
try:
while True:
mcp_mqtt.loop()
msg = bus.recv(1)
if msg is not None:
de=decon(msg.arbitration_id)
m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "action": hex(msg.data[0]) }
if de[2]==0 and de[4] == 6:
print("received state: ", hex(de[3]), hex(msg.data[0]), hex(msg.data[1]))
for key in coil_map:
address=coil_map[key]
if address[0] == de[3] and address[1] == msg.data[0]+1:
print("coil/"+key+" changed to "+str(msg.data[1]))
mcp_mqtt.publish("coil/"+key+"/state", msg.data[1] , retain=1)
except KeyboardInterrupt:
pass
finally:

2
tools/shutter2can.py

@ -30,7 +30,7 @@ event_map = {
coil_map = {
# up , down
'EZ_G': [ 0x03, 0x04 , 0x03, 0x05 ],
'EZ_N': [ 0x03, 0x06 , 0x03, 0x08 ],
'EZ_N': [ 0x03, 0x08 , 0x03, 0x06 ],
'WZ1': [ 0x00, 0x01 , 0x00, 0x01 ],
'WZ2': [ 0x00, 0x01 , 0x00, 0x01 ],
'WZ3': [ 0x00, 0x01 , 0x00, 0x01 ],

Loading…
Cancel
Save