Skip to content

Commit

Permalink
Merge pull request #106 from changtengfei/develop
Browse files Browse the repository at this point in the history
SW-209. Fix.
  • Loading branch information
twatteyne committed Jul 2, 2015
2 parents 519c3a9 + f59f6c3 commit 6413430
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,32 @@ def do_root(self, arg):
ms.triggerAction(moteState.moteState.TRIGGER_DAGROOT)
except ValueError as err:
self.stdout.write(err)


def do_set(self,arg):
"""
Sets mote with parameters
Usag
"""
if not arg:
self.stdout.write('Available ports:')
if self.app.moteStates:
for ms in self.app.moteStates:
self.stdout.write(' {0}'.format(ms.moteConnector.serialport))
else:
self.stdout.write(' <none>')
self.stdout.write('\n')
else:
try:
[port,image,command,parameter] = arg.split(' ')
for ms in self.app.moteStates:
try:
if (ms.moteConnector.serialport==port):
ms.triggerAction([moteState.moteState.SET_COMMAND,image,command,parameter])
except ValueError as err:
self.stdout.write(err)
except ValueError as err:
print "{0}:{1}".format(type(err),err)

def help_all(self):
"""Lists first line of help for all documented commands"""
names = self.get_names()
Expand Down Expand Up @@ -128,5 +153,6 @@ def do_quit(self, arg):

if __name__=="__main__":
app = openVisualizerApp.main()
app.eventBusMonitor.setWiresharkDebug(True)
cli = OpenVisualizerCli(app)
cli.cmdloop()
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ def _eventBusNotification(self,signal,sender,data):
lowpan = lowpan,
)
self._dispatchMeshDebugPacket(zep)

if signal=='fromMote.sniffedPacket':
body = data[0:-3]
crc = data[-3:-1]
frequency = data[-1]

# wrap with zep header
zep = self._wrapZepCrc(body,frequency)
self._dispatchMeshDebugPacket(zep)

if signal=='bytesToMesh':
# Forwards a copy of the 6LoWPAN packet destined for the mesh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ParserStatus
import ParserInfoErrorCritical as ParserIEC
import ParserData
import ParserPacket

class OpenParser(Parser.Parser):

Expand All @@ -24,10 +25,12 @@ class OpenParser(Parser.Parser):
SERFRAME_MOTE2PC_ERROR = ParserIEC.ParserInfoErrorCritical.SEVERITY_ERROR
SERFRAME_MOTE2PC_CRITICAL = ParserIEC.ParserInfoErrorCritical.SEVERITY_CRITICAL
SERFRAME_MOTE2PC_REQUEST = ord('R')
SERFRAME_MOTE2PC_SNIFFED_PACKET = ord('P')

SERFRAME_PC2MOTE_SETDAGROOT = ord('R')
SERFRAME_PC2MOTE_DATA = ord('D')
SERFRAME_PC2MOTE_TRIGGERSERIALECHO = ord('S')
SERFRAME_PC2MOTE_COMMAND_GD = ord('G')

SERFRAME_ACTION_YES = ord('Y')
SERFRAME_ACTION_NO = ord('N')
Expand All @@ -47,6 +50,7 @@ def __init__(self):
self.parserError = ParserIEC.ParserInfoErrorCritical(self.SERFRAME_MOTE2PC_ERROR)
self.parserCritical = ParserIEC.ParserInfoErrorCritical(self.SERFRAME_MOTE2PC_CRITICAL)
self.parserData = ParserData.ParserData()
self.parserPacket = ParserPacket.ParserPacket()

# register subparsers
self._addSubParser(
Expand Down Expand Up @@ -74,7 +78,11 @@ def __init__(self):
val = self.SERFRAME_MOTE2PC_CRITICAL,
parser = self.parserCritical.parseInput,
)

self._addSubParser(
index = 0,
val = self.SERFRAME_MOTE2PC_SNIFFED_PACKET,
parser = self.parserPacket.parseInput,
)
#======================== public ==========================================

#======================== private =========================================
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2010-2013, Regents of the University of California.
# All rights reserved.
#
# Released under the BSD 3-Clause license as published at the link below.
# https://openwsn.atlassian.net/wiki/display/OW/License
import logging
log = logging.getLogger('ParserPacket')
log.setLevel(logging.ERROR)
log.addHandler(logging.NullHandler())

import struct

from pydispatch import dispatcher

from ParserException import ParserException
import Parser

class ParserPacket(Parser.Parser):

HEADER_LENGTH = 2
MSPERSLOT = 15 #ms per slot.
IPHC_SAM = 4
IPHC_DAM = 0

def __init__(self):

# log
log.info("create instance")

# initialize parent class
Parser.Parser.__init__(self,self.HEADER_LENGTH)

#======================== public ==========================================

def parseInput(self,input):
# log
if log.isEnabledFor(logging.DEBUG):
log.debug("received packet {0}".format(input))

# ensure input not short longer than header
self._checkLength(input)

headerBytes = input[:2]

# remove mote id at the beginning.
input = input[2:]

if log.isEnabledFor(logging.DEBUG):
log.debug("packet without header {0}".format(input))

eventType='sniffedPacket'
# notify a tuple including source as one hop away nodes elide SRC address as can be inferred from MAC layer header
return (eventType,input)

#======================== private =========================================
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@
35: "UECHO",
36: "UINJECT",
37: "RRT",
38: "SECURITY",
}

