mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 01:47:47 +00:00
THCI: APIs for commissioning certification tests (#591)
This commit is contained in:
+162
-19
@@ -39,7 +39,9 @@ from IThci import IThci
|
|||||||
from pexpect_serial import SerialSpawn
|
from pexpect_serial import SerialSpawn
|
||||||
from GRLLibs.UtilityModules.Test import Thread_Device_Role, Device_Data_Requirement, MacType
|
from GRLLibs.UtilityModules.Test import Thread_Device_Role, Device_Data_Requirement, MacType
|
||||||
from GRLLibs.UtilityModules.enums import PlatformDiagnosticPacket_Direction, PlatformDiagnosticPacket_Type, AddressType
|
from GRLLibs.UtilityModules.enums import PlatformDiagnosticPacket_Direction, PlatformDiagnosticPacket_Type, AddressType
|
||||||
from GRLLibs.UtilityModules.ModuleHelper import ModuleHelper
|
from GRLLibs.UtilityModules.ModuleHelper import ModuleHelper,ThreadRunner
|
||||||
|
from GRLLibs.ThreadPacket.PlatformPackets import PlatformDiagnosticPacket, PlatformPackets
|
||||||
|
from Queue import Queue
|
||||||
|
|
||||||
|
|
||||||
class ARM(IThci):
|
class ARM(IThci):
|
||||||
@@ -67,6 +69,9 @@ class ARM(IThci):
|
|||||||
self.panId = ModuleHelper.Default_PanId
|
self.panId = ModuleHelper.Default_PanId
|
||||||
self.xpanId = ModuleHelper.Default_XpanId
|
self.xpanId = ModuleHelper.Default_XpanId
|
||||||
self.AutoDUTEnable = False
|
self.AutoDUTEnable = False
|
||||||
|
self.provisioningUrl = ''
|
||||||
|
self.__logThread = Queue()
|
||||||
|
self.__logThreadRunning = False
|
||||||
self.intialize()
|
self.intialize()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
ModuleHelper.WriteIntoDebugLogger("initialize() Error: " + str(e))
|
ModuleHelper.WriteIntoDebugLogger("initialize() Error: " + str(e))
|
||||||
@@ -437,6 +442,32 @@ class ARM(IThci):
|
|||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def __readCommissioningLogs(self, durationInSeconds):
|
||||||
|
"""read logs during the commissioning process
|
||||||
|
|
||||||
|
Args:
|
||||||
|
durationInSeconds: time duration for reading commissioning logs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Commissioning logs
|
||||||
|
"""
|
||||||
|
self.__logThreadRunning = True
|
||||||
|
logs = Queue()
|
||||||
|
t_end = time.time() + durationInSeconds
|
||||||
|
while time.time() < t_end:
|
||||||
|
try:
|
||||||
|
line = self.serial.readline()
|
||||||
|
if line:
|
||||||
|
print line
|
||||||
|
logs.put(line)
|
||||||
|
time.sleep(0.3)
|
||||||
|
|
||||||
|
except Exception,e:
|
||||||
|
print e
|
||||||
|
|
||||||
|
self.__logThreadRunning = False
|
||||||
|
return logs
|
||||||
|
|
||||||
def closeConnection(self):
|
def closeConnection(self):
|
||||||
"""close current serial port connection"""
|
"""close current serial port connection"""
|
||||||
print '%s call closeConnection' % self.port
|
print '%s call closeConnection' % self.port
|
||||||
@@ -564,18 +595,15 @@ class ARM(IThci):
|
|||||||
if self.isPowerDown:
|
if self.isPowerDown:
|
||||||
macAddr64 = self.mac
|
macAddr64 = self.mac
|
||||||
else:
|
else:
|
||||||
macAddr64 = self.__sendCommand('extaddr')[0]
|
if bType == MacType.FactoryMac:
|
||||||
|
macAddr64 = self.__sendCommand('eui64')[0]
|
||||||
|
elif bType == MacType.HashMac:
|
||||||
|
macAddr64 = self.__sendCommand('hashmacaddr')[0]
|
||||||
|
else:
|
||||||
|
macAddr64 = self.__sendCommand('extaddr')[0]
|
||||||
print macAddr64
|
print macAddr64
|
||||||
|
|
||||||
# only supports RandomMac now
|
return int(macAddr64, 16)
|
||||||
if bType == MacType.FactoryMac:
|
|
||||||
return int(macAddr64, 16)
|
|
||||||
elif bType == MacType.RandomMac:
|
|
||||||
return int(macAddr64, 16)
|
|
||||||
elif bType == MacType.HashMac:
|
|
||||||
return int(macAddr64, 16)
|
|
||||||
else:
|
|
||||||
return int(macAddr64, 16)
|
|
||||||
|
|
||||||
def getLL64(self):
|
def getLL64(self):
|
||||||
"""get link local unicast IPv6 address"""
|
"""get link local unicast IPv6 address"""
|
||||||
@@ -1631,25 +1659,128 @@ class ARM(IThci):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def startCollapsedCommissioner(self):
|
def startCollapsedCommissioner(self):
|
||||||
pass
|
"""start OpenThread stack
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True: successful to start OpenThread stack and thread interface up
|
||||||
|
False: fail to start OpenThread stack
|
||||||
|
"""
|
||||||
|
print '%s call startCollapsedCommissioner' % self.port
|
||||||
|
return self.__startOpenThread()
|
||||||
|
|
||||||
def setJoinKey(self, strPSKc):
|
def setJoinKey(self, strPSKc):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def scanJoiner(self, xEUI='*', strPSKd='threadjpaketest'):
|
def scanJoiner(self, xEUI='*', strPSKd='threadjpaketest'):
|
||||||
pass
|
"""start commissioner
|
||||||
|
|
||||||
|
Args:
|
||||||
|
xEUI: Joiner's extended address
|
||||||
|
strPSKd: Joiner's PSKd for commissioning
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True: successful to start commissioner
|
||||||
|
False: fail to start commissioner
|
||||||
|
"""
|
||||||
|
print '%s call scanJoiner' % self.port
|
||||||
|
cmd = 'commissioner start %s %s' % (strPSKd, self.provisioningUrl)
|
||||||
|
print cmd
|
||||||
|
if self.__sendCommand(cmd)[0] == 'Done':
|
||||||
|
if self.__logThreadRunning == False:
|
||||||
|
self.__logThread = ThreadRunner.run(target = self.__readCommissioningLogs, args = (120,))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def setProvisioningUrl(self, strURL='grl.com'):
|
def setProvisioningUrl(self, strURL='grl.com'):
|
||||||
pass
|
"""set provisioning Url
|
||||||
|
|
||||||
|
Args:
|
||||||
|
strURL: Provisioning Url string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True: successful to set provisioning Url
|
||||||
|
"""
|
||||||
|
print '%s call setProvisioningUrl' % self.port
|
||||||
|
self.provisioningUrl = strURL;
|
||||||
|
return True
|
||||||
|
|
||||||
def allowCommission(self, strPSKc="GRLPassword"):
|
def allowCommission(self, strPSKc="GRLPassword"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def joinCommissioned(self, strPSKd='GRLpassWordx', waitTime=20):
|
def joinCommissioned(self, strPSKd='threadjpaketest', waitTime=20):
|
||||||
pass
|
"""start joiner
|
||||||
|
|
||||||
|
Args:
|
||||||
|
strPSKd: Joiner's PSKd
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True: successful to start commissioner
|
||||||
|
False: fail to start commissioner
|
||||||
|
"""
|
||||||
|
print '%s call joinCommissioned' % self.port
|
||||||
|
self.__sendCommand('ifconfig up')
|
||||||
|
cmd = 'joiner start %s %s' %(strPSKd, self.provisioningUrl)
|
||||||
|
print cmd
|
||||||
|
if self.__sendCommand(cmd)[0] == "Done":
|
||||||
|
if self.__logThreadRunning == False:
|
||||||
|
self.__logThread = ThreadRunner.run(target = self.__readCommissioningLogs, args = (90,))
|
||||||
|
time.sleep(90)
|
||||||
|
|
||||||
|
self.__sendCommand('thread start')
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def getCommissioningLogs(self):
|
def getCommissioningLogs(self):
|
||||||
pass
|
"""get Commissioning logs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Commissioning logs
|
||||||
|
"""
|
||||||
|
rawLogs = self.__logThread.get()
|
||||||
|
ProcessedLogs = []
|
||||||
|
payload = []
|
||||||
|
while not rawLogs.empty():
|
||||||
|
rawLogEach = rawLogs.get()
|
||||||
|
print rawLogEach
|
||||||
|
if "[THCI]" not in rawLogEach:
|
||||||
|
continue
|
||||||
|
|
||||||
|
EncryptedPacket = PlatformDiagnosticPacket()
|
||||||
|
infoList = rawLogEach.split('[THCI]')[1].split(']')[0].split('|')
|
||||||
|
for eachInfo in infoList:
|
||||||
|
print eachInfo
|
||||||
|
info = eachInfo.split("=")
|
||||||
|
infoType = info[0].strip()
|
||||||
|
infoValue = info[1].strip()
|
||||||
|
if "direction" in infoType:
|
||||||
|
EncryptedPacket.Direction = PlatformDiagnosticPacket_Direction.IN if 'recv' in infoValue \
|
||||||
|
else PlatformDiagnosticPacket_Direction.OUT if 'send' in infoValue \
|
||||||
|
else PlatformDiagnosticPacket_Direction.UNKNOWN
|
||||||
|
elif "type" in infoType:
|
||||||
|
EncryptedPacket.Type = PlatformDiagnosticPacket_Type.JOIN_FIN_req if 'JOIN_FIN.req' in infoValue \
|
||||||
|
else PlatformDiagnosticPacket_Type.JOIN_FIN_rsp if 'JOIN_FIN.rsp' in infoValue \
|
||||||
|
else PlatformDiagnosticPacket_Type.JOIN_ENT_rsp if 'JOIN_ENT.ntf' in infoValue \
|
||||||
|
else PlatformDiagnosticPacket_Type.UNKNOWN
|
||||||
|
elif "len" in infoType:
|
||||||
|
EncryptedPacket.TLVsLength = int(infoValue)
|
||||||
|
payloadLineCount = int(infoValue)/16 + 1
|
||||||
|
while payloadLineCount > 0:
|
||||||
|
payloadLineCount = payloadLineCount - 1
|
||||||
|
payloadLine = rawLogs.get()
|
||||||
|
payloadSplit = payloadLine.split('|')
|
||||||
|
for block in range(1, 3):
|
||||||
|
payloadBlock = payloadSplit[block]
|
||||||
|
payloadValues = payloadBlock.split(' ')
|
||||||
|
for num in range(1, 9):
|
||||||
|
if ".." not in payloadValues[num]:
|
||||||
|
payload.append(int(payloadValues[num], 16))
|
||||||
|
|
||||||
|
EncryptedPacket.TLVs = PlatformPackets.read(EncryptedPacket.Type,payload) if payload != [] else []
|
||||||
|
|
||||||
|
ProcessedLogs.append(EncryptedPacket)
|
||||||
|
return ProcessedLogs
|
||||||
|
|
||||||
def MGMT_ED_SCAN(self, sAddr, xCommissionerSessionId, listChannelMask, xCount, xPeriod, xScanDuration):
|
def MGMT_ED_SCAN(self, sAddr, xCommissionerSessionId, listChannelMask, xCount, xPeriod, xScanDuration):
|
||||||
pass
|
pass
|
||||||
@@ -1694,8 +1825,20 @@ class ARM(IThci):
|
|||||||
def setActiveTimestamp(self, xActiveTimestamp):
|
def setActiveTimestamp(self, xActiveTimestamp):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setUdpJoinerPort(self, portNumber):
|
def setUdpJoinerPort(self, portNumber):
|
||||||
pass
|
"""set Joiner UDP Port
|
||||||
|
|
||||||
|
Args:
|
||||||
|
portNumber: Joiner UDP Port number
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True: successful to set Joiner UDP Port
|
||||||
|
False: fail to set Joiner UDP Port
|
||||||
|
"""
|
||||||
|
print '%s call setUdpJoinerPort' % self.port
|
||||||
|
cmd = 'joinerport %d' % portNumber
|
||||||
|
print cmd
|
||||||
|
return self.__sendCommand(cmd)[0] == 'Done'
|
||||||
|
|
||||||
def commissionerUnregister(self):
|
def commissionerUnregister(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user