Пример #1
0
 def send_alive_msg(self):
     with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
         seed = self.usb_handler.get_seed()
         pck = utils.create_packet(utils.ACTION_ISALIVE,
                                   _id=self.config_gateway['id'],
                                   addr=(self.config_gateway['ip'],
                                         self.sock_tcp.getsockname()[1]),
                                   update_seed_number=seed)
         s.sendto(pck, self.server_addr)
Пример #2
0
def delete_image(auth_token, name):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    data = {'token': auth_token, 'image_name': name}
    pck = utils.create_packet(utils.IMAGE_DELETE, data=json.dumps(data).encode())
    sock_server.sendall(pck)
    res_pck = utils.read_data_from_socket(sock_server)
    if res_pck:
        res = utils.segment_packet(res_pck)
    else:
        res = {'status': 500}
    sock_server.close()

    return res
Пример #3
0
def download_log(auth_token, data):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    token = {'token': auth_token}
    data = utils.update_request_data(data, token)
    pck = utils.create_packet(utils.DEBUG_GET_LOG,
                              data=json.dumps(data).encode())
    sock_server.sendall(pck)

    _dir = os.path.dirname(os.path.abspath(__file__)) + '/images'
    name = utils.get_and_store_log_file(sock_server, _dir, auth_token)
    sock_server.close()

    return _dir, name
Пример #4
0
def user_signup(data):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    pck = utils.create_packet(utils.USERS_SIGNUP, data=data.encode())
    sock_server.sendall(pck)

    res_pck = utils.read_data_from_socket(sock_server)
    if res_pck:
        res = utils.segment_packet(res_pck)
    else:
        res = {'status': 500}
    sock_server.close()

    return res
Пример #5
0
def get_images(auth_token):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    token = {'token': auth_token}
    pck = utils.create_packet(utils.IMAGES_GET, data=json.dumps(token).encode())
    sock_server.sendall(pck)

    res_pck = utils.read_data_from_socket(sock_server)
    if res_pck:
        res = utils.segment_packet(res_pck)
    else:
        res = {'status': 500}
    sock_server.close()

    return res
Пример #6
0
def end_debug_channel(auth_token, data):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    token = {'token': auth_token}
    data = utils.update_request_data(data, token)
    pck = utils.create_packet(utils.DEBUG_END, data=json.dumps(data).encode())
    sock_server.sendall(pck)

    res_pck = utils.read_data_from_socket(sock_server)
    if res_pck:
        res = utils.segment_packet(res_pck)
    else:
        res = {'status': 500}
    sock_server.close()

    return res
Пример #7
0
def save_timeslots(auth_token, slots):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    token = {'token': auth_token}
    data = utils.update_request_data(slots, token)
    pck = utils.create_packet(utils.TIMESLOTS_SAVE, data=json.dumps(data).encode())
    sock_server.sendall(pck)

    res_pck = utils.read_data_from_socket(sock_server)
    if res_pck:
        res = utils.segment_packet(res_pck)
    else:
        res = {'status': 500}
    sock_server.close()

    return res
Пример #8
0
def get_date_slots(auth_token, date):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    data = {}
    data.update({'token': auth_token})
    data.update(date)
    pck = utils.create_packet(utils.TIMESLOTS_GET_DAYSLOTS, data=json.dumps(data).encode())
    sock_server.sendall(pck)

    res_pck = utils.read_data_from_socket(sock_server)
    if res_pck:
        res = utils.segment_packet(res_pck)
    else:
        res = {'status': 500}
    sock_server.close()

    return res
Пример #9
0
def start_debug_channel(self, auth_token, data):
    sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_server.connect((settings.SERVER_IP, int(settings.SERVER_PORT)))

    token = {'token': auth_token}
    data = utils.update_request_data(data, token)
    pck = utils.create_packet(utils.DEBUG_START,
                              data=json.dumps(data).encode())
    sock_server.sendall(pck)

    while True:
        res_pck = utils.read_data_from_socket(
            sock_server, timeout=None)  # Wait for debug data
        if res_pck:
            res = utils.segment_packet(res_pck)
            if 'message' in res:
                socketio.emit('on_debug', res)
                sock_server.close()
                return
            else:
                socketio.emit('on_debug', res)
        else:
            sock_server.close()
            return
Пример #10
0
def instruct_dobot(instructions):
    instructions = json.loads(instructions)

    # Create the socket
    s = socket.socket(
        socket.AF_INET, socket.SOCK_STREAM)
    # Connect to the dobot server
    s.connect(('localhost', 5555))

    print('Sending instruction:\n')

    for i, instruction in enumerate(instructions):
        packet = create_packet(
            x=instruction['x'],
            y=instruction['y'],
            z=instruction['z'],
            rotation=instruction['rotation'],
        )

        s.send(packet)
        time.sleep(1)

    s.shutdown(socket.SHUT_RDWR)
    s.close()
Пример #11
0
    print_bytes, \
    print_state, \
    float_to_byte, \
    create_packet, \
    correct_packet, \
    find_last_packet

from test import get_instructions

# Create the socket
s = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM)
# Connect to the dobot server
s.connect(('localhost', 5555))

packet1 = create_packet(x=225.0, y=-20.0, z=-50.0, rotation=0.0)
packet2 = create_packet(x=225.0, y=0.0, z=-50.0, rotation=0.0)
packet3 = create_packet(x=225.0, y=20.0, z=-50.0, rotation=0.0)

while True:
    user_input = input('>> ')

    if user_input == 'send packet 1':
        s.send(packet1)

    elif user_input == 'send packet 2':
        s.send(packet2)

    elif user_input == 'send packet 3':
        s.send(packet3)
Пример #12
0
 def nodes_reset_req(self, data, sock_server, **kwargs):
     nodes_status = self.usb_handler.nodes_reset(data['node_ids'])
     pck = utils.create_packet(utils.GATEWAY_NODES_RESET, data=json.dumps(nodes_status).encode())
     sock_server.sendall(pck)
Пример #13
0
 def nodes_flash_req(self, data, sock_server, **kwargs):
     nodes_status = self.usb_handler.nodes_flash(data['node_ids'], data['image_name'])
     pck = utils.create_packet(utils.GATEWAY_NODES_FLASH, data=json.dumps(nodes_status).encode())
     sock_server.sendall(pck)
Пример #14
0
 def send_debug_data(self, data):
     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
         s.connect(self.server_addr)
         pck = utils.create_packet(utils.DEBUG_GATEWAY,
                                   data=json.dumps(data).encode())
         s.sendall(pck)