本文整理汇总了Python中SmartMeshSDK.utils.FormatUtils.formatDictionnary方法的典型用法代码示例。如果您正苦于以下问题:Python FormatUtils.formatDictionnary方法的具体用法?Python FormatUtils.formatDictionnary怎么用?Python FormatUtils.formatDictionnary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmartMeshSDK.utils.FormatUtils
的用法示例。
在下文中一共展示了FormatUtils.formatDictionnary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dataCallback
# 需要导入模块: from SmartMeshSDK.utils import FormatUtils [as 别名]
# 或者: from SmartMeshSDK.utils.FormatUtils import formatDictionnary [as 别名]
def _dataCallback(self, notifName, notifParams):
# log
if isinstance(self.apiDef,IpMgrDefinition.IpMgrDefinition):
# IpMgrSubscribe generates a named tuple
log.debug(
"notifClient._dataCallback {0}:\n{1}".format(
notifName,
FormatUtils.formatNamedTuple(notifParams)
)
)
elif isinstance(self.apiDef,HartMgrDefinition.HartMgrDefinition):
# HartMgrSubscriber generates a dictionary
log.debug(
"notifClient._dataCallback {0}:\n{1}".format(
notifName,
FormatUtils.formatDictionnary(notifParams)
)
)
else:
output = "apiDef of type {0} unexpected".format(type(self.apiDef))
log.critical(output)
print output
raise SystemError(output)
# record current time
timeNow = time.time()
# read MAC address from notification
mac = self._getMacFromNotifParams(notifParams)
# lock the data structure
self.dataLock.acquire()
# add mac/type to data, if necessary
if mac not in self.data:
self.data[mac] = {}
if notifName not in self.data[mac]:
self.data[mac][notifName] = 0
# add mac/type to updates, if necessary
if mac not in self.updates:
self.updates[mac] = []
if notifName not in self.updates[mac]:
self.updates[mac].append(notifName)
# increment counter
self.data[mac][notifName] += 1
# unlock the data structure
self.dataLock.release()
# transform HART OAP notification into equivalent IP version
if isinstance(self.apiDef,HartMgrDefinition.HartMgrDefinition):
# we are connected to a HART manager
if (notifName in ['data']) and (len(notifParams['payload'])>2):
notifName = IpMgrSubscribe.IpMgrSubscribe.NOTIFDATA
notifParams = IpMgrConnectorMux.IpMgrConnectorMux.Tuple_notifData(
utcSecs = int(notifParams['time']/1000),
utcUsecs = (notifParams['time']%1000)*1000,
macAddress = mac,
srcPort = OAPMessage.OAP_PORT,
dstPort = OAPMessage.OAP_PORT,
data = tuple(notifParams['payload'][2:]),
)
# parse OAP packet
if notifName in [IpMgrSubscribe.IpMgrSubscribe.NOTIFDATA]:
try:
self.oap_dispatch.dispatch_pkt(notifName, notifParams)
except Exception as ex:
traceback.print_exc()
示例2: _dataCallback
# 需要导入模块: from SmartMeshSDK.utils import FormatUtils [as 别名]
# 或者: from SmartMeshSDK.utils.FormatUtils import formatDictionnary [as 别名]
def _dataCallback(self, notifName, notifParams):
# log
if isinstance(self.apiDef,IpMgrDefinition.IpMgrDefinition):
# IpMgrSubscribe generates a named tuple
log.debug(
"notifClient._dataCallback {0}:\n{1}".format(
notifName,
FormatUtils.formatNamedTuple(notifParams)
)
)
elif isinstance(self.apiDef,HartMgrDefinition.HartMgrDefinition):
# HartMgrSubscriber generates a dictionary
log.debug(
"notifClient._dataCallback {0}:\n{1}".format(
notifName,
FormatUtils.formatDictionnary(notifParams)
)
)
else:
output = "apiDef of type {0} unexpected".format(type(self.apiDef))
log.critical(output)
print output
raise SystemError(output)
# record current time
timeNow = time.time()
# read MAC address from notification
mac = self._getMacFromNotifParams(notifParams)
# lock the data structure
self.dataLock.acquire()
# add mac/type to data, if necessary
if mac not in self.data:
self.data[mac] = {}
if notifName not in self.data[mac]:
self.data[mac][notifName] = 0
# add mac/type to updates, if necessary
if mac not in self.updates:
self.updates[mac] = []
if notifName not in self.updates[mac]:
self.updates[mac].append(notifName)
# increment counter
self.data[mac][notifName] += 1
# transform HART OAP notification into equivalent IP version
if isinstance(self.apiDef,HartMgrDefinition.HartMgrDefinition):
# we are connected to a HART manager
if (notifName in ['data']) and (len(notifParams['payload'])>2):
notifName = IpMgrSubscribe.IpMgrSubscribe.NOTIFDATA
notifParams = IpMgrConnectorMux.IpMgrConnectorMux.Tuple_notifData(
utcSecs = int(notifParams['time']/1000),
utcUsecs = (notifParams['time']%1000)*1000,
macAddress = mac,
srcPort = OAPMessage.OAP_PORT,
dstPort = OAPMessage.OAP_PORT,
data = tuple(notifParams['payload'][2:]),
)
# calculate latency
try:
if notifName in [IpMgrSubscribe.IpMgrSubscribe.NOTIFDATA,
IpMgrSubscribe.IpMgrSubscribe.NOTIFIPDATA,]:
try:
latency = self.latencyCalculator.getLatency(
float(notifParams.utcSecs)+(float(notifParams.utcUsecs)/1000000.0),
timeNow)
# lat. current
if COL_LAT_CUR not in self.data[mac]:
self.data[mac][COL_LAT_CUR] = '-'
if COL_LAT_CUR not in self.updates[mac]:
self.updates[mac].append(COL_LAT_CUR)
self.data[mac][COL_LAT_CUR] = latency
# lat. min
if (
(
(COL_LAT_MIN in self.data[mac])
and
(latency<self.data[mac][COL_LAT_MIN])
)
or
(
(COL_LAT_MIN not in self.data[mac])
)
or
(
(COL_LAT_MIN in self.data[mac])
and
(self.data[mac][COL_LAT_MIN]=='-')
)
):
if COL_LAT_MIN not in self.data[mac]:
self.data[mac][COL_LAT_MIN] = '-'
if COL_LAT_MIN not in self.updates[mac]:
#.........这里部分代码省略.........