Exemplo n.º 1
0
    def test_dummy(self):
        bridge = Bridge()

        c = string.digits + string.ascii_letters
        n = string.digits

        for i in range(1,10):
            ranIDLen = random.randint(1,10)
            ranPWLen = random.randint(1,10)
            ranNameLen = random.randint(0,5)
            ranID  = ''.join(random.sample(c,ranIDLen))
            ranPW  = ''.join(random.sample(c,ranPWLen))
            ranName = ''.join(random.sample(c,ranNameLen))
            ranPhone = "010"+str(''.join(random.sample(n,8)))
            ranAddress = ''.join(random.sample(c,ranNameLen))
            doc = { 'id':ranID,'pw':ranPW,'name':ranName,'phone':ranPhone,'address':ranAddress}
#            doc = { 'name':ranName,'phone':ranPhone,'address':ranAddress}
#            doc = {'address':ranAddress}
#            doc = { 'id':ranID, 'address':ranAddress}
            try:
                pass
#                bridge.application('App3').schema('JoinPage').insert(doc)
            except:
                 print ("insert faild", sys.exc_info()[0])


        cursor = bridge.application('App3').schema('JoinPage').find({'phone':"01017935084"})
        data = json_util.dumps(cursor)
        print(data)

#        for i in range(1,50):
 #           bridge.application('App3').schema('JoinPage').find({'id':'1'},{'pw':'0'})

 #       for i in range(1,80):
 #           bridge.application('App3').schema('JoinPage').find({'name':'1'},{ 'phone':'0'})
Exemplo n.º 2
0
    def get(self):
        #client = MongoClient(self.__machine.addr, self.__machine.port )
        #db = client.db
        #result = db[self.__hostUrl].find(self.__hostQuery)
        bridge = Bridge(self.__machine)
        result = bridge.application('lesser').schema(self.__hostUrl).find(self.__hostQuery)
        print(result)


        return result
Exemplo n.º 3
0
    def post(self):
        #client = MongoClient(self.__machine.addr, self.__machine.port )
        #db = client.db
        #result = {'object_id' : db[self.__hostUrl].insert(self.__hostText).inserted_id}
        bridge = Bridge(self.__machine)
        result = {'object_id' :
                      bridge.application('lesser')
                          .schema(self.__hostUrl)
                          .insert(self.__hostText).inserted_id
                  }

        print(result)

        return result
Exemplo n.º 4
0
    def __init__(self, poll_freq=10):
        self.poll_freq = poll_freq
    
        # Init motor driver and GPIO
        self.driver = Driver()
        self.control = (0, 0,)
        
        self.PIN_IN = 3
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.PIN_IN, GPIO.IN)
        GPIO.add_event_detect(self.PIN_IN, GPIO.FALLING, callback=lambda _: self.toggle(), bouncetime=200)

        # Init communication bridge
        self.bridge = Bridge()
        self.bridge.connect()
Exemplo n.º 5
0
class Main:
    def __init__(self, poll_freq=10):
        self.poll_freq = poll_freq
    
        # Init motor driver and GPIO
        self.driver = Driver()
        self.control = (0, 0,)
        
        self.PIN_IN = 3
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.PIN_IN, GPIO.IN)
        GPIO.add_event_detect(self.PIN_IN, GPIO.FALLING, callback=lambda _: self.toggle(), bouncetime=200)

        # Init communication bridge
        self.bridge = Bridge()
        self.bridge.connect()
        
    def toggle(self):
        pass

    def step(self):
        throttle = self.bridge.get_handler('control/throttle').get_latest()
        steering = self.bridge.get_handler('control/steering').get_latest()
        control = (throttle, steering,)
        
        if control != self.control:
            print(f'[debug] Setting control to {control}')
            self.control = control
            self.driver.go(*control)

    def poll(self):
        while True:
            time.sleep(1/self.poll_freq)
            self.step()

    def run(self):
        t = Thread(target=self.poll, daemon=True)
        t.start()
    
        while True:
            if input() == '':
                break

        self.driver.stop()
        self.driver.cleanup()
Exemplo n.º 6
0
import logging
from logging.handlers import RotatingFileHandler

if __name__ == '__main__':
    sys.path.append(os.getcwd())
    # comment out the following 2 lines to print debug info on stdout
    logging.basicConfig(format='%(asctime)s %(message)s',
                        datefmt='%m/%d/%Y %I:%M:%S %p',
                        level=logging.INFO,
                        filename='maskednet.log')
    logging.getLogger().addHandler(
        RotatingFileHandler('maskednet.log', maxBytes=1024, backupCount=0))
sys.path[0] = os.path.dirname(os.path.realpath(__file__))

from server.srv import Server
from client.client import Client
from bridge.bridge import Bridge
from utils.configurator import Configurator

configurator = Configurator()

server = Server(address=configurator.get('Server', 'address'),
                model_port=configurator.get('Server', 'model_port'),
                bridge_port=configurator.get('Server', 'bridge_port'))
client = Client(server_uri=configurator.get('Client', 'server_uri'))
bridge = Bridge(server_uri=configurator.get('Bridge', 'server_uri'))

server.start()
client.start()
bridge.start()
Exemplo n.º 7
0
def init_controller_obj():
    # let's get this party started
    controller_obj = Bridge()
    return controller_obj
Exemplo n.º 8
0
from bridge.bridge import Bridge

if __name__ == '__main__':
    br = Bridge()