Esempio n. 1
0
 def __init__(self,
              host=bridge.DEFAULT_HOST,
              ghidra_server_port=bridge.DEFAULT_SERVER_PORT,
              local_server_port=bridge.DEFAULT_CLIENT_PORT):
     self.bridge = bridge.Bridge(host=host,
                                 server_port=local_server_port,
                                 client_port=ghidra_server_port)
Esempio n. 2
0
def MasterController():
    global vehicle_dict, theBridge
    global idx_twin, idx_pool, time_ref, delay_min, time_boundary, time_length, time_window, num_seg_per_time_window
    global echo_flag_monitor, echo_flag_manager, echo_flag_schedul, echo_flag_analyst
    global t_pool, A_pool, num_pool, idx_pool, idx_twin


    #    echo_flag_monitor = True
    #    echo_flag_manager = True
    #    echo_flag_schedul = True
    echo_flag_analyst = True

    theBridge = bridge.Bridge("A_bridge")  # 生成桥梁
    theBridge.SetSegmentNumber(100)  # 缺省128段
    theBridge.ModeAnalyze(3)  # 缺省3阶模态分析

    num_mode = theBridge.num_mode  # 取模态数

    #        omg = theBridge.omegaList[-1]                    # 最高阶模态频率
    #        period = 2.0*np.pi/omg                           # 最高阶模态周期
    #        t_num = int(time_length/period*100.0) + 1

    t_num = num_seg_per_time_window  # 时间窗分段数

    # 为数据池配置空间
    t_pool = [0.0] * (t_num * num_pool)  # 矢量 t_pool,num_pool*t_num 维
    A_pool = [[0.0 for col in range(num_mode)] for row in
              range(t_num * num_pool)]  # 矩阵 A_pool,num_pool*t_num 行,num_mode列

    print "theBridge.omegaList = ", theBridge.omegaList
    print "theBridge.zetaList  = ", theBridge.zetaList

    time_cond = threading.Condition()
    dict_lock = threading.Lock()

    manager = Manager(time_cond, dict_lock)
    monitor = Monitor(time_cond, dict_lock)
    schedul = Schedul(time_cond, dict_lock)
    analyst = Analyst(time_cond, dict_lock)

    manager.start()
    monitor.start()
    schedul.start()
    analyst.start()

    #    ShowAnimate(dict_lock)

    manager.join()
    monitor.join()
    schedul.join()
    analyst.join()
Esempio n. 3
0
 def handle(self):
     """Handles client connection for server"""
     thebridge = bridge.Bridge(self.request)
     buf = b''
     while True:
         data = self.request.recv(1024)
         if not data: break
         buf += data
         lines = buf.split(b'\r\n')
         buf = lines.pop()
         for line in lines:
             print('<', line)
             thebridge.handle(line.decode('utf-8', 'replace'))
     thebridge.disconnect()
Esempio n. 4
0
File: game.py Progetto: yuvadm/r0ket
    def __init__(self,
                 device,
                 gameName,
                 gameChannel,
                 announcechannel,
                 announcemac,
                 maxplayer=0,
                 askname=False,
                 shortpackets=False):
        self.gameName = gameName
        self.channel = gameChannel
        self.gamemac = [int(random.random() * 254) for x in range(1, 6)]
        self.playermac = list(self.gamemac)
        self.playermac[4] += 1
        self.gameid = int(random.random() * (2**15))

        flags = 0
        if maxplayer == 0:
            flags = 1
        if shortpackets:
            flags += 2
        self.bridge = bridge.Bridge(device, self.channel, self.gamemac)
        self.announce = packets.Announce(self.gamemac, self.channel,
                                         self.gameid, flags, self.gameName)

        self.announcequeue = Queue.Queue()
        self.bridge.registerQueue(self.announcequeue)
        self.announcechannel = announcechannel
        self.announcemac = announcemac
        self.askname = askname

        self.sendAnnounce()

        self.maxplayer = maxplayer
        self.players = {}
        self.callbacks = []
        self.queue = Queue.Queue()
        self.bridge.registerQueue(self.queue)
        self.bridge.registerCallback(self.receivedPacket)
        self.checkPlayers()
Esempio n. 5
0
    def __init__(self, player):
        """ Create level 2. """

        # Player start position
        self.posx = 290
        self.posy = 580

        # Call the parent constructor
        Level.__init__(self, player)

        # Door
        block = door.Door()
        block.rect.x = 522
        block.rect.y = 0
        block.player = self.player
        self.door_list.add(block)

        # Walls
        self.walls = [[wall.Wall(0), 58, 0], [wall.Wall(1), 116, 0],
                      [wall.Wall(1), 174, 0], [wall.Wall(1), 232, 0],
                      [wall.Wall(1), 290, 0], [wall.Wall(1), 348, 0],
                      [wall.Wall(1), 406, 0], [wall.Wall(1), 464, 0]]
        for w in self.walls:
            block = w[0]
            block.rect.x = w[1]
            block.rect.y = w[2]
            block.player = self.player
            self.walls_list.add(block)

        # Chest
        self.hearts_needed = 4
        block = chest.Chest(4)
        block.rect.x = 58
        block.rect.y = 348
        block.player = self.player
        self.chest_list.add(block)

        # Hearts
        self.hearts = [[heart.Heart(2), 116, 116], [heart.Heart(0), 580, 116],
                       [heart.Heart(0), 58, 638], [heart.Heart(0), 464, 522]]
        for h in self.hearts:
            block = h[0]
            block.rect.x = h[1]
            block.rect.y = h[2]
            block.player = self.player
            self.hearts_list.add(block)

        # Dragon
        #block = snake.Snake()
        #block.rect.x = 406
        #block.rect.y = 348
        #block.player = self.player
        #self.enemy_list.add(block)

        # Array with type of artifacts, and x, y location of them.
        level = [[artifact.Artifact("Assets/Rock.png", self), 348, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 58],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 464, 116],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 464],
                 [artifact.Artifact("Assets/Rock.png", self), 348, 522],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 464],
                 [artifact.Artifact("Assets/Rock.png", self), 406, 522],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 348],
                 [artifact.Artifact("Assets/Tree.png", self), 174, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 348],
                 [artifact.Artifact("Assets/Tree.png", self), 232, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 406],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 522, 464],
                 [artifact.Artifact("Assets/Tree.png", self), 406, 174],
                 [artifact.Artifact("Assets/Tree.png", self), 464, 174]]
        for a in level:
            block = a[0]
            block.rect.x = a[1]
            block.rect.y = a[2]
            block.player = self.player
            self.artifact_list.add(block)

        # Green blocks
        block = artifact.Artifact("Assets/Block.png", self, True)
        block.rect.x = 232  #406
        block.rect.y = 580
        block.player = self.player
        self.block_list.add(block)

        waters = [[water.Water(), 58, 232], [water.Water(), 116, 232],
                  [water.Water(), 174, 232], [water.Water(), 232, 232],
                  [water.Water(), 58, 290], [water.Water(), 116, 290],
                  [water.Water(), 174, 290], [water.Water(), 232, 290],
                  [water.Water(), 348, 232], [water.Water(), 406, 232],
                  [water.Water(), 464, 232], [water.Water(), 522, 232],
                  [water.Water(), 348, 290], [water.Water(), 406, 290],
                  [water.Water(), 464, 290], [water.Water(), 522, 290],
                  [water.Water(), 638, 232], [water.Water(), 638, 290],
                  [water.Water(), 638, 348], [water.Water(), 638, 406],
                  [water.Water(), 638, 464], [water.Water(), 638, 522],
                  [water.Water(), 638, 580], [water.Water(), 638, 638],
                  [water.Water(), 580, 638], [water.Water(), 522, 638],
                  [water.Water(), 464, 638], [water.Water(), 406, 638]]

        for w in waters:
            block = w[0]
            block.rect.x = w[1]
            block.rect.y = w[2]
            block.player = self.player
            self.water_list.add(block)

        bridges = [[bridge.Bridge("VERTICAL"), 290, 232],
                   [bridge.Bridge("VERTICAL"), 290, 290],
                   [bridge.Bridge("VERTICAL"), 580, 232],
                   [bridge.Bridge("VERTICAL"), 580, 290]]

        for b in bridges:
            block = b[0]
            block.rect.x = b[1]
            block.rect.y = b[2]
            block.player = self.player
            self.bridge_list.add(block)
