コード例 #1
0
def createBeacons():
    beacon1 = beacon.Beacon()
    beacon2 = beacon.Beacon()
    beacon3 = beacon.Beacon()
    beacon1.setGPS(0, 32.250327, -110.935402, 0)
    beacon2.setGPS(1, 32.232162, -110.951885, 45)
    beacon3.setGPS(2, 32.226696, -110.960383, 90)
    return [beacon1, beacon2, beacon3]
コード例 #2
0
ファイル: GPSMap.py プロジェクト: Labbaker/SeniorDesign
def createBeacons():
    beacon1 = beacon.Beacon()
    beacon2 = beacon.Beacon()
    beacon3 = beacon.Beacon()
    beacon1.setGps(0, 32.950327, -112.605402, 0)
    beacon2.setGps(1, 32.932162, -112.551885, 45)
    beacon3.setGps(2, 32.926696, -112.560383, 90)
    return [beacon1, beacon2, beacon3]
コード例 #3
0
    def SvcDoRun(self):

        import sys, os

        p = os.path.dirname(__file__)

        f = open(os.path.join(p, 'log.txt'), 'w')
        sys.stdout = f
        sys.stderr = f

        port = config.getPort()

        httpd = httpserver.TivoHTTPServer(('', int(port)),
                                          httpserver.TivoHTTPHandler)

        for section, settings in config.getShares():
            httpd.add_container(section, settings)

        b = beacon.Beacon()
        b.add_service('TiVoMediaServer:' + str(port) + '/http')
        b.start()

        while 1:
            sys.stdout.flush()
            (rx, tx, er) = select.select((httpd, ), (), (), 5)
            for sck in rx:
                sck.handle_request()
            rc = win32event.WaitForSingleObject(self.stop_event, 5)
            if rc == win32event.WAIT_OBJECT_0:
                b.stop()
                break
コード例 #4
0
def setup(in_service=False):
    config.init(sys.argv[1:], in_service)
    config.init_logging()
    sys.excepthook = exceptionLogger

    port = config.getPort()

    httpd = httpserver.TivoHTTPServer(('', int(port)),
                                      httpserver.TivoHTTPHandler)

    logger = logging.getLogger('pyTivo')
    logger.info('Last modified: ' + last_date())
    logger.info('Python: ' + platform.python_version())
    logger.info('System: ' + platform.platform())

    for section, settings in config.getShares():
        httpd.add_container(section, settings)

    b = beacon.Beacon()
    b.add_service('TiVoMediaServer:%s/http' % port)
    b.start()
    if 'listen' in config.getBeaconAddresses():
        b.listen()

    httpd.set_beacon(b)
    httpd.set_service_status(in_service)

    logger.info('pyTivo is ready.')
    return httpd
コード例 #5
0
    def handle_msg(self, msg_pmt):
        msg = pmt.cdr(msg_pmt)
        if not pmt.is_u8vector(msg):
            print "[ERROR] Received invalid message type. Expected u8vector"
            return
        packet = str(bytearray(pmt.u8vector_elements(msg)))

        try:
            print(str(beacon.Beacon(packet[4:])))
        except ValueError as e:
            print e
コード例 #6
0
def setup(in_service=False):
    config.init(sys.argv[1:])
    config.init_logging()
    sys.excepthook = exceptionLogger

    port = config.getPort()

    httpd = httpserver.TivoHTTPServer(('', int(port)),
                                      httpserver.TivoHTTPHandler)

    logger = logging.getLogger('pyTivo')
    logger.info('Last modified: ' + last_date())
    logger.info('Python: ' + platform.python_version())
    logger.info('System: ' + platform.platform())

    for section, settings in config.getShares():
        httpd.add_container(section, settings)
        # Precaching of files: does a recursive list of base path
        if settings.get('precache', 'False').lower() == 'true':
            plugin = GetPlugin(settings.get('type'))
            if hasattr(plugin, 'pre_cache'):
                logger.info('Pre-caching the ' + section + ' share.')
                pre_cache_filter = getattr(plugin, 'pre_cache')

                def build_recursive_list(path):
                    try:
                        for f in os.listdir(path):
                            f = os.path.join(path, f)
                            if os.path.isdir(f):
                                build_recursive_list(f)
                            else:
                                pre_cache_filter(f)
                    except:
                        pass

                build_recursive_list(settings.get('path'))

    b = beacon.Beacon()
    b.add_service('TiVoMediaServer:%s/http' % port)
    b.start()
    if 'listen' in config.getBeaconAddresses():
        b.listen()

    httpd.set_beacon(b)
    httpd.set_service_status(in_service)

    logger.info('pyTivo is ready.')
    return httpd