errorDescriptions = {
1: "received an echo request",
2: "received an echo reply",
3: "getData asks for too few bytes, maxNumBytes={0}, fill level={1}",
4: "the input buffer has overflown",
5: "the command is not allowerd, command = {0}",
5: "the command is not allowed, command = {0}",
6: "unknown transport protocol {0} (code location {1})",
7: "wrong TCP state {0} (code location {1})",
8: "TCP reset while in state {0} (code location {1})",
Expand Down Expand Up @@ -102,4 +103,6 @@
55: "invalid packet frome radio, length {1} (code location {0})",
56: "busy receiving when stop of serial activity, buffer input length {1} (code location {0})",
57: "wrong CRC in input Buffer (input length {0})",
58: "frame received at asn {0} with timeCorrection of {1}",
59: "security error on frameType {0}, code location {1}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,79 @@ def _cmdToMote_handler(self,sender,signal,data):
self._sendToMoteProbe(
dataToSend = dataToSend,
)
elif data['action'][0]==moteState.moteState.SET_COMMAND:
# this is command for golden image
with self.stateLock:
[success,dataToSend] = self._GDcommandToBytes(data['action'][1:])

if success == False:
return

# print dataToSend
# send command to GD image
self._sendToMoteProbe(
dataToSend = dataToSend,
)
else:
raise SystemError('unexpected action={0}'.format(data['action']))

def _GDcommandToBytes(self,data):

outcome = False
dataToSend = []

# get imageId
if data[0] == 'gd_root':
imageId = 1
elif data[0] == 'gd_sniffer':
imageId = 2
else:
print "============================================="
print "Wrong Image ({0})! (Available: gd_root OR gd_sniffer)\n".format(data[0])
return [outcome,dataToSend]

# get commandId
commandIndex = 0
for cmd in moteState.moteState.COMMAND_ALL:
if data[1] == cmd[0]:
commandId = cmd[1]
commandLen = cmd[2]
break
else:
commandIndex += 1

# check avaliability of command
if commandIndex == len(moteState.moteState.COMMAND_ALL):
print "============================================="
print "Wrong Command Type! Available Command Type: {"
for cmd in moteState.moteState.COMMAND_ALL:
print " {0}".format(cmd[0])
print " }"
return [outcome,dataToSend]

# get parameter
parameter = int(data[2])
if parameter <= 0xffff:
parameter = [(parameter & 0xff),((parameter >> 8) & 0xff)]
dataToSend = [OpenParser.OpenParser.SERFRAME_PC2MOTE_COMMAND_GD,
1, # version
imageId,
commandId,
commandLen, # length
parameter[0],
parameter[1]
]
else:
# more than two bytes parameter, error
print "============================================="
print "Paramter Wrong! (Available: 0x0000~0xffff)\n"
return [outcome,dataToSend]

# the command is legal if I got here
outcome = True
return [outcome,dataToSend]


def _bytesToMesh_handler(self,sender,signal,data):
assert type(data)==tuple
assert len(data)==2
Expand Down
2 changes: 2 additions & 0 deletions software/openvisualizer/openvisualizer/moteProbe/moteProbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def run(self):

if self.mode==self.MODE_SERIAL:
self.serial = serial.Serial(self.serialport,self.baudrate)
self.serial.setDTR(0)
self.serial.setRTS(0)
elif self.mode==self.MODE_EMULATED:
self.serial = self.emulatedMote.bspUart
elif self.mode==self.MODE_IOTLAB:
Expand Down
26 changes: 26 additions & 0 deletions software/openvisualizer/openvisualizer/moteState/moteState.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,32 @@ class moteState(eventBusClient.eventBusClient):
]

TRIGGER_DAGROOT = 'DAGroot'
SET_COMMAND = 'imageCommand'

# command for golen image: command, id length
COMMAND_SET_EBPERIOD = ['ebPeriod', 0, 1]
COMMAND_SET_CHANNEL = ['channel', 1, 1]
COMMAND_SET_KAPERIOD = ['kaPeriod', 2, 2]
COMMAND_SET_DIOPERIOD = ['dioPeriod', 3, 2]
COMMAND_SET_DAOPERIOD = ['daoPeriod', 4, 2]
COMMAND_PING_MOTE = ['ping', 5, 8]
COMMAND_SET_DAGRANK = ['dagrank', 6, 2]
COMMAND_SET_SECURITY_STATUS = ['security', 7, 1]
COMMAND_SET_FRAMELENGTH = ['frameLength', 8, 2]
COMMAND_SET_ACK_STATUS = ['ackReply', 9, 1]
COMMAND_ALL = [
COMMAND_SET_EBPERIOD ,
COMMAND_SET_CHANNEL,
COMMAND_SET_KAPERIOD,
COMMAND_SET_DIOPERIOD,
COMMAND_SET_DAOPERIOD,
COMMAND_PING_MOTE,
COMMAND_SET_DAGRANK,
COMMAND_SET_SECURITY_STATUS,
COMMAND_SET_FRAMELENGTH,
COMMAND_SET_ACK_STATUS,
]

TRIGGER_ALL = [
TRIGGER_DAGROOT,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class typeComponent(openType.openType):
COMPONENT_UECHO = 0x23
COMPONENT_UINJECT = 0x24
COMPONENT_RRT = 0x25
COMPONENT_SECURITY = 0x26

def __init__(self):
# log
Expand Down Expand Up @@ -158,6 +159,9 @@ def update(self,type):

elif type==self.COMPONENT_RRT:
self.desc = 'RRT'

elif type==self.COMPONENT_SECURITY:
self.desc = 'SECURITY'
else:
self.desc = 'unknown'
self.addr = None
Expand Down

0 comments on commit 6413430

Please sign in to comment.