def registrarBoleto(self,mensaje): global conexion_activa if(not conexion_activa): """ Si no hay comunicacion con el servidor se procede a encolar los datos del pago para registrarlos cuando vuelva la conexion""" try: print("Sin conexion") print("Encolando nuevo boleto: ",cola.incluir(mensaje)) print("boletos pendientes: ",cola.inspeccionar()) print("Cantidad de boletos: ",cola.tamano()) resultado=-1 except: print("Error al encolar el boleto") else: """ Si hay comunicacion con el servidor se busca que no existan pagos pendientes por alguna perdida de comunicaion y posteriormente se registra el pago vuelva la conexion""" try: validacion = clientes.configSocket("registro boleto",mensaje) resultado = clientes.enviarMensaje(validacion,mensaje) if(resultado==-1): print("No se pudo registrar el boleto") print("vacia", cola.estaVacia()) while(not cola.estaVacia()): print("boleto pendientes: ",cola.inspeccionar()) print("boleto restantes: ",cola.tamano()) validacion = clientes.configSocket("registro boleto",mensaje) resultado = clientes.enviarMensaje(validacion,cola.extraer()) if(resultado==-1): #break print("No se pudo registrar el boleto") except: print("Error al registrar boleto pendientes")
def registrarPago(self, mensaje): try: Servidor.configSocket("pago boleto", mensaje) if (resultado == "boleto no localizado"): print("Registrando boleto no localizado...") else: print("boleto no localizado, esperando su registro...") return resultado except: print("Error en el registro del pago") return -1
def logPrendido(self): mensaje = str("2") + "," + str("1") + "," + str(21) resultado = Servidor.configSocket("log", mensaje) if (resultado == -1): return False else: return True
def tecladoSum(self, val): global var if (val == 10 and var == 1): #Borrar el ultimo caracter idUser = self.lineIdEmpleado.text()[0:-1] self.lineIdEmpleado.setText(idUser) elif (val == 10 and var == 2): pasw = self.lineContrasena.text()[0:-1] self.lineContrasena.setText(pasw) elif (val == 11 and var == 1): #Limpiar el campo de texto self.lineIdEmpleado.setText("") elif (val == 11 and var == 2): self.lineContrasena.setText("") elif (val >= 0 and val <= 9 and var == 1): #Simbolos numericos para iniciar sesión self.lineIdEmpleado.setText(self.lineIdEmpleado.text() + str(val)) elif (val >= 0 and val <= 9 and var == 2): self.lineContrasena.setText(self.lineContrasena.text() + str(val)) elif (val == 12): #Inicio de sesion #FUNCION PARA INICIAR SESION mensajePsw = self.lineContrasena.text() mensajeIdUser = self.lineIdEmpleado.text() #print(mensajePsw) #print(mensajeIdUser) mensaje = str(mensajeIdUser) + "," + str(mensajePsw) self.lineContrasena.setText("") self.lineIdEmpleado.setText("") algo = cliente.configSocket("inicio sesion", mensaje) print("Eetoy en MAIN:", algo) if (algo == "Inicio de \nSesion Exitoso"): self.cambia(1) self.label_3.setVisible(False) else: self.label_3.setVisible(True)
def pollConexion(self, tipo, nodo): timestamp = datetime.now() mensaje = str("2") + "," + str(tipo) + "," + str(nodo) resultado = Servidor.configSocket("log", mensaje) if (resultado == -1): return False else: return True
def servidorActivo(self): timestamp = datetime.now() mensaje = str("2") + "," + str("0") + "," + str(21) resultado = Servidor.configSocket("log", mensaje) if (resultado == -1): return False else: return True
def buscarTicket(self, mensaje): try: resultado = Servidor.configSocket("informacion boleto", mensaje) if (resultado == "boleto no localizado"): print("Registrando boleto no localizado...") else: print("boleto no localizado, esperando su registro...") return resultado except: print("Error en la busqueda del ticket") return -1
def aplicarDescuento(self): global leido, killer, banderaServer, folio, inTerminal, inFecha, inHora self.desactivarBotones() tipoDescuento = 2 #(Cinemex) mensaje = str(folio) + "," + str(inTerminal) + "," + str( inFecha) + " " + str(inHora) + "," + str(tipoDescuento) algo = cliente.configSocket("descuento a aplicar", mensaje) #print("Mensaje del servidor: ",algo) self.mensajeServer.setText(algo) banderaServer = 1 leido = 0 killer = 0
def logPrendido(self, nodo): mensaje = str("2") + "," + str("1") + "," + str(nodo) resultado = Servidor.configSocket("log", mensaje) resultado = str(resultado.decode('utf-8')) print("hora del servidor:", resultado) if (resultado == -1): return False else: os.system("echo eum | sudo -S date -s '" + resultado + "'") print("hora del servidor:", resultado) return True
def pedirLogs (self): self.inicioDeInstruccion = True print ("PedirLogs", end =" ") try: resultado = Servidor.configSocket("log", mensaje) if resultado == -1: self.conexion_activa = False else: self.conexion_activa = True except: self.conexion_activa = False print ("No se pudo obtenerLogs") #print ("Imprimiendo LOGS", self.logs, end =" ") self.inicioDeInstruccion = False
def obtenerLogs(self): mensaje = str("2") + "," + str("4") + "," + str(21) logs = Servidor.configSocket("log", mensaje) if (logs == -1): return False else: logsResult = [] logs = str(logs.decode('utf-8')) tmp = len(logs) logs = logs[:tmp - 1] logs = logs.replace("[", " ") logs = logs.split(",") #logs = logs[3] #logs = logs.split(',') #for log in logs: # print("Nodo: "+str(log[3])+" "+"Fecha:"+str(log[1])) for log in logs: tmp = len(log) log = log[2:tmp - 1] logsResult.append(log) return logsResult
def leerBotones(self): global espera, pantalla_cont, reproduccion, red, green, blue, rrr, iface, tolerancia, gerencia if (red < 50): rrr = 1 if (red > 150): rrr = 0 if (rrr == 0): red = red - 20 green = green - 20 blue = blue - 20 else: red = red + 20 green = green + 20 blue = blue + 20 self.lboleto.setStyleSheet("color:rgb(" + str(red) + ", " + str(green) + ", " + str(blue) + ");background-color:transparent;") self.fechaLabel() tiempo = 0 if self.f1 != True: self.f2 = False print("------Preguntar Botones --------") if (iface == 1): iface = 0 self.apagarRasp() #self.apagarRasp() if pantalla_cont > 0: pantalla_cont = pantalla_cont + 1 print(pantalla_cont) if pantalla_cont == 30: self.stackedWidget.setCurrentIndex(0) self.lboleto.setText("---> Inserte su boleto <---") pantalla_cont = 0 if botones.leerMasa() == 1: if self.error == 0 and botones.leerAyuda() == 1: #Agregar dato desde la BD mensaje_envio = str(idSal) + "," + str(1) + "," + str( "iniciado") + "," validacion = cliente.configSocket("log salida", mensaje_envio) self.error = 1 mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensajeayuda.mp3' ) mixer.music.play() #self.stackedWidget.setCurrentIndex(8) print("dentro del error") elif self.error == 1 and botones.leerAyuda() == 0: print("dentro del contador:") print(espera) espera = espera + 1 if espera == 25: espera = 0 self.error = 0 #self.stackedWidget.setCurrentIndex(1) elif self.error == 0 and botones.leerAyuda() == 0: if self.mensaje == 1: archivo = open("datos.txt", "w") archivo.close() self.mensaje = 0 #self.stackedWidget.setCurrentIndex(1) mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje1.mp3' ) mixer.music.play() if os.stat("datos.txt").st_size != 0: archivo = open("datos.txt", "r") contenido = archivo.readlines() banner2 = False #IF para validar que el boleto se pudo leer de manera correcta for linea in contenido: if linea == "Estacionamientos unicos de Mexico\n" or ( str("CHT") in str(linea)): banner2 = True archivo.close() if banner2 == True: os.system("sudo wmctrl -a 'zbar'") print("ticket detectado") self.f1 = True archivo = open("datos.txt", "r") contenido = archivo.readlines() i = 0 banner = False tam = len(contenido) for linea in contenido: if i == 1: idBol = linea if i == 2: idExp = linea if i == 3: fecBol = linea if i == 4: horBol = linea if linea == "Estacionamientos unicos de Mexico\n": banner = True if (str("CHT") in str(linea)): gerencia = True if banner == True: i += 1 archivo.close() aux = "" i = 0 if (gerencia == False): idExp = int(idExp) idBol = int(idBol) for dat in fecBol: if i < 10: aux = aux + dat i += 1 fecBol = aux aux = "" i = 0 for dat in horBol: if i < 8: aux = aux + dat i += 1 horBol = aux i = 0 aux = "" for dat in fecBol: if i > 5: aux = aux + dat i += 1 aux = aux + "-" i = 0 for dat in fecBol: if i > 2 and i < 5: aux = aux + dat i += 1 aux = aux + "-" i = 0 for dat in fecBol: if i < 2: aux = aux + dat i += 1 fecBol = aux print( str(idExp) + " " + str(idBol) + " " + fecBol + " " + horBol) fechaConc = str(fecBol) + " " + str(horBol) archivo = open("datos.txt", "w") archivo.close() #pass else: self.mensaje = 9 elif botones.leerMasa() == 0: self.mensaje = 1 self.stackedWidget.setCurrentIndex(0) if self.f1 == True and self.f2 == False: ''' Operacion 1.- Autorizacion de salida''' if gerencia == False: mensaje_envio = str(idBol) + "," + str( idExp) + "," + fechaConc + "," + str(1) validacion = cliente.configSocket("autorizacion salida", mensaje_envio) print(validacion) print(validacion, fechaConc) print(validacion, fechaConc) dh = self.restar_hora(horBol.split(':', 2), fecBol.split('-')) try: dias = dh[0] horas = dh[1] minutos = dh[2] #horas=horas+(dias*24) #tiempoEstacionado=horas #print("DHDHDHDHDHDHDHDHDHD",dh) if (dias == 0): if (minutos < tolerancia): validacion = "finalizado" botones.abrir() print("abrido") except Exception as error: print("Errrr Toleeee", error) pass if gerencia == True: validacion = "finalizado" gerencia = False #self.lboleto.setText(validacion) if validacion == "finalizado": self.f2 = self.f3 = True elif validacion == "volver a pagar": self.lboleto.setText("---> Tiempo de salida excedido <---") mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje4.mp3') mixer.music.play() self.f1 = False #self.stackedWidget.setCurrentIndex(4) pantalla_cont = 1 elif validacion == "pago no realizado": self.lboleto.setText("---> Favor de pagar su boleto... <---") mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje2.mp3') mixer.music.play() self.f1 = False #self.stackedWidget.setCurrentIndex(2) pantalla_cont = 1 elif validacion == "boleto no encontrado": mixer.init() self.lboleto.setText("---> Favor de pagar su boleto <---") mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje2.mp3') #mixer.music.load('/home/pi/Documents/eum/app/salida/sonidos/mensaje7.mp3') mixer.music.play() self.f1 = False #self.stackedWidget.setCurrentIndex(7) pantalla_cont = 1 elif validacion == "boleto obsoleto": self.lboleto.setText("---> Boleto usado <---") mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje3.mp3') mixer.music.play() self.f1 = False #self.stackedWidget.setCurrentIndex(3) pantalla_cont = 1 elif validacion == "sin comunicacion servidor": mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje5.mp3') mixer.music.play() self.f1 = False #self.stackedWidget.setCurrentIndex(5) pantalla_cont = 1 elif validacion == "error": mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje5.mp3') mixer.music.play() self.f1 = False #self.stackedWidget.setCurrentIndex(5) pantalla_cont = 1 if self.f1 == True and self.f2 == True: #self.stackedWidget.setCurrentIndex(6) pantalla_cont = 1 if reproduccion == 0: self.lboleto.setText("---> Retire su boleto <---") mixer.init() mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensajeboleto.mp3' ) mixer.music.play() time.sleep(3.2) mixer.music.load( '/home/pi/Documents/eum/app/salida/sonidos/mensaje6.mp3') mixer.music.play() reproduccion = 1 if self.f3 == True and self.f4 == False and self.f5 == False and self.f6 == False: if self.f7 == False: time.sleep(0.5) botones.abrir() self.f7 = True self.f4 = botones.leerBobina2Subida() if self.f4 == True: self.f3 = False if self.f3 == False and self.f4 == True and self.f5 == False and self.f6 == False: self.f5 = botones.abrirBarrera() if self.f5 == True: self.f4 = False if self.f3 == False and self.f4 == False and self.f5 == True and self.f6 == False: self.f6 = botones.CerrarBarrera() if self.f6 == True: self.f5 = False if self.f3 == False and self.f4 == False and self.f5 == False and self.f6 == True: print("Ya cerre barrera restablesco fs") self.f1 = self.f2 = self.f3 = self.f4 = self.f5 = self.f6 = self.f7 = False reproduccion = 0 QtCore.QTimer.singleShot(100, self.leerBotones)
def leerBotones(self): tiempo = 0 if self.mensaje == 1: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\"></span></p></body></html>", None)) elif self.mensaje == 2: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\">Ingrese su boleto</span></p></body></html>", None)) elif self.mensaje == 3: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\"></span></p></body></html>", None)) elif self.mensaje == 4: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\"></span></p></body></html>", None)) elif self.mensaje == 5: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\"></span></p></body></html>", None)) elif self.mensaje == 6: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\"></span></p></body></html>", None)) elif self.mensaje == 7: self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\">Sin coneccion a la Base de Datos</span></p></body></html>", None)) if self.f1 != True: self.f2 = False print("------Preguntar Botones --------") if botones.leerMasa() == 1: if self.mensaje == 1: self.mensaje = 2 if os.stat("datos.txt").st_size != 0: print("ticket detectado") self.f1 = True configuracion = [] archivo = open("datos.txt", "r") contenido = archivo.readlines() i = 0 for linea in contenido: configuracion.append(linea) if i == 0: idExp = linea if i == 1: idBol = linea if i == 2: fecBol = linea if i == 3: horBol = linea i += 1 archivo.close() fechaConc = str(fecBol) + " " + str(horBol) print(idExp) print(idBol) print(fechaConc) archivo = open("datos.txt", "w") archivo.close() #pass elif botones.leerMasa() == 0: self.mensaje = 1 if self.f1 == True and self.f2 == False: ''' Operacion 1.- Autorizacion de salida''' #mensaje = (idBoleto,idExpedidora,fechaExpedicion) mensaje = idBol + "," + idExp + "," + fechaConc validacion = cliente.configSocket("autorizacion salida", mensaje) #validacion = "finalizado" print(validacion) if validacion == "finalizado": self.f2 = self.f3 = True self.label_4.setText( _translate( "ventanaAcceso", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt;\">Gracias por su visita</span></p></body></html>", None)) elif validacion == "volver a pagar": self.f1 = False self.mensaje = 3 elif validacion == "pago no realizado": self.f1 = False self.mensaje = 4 elif validacion == "sin respuesta servidor": self.f1 = False self.mensaje = 5 elif validacion == "sin comunicacion servidor": self.f1 = False self.mensaje = 6 elif validacion == "error": self.f1 = False self.mensaje = 7 if self.f1 == True and self.f2 == True: if self.f3 == True and self.f4 == False and self.f5 == False and self.f6 == False: time.sleep(0.5) botones.abrir() while (self.f3 == True and self.f4 == False): time.sleep(0.2) print("Barrera Esperando que pase el carro...") self.f4 = botones.leerBobina2Subida() self.f3 = False if self.f3 == False and self.f4 == True and self.f5 == False and self.f6 == False: while (self.f4 == True and self.f5 == False): time.sleep(0.2) self.f5 = botones.abrirBarrera() self.f4 = False if self.f3 == False and self.f4 == False and self.f5 == True and self.f6 == False: while (self.f6 == False): time.sleep(0.2) self.f6 = botones.CerrarBarrera() self.f5 = False if self.f3 == False and self.f4 == False and self.f5 == False and self.f6 == True: botones.cerrar() print("Ya cerre barrera restablesco fs") self.f1 = self.f2 = self.f3 = self.f4 = self.f5 = self.f6 = False QtCore.QTimer.singleShot(200, self.leerBotones)