def run(self): global gQueues, gQueue_ret while True: _recv_json = gQueues[self.__id].get(block=True) _timet_in = time.time() _recv_dict = json.loads(_recv_json) if time.time() - self.__timet > 30: self.__timet = time.time() self.__logger.info( "sum=%d, ok=%d, err=%d in 30sec" % (self.__downloadOKCnt + self.__downloadErrCnt, self.__downloadOKCnt, self.__downloadErrCnt)) self.__downloadOKCnt = 0 self.__downloadErrCnt = 0 step = 1 _err = "OK" try: socket.setdefaulttimeout(1) _ret1, _err = wtclib.http_get_cgi_msg2device( {"Lamp": _recv_dict['Lamp']}, ip=_recv_dict['ip'], cgi_name="setting") step = _ret1 except Exception, e: step = -1 self.__logger.warning(str(e) + ' ' + _recv_dict['sn']) _err = str(e) finally:
_ai_ip = "None" _cgi_time = "None" if None != _status_dict: if "AISERVERIP" in _status_dict: _ai_ip = _status_dict["AISERVERIP"] if "timenow" in _status_dict: _cgi_time = _status_dict["timenow"] ret_file = wtclib.http_post_file2device( "reboot_upgrade.zip", _hvpd[4], "upgrade.cgi") mylogger.info("post file") if 200 == ret_file: _post_file = "OK" else: _post_file = "failt" ret, err = wtclib.http_get_cgi_msg2device( _dic1, _hvpd[4], "setting") mylogger.info("http_get_cgi_msg2device") if 1 != ret: _cgi_msg2device = "failt" else: _cgi_msg2device = "OK" _sql = "insert into hvpdlog(cameraID,cmosID,ip,reboot_time,AISERVERIP,cgi_timenow,ret_postfile,ret_cgi_msg2device )" \ "values('%s',%d,'%s',datetime('now','localtime'),'%s','%s','%s','%s')"\ %(_hvpd[0],_hvpd[1],_hvpd[4],_ai_ip,_cgi_time,_post_file,_cgi_msg2device) reboot_Log_cur.execute(_sql) sqlite_cur.execute( "update hvpdOnline set reboot_timet=%d, reboot_time=datetime('now','localtime') " "where cameraID='%s' and cmosID=%d;" % (_timeNow, _hvpd[0], _hvpd[1])) mylogger.info("write log") except Exception, e:
_ai_file = "/1.jpg" except Exception, e: mylogger.error(str(e)) mylogger.error(_sql) return #_dic_pos = {} #mylogger.debug(json.dumps(_ret_dict)) try: AIfile = _ai_file[_ai_file.rfind('/') + 1:] _ret_dict.update({"AIfile": AIfile}) #mylogger.debug(json.dumps(_ret_dict)) mylogger.info(json.dumps(_ret_dict) + " to %s" % _dic_info["sn"]) _ret, _err = wtclib.http_get_cgi_msg2device(dict_msg=_ret_dict, ip=_cameraIp, cgi_name="setting") if 1 != _ret: mylogger.warning("get msg2device = %s" % _err) else: try: _sql = "update spacestatustable set plate_RenewTime=%d,YUVGetfilesTime=%d" \ " where cameraID='%s'" % (_timeSec, _timeSec, _dic_info["sn"]) cur.execute(_sql) except Exception, e: mylogger.error(str(e)) mylogger.error(_sql) except Exception, e: mylogger.error(str(e)) return
return except Exception, e: mylogger.error(str(e)) return try: #_dic_msg = {"plate%dpos"%_car:"%d,%d;%d,%d"%(_LTx, _LTy, _RBx, _RBy),"plate%dget"%_car:500} AIfile = _ai_out[2][_ai_out[2].rfind('/') + 1:] _dic_msg = { "plate%dpos" % _car: "%d,%d;%d,%d" % (_LTx, _LTy, _RBx, _RBy), "plate%dget" % _car: 55, "AIfile": AIfile } #_dic_msg.update(_dic_pos) mylogger.info(json.dumps(_dic_msg) + " to %s" % _dic_info["sn"]) _ret, _err = wtclib.http_get_cgi_msg2device(dict_msg=_dic_msg, ip=_cameraInfo[4], cgi_name="setting") if 1 != _ret: mylogger.warning("get msg2device = " + _err) else: try: cur.execute( "update SpaceForReInfoTable set plateLTx=%d, plateLTy=%d, plateRBx=%d, plateRBy=%d, RenewTime=%d where " "Spaceid='%s'" % (_LTx, _LTy, _RBx, _RBy, _timeSec, _dic_info["space"])) except Exception, e: mylogger.error(str(e)) except Exception, e: mylogger.error(str(e)) mylogger.error("ip is %s" % _cameraInfo[4]) mylogger.error()
def fix_hvpd_ip_addr(cur): global mylog mylog.debug("fix hvpd ip") try: a1 = cur.execute("select * from hvpdIpAddrSettingTable where ReNewFlag<>0") if 0 == a1: mylog.debug("0 hvpd fix ip") return mylog.info("%d hvpds fix ip"%a1) try: _hvpds = cur.fetchmany(a1) except Exception, e: print str(e) + " in line: " + str(sys._getframe().f_lineno) return except (Exception) as e: mylog.error(str(e)) return _pid = os.getpid() for _hvpdIP in _hvpds: try: if 2 == _hvpdIP[2]: a1 = cur.execute("select * from OnlineHvpdStatusTableMem where cameraID='%s' and cmosID=%d" % ( _hvpdIP[0], _hvpdIP[1])) if 0 == a1: continue _OnlineInfo = cur.fetchmany(1)[0] _dic1 = {"Fip": "0", "Fmask": "0", "Frouter": "0", "Fip_set": 0} _timeSec = time.time() wdi(cur) (val, err) = wtclib.http_get_cgi_msg2device(_dic1, ip=_OnlineInfo[4], cgi_name="setting") if 0 != val: cur.execute("update hvpdIpAddrSettingTable set ReNewFlag=0, NewIP=NULL,NewMask=NULL,NewGateway=NULL where cameraID='%s' and cmosID=%d" % ( _hvpdIP[0], _hvpdIP[1])) continue val = 0 err = "IP Error " if None == _hvpdIP[6]: val = 3 err += "ip=None " if None == _hvpdIP[7]: val = 4 err += "mask=None " if None == _hvpdIP[8]: val = 5 err += "router=None" if 0 == val: err = "" if 0 == val and 0 == check_ip_is_ok(_hvpdIP[6]) and 0 == check_ip_is_ok(_hvpdIP[7]) and 0 == check_ip_is_ok(_hvpdIP[8]): a1 = cur.execute("select * from OnlineHvpdStatusTableMem where cameraID='%s' and cmosID=%d"%(_hvpdIP[0], _hvpdIP[1])) if 0 == a1: continue _OnlineInfo = cur.fetchmany(1)[0] _dic1 = {"Fip":_hvpdIP[6], "Fmask":_hvpdIP[7], "Frouter":_hvpdIP[8], "reboot":1,"Fip_set":1} _timeSec = time.time() wdi(cur) (val, err) = wtclib.http_get_cgi_msg2device(_dic1, ip=_OnlineInfo[4], cgi_name="setting") else: val = 2 err = "IP is not good where ip=%s mask=%s router=%s" % (_hvpdIP[6], _hvpdIP[7], _hvpdIP[8]) if 0 != val: cur.execute("update hvpdIpAddrSettingTable set ReNewFlag=0 where cameraID='%s' and cmosID=%d"%(_hvpdIP[0], _hvpdIP[1])) #print "fix %s ip to %s,%s,%s"%(_hvpdIP[0], _hvpdIP[6], _hvpdIP[7], _hvpdIP[8]) mylog.info("fix %s ip to %s,%s,%s"%(_hvpdIP[0], _hvpdIP[6], _hvpdIP[7], _hvpdIP[8])) if "" != err: mylog.warning(err) except Exception, e: print str(e) + " in line: " + str(sys._getframe().f_lineno) mylog.error(str(e))
_need_update = 0 if 0 == hvpd[1]: _CmosOffset = 1 else: _CmosOffset = 4 _vals = [None,None,None] for i in range(_ai_setting[3]): _vals[i] = calc_phase_val3(_xy8_3[8*i:8*(i+1)]) if None == _vals[i]: mylog.debug("%s space%d All position is 0000"%(hvpd[0], i+1)) return _dict_buff = {"phase%dpos"%(i+_CmosOffset):_vals[i]} _dict_msg.update(_dict_buff) mylog.debug("%s update phase to %s @ %s" % (hvpd[0], json.dumps(_dict_msg), hvpd[4])) (_ret, err)=wtclib.http_get_cgi_msg2device(_dict_msg, hvpd[4], cgi_name="setting") if(0 == _ret): mylog.warning('update phase to %s %s'%(hvpd[0], err)) return mylog.debug('update phase to %s %s' % (hvpd[0], err)) try: cur.execute("update CameraPhaseCheckSettingTableMem set phase1pos='%s',phase2pos='%s',phase3pos='%s'," "RenewTimet=%d, RenewDate=now() where cameraID='%s' and cmosID=%d" %(_vals[0],_vals[1],_vals[2], int(time.time()),hvpd[0], hvpd[1])) except Exception, e: mylog.error(str(e)) return import hvpd_status def get_one_hvpd_version(hvpd, cur):
continue if len(_ucmq_dic["sn"]) < 12: continue b1 = cur.execute("select * from DeviceTable where CPUID='%s'" % _ucmq_dic["sn"]) if 0 != b1: _camera_info = cur.fetchmany(1)[0] _dic_msg_set = { "FMAC": _camera_info[2], "Fsn": _camera_info[3], "reboot": 1 } (_val, _err) = wtclib.http_get_cgi_msg2device(_dic_msg_set, _ucmq_dic["ip"], cgi_name="setting") continue _localTime = time.localtime() _year = _localTime.tm_year - 2000 _mon = _localTime.tm_mon try: _old_dev = cur.fetchmany( cur.execute( "select * from DeviceTable where cameraID=(select max(cameraID) as cameraID from DeviceTable)" ))[0] except Exception, e: print str(e) os._exit()
if None == _cur: time.sleep(5) else: break print "DB connect OK" while True: print "********" try: a1 = _cur.execute("select * from OnlineHvpdStatusTableMem") _hvpds = _cur.fetchmany(a1) socket.setdefaulttimeout(1) try: for _hvps in _hvpds: if None == _hvps[4]: continue wtclib.http_get_cgi_msg2device({"Lamp": "R:0,G:20,B:0"}, ip=_hvps[4],cgi_name="setting") print "%s is Green"%_hvps[4] except Exception, e: print str(e) time.sleep(5) try: for _hvps in _hvpds: if None == _hvps[4]: continue wtclib.http_get_cgi_msg2device({"Lamp": "R:0,G:0,B:20"}, ip=_hvps[4],cgi_name="setting") print "%s is Blue" % _hvps[4] except Exception, e: print str(e) time.sleep(5) for _hvps in _hvpds: if None == _hvps[4]: