示例#1
0
 def remove_client(self, client):
     comms.send(client, comms.EOT)
     client_name = self.get_client_name(client)
     print 'Server: end connection with %s' % client_name
     client.close()
     self.inputs.remove(client)
     del self.client_map[client_name]
     del self.client_name_map[client]
示例#2
0
 def remove_client(self, client):
     comms.send(client, comms.EOT)
     client_name = self.get_client_name(client)
     print 'Server: end connection with %s' % client_name
     client.close()
     self.inputs.remove(client)
     del self.client_map[client_name]
     del self.client_name_map[client]
示例#3
0
def doMoveAndTurn():
    x = int(raw_input("X: "))
    y = int(raw_input("Y: "))
    heading = math.degrees(math.atan2(y, x))
    distance = math.sqrt(x**2+y**2)

    finalHeading = int(raw_input("Final Heading: "))
    finalHeading = (finalHeading-heading)%360
    cmd = b"M"+struct.pack(">h", heading)+struct.pack(">h", distance)+struct.pack(">h", finalHeading)
    comms.send(cmd, robot_id)
示例#4
0
def doMoveAndTurn():
    x = int(raw_input("X: "))
    y = int(raw_input("Y: "))
    heading = math.degrees(math.atan2(y, x))
    distance = math.sqrt(x**2 + y**2)

    finalHeading = int(raw_input("Final Heading: "))
    finalHeading = (finalHeading - heading) % 360
    cmd = b"M" + struct.pack(">h", heading) + struct.pack(
        ">h", distance) + struct.pack(">h", finalHeading)
    comms.send(cmd, robot_id)
示例#5
0
def doOpts():
    subcmd = raw_input("[trkm]: ")
    if subcmd == "t":
        cmd = b"ot"+struct.pack(">B", int(raw_input("t value: ")))
    elif subcmd == "r":
        cmd = b"or"+struct.pack(">B", int(raw_input("r value: ")))
    elif subcmd == "k":
        cmd = b"ok"+struct.pack(">B", int(raw_input("k1 value: ")))+struct.pack(">B", int(raw_input("k1 value: ")))
    elif subcmd == "m":
        cmd = b"om"+struct.pack(">B", int(raw_input("m value: ")))
    else:
        return
    comms.send(cmd, robot_id)
示例#6
0
def log_data(sensor_data):
    global filename, batch_data
    batch_data.append(",".join([str(value) for value in sensor_data]))
    if len(batch_data) >= LOG_FREQUENCY:
        print(batch_data)
        #s = ["".join(x) for x in batch_data]
        #print(s)

        send(_TCP_CONN, "9K2S", "OBC",
             batch_data[0])  #[s.join(x) for x in batch_data])

        with open(filename, "a") as f:
            for line in batch_data:
                f.write(line + "\n")
        batch_data = []
示例#7
0
def doOpts():
    subcmd = raw_input("[trkm]: ")
    if subcmd == "t":
        cmd = b"ot" + struct.pack(">B", int(raw_input("t value: ")))
    elif subcmd == "r":
        cmd = b"or" + struct.pack(">B", int(raw_input("r value: ")))
    elif subcmd == "k":
        cmd = b"ok" + struct.pack(">B", int(
            raw_input("k1 value: "))) + struct.pack(
                ">B", int(raw_input("k1 value: ")))
    elif subcmd == "m":
        cmd = b"om" + struct.pack(">B", int(raw_input("m value: ")))
    else:
        return
    comms.send(cmd, robot_id)
示例#8
0
 def send_message(self, client_name, data):
     client = self.get_client(client_name)
     if client == None:
         raise ClientNotFoundException()
     self.response_received[client_name] = None
     comms.send(client, comms.MSG, data)
     timer = threading.Timer(30.0, self.send_message_failed, [client_name])
     timer.start()
     rate = bwi_tools.WallRate(10)
     while self.response_received == None:
         rate.sleep()
     timer.cancel()
     if self.response_received == comms.ACK:
         return True
     return False
示例#9
0
 def send_message(self, client_name, data):
     client = self.get_client(client_name)
     if client == None:
         raise ClientNotFoundException()
     self.response_received[client_name] = None
     comms.send(client, comms.MSG, data)
     timer = threading.Timer(30.0, self.send_message_failed, [client_name])
     timer.start()
     rate = bwi_tools.WallRate(10)
     while self.response_received == None:
         rate.sleep()
     timer.cancel()
     if self.response_received == comms.ACK:
         return True
     return False
