Example #1
0
 def __init__(self, host = 'localhost', port = 7809, timeout = 30, 
                         logger_id = 0x001, computer_id = 0x802 ):
     """ 
         this initilizer function sets up the connection
         
     arguments:
         host:       (string) a string repesenting the ip for the connection
         port:       (int) the port number
         timeout:    (int) timeout value
         logger_id:  (int) the ID of the logger
         computer_id:(int) the id of the computer 
     """
     self.host = host
     self.port = port
     self.timeout = timeout
     self.l_id = logger_id
     self.c_id = computer_id
     self.link = pakbus.open_socket(self.host, self.port
                                              , self.timeout)
     self.ping()
     self.progs = []
     self.table_list = []
     FileData, Response = pakbus.fileupload(self.link, self.l_id, self.c_id
                                                     , '.TDF')
     self.tabledef = pakbus.parse_tabledef(FileData)
     
     self.fetchprogs()
Example #2
0
 def refresh_tabledef(self):
     """
         refresh the table definition
     """
     self.ping()
     FileData, Response = pakbus.fileupload(self.link, self.l_id, self.c_id
                                                     , '.TDF')
     self.tabledef = pakbus.parse_tabledef(FileData)
Example #3
0
 def fetchprogs(self):
     """
         makes a list of the programs avaible on the data logger
     """
     FileData, Response = pakbus.fileupload(self.link, self.l_id, self.c_id 
                                                     , '.DIR')
     file_dir = pakbus.parse_filedir(FileData)
     for files in file_dir['files']:
         self.progs.append(files['FileName'])
Example #4
0
 def download (self, file_name):
     """ Function doc """
     data, code = pkb.fileupload(self.socket, 
                                self.logger_id,
                                self.cpu_id,
                                file_name,
                                self.security_code)
     
     return data, (False if code == 14 else True)
Example #5
0
    def __init__(self, db, socket, my_node_id, metric_id, pakbus_id, 
                 data_callback = None,
                 record_callback = None,
                 #wu_object = None,
                 security_code = 0x1111):
        """
        db is the sqlite db to use to store the last record numbers
        
        the data_callback is called for each time series (eg for openTSDB)
        the record callback is called once for each row in the datalogger's table 
        
        """
        #self.number = number

        self.log = logging.getLogger(__name__)
        
        self.db = sqlite3.connect(db)

        self.my_node_id = my_node_id
        self.metric_id = metric_id
        self.pakbus_id = pakbus_id
        self.security_code = security_code
        self.data_callback = data_callback
        self.record_callback = record_callback
        #self.wu_object = wu_object
        
        self.log.debug("Getting serial number for {}@{}".format(metric_id, pakbus_id))

        self.serno = pakbus.get_cr1000_serial(socket,
                                 self.pakbus_id,
                                 self.my_node_id,
                                 self.security_code)
        self.log.info("{}@{} has serial number {}".format(metric_id, pakbus_id, self.serno))
          
        self.log.debug("Getting table defs")
        self.FileData, RespCode = pakbus.fileupload(socket, 
                                          self.pakbus_id, 
                                          self.my_node_id, 
                                          FileName = '.TDF',
                                          SecurityCode = self.security_code)
        
        # todo, check resp code!
        self.log.debug(" -- table def RespCode was: {}".format(RespCode))
        #self.log.debug("Filedata = {}".format(self.FileData))
        
        self.tabledef = pakbus.parse_tabledef(self.FileData)

        self.log.debug("tabledef = {}".format(self.tabledef))

        self.list_of_tables = self.getTables(socket, 3)
        
        self.last_collect = {"ts": None,
                             "NextRecNbr": None}
        
        self.check_db()
Example #6
0
 def download(self, filename, s_cond = 0x0000):
     """ 
         downloads a file from the loger 
         
     arguments: 
         filename:   (string) the file name
         s_cond:     (int) the securit condition
     
     returns:
         the response from the logger
     """
     self.ping()
     filedata, response = pakbus.fileupload(self.link, self.l_id, self.c_id, 
                                     "CPU:"+filename ,s_cond)
                                     
     if response != 13:
         return response 
     f = open(filename,'w')
     #~ print filedata
     f.write(filedata)
     f.close()
     return response
Example #7
0
 def getTables(self, socket, count):
     ''' Get all tables in the datalogger except for "Public" and "Status"
         count: maximum number of retries
     '''
     list_of_tables = []
     
     self.log.debug('Getting tables for {}'.format( self.metric_id))
     
     if self.FileData:
         for tableno in range(len(self.tabledef)):
             # ignore tables "Public" and "Status"
             if self.tabledef[tableno]['Header']['TableName'] != "Public" and self.tabledef[tableno]['Header']['TableName'] != "Status":
                 list_of_tables += [Table(self.tabledef[tableno]['Header']['TableName'], self.tabledef, tableno)]
     else:
         if (count > 0):
             self.FileData, RespCode = pakbus.fileupload(socket, self.pakbus_id, self.my_node_id, FileName = '.TDF')                        
             self.log.debug(" -- table def RespCode was: {}".format(RespCode))
             return self.getTables(socket, count-1)
         else:
             # raise exception??
             print "Could not get tables for datalogger with metric: " + str(self.metric_id) + " and pakbus: " + str(self.pakbus_id) + " after 3 tries."
     return list_of_tables
