From 9bb92bf5a5d3e309359a92d8d65b4e93601fc5a5 Mon Sep 17 00:00:00 2001 From: Paul Squizzato Date: Tue, 21 Mar 2023 11:52:44 +0000 Subject: [PATCH] =?UTF-8?q?Preparation=20=C3=A0=20la=20v=C3=A9rification?= =?UTF-8?q?=20des=20r=C3=A8gles=20dans=20ecritureBDD.py,=20la=20fonction?= =?UTF-8?q?=20est=20l=C3=A0=20faut=20juste=20l'impl=C3=A9menter,=20bref=20?= =?UTF-8?q?chouette=20:cool:=20:smiley:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/decoderBrut.py | 6 ++++++ src/ecritureBDD.py | 13 ++++++++++--- src/triPacket.py | 18 +++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/decoderBrut.py b/src/decoderBrut.py index e83211d..9eb65f2 100644 --- a/src/decoderBrut.py +++ b/src/decoderBrut.py @@ -116,5 +116,11 @@ if not db_user: db_password = getpass.getpass('user password : ') connec=[db_host,db_name,db_user,db_password] +# si register 5 = 55 et coil 3 = 1 et coil 12 = 0 : +# ecriture sur le registre 8 à 72 ou coil 9 à 1 impossibles +# if ['r',5,55] and ['c',3,1] and ['c',12,0] and ecriture ['r',8,72]: + #bloquer ecriture +# ecrire registre 5 72,4,4,55,4 + scapy.sniff(iface="lo", prn=decode) diff --git a/src/ecritureBDD.py b/src/ecritureBDD.py index 901fbbe..75c14fb 100644 --- a/src/ecritureBDD.py +++ b/src/ecritureBDD.py @@ -2,13 +2,20 @@ import psycopg2 as psy import pandas as pd import getpass -def ecritureBDD(typeMem,addresse,valeur,connec): +def verifRegle(a): + return True + +def ecritureBDD(lStatus,connec): co = None try: co = psy.connect(host=connec[0],database=connec[1],user=connec[2],password=connec[3]) cur = co.cursor() - cur.execute("INSERT INTO Status VALUES (%s,%s,%s ) ON CONFLICT (addresse,type) DO UPDATE SET valeur=%s;",(addresse,typeMem,valeur,valeur)) - co.commit() + for i in lStatus: + cur.execute("INSERT INTO Status VALUES (%s,%s,%s ) ON CONFLICT (addresse,type) DO UPDATE SET valeur=%s;",(i[1],i[0],i[2],i[2])) + if verifRegle(co): + co.commit() + else: + co.rollback() cur.close() except(Exception,psy.DatabaseError) as error: print(error) diff --git a/src/triPacket.py b/src/triPacket.py index b5309d8..f84d815 100644 --- a/src/triPacket.py +++ b/src/triPacket.py @@ -1,18 +1,22 @@ from ecritureBDD import ecritureBDD -def triPacket(lPkt,connec): +def decoupePacket(lPkt): if type(lPkt)!=list: print('pas liste') return if len(lPkt)==0: - print('vide') + print('liste vide') return if len(lPkt)==1: - triPacket(lPkt[0],connec) - return + return decoupePacket(lPkt[0]) if len(lPkt)==3 and type(lPkt[0])==str: - ecritureBDD(lPkt[0],int(lPkt[1]),int(lPkt[2]),connec) - return + return [[lPkt[0],int(lPkt[1]),int(lPkt[2])]] else: + l=[] for i in lPkt: - triPacket(i,connec) + l+=decoupePacket(i) + return l + +def triPacket(lPkt,connec): + lNettoyee=decoupePacket(lPkt) + ecritureBDD(lNettoyee,connec)