Skip to content

Commit

Permalink
Ezsp work
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed May 17, 2024
1 parent e0671b0 commit fbfa45c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/python/AbeilleEzsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ def shutdown():
if (cmd["name"] == 'RSTACK'):
break

sendCmd(serPort, "version")
ezspSend(serPort, "nop")
# sendCmd(serPort, "version")
while True: # Until transmitted
status, cmd = ashRead(serPort)
if (cmd["name"] != "NAK"):
break
sendCmd(serPort, "version") # Retransmit
# if (cmd["name"] != "NAK"):
# break
# sendCmd(serPort, "version") # Retransmit

logging.info('Exiting AbeilleEzsp')
82 changes: 82 additions & 0 deletions core/python/AbeilleEzspCmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,84 @@
# EmberZnet/EZSP commands
# Tcharp38

ezspSeq = 0 # Sequence number
ashFrmNum = 0 # Last transmitted ASH frame

# Encapsulate EZSP data into ASH protocol
def ashFormat(ashCmdName, data):
ashFrame = bytes()
if (ashCmdName == "DATA"):
frmNum = ashFrmNum + 1 # Last transmitted frame + 1
if (frmNum > 255):
frmNum = 0
reTx = 0 # set to 1 in a retransmitted DATA frame
ackNum = 12
ctrlByte = (frmNum << 4) | (reTx << 3) | ackNum
crc = 12
flagByte = 0x7E

ashFrame += ctrlByte.to_bytes(1, "big")
ashFrame += data
ashFrame += crc.to_bytes(2, "big")
ashFrame += flagByte.to_bytes(1, "big")
else:
print("ERROR:")
return

return ashFrame

def cmdName2Id(cmdName):
if cmdName == "version":
cmdId = 0x0000
elif cmdName == "nop":
cmdId = 0x0005
elif cmdName == "getMfgToken":
cmdId = 0x000B
else:
print("ERROR: cmdName2Id(): cmdName %s is unknown" % cmdName)
cmdId = 0x0000

return cmdId

def ezspSend(serPort, cmdName):
print("ezspSend(%s)" % cmdName)

# Reminder: Seq | Frame control (2B) | Frame ID (2B) | Parameters
global ezspSeq
seq = ezspSeq
nwkIdx = 0 # ?
sleepMode = 0 # ?
fcLow = (nwkIdx << 5) | sleepMode
secEnabled = 0 # ?
padEnabled = 0 # ?
frmFormatVersion = 0 # ?
fcHigh = (secEnabled << 7) | (padEnabled << 6) | frmFormatVersion
fc = (fcHigh << 7) | fcLow
frameId = cmdName2Id(cmdName)

# Creating EZSP frame
ezspFrame = bytes()
ezspFrame += seq.to_bytes(1, "big")
ezspFrame += fc.to_bytes(2, "big")
ezspFrame += frameId.to_bytes(2, "big")
# TODO: Add parameters if any
print("ezspFrame=", ezspFrame)

# Creating ASH frame
ashFrame = ashFormat("DATA", ezspFrame)

dataBytes = bytes(ashFrame)
serPort.write(dataBytes)

# If SENT
ezspSeq += 1
if (ezspSeq > 255):
ezspSeq = 0
global ashFrmNum
ashFrmNum += 1
if (ashFrmNum > 255):
ashFrmNum = 0

def sendCmd(serPort, cmdName):
print("send(%s)" % cmdName)

Expand All @@ -11,6 +89,10 @@ def sendCmd(serPort, cmdName):
elif (cmdName == "version"):
ezsp = [0x25, 0x00, 0x00, 0x00, 0x02, 0x1A, 0xAD, 0x7E]

elif (cmdName == "getMfgToken"):
ezspSend("getMfgToken")
return

else:
print("sendCmd() ERROR: Unknown cmd %s" % cmdName)
return
Expand Down

0 comments on commit fbfa45c

Please sign in to comment.