[Tinyos-2-commits] CVS: tinyos-2.x/apps/UDPEcho/util Listener.py, NONE, 1.1 MySQLListener.py, NONE, 1.1 UdpReport.py, NONE, 1.1

sdhsdh sdhsdh at users.sourceforge.net
Mon Jan 19 16:33:24 PST 2009


Update of /cvsroot/tinyos/tinyos-2.x/apps/UDPEcho/util
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7358/UDPEcho/util

Added Files:
	Listener.py MySQLListener.py UdpReport.py 
Log Message:
 - commit blip stack apps



--- NEW FILE: Listener.py ---

import socket
import UdpReport
import re
import sys

port = 7000

if __name__ == '__main__':

    s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    s.bind(('', port))

    while True:
        data, addr = s.recvfrom(1024)
        if (len(data) > 0):

            rpt = UdpReport.UdpReport(data=data, data_length=len(data))

            print addr
            print rpt


--- NEW FILE: MySQLListener.py ---

import socket
import UdpReport
import re
import sys
import MySQLdb

port = 7000

if __name__ == '__main__':
    conn = MySQLdb.connect (host = "localhost",
                            user = "root",
                            db = "b6lowpan")
    cursor = conn.cursor()
    s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    s.bind(('', port))
    if len(sys.argv) < 2:
        print "\tListener.py <tablename>"
        sys.exit(1)

    try:
        drop = "DROP TABLE " + str(sys.argv[1])
        cursor.execute(drop)
    except:
        print "Drop failed... continuing"

    methods = []
    create_table = "CREATE TABLE " + str(sys.argv[1]) + " ("
    create_table += "ts TIMESTAMP, origin INT(4), "
    insert = "INSERT INTO " + sys.argv[1] + " (origin, "


    re = re.compile('^get_(.*)')
    for method in dir(UdpReport.UdpReport):
        result = re.search(method)
        if result != None:
            create_table += str(result.group(1)) + " INT(4), "
            insert += str(result.group(1)) + ", "
            methods.append(str(result.group(1)))

    create_table = create_table[0:len(create_table) - 2]
    insert = insert[0:len(insert) - 2]
    create_table += ")"
    insert += ") VALUES ("
    print insert
    print create_table

    cursor.execute(create_table)

    while True:
        data, addr = s.recvfrom(1024)
        if (len(data) > 0):


            print
            print str(len(data)) + ":", 
            for i in data:
                print "0x%x" % ord(i),
 
            print
            rpt = UdpReport.UdpReport(data=data, data_length=len(data))
            addr = addr[0]
            AA = addr.split(":")
            print addr
            print rpt


            thisInsert = insert
            thisInsert += "0x" + AA[-1] + ", "

            

            for m in methods:
                try:
                    getter = getattr(rpt, 'get_' + m, None)
                    val = getter()
                except:
                    val = 0
                if (isinstance(val, list)):
                    val = val[0]
                thisInsert += str(val) + ", "
            thisInsert = thisInsert[0:len(thisInsert) - 2]
            thisInsert += ")"

            print thisInsert

            cursor.execute(thisInsert)

    conn.close()


--- NEW FILE: UdpReport.py ---
#
# This class is automatically generated by mig. DO NOT EDIT THIS FILE.
# This class implements a Python interface to the 'UdpReport'
# message type.
#

import tinyos.message.Message

# The default size of this message type in bytes.
DEFAULT_MESSAGE_SIZE = 32

# The Active Message type associated with this message.
AM_TYPE = -1

class UdpReport(tinyos.message.Message.Message):
    # Create a new UdpReport of size 32.
    def __init__(self, data="", addr=None, gid=None, base_offset=0, data_length=32):
        tinyos.message.Message.Message.__init__(self, data, addr, gid, base_offset, data_length)
        self.amTypeSet(AM_TYPE)
[...1012 lines suppressed...]
        return 1
    
    #
    # Return the number of elements in the array 'route.parent.stats.receptions'
    #
    def numElements_route_parent_stats_receptions():
        return 2
    
    #
    # Return the number of elements in the array 'route.parent.stats.receptions'
    # for the given dimension.
    #
    def numElements_route_parent_stats_receptions(self, dimension):
        array_dims = [ 2,  ]
        if dimension < 0 or dimension >= 1:
            raise IndexException
        if array_dims[dimension] == 0:
            raise IndexError
        return array_dims[dimension]
    



More information about the Tinyos-2-commits mailing list