Esempio n. 1
0
def testMore():
    s = ServerConnection("localhost", 47757, "2", "CathodioN", "test", "DummyDevice", "OpenMoko")
    try:
        print "Available groups are: "
        groups =  s.requestGroups()
        for x in groups:
            print "\t%s" %x
        print "Joining group %s" %(groups[0])
        s.joinGroup(groups[0])
        print "\tOK"
        
        pos = Position(23.4545,45.345345,1234.34,89.63,180)
        print "Sending my position: " + str(pos)
        s.sendPosition(pos)
        print "\tOK"
        
        wp = Waypoint(23.234,234.34343,125,"Carpool Parking Space")
        print "Sending my waypoint: " + str(wp)
        s.sendWaypoint(wp)
        print "\tOK"
        
        posOthers = s.requestPositions()
        print "Position of others"
        for pos in posOthers.keys():
            print "\t" + pos + ":" + str(posOthers[pos])

        wpOthers = s.requestWaypoints()
        print "Waypoints of others"
        for wp in wpOthers.keys():
            print "\t" + wp + ":" + str(wpOthers[wp])

    except pygls.GLSException.GLSException, e:
        print "Connection error: " + e.getMsg() + "\n\t" + e.getLongMsg()
Esempio n. 2
0
def testConnection():
    #s = ServerConnection("localhost", 47757, "2", "kichkasch", "secret", "DummyDevice", "OpenMoko")
    s = ServerConnection("localhost", 47757, "2", "CathodioN", "test", "DummyDevice", "OpenMoko")
    try:
        s.testConnection()
    except pygls.GLSException.GLSException, e:
        print "Connection error: " + e.getMsg() + "\n\t" + e.getLongMsg()
Esempio n. 3
0
def moveAround(loops, delay):
    print "Starting up"
    print "\tConnection parameters: %s|%s@%s:%d [group:%s]" %( USER , PASSWORD, SERVER, PORT, GROUP)
    print "\tDoing %d updates with %d seconds delay in between 2 updates." %(loops, delay)
    s = ServerConnection(SERVER, PORT, PROTOCOL_VERSION, USER, PASSWORD, DEVICE, GROUP)
    try:
        print "\n\tJoining group %s" %(GROUP)
        s.joinGroup(GROUP)
        print "\t\tOK"
        
        print "my speed: %f" %SPEED
        deltaX = random.random()* SPEED * 200 - (SPEED*100)
        deltaY = random.random()* SPEED * 200 - (SPEED*100)
        pos = Position(52.538643+deltaX,13.421938+deltaY,1234.34,89.63,180) # this way, 2 won't start exactly at the same location :)
        current = 0
        while loops == 0 or current < loops:
            deltaX = random.random()* SPEED - (SPEED/2)
            deltaY = random.random()* SPEED - (SPEED/2)
            print "\tMoving %f / %f." %(deltaX, deltaY)
            pos = Position(pos.getLatitude()+deltaX,pos.getLongitude()+deltaY,1234.34,89.63,180)
            print "Sending my position: " + str(pos)
            s.sendPosition(pos)
            print "\tOK"
            current +=1
            time.sleep(delay)
        
    except pygls.GLSException.GLSException, e:
        print "Connection error: " + e.getMsg() + "\n\t" + e.getLongMsg()
Esempio n. 4
0
def startup():
    print "Starting up"
    print "\tConnection parameters: %s|%s@%s:%d [group:%s]" %( USER , PASSWORD, SERVER, PORT, GROUP)
    print "\tPresentation parameters: (%d|%d) - (%d|%d)" %(VIEWAREA[0],VIEWAREA[1],VIEWAREA[2],VIEWAREA[3])
    s = ServerConnection(SERVER, PORT, PROTOCOL_VERSION, USER , PASSWORD, DEVICE , GROUP)
    try:
        print "\n\tJoining group %s" %(GROUP)
        s.joinGroup(GROUP)
        print "\t\tOK"

        root = Tk()
        root.title("Simple GLS Location visualiser")
        global canvas
        canvas = Canvas(root, width=SIZE_X, height=SIZE_Y)
        canvas.pack()
        #root.mainloop()

        return s, canvas
    except pygls.GLSException.GLSException, e:
        print "Connection error: " + e.getMsg() + "\n\t" + e.getLongMsg()
        return None, None