Example #8
0
# Data logger PakBus Node Id
NodeId = str2int(cf.get('pakbus', 'node_id'))
# My PakBus Node Id
MyNodeId = str2int(cf.get('pakbus', 'my_node_id'))

# Open socket
s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'), cf.getint('pakbus', 'timeout'))

# check if remote node is up
msg = pakbus.ping_node(s, NodeId, MyNodeId)
if not msg:
    raise Warning('no reply from PakBus node 0x%.3x' % NodeId)

#
# Main program
#

# Upload directory data
FileData, Response = pakbus.fileupload(s, NodeId, MyNodeId, '.DIR')

# List files in directory
filedir = pakbus.parse_filedir(FileData)
for file in filedir['files']:
    print file

# say good bye
pakbus.send(s, pakbus.pkt_bye_cmd(NodeId, MyNodeId))

# close socket
s.close()
Example #9
0
MyNodeId = str2int(cf.get("pakbus", "my_node_id"))

# Open socket
s = pakbus.open_socket(cf.get("pakbus", "host"), cf.getint("pakbus", "port"), cf.getint("pakbus", "timeout"))

# check if remote node is up
msg = pakbus.ping_node(s, NodeId, MyNodeId)
if not msg:
    raise Warning("no reply from PakBus node 0x%.3x" % NodeId)

#
# Main program
#

# Upload directory data
FileData, Response = pakbus.fileupload(s, NodeId, MyNodeId, ".DIR")

# print FileData
# print '\n'


# List files in directory
filedir = pakbus.parse_filedir(FileData)


# print filedir
# print '\n'


for file in filedir["files"]:
    print file
Example #10
0
NodeId = str2int(cf.get('pakbus', 'node_id'))
# My PakBus Node Id
MyNodeId = str2int(cf.get('pakbus', 'my_node_id'))

# Open socket
s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'),
                       cf.getint('pakbus', 'timeout'))

# check if remote node is up
msg = pakbus.ping_node(s, NodeId, MyNodeId)
if not msg:
    raise Warning('no reply from PakBus node 0x%.3x' % NodeId)

#
# Main program
#

# Upload directory data
FileData, Response = pakbus.fileupload(s, NodeId, MyNodeId, '.DIR')

# List files in directory
filedir = pakbus.parse_filedir(FileData)
for file in filedir['files']:
    print file

# say good bye
pakbus.send(s, pakbus.pkt_bye_cmd(NodeId, MyNodeId))

# close socket
s.close()
Example #11
0
# Open socket
s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'),
                       cf.getint('pakbus', 'timeout'))

# check if remote node is up
msg = pakbus.ping_node(s, NodeId, MyNodeId)
if not msg:
    raise Warning('no reply from PakBus node 0x%.3x' % NodeId)

#
# Main program
#

# Upload directory data
FileData, Response = pakbus.fileupload(s, NodeId, MyNodeId, '.DIR')

#print FileData
#print '\n'

# List files in directory
filedir = pakbus.parse_filedir(FileData)

#print filedir
#print '\n'

for file in filedir['files']:
    print file
print '\n'

# pakbus address
Example #12
0
MyNodeId = str2int(cf.get('pakbus', 'my_node_id'))

# Open socket
s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'), cf.getint('pakbus', 'timeout'))

# check if remote node is up
msg = pakbus.ping_node(s, NodeId, MyNodeId)
if not msg:
    raise Warning('no reply from PakBus node 0x%.3x' % NodeId)

#
# Main program
#

# Get table definition structure
FileData, RespCode = pakbus.fileupload(s, NodeId, MyNodeId, FileName = '.TDF')

if FileData:
    tabledef = pakbus.parse_tabledef(FileData)
    for tableno in range(1, len(tabledef) + 1):
        print 'Table %d: %s' % (tableno, tabledef[tableno - 1]['Header']['TableName'])
        print 'Table signature: 0x%X' % tabledef[tableno - 1]['Signature']
        print 'Header:', tabledef[tableno - 1]['Header']
        for fieldno in range(1, len(tabledef[tableno - 1]['Fields']) + 1):
            print 'Field %d:' % (fieldno), tabledef[tableno - 1]['Fields'][fieldno - 1]
        print

# say good bye
pkt = pakbus.pkt_bye_cmd(NodeId, MyNodeId)
pakbus.send(s, pkt)