Exemplo n.º 1
0
    def post(self, _id, _buuid):
        try:
            project = yield dbapi.find_one_by_id("projects", _id)
            project = projectmanager.Project(project)

            board = project.get_board_by_id(_buuid)
            to_jid = board['jid']

            params = ujson.loads(self.request.body.decode('utf-8'))
            logging.info(params)

            cmd = project.get_command(params['cmd_type'])

            commander.send_command(cmd.name, to_jid, values=params['values'], cmd=cmd)

            self.write(json_encode({
                'status': 200,
            }))
            self.set_header("Content-Type", "application/json")        

        except Exception as e:

            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")
Exemplo n.º 2
0
 def post(self):
     logging.info(self.request.arguments)
     command_name = self.get_argument('cmd', None)
     to_jid = self.get_argument('jid', None)
     values = extract_request_dict(self.request, 'values')
     logging.info('---' + str(values))
     try:
         commander.send_command(command_name, to_jid, values)
     except ValueError, e:
         return self.write({
             'status': 400,
             'error': str(e)
         })
Exemplo n.º 3
0
    def post(self, _id, _buuid):
        try:
            project = yield dbapi.find_one_by_id("projects", _id)
            project = projectmanager.Project(project)

            board = project.get_board_by_id(_buuid)
            to_jid = board['jid']

            params = {} 
            reqbody = self.request.body.decode('utf-8')
            if reqbody:
                ujson.loads(reqbody)
            logging.info(params)
            filename = params.get("filename", None)

            if not filename:
                filename = project.fwcode.generateFullFw()
            
            firmwares = flashmanager.list_firmwares(_id, project.value['secretsalt'], project.value['fwextension'])
            #get md5
            md5 = [fw["md5"] for fw in firmwares if fw['filename'] == filename][0]

            #prepare and send command
            cmd_name = "Upload Firmware"
            values = {'fw.file': filename, 'fw.md5': md5}
            cmd = ibcommands.commands_by_name[cmd_name]

            commander.send_command(cmd_name, to_jid, values=values, cmd=cmd)

            self.write(json_encode({
                'status': 200,
            }))
            self.set_header("Content-Type", "application/json")        

        except Exception as e:

            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")
Exemplo n.º 4
0
    def send_firmware_chunks(self, msg):
        fw = msg.get('fw')
        if fw is None:
            return

        from_jid = msg.get('from').split('/')[0]

        num_chunks = fw.get('qty', 0)
        dim_chunk = fw.get('dim', 256)
        area = fw.get('area', 0)
        block = fw.get('block', 0)
        active_file = fw.get('file', None)
        active_projectid = fw.get('projectid', None)

        if active_file is None or active_file == '':
            commander.send_command('Transfer Complete', from_jid, {
                'fw.area': area,
                'fw.block': block,
                'fw.file': active_file,
            })
            return

        chunks = flashmanager.get_b64_chunks(active_projectid, active_file, dim_chunk)
        for i in range(num_chunks):
            data = chunks[block+i].strip() if block+i < len(chunks) else None
            values = {
                'fw.area': area,
                'fw.block': block + i,
                'fw.file': active_file,
            }
            if data is None:
                commander.send_command('Transfer Complete', from_jid, values)
                break
            else:
                values['fw.data'] = data
                commander.send_command('Send Chunk', from_jid, values)

        progress_msg = {
            'type': 'progress',
            'area': area,
            'to': from_jid,
            'total_chunks': len(chunks),
            'chunks_sent': block + num_chunks if data else len(chunks)
        }

        self._broadcast_interface(progress_msg)
Exemplo n.º 5
0
 def set_time(self, msg):
     commander.send_command('timeset', msg['from'])