コード例 #7
0
    def update(self, event):
        #pin acking
        i = 0
        ID = None
        LAT = None
        LON = None
        TIMEST = None
        DEVID = None
        BEAID = None
        SEV = None
        STAT = None

        if (self.ser.in_waiting > 0):
            while (self.ser.in_waiting > 0):
                """
                # Read a line from the serial buffer,
                # decode it using utf-8 and
                # split it into chunks at each comma
                """
                line = self.ser.readline().decode("utf-8")
                self.outFile.write(line)
                #print(line)
                line = line.split(',')
                for i in range(len(line)):
                    if line[i] == 'PG':
                        for i in range(len(line)):
                            if line[i] == 'ID':
                                ID = int(line[i + 1])
                            elif line[i] == 'LT':
                                LAT = float(line[i + 1]) / 1000000
                            elif line[i] == 'LN':
                                LON = float(line[i + 1]) / 1000000
                            elif line[i] == 'TS':
                                TIMEST = float(line[i + 1])
                        inList = False
                        for beaconTmp in self.beacons:
                            if beaconTmp.id == ID:
                                beaconTmp.setGPS(ID, LAT, LON, TIMEST)
                                inList = True
                            else:
                                beaconTmp = beacon.Beacon()
                                beaconTmp.setGPS(ID, LAT, LON, TIMEST)
                                self.beacons.append(beaconTmp)
                    #AT,ID,0,DI,0,BI,0,SV,0,TS,0,LT,0,LN,0
                    elif line[i] == 'AT':
                        for i in range(len(line)):
                            if line[i] == 'ID':
                                ID = int(line[i + 1])
                            elif line[i] == 'DI':
                                DEVID = float(line[i + 1])
                            elif line[i] == 'BI':
                                BEAID = float(line[i + 1])
                            elif line[i] == 'SV':
                                SEV = float(line[i + 1])
                            elif line[i] == 'ST':
                                STAT = float(line[i + 1])
                            elif line[i] == 'TS':
                                TIMEST = float(line[i + 1])
                            elif line[i] == 'LT':
                                LAT = float(line[i + 1])
                            elif line[i] == 'LN':
                                LON = float(line[i + 1])
                            inList = False
                            for alertTmp in self.alerts:
                                if alertTmp.id == ID:
                                    alertTmp.setAlertInfo(
                                        ID, DEVID, BEAID, SEV, STAT, TIMEST,
                                        LAT, LON)
                                    inList = True
                                else:
                                    alertTmp = alert.Alert()
                                    alertTmp.setAlertInfo(
                                        ID, DEVID, BEAID, SEV, STAT, TIMEST,
                                        LAT, LON)
                                    self.alerts.append(AlertTmp)
                #print("ID:",ID,"\t","LAT:",LAT,"\t","LON:",LON,"\t","HEAD:",HEAD)
            #print("render")
            self.mapPanel.beacons = self.beacons
            self.beaconPanel.beacons = self.beacons
            self.alertPanel.alerts = self.alerts
            self.mapPanel.refresh()
            self.beaconPanel.refresh()
            self.alertPanel.refresh()
            self.Show()
コード例 #8
0
 def createBeacons(self):
     self.beacon1 = beacon.Beacon()
     self.beacon1.setGPS(0, 32.250327, -110.935402, 0)
     self.beacons = [self.beacon1]
コード例 #9
0
import beacon
import zerorpc

b = beacon.Beacon(12000, "abc")
b.daemon = True
b.start()


class HelloRPC(object):
    def hello(self, name):
        return "Hello, %s" % name


s = zerorpc.Server(HelloRPC())
s.bind("tcp://0.0.0.0:4242")
s.run()
コード例 #10
0
 def test_beacon_incorrect(self):
     with pytest.raises(RuntimeError):
         beacon.Beacon("This is not XML")
コード例 #11
0
 def test_beacon_correct(self):
     b = beacon.Beacon(SAMPLE)
     assert b["version"] == "Version 1.0"
     assert b[
         "outputValue"] == "3E3F13AB4786C101BEFE153B25F40490821B78B6AA77C5E76A2C912073A91866F2F7896E016907754E02161E4C2AA48B06766BFC48FFA568B1164D630D9818D5"  # NOQA
コード例 #12
0
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((settings.http.bind_address, settings.http.port))
            print "Server already running, exiting."
            sys.exit(2)
        except socket.error, msg:
            pass
        log.info("Socket free.")

        uzbl = None
        if not settings.staging:
            # Get the browser going
            uzbl = browser.Browser()
            p = playlist.Player(uzbl, 'playlist.json')
            log.info("Starting player thread")
            p.start()

            if hasattr(settings, 'server_url'):
                b = beacon.Beacon(utils.get_mac_address(settings.interface),
                                  uzbl)
                log.info("Starting beacon thread")
                b.start()
            else:
                log.info("No server configured, operating in standalone mode.")

    log.info("Serving requests.")
    bottle.run(port=settings.http.port,
               host=settings.http.bind_address,
               debug=settings.debug,
               reloader=settings.debug)
コード例 #13
0
    if settings.get('precache', 'False').lower() == 'true':
        plugin = GetPlugin(settings.get('type'))
        if hasattr(plugin, 'pre_cache'):
            print 'Pre-caching the', section, 'share.'
            pre_cache_filter = getattr(plugin, 'pre_cache')

            def build_recursive_list(path):
                try:
                    for f in os.listdir(path):
                        f = os.path.join(path, f)
                        if os.path.isdir(f):
                            build_recursive_list(f)
                        else:
                            pre_cache_filter(f)
                except:
                    pass

            build_recursive_list(settings.get('path'))

b = beacon.Beacon()
b.add_service('TiVoMediaServer:' + str(port) + '/http')
b.start()
if 'listen' in config.getBeaconAddresses():
    b.listen()

print 'pyTivo is ready.'
try:
    httpd.serve_forever()
except KeyboardInterrupt:
    b.stop()
コード例 #14
0
                else:
                    if beacon.is_active_long_time(
                            now) or beacon.is_rssi_changed():
                        if now - self.started_at > 10:
                            self.send("/api/beacons",
                                      json.dumps(beacon.jsonify()))
                        else:
                            print("too early to send changed rssi")

    def send(self, url, payload):
        """
        Sends payload to server by TCP/IP socket

        :param url: Endpoint
        :param payload: JSON data
        """

        print(url + ": " + payload)
        try:
            requests.post(self.rest_url + url,
                          headers={"Content-Type": "application/json"},
                          data=payload)
        except requests.exceptions.ConnectionError:
            print('Connection error')


if __name__ == "__main__":
    Main("livingroom", "http://192.168.1.203:3000", [
        b.Beacon("c6:f8:b3:66:d1:95", "kocar"),
    ]).run()