Пример #1
0
 def outLockStatusReport(self, data):
     data = int(data)
     head = tp.MsgHead()
     head.iMsgType = tp.MsgTypeEnum.STATUS_REPORT
     head.iSubMsgType = tp.MsgSubTypeEnum.UNUSED
     head.iPayloadLen = ct.sizeof(tp.MsgHead) + ct.sizeof(
         tp.ControllerStatus)
     head.iFeedBack = 1
     status = tp.ControllerStatus()
     try:
         arrs = []
         n = 0
         while n < 10:
             gp = os.popen('cat /dev/gpio-P1.7')
             p = gp.read()
             gp.close()
             if p:
                 n = n + 1
                 arrs.append(int(p[0]))
             time.sleep(0.01)
         if 0 in arrs:
             x = int(mod_config.getConfig("device",
                                          "doorclosestatus"))  #关门状态
         else:
             x = int(mod_config.getConfig("device",
                                          "dooropenstatus"))  #开门状态
         status.iInputStatus[0] = ct.c_int32(x)
         if data == 1:
             status.iOutputStatus[0] = ct.c_int32(1)
         else:
             if x == 1:
                 status.iOutputStatus[0] = ct.c_int32(1)
             else:
                 status.iOutputStatus[0] = ct.c_int32(0)
     except Exception, e:
         status.iOutputStatus[0] = ct.c_int32(data)
         status.iInputStatus[0] = ct.c_int32(0)
         logging.error('读取gpio-P1.7出错', e)
Пример #2
0
 def reportDoorStatus(self):
     y = 0
     howtime = int(mod_config.getConfig("device", "howtime"))  #多长时间报警
     alarminterval = int(mod_config.getConfig("device",
                                              "alarminterval"))  #报警间隔时间
     opentime = time.time()  #开门的时间
     while self.socketreconnect:
         try:
             arrs = []
             n = 0
             while n < 10:
                 gp = os.popen('cat /dev/gpio-P1.7')
                 p = gp.read()
                 gp.close()
                 if p:
                     n = n + 1
                     arrs.append(int(p[0]))
                 time.sleep(0.01)
             if 0 in arrs:
                 x = int(mod_config.getConfig("device",
                                              "doorclosestatus"))  #关门状态
             else:
                 x = int(mod_config.getConfig("device",
                                              "dooropenstatus"))  #开门状态
             if y != x:
                 y = x
                 head = tp.MsgHead()
                 head.iMsgType = tp.MsgTypeEnum.STATUS_REPORT
                 head.iSubMsgType = tp.MsgSubTypeEnum.UNUSED
                 head.iPayloadLen = ct.sizeof(tp.MsgHead) + ct.sizeof(
                     tp.ControllerStatus)
                 head.iFeedBack = 1
                 status = tp.ControllerStatus()
                 status.iInputStatus[0] = ct.c_int32(y)
                 status.iOutputStatus[0] = ct.c_int32(y)
                 # self.sock.send(head.pack() + status.pack())
                 self.sockSend(head.pack() + status.pack())
                 if y == 1:
                     opentime = time.time()
                 os.system(
                     'echo ' +
                     str(mod_config.getConfig("device", "lockstatus")) +
                     ' > /dev/gpio-P1.24')  # 上锁
                 if y == 0 and self.isgivealarm == 1 and self.givealarmtime >= 1:
                     self.givealarmtime = 0
                 if int(mod_config.getConfig("device",
                                             "isvideo")) == 1:  #是否录像
                     if y == 1:
                         uitime = time.time()
                         filename = time.strftime("%Y%m%d%H%M%S",
                                                  time.localtime(uitime))
                         os.system(
                             'openRTSP -t -F "/media/sd-mmcblk0p1/' +
                             filename +
                             '." "rtsp://192.168.1.10:554/user=admin&password=&channel=1&stream=0.sdp?real_stream" &'
                         )
                         self.giveAlarm(3, 4, 3, int(uitime))
                     else:
                         rtsp = os.popen(
                             "ps | grep 'openRTSP -t -F /media/sd-mmcblk0p1/' | grep -v grep | awk '{print $1}'"
                         )
                         pid = rtsp.read()
                         rtsp.close()
                         if pid:
                             os.system('kill -HUP ' + pid)
             else:
                 currenttime = time.time()
                 if self.isgivealarm == 0 and x == 1 and (
                         int(currenttime - opentime) == howtime or
                     (int(currenttime - opentime) > howtime
                      and int(currenttime - opentime) %
                      (self.givealarmtime + alarminterval) == 0)):  #开门时间太久
                     ga = threading.Thread(
                         target=self.openDoorLongGiveAlarm)
                     ga.start()
         except Exception, e:
             logging.error(e)
             continue