Esempio n. 6
0
def main():
    '''Main method. Inits gpio, bridge, jack, and pyo. Then reads effects and starts handling gpio'''
    # If GPIO is enabled, initialize the pins and GPIO module.
    if GPIO_CAPABLE:
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(button_pin, GPIO.IN, GPIO.PUD_UP)
        GPIO.setup(23, GPIO.OUT)

        gpio_controller = gpiocontrol.GpioController()

    # Initialize the bridge to allow the app to accept connections.
    bridge_conn = bridge.Bridge()

    # Set up custom options for the sockets
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #UDP SOCKET
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #TCP SOCKET
    s.setblocking(0)
    sock.setblocking(0)
    s.bind(('', 10000))
    sock.bind(('', 10001))

    jack_id = jackserver.start_jack_server()

    # give the application time for JACK to boot.
    time.sleep(5)

    # JACK and Pyo set up procedures
    pyo_server = start_pyo_server()
    pyo_server.setJackAuto()

    # Read input from the audio device on channel 0
    # and apply the necessary effects from the config file 
    enabled_effects = chain_effects(pyo.Input(chnl=0), configparser.get_effects())
    apply_effects( enabled_effects )

    # Create necessary variables used by the GPIO controller module
    record_table = []
    audio_recorder = []
    loop = []
    record_table.append(pyo.NewTable(length=60, chnls=1, feedback=0.5))
    audio_recorder.append(pyo.TableRec((enabled_effects[len(enabled_effects) - 1]), table=record_table[-1], fadetime=0.05))
    already_recording = False
    recording_time = 0
    inactive_end_time = 0
    signal.signal(signal.SIGINT, partial(signal_handler, jack_id, pyo_server))

    while True:
        # Executes GPIO and loop machine logic flow.
        if GPIO_CAPABLE:
            # Read the state of the button press. 
            BUTTON_STATE = gpio_controller.update_gpio()
            # Perform actions dependent on the state of the button press.
            if BUTTON_STATE == 'INACTIVE' or BUTTON_STATE == 'LOOPING':
                inactive_end_time = time.time()
            if BUTTON_STATE == 'RECORDING':
                recording_time = time.time()
                if not already_recording:
                    print("Recording audios for 5 segundos")
                    (audio_recorder[-1]).play()
                    already_recording = True
            elif BUTTON_STATE == 'ACTIVATE_LOOP':
                loop_len = recording_time - inactive_end_time
                loop.append(
                    pyo.Looper(
                        table=record_table[-1],
                        dur=loop_len, xfade=0,
                        mul=1).out()
                    )
                record_table.append(
                    pyo.NewTable(
                        length=60,
                        chnls=1,
                        feedback=0.5)
                    )
                audio_recorder.append(
                    pyo.TableRec(
                        (enabled_effects[len(enabled_effects) - 1]),
                        table=record_table[-1],
                        fadetime=0.05)
                    )
                print("ACTIVATING LOOP")
                gpio_controller.set_state("LOOPING")
                already_recording = False
            elif BUTTON_STATE == 'CLEAR_LOOP':
                loop = []
                record_table = []
                audio_recorder = []
                record_table.append(
                    pyo.NewTable(
                        length=60,
                        chnls=1,
                        feedback=0.5)
                    )
                audio_recorder.append(
                    pyo.TableRec(
                        (enabled_effects[len(enabled_effects) - 1]),
                        table=record_table[-1],
                        fadetime=0.05)
                    )
                gpio_controller.set_state("INACTIVE")

        # See if we got a message from the frontend application
        res = bridge_conn.backend(s,sock)
        if res:
            print(res)
            if 'UPDATEPORT' == res[0]:
                # There was a request to update the ports. Kill the
                # JACK server and restart it with the new ports.
                print("Request to update ports")
                pyo_server.shutdown()
                jackserver.kill_jack_server(jack_id)
                time.sleep(2)
                jack_id = jackserver.start_jack_server(jackserver.filter_port_selection(res[1]), jackserver.filter_port_selection(res[2]))
                time.sleep(2)
                pyo_server.reinit(**PYO_INIT_SETTINGS)
                pyo_server.boot()
                pyo_server.start()
            enabled_effects[-1].stop()
            enabled_effects = chain_effects(pyo.Input(chnl=0), configparser.get_effects())
            apply_effects( enabled_effects )
        time.sleep(0.0001)