示例#10
0
 def _send_next(self):
     msg = self._msg_queue[0]
     if msg.destination not in self._robots_in_view:
         rospy.logwarn(
             "%s attempted to send %s to %s, but robot was not in view" %
             (rospy.get_caller_id(), msg.data, msg.destination))
         del self._msg_queue[0]
     else:
         rospy.loginfo("%s attempting to send %s to %s" %
                       (rospy.get_caller_id(), msg.data, msg.destination))
         try:
             send(msg.destination, self._ip_addresses[msg.destination],
                  self.hostname, msg.topic, msg.data)
             del self._msg_queue[0]
             rospy.loginfo(
                 "%s successfully sent %s to %s" %
                 (rospy.get_caller_id(), msg.data, msg.destination))
         except:  # What's this catching?
             # Possibly have a limit for attempts - we don't want to loop forever.
             pass
示例#11
0
def doData():
    filename = raw_input("File to transmit: ")
    i2c_freq = int(raw_input("Frequency on i2c: "))
    with open(filename, mode='rb') as infile:
        data = infile.read(255)

    chunk_count = int(math.ceil(len(data) * 1.0 / chunk_size))

    # d[1B packet num][1B i2c freq][1B data len]
    cmd = b"d\x00" + struct.pack(">B", i2c_freq) + struct.pack(">B", len(data))
    comms.send(cmd, robot_id)
    # print ":".join("{:02x}".format(ord(c)) for c in cmd)

    for i in range(chunk_count):
        # time.sleep(1)
        # d[1B packet num][1B index of first byte in packet][1B packet len][data]
        data_size = chunk_size if i != chunk_count - 1 else len(
            data) % chunk_size
        first_byte = i * chunk_size
        data_str = b"d" + struct.pack(">B", i + 1) + struct.pack(
            ">B", first_byte) + struct.pack(">B", data_size) + b"".join(
                data[first_byte:first_byte + data_size])
        # print ":".join("{:02x}".format(ord(c)) for c in data_str)
        comms.send(data_str, robot_id)

    while (comms.packetlist != []):
        time.sleep(1)

    # d[1B FF]
    cmd = b"d\xff"
    comms.send(cmd, robot_id)
示例#12
0
def doData():
    filename = raw_input("File to transmit: ")
    i2c_freq = int(raw_input("Frequency on i2c: "))
    with open(filename, mode='rb') as infile:
        data = infile.read(255)

    chunk_count = int( math.ceil(len(data)*1.0/chunk_size))

    # d[1B packet num][1B i2c freq][1B data len]
    cmd = b"d\x00" + struct.pack(">B", i2c_freq) + struct.pack(">B", len(data))
    comms.send(cmd, robot_id)
    # print ":".join("{:02x}".format(ord(c)) for c in cmd)

    for i in range(chunk_count):
        # time.sleep(1)
        # d[1B packet num][1B index of first byte in packet][1B packet len][data]
        data_size = chunk_size if i != chunk_count-1 else len(data)%chunk_size
        first_byte = i*chunk_size
        data_str = b"d" + struct.pack(">B", i+1) + struct.pack(">B", first_byte) + struct.pack(">B", data_size) + b"".join(data[first_byte:first_byte+data_size])
        # print ":".join("{:02x}".format(ord(c)) for c in data_str)
        comms.send(data_str, robot_id)

    while (comms.packetlist != []):
        time.sleep(1)

    # d[1B FF]
    cmd = b"d\xff"
    comms.send(cmd, robot_id)
示例#13
0
def query(q):
    """
    Fetch list of work items given a wiql query
    """
    response = comms.send(
        'POST',
        url=f'https://dev.azure.com/{organisation}/_apis/wit/wiql',
        headers=default_headers(),
        content={"query": q})

    ids = [item['id'] for item in response.json()['workItems']]

    work_items = get_work_items_by_id(ids)

    return work_items
示例#14
0
 def ipcDisable(self, listItemId):
     comms.send('disable-' + listItemId)
