示例#1
0
    def post(self):
        '''处理精确控制'''
        true_code = True
        err_msg = ""
        arg_of_cmd = 0

        cmd = self.get_argument("command").strip().lower()
        arg_of_cmd = self.get_argument("args").strip().lower()
        target = self.get_argument("target").strip().lower().encode('utf-8')
        arg = 0
        if arg_of_cmd != "":
            arg = int(arg_of_cmd)
        if arg > 99 or arg < 0:
            err_msg += "时间参数应大于0小于100"
            true_code = False

        print arg_of_cmd
        if true_code:
            print cmd, target
            encoded_cmd_list, cmd_type = operate_serial.encode_cmd(cmd, target, arg_of_cmd)
            print encoded_cmd_list
            results = operate_serial.send_cmd(encoded_cmd_list, cmd_type)
            if type(results) == type(list()):
                max_try = 0
                for result in results:
                    if result[2] == 0:
                        max_try += 5
                    else:
                        max_try += result[1] - 1
                results_str = self.convert_results(results)
                self.write(results_str + '-' + str(max_try))
            else:
                self.write(results)
        else:
            self.write(err_msg)
示例#2
0
    def post(self):
        '''处理基本控制'''
        cmd = self.get_argument("command").strip().lower()
        target = self.get_argument("towho").strip().lower()
        print cmd, target

        encoded_cmd_list, cmd_type = operate_serial.encode_cmd(cmd, target)
        results = operate_serial.send_cmd(encoded_cmd_list, cmd_type)
        if type(results) == type(list()):
            max_try = 0
            for result in results:
                if result[2] == 0:
                    max_try += 5
                else:
                    max_try += result[1] - 1
            self.write(self.convert_results(results) + '-' + str(max_try))
        else:
            self.write(results)
示例#3
0
    def post(self):
        '''处理批量指令'''
        arg_name_err = "第%s条代码的第%d个参数名称有错"
        arg_value_err = "第%s条代码的第%d个参数值不符合要求"
        err_msg = ""
        arg_of_cmd = 0

        multi_cmds = self.get_argument("multicmds").strip().lower().encode('utf-8')
        cmd_list = multi_cmds.split(";")
        if multi_cmds.endswith(';'):
            cmd_list = cmd_list[:-1]

        # 检查语法与逻辑错误
        true_code = True
        for index, cmd in enumerate(cmd_list):
            target = None
            cmd = cmd.strip("\n")
            cmd_parts = re.split(r'\s+', cmd)
            cmd = cmd_parts[0]
            cmd_len = len(cmd_parts)
            var_time_count = 0
            var_car_count = 0
            if cmd_len == 2 or cmd_len == 3:
                second_part_list = cmd_parts[1].split("=")
                if second_part_list[0].strip() == "time":
                    arg_of_cmd = int(second_part_list[1].strip())
                    print arg_of_cmd
                    if arg_of_cmd > 99 or arg_of_cmd < 0:
                        err_msg += "第%s条代码:时间参数应大于0小于100" %(str(index+1), ) + "<br />"
                        true_code = False
                    var_time_count += 1
                elif second_part_list[0].strip() == "car":
                    target = second_part_list[1].strip()
                    if target not in operate_serial.version_dict.keys():
                        err_msg += "第%s条代码:不存在该小车" %(str(index+1), ) + "<br />"
                        true_code= False
                    var_car_count += 1
                else:
                    true_code = False
                    err_msg += arg_name_err % (str(index+1), 1) + "<br />"
            if cmd_len == 3:
                third_part_list = cmd_parts[2].split("=")
                if third_part_list[0].strip() == "time":
                    if var_time_count == 1:
                        true_code = False
                        err_msg += "第%s条代码重复出现参数time" % (str(index+1), ) + "<br />"
                    else:
                        arg_of_cmd = int(third_part_list[1].strip())
                        if arg_of_cmd > 99 or arg_of_cmd < 0:
                            err_msg += "第%s条代码:时间参数应大于0小于100"
                            true_code = False
                        print arg_of_cmd
                        var_time_count += 1
                elif third_part_list[0].strip() == "car":
                    if var_car_count == 1:
                        true_code = False
                        err_msg += "第%s条代码重复出现参数car" % (str(index+1), ) + "<br />"
                    else:
                        target = third_part_list[1].strip()
                        if target not in operate_serial.version_dict.keys():
                            err_msg += "第%s条代码:不存在该小车" %(str(index+1), ) + "<br />"
                            true_code = False
                        var_car_count += 1
                else:
                    true_code = False
                    err_msg += arg_name_err % (str(index+1), 2) + "<br />"
            if cmd not in operate_serial.CMD_CODE.keys() or target == None:
                err_msg += '第%s条代码:指令格式不对' %(str(index+1), ) + "<br />"
                true_code = False

        if true_code:
            # 如果没有语法与逻辑错误,则逐条指令解析并发送

            results = ''
            arg_of_cmd = ''
            all_max_try = 0
            for ctr_cmd in cmd_list:
                ctr_cmd = ctr_cmd.strip("\n")
                cmd_parts = re.split(r'\s+', ctr_cmd)
                cmd = cmd_parts[0]
                cmd_len = len(cmd_parts)
                if cmd_len >= 2:
                    second_part_list = cmd_parts[1].split('=')
                    if second_part_list[0].strip() == 'time':
                        arg_of_cmd = second_part_list[1].strip()
                    elif second_part_list[0].strip() == 'car':
                        target = second_part_list[1].strip()
                if cmd_len == 3:
                    third_part_list = cmd_parts[2].split('=')
                    if third_part_list[0].strip() == 'time':
                        arg_of_cmd = third_part_list[1].strip()
                    elif third_part_list[0].strip() == 'car':
                        target = third_part_list[1].strip()
                encoded_cmd_list, cmd_type = operate_serial.encode_cmd(cmd, target, arg_of_cmd)
                result = operate_serial.send_cmd(encoded_cmd_list, cmd_type)
                if type(result) == type(list()):
                    for r in result:
                        if r[2] == 0:
                            all_max_try += 5
                        else:
                            all_max_try = r[1] - 1
                    results += self.convert_results(result)
                else:
                    results += result + "<br />"
            self.write(results + '-' + str(all_max_try))
        else:
            self.write(err_msg)