Skip to content

Commit

Permalink
Merge pull request #172 from ftheoleyre/develop_FW-693
Browse files Browse the repository at this point in the history
FW-693: printf capabilities for the openwsn motes
  • Loading branch information
changtengfei authored Mar 8, 2018
2 parents 6d225cd + 260c23d commit 5e0c137
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 3 deletions.
8 changes: 7 additions & 1 deletion software/openvisualizer/bin/openVisualizerApp/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ formatter=console
#============================ loggers =========================================

[loggers]
keys=root,eventBusMonitor,openTun,openTunWindows,openTunLinux,eventBusClient,lbrClient,moteConnector,moteProbe,moteProbeUtils,moteState,openLbr,OpenParser,Parser,OpenHdlc,ParserData,ParserInfoErrorCritical,ParserStatus,RPL,SourceRoute,udpInject,JRC,openVisualizerApp,openVisualizerGui,openVisualizerCli,openVisualizerWeb,OVtracer
keys=root,eventBusMonitor,openTun,openTunWindows,openTunLinux,eventBusClient,lbrClient,moteConnector,moteProbe,moteProbeUtils,moteState,openLbr,OpenParser,Parser,OpenHdlc,ParserData,ParserPrintf,ParserInfoErrorCritical,ParserStatus,RPL,SourceRoute,udpInject,JRC,openVisualizerApp,openVisualizerGui,openVisualizerCli,openVisualizerWeb,OVtracer

[logger_root]
level=ERROR
Expand Down Expand Up @@ -128,6 +128,12 @@ handlers=std
propagate=0
qualname=ParserData

[logger_ParserPrintf]
level=INFO
handlers=std
propagate=0
qualname=ParserPrintf

[logger_ParserInfoErrorCritical]
level=INFO
handlers=std,console
Expand Down
13 changes: 11 additions & 2 deletions software/openvisualizer/openvisualizer/moteConnector/OpenParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ParserInfoErrorCritical as ParserIEC
import ParserData
import ParserPacket
import ParserPrintf

class OpenParser(Parser.Parser):

Expand All @@ -26,6 +27,7 @@ class OpenParser(Parser.Parser):
SERFRAME_MOTE2PC_CRITICAL = ParserIEC.ParserInfoErrorCritical.SEVERITY_CRITICAL
SERFRAME_MOTE2PC_REQUEST = ord('R')
SERFRAME_MOTE2PC_SNIFFED_PACKET = ord('P')
SERFRAME_MOTE2PC_PRINTF = ord('F')

SERFRAME_PC2MOTE_SETDAGROOT = ord('R')
SERFRAME_PC2MOTE_DATA = ord('D')
Expand All @@ -51,7 +53,8 @@ def __init__(self):
self.parserCritical = ParserIEC.ParserInfoErrorCritical(self.SERFRAME_MOTE2PC_CRITICAL)
self.parserData = ParserData.ParserData()
self.parserPacket = ParserPacket.ParserPacket()

self.parserPrintf = ParserPrintf.ParserPrintf()

# register subparsers
self._addSubParser(
index = 0,
Expand Down Expand Up @@ -83,6 +86,12 @@ def __init__(self):
val = self.SERFRAME_MOTE2PC_SNIFFED_PACKET,
parser = self.parserPacket.parseInput,
)
self._addSubParser(
index = 0,
val = self.SERFRAME_MOTE2PC_PRINTF,
parser = self.parserPrintf.parseInput,
)

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

#======================== private =========================================
#======================== private =========================================
136 changes: 136 additions & 0 deletions software/openvisualizer/openvisualizer/moteConnector/ParserPrintf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Copyright (c) 2017, CNRS.
# 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('ParserPrintf')
log.setLevel(logging.INFO)
log.addHandler(logging.NullHandler())

import struct

from pydispatch import dispatcher
import StackDefines

from ParserException import ParserException
import Parser

class ParserPrintf(Parser.Parser):

HEADER_LENGTH = 2
MSPERSLOT = 15 #ms per slot.

STRING = 0
INT32 = 1


def __init__(self):

# log
log.debug('create ParserPrintf instance')

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

self._asn= ['asn_4', # B
'asn_2_3', # H
'asn_0_1', # H
]

self.buf_addr = "" #address for the buffer
self.buf_txt = "" #buffer for the messages (to flush when I receive a '\n')
self.buf_asn = ""

#returns a string with the decimal value of a uint16_t
def BytesToString(self, bytes):
str = ''
i = 0

#print bytes

for byte in bytes:
str = format(eval('{0} + {1} * 256 ** {2}'.format(str, byte, i)))
#print ('{0}:{1}'.format(i, str))
i = i + 1

return(str)

def BytesToStr(self, bytes):
str = ''
i = 0

for byte in bytes:
str = str + unichr(byte)


return(str)

def BytesToAddr(self, bytes):
str = ''
i = 0

for byte in bytes:
str = str + '{:02x}'.format(byte)
#if (i < len(bytes)-1):
# str = str + '-'
i += 1

return(str)

#prints the content of the buffer and flushes it
def flush(self):

print("(asn={0}) from {1}: {2}\n".format(
self.buf_asn,
self.buf_addr,
self.buf_txt
)
)

log.info("(asn={0}) from {1}: {2}\n".format(
self.buf_asn,
self.buf_addr,
self.buf_txt
)
)

self.buf_txt = ""
self.buf_addr = ""
self.buf_asn = ""

def parseInput(self,input):

# log
if log.isEnabledFor(logging.DEBUG):
log.debug('received printf {0}'.format(input))

#subtype: string
if (input[0] == self.STRING) :
self.buf_addr = self.BytesToAddr(input[1:3])
self.buf_asn = self.BytesToString(input[3:8])
for c in input[8:] :
if (c == 10): #EOL
self.flush()
self.buf_txt = self.buf_txt + unichr(c)

#subtype integer
elif(input[0] == self.INT32):
self.buf_txt = self.buf_txt + self.BytesToString(input[1:5])
else:
print("Unkwnon printf subtype\n")

#everything was fine
return ('error', input)


def _translateCallingComponent(self,callingComponent):
try:
return StackDefines.components[callingComponent]
except KeyError:
return "unknown component code {0}".format(callingComponent)

#======================== private =========================================


0 comments on commit 5e0c137

Please sign in to comment.