示例#15
0
class Server(threading.Thread):
    def __init__(self, callback=None, host='', port=12345, max_connections=1):

        threading.Thread.__init__(self)

        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.server.bind((host, port))
        print 'Server: listening to port', port, '...'
        self.server.listen(max_connections)

        self.inputs = [self.server]

        #signal.signal(signal.SIGINT, self.signal_handler)
        self.callback = callback

        self.client_map = {}
        self.client_name_map = {}
        self.response_received = {}

        self.alive = False
        self.server_lock = threading.Lock()

    def run(self):

        rate = bwi_tools.WallRate(20)

        self.alive = True
        while True:
            self.server_lock.acquire()
            if not self.alive:
                break
            try:
                inputready,outputready,exceptready = \
                        select.select(self.inputs, [], [], 0.01)
            except select.error, e:
                break
            except socket.error, e:
                break

            for s in inputready:
                if s == self.server:
                    # handle the server socket
                    client, address = self.server.accept()
                    self.add_client(client, address)
                else:
                    try:
                        type, data = comms.recv(s)
                        if type == comms.ENQ:
                            comms.send(s, comms.ACK)
                        elif type == comms.EOT:
                            self.remove_client(s)
                        elif type == comms.MSG:
                            success = False
                            if data and self.callback != None:
                                success = self.callback(
                                    self.get_client_name(s), data)
                            if success:
                                comms.send(s, comms.ACK)
                            else:
                                comms.send(s, comms.NACK)
                        elif type == comms.ACK or type == comms.NACK:
                            self.response_received[self.get_client_name(
                                s)] = type

                    except socket.error, e:
                        self.remove_client(s)
示例#16
0
 def ipcWindowed(self):
     comms.send('windowed')
示例#17
0
 def ipcScreenBlack(self):
     comms.send('screen-black')
示例#18
0
 def ipcToggleVisibility(self):
     comms.send('toggle-visibility')
示例#19
0
 def ipcToggleFullscreen(self):
     comms.send('toggle-fullscreen')
示例#20
0
 def ipcPlay(self):
     comms.send('play')
示例#21
0
def doKick():
    distance = int(raw_input("Distance to kick: "))
    cmd = b"k"+struct.pack(">h", distance)
    comms.send(cmd, robot_id)
示例#22
0
        # Pack the data with struct
        packet = str(sensor.sensor.id) + "," + str(
            time.time()) + "," + str(data)

        # Put the packed data into a buffer for sending
        packetBuffer.append(packet)


# Loop through the sensors and create a thread for each
threads = []
for sensor in sensors:
    # Create the thread and give it a sensor as an argument
    thread = threading.Thread(target=worker, args=(sensor, ))

    # Make it a daemon so it dies on ctrl+c
    thread.daemon = True

    # Put it in the list of threads
    threads.append(thread)

    # Start the thread
    thread.start()

# Send data to base-station
while True:
    try:
        data = packetBuffer.pop(0)
        comms.send(data)
    except:
        time.sleep(0.1)
示例#23
0
def doKick():
    distance = int(raw_input("Distance to kick: "))
    cmd = b"k" + struct.pack(">h", distance)
    comms.send(cmd, robot_id)
示例#24
0
def doTurn():
    angle = int(raw_input("Angle: "))
    cmd = b"t" + struct.pack(">h", angle)
    comms.send(cmd, robot_id)
示例#25
0
 def ipcEnable(self, listItemId):
     comms.send('enable-' + listItemId)
示例#26
0
def doMove():
    distance = int(raw_input("Distance: "))

    cmd = b"m"+struct.pack(">h", distance)
    comms.send(cmd, robot_id)
示例#27
0
 def funComms(self):
     comms.send('test')
示例#28
0
 def ipcNext(self):
     comms.send('next')
示例#29
0
 def ipcTogglePlay(self):
     comms.send('toggle-play')
示例#30
0
 def ipcPrev(self):
     comms.send('prev')
示例#31
0
 def ipcScreenEnable(self):
     comms.send('screen-enable')
示例#32
0
 def ipcRefresh(self):
     comms.send('refresh')
示例#33
0
 def ipcFullscreen(self):
     comms.send('fullscreen')
示例#34
0
 def ipcGet(self, item):
     comms.send('get-' + item)
示例#35
0
def doTurn():
    angle = int(raw_input("Angle: "))
    cmd = b"t"+struct.pack(">h", angle)
    comms.send(cmd, robot_id)
示例#36
0
 def ipcTarget(self, target):
     comms.send('target-' + target)
示例#37
0
 def ipcPause(self):
     comms.send('pause')
示例#38
0
def doMove():
    distance = int(raw_input("Distance: "))

    cmd = b"m" + struct.pack(">h", distance)
    comms.send(cmd, robot_id)