Esempio n. 7
0
### Import bridge library
import bridge as b

### Instantiate the emulator
bridge = b.Bridge()

### Run the emulator
bridge.run()
    else :
        rows = arcpy.SearchCursor(tableName,"",coordinateSystem)
    bc = bridge.BridgeCollection() 
    for row in rows:
        arcpy.AddMessage("Adding Bridge to List "+ str(row.OBJECTID))       
        feat=row.getValue("SHAPE")
        shape=feat.__geo_interface__
#         geo = asShape(shape)
#         print geo.wkt
        current_Bridge = bridge.Bridge(shape,
                                row.PUENTE,
                                str(row.NUMERO)+"_"+str(row.CO_VI)+"_"+str(row.ELEM)+"_"+str(row.CIV),
                                row.TI_PU,
                                row.TIPO,
                                ADDRESS=row.DIRECCION,
                                LAST_ADDRESS=row.DIRECCION_ANTIGUA,
                                CONSTRUCTION_DATE=row.FECHA_CONSTRUCCION,
                                LENGTH=row.LONGITUD,
                                WIDTH=row.ANCHO,
                                SUPERSTRUCTURE_AREA=row.AREA_PUENTE,
                                VERTICAL_GAUGE=row.GALIBO,
                                LEVEL=row.PTE_NIVEL,
                                )
        current_Bridge.set_local_id(row.OBJECTID)                
        bc.add_bridge(current_Bridge)
    arcpy.AddMessage("Exporting Data to Openerp")
    bc.export_to_openerp(user_name,password, database_name, openerp_server_url)
     
except Exception as e:    
    arcpy.AddError(e)
    print e
    raise e
Esempio n. 9
0
    list_items = list_elements.find_elements_by_tag_name("li")

    json_output = "[ "

    for item in list_items:
        split_item = item.text.replace('Bridge ', '').replace(
            'Bridge Status:', '').replace('Status: ',
                                          '').replace('Next Arrival: ',
                                                      '').splitlines()

        bridge_id = split_item[0]
        bridge_status = split_item[2]
        next_arrival = split_item[3]

        canal_bridge = bridge.Bridge(bridge_id, bridge_status, next_arrival)
        json_output += canal_bridge.toJsonString() + " ,"

    driver.quit()

    json_output = json_output[:-1]
    json_output += " ]"

    data = {'payload': json_output}

    update_status_url = welland_canal_api + '/update_bridge_status'

    request = requests.post(url=update_status_url, data=data)
    print(json_output)
except:
    print('An error occurred.')
Esempio n. 10
0
import time

import numpy as np
from scipy.integrate import odeint
from matplotlib import pyplot as plt
from matplotlib import animation

import vehicle
import bridge

start_flag = False
finish_flag = False

sec_grade = 6  # 微秒

theBridge = bridge.Bridge("A_bridge")  # 运行桥梁
vehicle_dict = dict()  # 车辆字典

time_ref = 0  # 参考时间(初值零)

delay_min = vehicle.t_delay_fast  # 最小时间延迟
time_boundary = (0, 0)  # 时间边界(初值)

time_length = delay_min / 4.0  # 时间窗口长度(初值)
time_window = (0, 0)  # 时间窗口(初值)
num_seg_per_time_window = 50  # 每时窗分段数

A_pool = list()  # 模态坐标数据池
t_pool = list()  # 时间数据池
num_pool = 6  # 预留num_pool个数据池,供循环存放num_pool个时间窗口的模态响应数据
idx_pool = 0  # 当前数据池