当前位置: 首页>>代码示例>>Python>>正文


Python FormatUtils.formatDictionnary方法代码示例

本文整理汇总了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()
开发者ID:dustcloud,项目名称:smartmeshsdk,代码行数:76,代码来源:PkGen.py

示例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]:
#.........这里部分代码省略.........
开发者ID:dustcloud,项目名称:smartmeshsdk,代码行数:103,代码来源:TempMonitor.py


注:本文中的SmartMeshSDK.utils.FormatUtils.formatDictionnary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。