Esempio n. 5
0
    def _startup(self):
        """
        Establishes the connection to the GLS server and sets up a continous download of position data.
        
        A new thread is started that will perform updates on the GPS position data on a regular basis.
        
        Applies its settings from a configuration file located in Setup/glssettings.txt
        """
        if self._loadSettings() != 0:
            return -1

        self._s = ServerConnection(self._servername, self._port, PROTOCOL_VERSION, self._username , self._password, self._device , self._groupname)
        self._group = poiGroup(self._groupname)
        self.groups.append(self._group)
        thread.start_new_thread(self._updatePositionsPeriodically, () )
        self._up = 1
        return 0
Esempio n. 6
0
class pyglsPoiModule(poiModule):
    """
    Maintains connection to the GLS server and requests information from there when necessary.
    """
    def __init__(self, modules, parent):
        print "Starting up module GPS location sharing (GLS) in background."
        self._parent = parent
        poiModule.__init__(self, modules)
        if self._startup() == 0:
            self.draw = True
        else:
            self.draw = False
        
    def __del__(self):
        """
        Setting local variable to "false" in order to notify threads about termination.
        """
        self._up = 0
 
    def _loadSettings(self):
        """
        Loads all settings for the GLS module from a configuration file.
        """
        config = ConfigParser.ConfigParser()
        try:
            config.read(FILENAME_GLSSETTINGS)
            self._servername =  config.get("pygls", "server")
            self._port =  int(config.get("pygls", "port"))
            self._groupname =  config.get("pygls", "group")
            self._username =  config.get("pygls", "user")
            self._password =  config.get("pygls", "password")
            self._device =  config.get("pygls", "device")
            self._delay =  int(config.get("pygls", "delay"))
            self._forceRedraw = int(config.get("pygls", "forceredraw"))
            if self._password.strip == "" or self._password == "None":
                self._password = None
        except:
            print "Could not load settings for GLS module (%s)." %(FILENAME_GLSSETTINGS)
            return -1
        return 0
        
    def _startup(self):
        """
        Establishes the connection to the GLS server and sets up a continous download of position data.
        
        A new thread is started that will perform updates on the GPS position data on a regular basis.
        
        Applies its settings from a configuration file located in Setup/glssettings.txt
        """
        if self._loadSettings() != 0:
            return -1

        self._s = ServerConnection(self._servername, self._port, PROTOCOL_VERSION, self._username , self._password, self._device , self._groupname)
        self._group = poiGroup(self._groupname)
        self.groups.append(self._group)
        thread.start_new_thread(self._updatePositionsPeriodically, () )
        self._up = 1
        return 0
               
    def _updatePositionsPeriodically(self):
        """"
        Initiates a pull of gps positions from the server periodically.
        """
        while self._up:
            self._loadPositionsFromServer()
            if self._forceRedraw:
                self._parent.forceRedraw()
            time.sleep(self._delay)

    def _loadPositionsFromServer(self):
        """
        Performs a single download of all available positions on the server.
        """
##        print "pyglsModule: Loading GLS positions from GLS server."
        # clear last positions
        del self._group.items[:]
        
        try:
            self._s.joinGroup(self._groupname)
            posOthers = self._s.requestPositions()
            self._s.closeConnection()
            for pos in posOthers.keys():
##                print "\t" + pos + ":" + str(posOthers[pos])
                item = poi(posOthers[pos].getLatitude(), posOthers[pos].getLongitude())
                item.title = "GLS:%s (OpenMoko)" %(pos)
                self._group.items.append(item)
            return posOthers
        except pygls.GLSException.GLSException, e:
            print "Connection error: " + e.getMsg() + "\n\t" + e.getLongMsg()