Esempio n. 1
0
def formatDataPort(values, index):
    if not values: return None
    values = Quasar.Status.StatusDict(values, prefix="DataPort%s_" % index)
    idx = QTools.Counter()
    dict = {}

    dict['TotalDataPacketsSent'] = (idx.inc(), "Total Data Packets Sent", QTools.fancy_integer(int(values['TotalDataPacketsSent'])))
    dict['TotalPacketsResent'] = (idx.inc(), "Total Packets Resent", QTools.fancy_integer(int(values['TotalPacketsResent'])))
    dict['TotalFillPacketsSent'] = (idx.inc(), "Total Fill Packets Sent", QTools.fancy_integer(int(values['TotalFillPacketsSent'])))
    dict['ReceiveSequenceErrors'] = (idx.inc(), "Receive Sequence Errors", QTools.fancy_integer(int(values['ReceiveSequenceErrors'])))
    dict['BytesOfPacketCurrentlyUsed'] = (idx.inc(), "Bytes of Packet Buffer Currently Used", values['BytesOfPacketCurrentlyUsed'])
    dict['TimeOfLastDataPacketAcked'] = (idx.inc(), "Time of Last Data Packet Acknowledged", values['TimeOfLastDataPacketAcked'])
    value = values['PhysicalInterfaceNumber']
    if_str = "Unrecognized"
    if value in range(0,3):
        if_str = "Serial Port %d" % (value+1,)
    elif value == 3:
        if_str = "Ethernet Port"
    result_str = "%d (%s)" % (value, if_str)
    dict['PhysicalInterfaceNumber'] = (idx.inc(), "Physical Interface Number", result_str)
    dict['DataPortNumber'] = (idx.inc(), "Data Port Number", values['DataPortNumber'] + 1)
    dict['RetransmissionTimeout'] = (idx.inc(), "Retransmission Timeout", "%d milliseconds" % (values['RetransmissionTimeout'] * 10,))
    value = values['DataPortFlags']
    result_str = ""
    if value & 0x0001: 
        result_str += "Baler should disconnect and prepare to reconnect to a data vacuum. "
    if value & 0x0002: 
        result_str += "Baler should stay powered on. "
    if value & 0x0004: 
        result_str += "Baler should shut down immediately. "
    if value & 0x8000: 
        result_str += "Packet memory reduced due to bad packet memory RAM. "
    dict['DataPortFlags'] = (idx.inc(), "Data Port Flags", values['DataPortFlags'])

    return dict
