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()
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()
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]: self.updates[mac].append(COL_LAT_MIN) self.data[mac][COL_LAT_MIN] = latency # max if (((COL_LAT_MAX in self.data[mac]) and (latency > self.data[mac][COL_LAT_MAX])) or ((COL_LAT_MAX not in self.data[mac])) or ((COL_LAT_MAX in self.data[mac]) and (self.data[mac][COL_LAT_MAX] == '-'))): if COL_LAT_MAX not in self.data[mac]: self.data[mac][COL_LAT_MAX] = '-' if COL_LAT_MAX not in self.updates[mac]: self.updates[mac].append(COL_LAT_MAX) self.data[mac][COL_LAT_MAX] = latency except RuntimeError: # can happen if latency calculator hasn't acquired lock yet pass except Exception as err: print err # unlock the data structure self.dataLock.release() # parse OAP packet if notifName in [IpMgrSubscribe.IpMgrSubscribe.NOTIFDATA]: self.oap_dispatch.dispatch_pkt(notifName, notifParams)
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]: self.updates[mac].append(COL_LAT_MIN) self.data[mac][COL_LAT_MIN] = latency # max if ( ( (COL_LAT_MAX in self.data[mac]) and (latency>self.data[mac][COL_LAT_MAX]) ) or ( (COL_LAT_MAX not in self.data[mac]) ) or ( (COL_LAT_MAX in self.data[mac]) and (self.data[mac][COL_LAT_MAX]=='-') ) ): if COL_LAT_MAX not in self.data[mac]: self.data[mac][COL_LAT_MAX] = '-' if COL_LAT_MAX not in self.updates[mac]: self.updates[mac].append(COL_LAT_MAX) self.data[mac][COL_LAT_MAX] = latency except RuntimeError: # can happen if latency calculator hasn't acquired lock yet pass except Exception as err: print err # unlock the data structure self.dataLock.release() # parse OAP packet if notifName in [IpMgrSubscribe.IpMgrSubscribe.NOTIFDATA]: self.oap_dispatch.dispatch_pkt(notifName, notifParams)