def cmd_return_response(clock_sn, command, content): LTraceDebug('cmd_return_response ' + str(command)) LTraceDebug('cmd_return_response content:' + content) cmd_response = parse_cmd_return_data(content) LTraceDebug(str(cmd_response)) if type(cmd_response).__name__ != 'list': clock_cmd_processor(clock_sn).cmd_return_dispatch(cmd_response) else: for it_cmd in cmd_response: clock_cmd_processor(clock_sn).cmd_return_dispatch(it_cmd) return ['OK']
def heart_beat_process(clock_sn, command, content): LTraceDebug('heart_beat_process ' + str(command)) clock_handle(clock_sn).kick_ass() cmd_line = clock_cmd_processor(clock_sn).cmd_lines_need_to_send() if cmd_line is None: return [] else: return cmd_line
def add_clock_attendance_log(clock_sn, command, content=None): if content is None: return None records = parse_attendance_table_parameters(content) for record in records: server_processor(clock_sn).send_att_log(record) LTraceDebug(records) return ['OK']
def check_server_cmd(self, kick_time): if self.server_processor.is_updating_users(): return if (kick_time - self.heart_beat['lastServerCmd'] ) > self.heart_beat['getServerCmdInterval']: LTraceDebug('check_server_cmd !') self.server_processor.get_server_cmd() self.heart_beat['lastServerCmd'] = kick_time
def add_clock_operate_log(clock_sn, command, content=None): if content is None: return None operations = parse_operate_table_parameters(content) LTraceDebug('add_clock_operate_log operation: {0}'.format(operations)) for operation in operations: process_clock_operation(clock_sn, operation) feedback = ['OK'] return feedback
def get_command(cmd_content): cmd_items = cmd_content.split('&') LTraceDebug(cmd_items) cmd_data = {} for cmd_item in cmd_items: if cmd_item != '': tmp = cmd_item.split('=') cmd_data[tmp[0]] = tmp[1] return cmd_data
def update_clock_information(clock_sn, command, content=None): """ :param clock_sn: :param command: :param content: INFO=Ver6.39 Apr 28 2008,2,0,0,192.168.1.201,10,7,15,11,011 INFO=固件版本号,登记用户数,登记指纹数,考勤记录数,考勤机IP 地址,指纹算法版本 :return: """ LTraceDebug("update_clock_information " + clock_sn) tmp = command['INFO'].split(',') info = { 'FWVersion': tmp[0], 'UserCount': tmp[1], 'FPCount': tmp[2], 'TransactionCount': tmp[3], 'IPAddress': tmp[4], 'FPVersion': tmp[5] } LTraceDebug('update_clock_information info: {0}'.format(info)) clock_cmd_processor(clock_sn).update_clock_basic_info(info) return []
def cmd_return_dispatch(self, response): dispatch_table = { 'INFO': self.update_clock_basic_info, # 'DATA': } LTraceDebug('cmd_return_dispatch in {0}'.format(response)) if response['CMD'] in dispatch_table: dispatch_table[response['CMD']](response['data']) if int(response['Return']) != 0: cmd = db.get_cmd_line(self.sn, int(response['ID'])) if cmd is not None: error_log( self.sn, 'FP_Failed (' + response['Return'] + '):' + cmd['cmdLine'][0:80]) db.del_cmd_line(self.sn, int(response['ID']))
def __init__(self, clock_sn): self.sn = clock_sn self.cmd_processor = clock_cmd_processor(clock_sn) self.server_processor = server_processor(clock_sn) self.options = db.get_clock_options(clock_sn) if self.options is None: self.options = copy.deepcopy(DefaultClockOptions) db.update_clock_options(clock_sn, DefaultClockOptions) self.heart_beat = db.get_heartbeat_setting(clock_sn) LTraceDebug(self.heart_beat) if self.heart_beat is None: self.heart_beat = copy.deepcopy(DefaultHeartBeatSetting) self.heart_beat['syncAttLogTime'] += random.randrange(0, 600, 17) self.heart_beat['syncStudentTime'] += random.randrange(0, 3000, 27) db.update_heartbeat_setting(clock_sn, DefaultHeartBeatSetting) info_log(self.sn, '考勤机(' + self.sn + ')上线!!') LTraceInfo('考勤机(' + self.sn + ')上线!!') CmdGenerator.clock_info(self.sn)
def update_clock_basic_info(self, info): LTraceDebug('update_clock_basic_info in: {0}'.format(info)) db.update_clock_info(self.sn, info) return
def cmd_check_response(clock_sn, command, content): LTraceDebug('cmd_check_response ' + str(command)) return []