Esempio n. 2
0
    def _exec_monitor(self, q330):
        status_types = [ 'ping_info', 
                         'ping_status',
                         'Global',    
                         'PLL',
                         'BoomPosition',
                         'DataPort1',
                         'DataPort2',
                         'DataPort3',
                         'DataPort4' ]

        # Collect all of the status information needed in order
        # to construct our results. This way all of our data 
        # is available at once, which is useful considering that
        # some of the information for sections in the print-out
        # are pulled from multiple status types.
        #
        # _batch_ping uses the minimum necessary number of request
        results = self._batch_ping(q330, status_types)

        # Ping Info Stats
        if results.has_key('ping_info'):
            result = results['ping_info']
            # Tag ID
            if result.has_key('KMIPropertyTag') and result.has_key('SystemSoftwareVersion'):
                version = result['SystemSoftwareVersion']
                version_major = version >> 8
                version_minor = version & 0x00ff
                self._print("        Tag ID: %d" % result['KMIPropertyTag'])
                self._print("      Firmware: %d.%d" % (version_major, version_minor))
        # Ping Status Stats
        if results.has_key('ping_status'):
            result = results['ping_status']
            # Time of Last Reboot
            if result.has_key('TimeOfLastReboot'):
                time_reboot = QTools.q330_to_unix_time(result['TimeOfLastReboot'])
                time_now = float(calendar.timegm(time.gmtime()))
                uptime = (time_now - time_reboot) / 86400.0
                self._print("     Boot Time: %s UTC (%.02f days uptime)" % (time.strftime("%Y/%m/%d %H:%M", time.gmtime(time_reboot)), uptime))
        # Global Stats
        if results.has_key('Global'):
            result = Quasar.Status.StatusDict(results['Global'], prefix='Global_')
            # Station Time
            if result.has_key('SecondsOffset') and result.has_key('USecOffset') and result.has_key('CurrentDataSequenceNumber'):
                seconds = result['SecondsOffset'] + result['CurrentDataSequenceNumber']
                usecs = result['USecOffset']
                time_now = float(calendar.timegm(time.gmtime()))
                time_station = QTools.q330_to_unix_time(seconds)
                self._print("      GPS Time: %s.%06d" % (time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(time_station)), usecs))
            # Clock Quality
            if result.has_key('ClockQuality'):
                clock_quality = result['ClockQuality']
                result_string = ""
                if ((clock_quality & 0xc0) >> 6) == 1:
                    result_string += "PLL Hold"
                elif ((clock_quality & 0xc0) >> 6) == 2:
                    result_string += "PLL Tracking"
                elif ((clock_quality & 0xc0) >> 6) == 3:
                    result_string += "PLL Locked"
                else:
                    result_string += "PLL not enabled"
                if not (clock_quality & 0x01):
                    result_string += " (Clock has never been locked)"
                elif clock_quality & 0x20:
                    result_string += " (Speculative Lock based on internal clock)"
                elif clock_quality & 0x10:
                    result_string += " (Timemarks currently frozen due to filtering)"
                elif clock_quality & 0x04:
                    result_string += " (Clock has 3-D lock)"
                elif clock_quality & 0x02:
                    result_string += " (Clock has 2-D lock)"
                elif clock_quality & 0x08:
                    result_string += " (Clock has 1-D lock)"
                else:
                    result_string += " (Clock has been locked)"
                self._print(" Clock Quality: %s" % result_string)
        # PLL Stats
        if results.has_key('PLL'):
            result = Quasar.Status.StatusDict(results['PLL'], prefix='PLL_')
            # Phase
            if result.has_key('TimeError'):
                time_error = result['TimeError']
                result_string = "%dus" % int(time_error * 1000000)
                self._print("         Phase: %s" % result_string)
        # Boom Position Stats
        if results.has_key('BoomPosition'):
            result = Quasar.Status.StatusDict(results['BoomPosition'], prefix='BoomPosition_')
            # System Temperature
            if result.has_key('SystemTemperature'):
                self._print("   Temperature: %d C" % result['SystemTemperature'])
            # System Power
            if result.has_key('InputPower') and result.has_key('MainCurrent'):
                volts = result['InputPower'] * 0.15
                amps  = result['MainCurrent'] / 1000.0
                watts = volts * amps
                self._print("   Input Power: %.02f VDC, %.02f W" % (volts, watts))
            if result.has_key('MainCurrent'):
                pass
            # Boom Positions
            for i in range(1,7):
                key = "Channel%dBoom" % i
                position = "Unknown"
                if result.has_key(key):
                    position = "%d" % result[key]
                result_string = "        Boom %d: %s" % (i, position)
                self._print(result_string)

        # Data Port Stats
        if results.has_key('ping_info'):
            info = results['ping_info']
            data_ports = {}
            max_capacity_len = 0
            max_percent_len = 0
            max_packets_len = 0
            for i in range(1, 5):
                data_ports[i] = {}
                dp_info = data_ports[i]
                key = "DataPort%d" % i
                port_key = "DataPort%dPacketMemorySize" % i
                if results.has_key(key) and info.has_key(port_key):
                    result = Quasar.Status.StatusDict(results[key], prefix=key+'_')
                    buffer_bytes = info[port_key]
                    buffer_capacity = buffer_bytes / 1048576.0
                    buffer_capacity_str = "%.02f" % buffer_capacity
                    max_capacity_len = max(len(buffer_capacity_str), max_capacity_len)
                    dp_info['capacity'] = buffer_capacity_str
                    # Buffer Percent Full
                    if result.has_key('BytesOfPacketCurrentlyUsed'):
                        buffer_used = float(result['BytesOfPacketCurrentlyUsed'])
                        buffer_percent = (buffer_used / buffer_bytes) * 100.0
                        buffer_percent_str = "%.02f%%" % buffer_percent
                        max_percent_len = max(len(buffer_percent_str), max_percent_len)
                        dp_info['percent'] = buffer_percent_str
                    # Packet Counts
                    if result.has_key('TotalDataPacketsSent'):
                        packet_count_str = QTools.fancy_integer(result['TotalDataPacketsSent'])
                        max_packets_len = max(len(packet_count_str), max_packets_len)
                        dp_info['packets'] = packet_count_str

            for i in range(1, 5):
                dp_info = data_ports[i]
                data_port_str = "   Data Port %d:" % i
                if dp_info.has_key('capacity'):
                    data_port_str += " %s MiB" % dp_info['capacity'].rjust(max_capacity_len)
                if dp_info.has_key('percent'):
                    data_port_str += " (%s full)." % dp_info['percent'].rjust(max_percent_len)
                if dp_info.has_key('packets'):
                    data_port_str += " Packets sent: %s" % dp_info['packets'].rjust(max_packets_len)

                self._print(data_port_str)

        self._add_result(results)