mise en place des scripts pour la génération du package python et deb

This commit is contained in:
Vincent BENOIT
2022-11-15 14:36:48 +01:00
parent 5ea494e645
commit f6c37733a0
16 changed files with 1973 additions and 218 deletions
Executable
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Author : vincent.benoit@benserv.fr
# Date : 11/2022
# Version : 1.0
# Brief : création des packages necessaires pour le processus KineIntercom
#
###########################################################################
create_deb() {
dirname=kineintercommisc-$1
/usr/bin/mkdir -p bdist_deb/$dirname
cd bdist_deb/$dirname
/usr/bin/dh_make -t $2/template -n -y -i -d
/usr/bin/find $2/misc -type f -exec /usr/bin/cp -a {} . \;
/usr/bin/dpkg-buildpackage -b -uc -us -rfakeroot
cd ..
if [ $? == "0" ] && [ ! -d "$2/dist" ]; then
/usr/bin/mkdir -p $2/dist
/usr/bin/find . -type f -name "*.deb" -exec /usr/bin/cp -a {} $2/dist \;
fi
}
create_wheel() {
cd $1
/usr/bin/python3 setup.py bdist_wheel --universal
}
echo "*** Remove old dirs ***"
/usr/bin/rm -rf bdist_deb build dist *.egg-info
echo "*** read version ***"
vers=`/usr/bin/cat src/VERSION`
rootpath=`pwd`
echo "*** Create Debian Misc Package ***"
create_deb "$vers" "$rootpath"
echo "*** Create Python Package ***"
create_wheel "$rootpath"
echo "*** that's All Folks ...***"
File diff suppressed because it is too large Load Diff
+406
View File
@@ -0,0 +1,406 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://git.nas.benserv.fr/vincent/Kine-backend/src/branch/master/db.json",
"type": "object",
"title": "KineIntercom database",
"description": "This document records the parameters of KineIntercom process",
"required": [
"CODE_PIN",
"DTMF_CODE",
"DTMF_DURATION",
"HORAIRES",
"INFOS",
"NUM_AUTORISE",
"OPERATION",
"PIN_ACTIF",
"TONE_DURATION",
"utilisateur"
],
"properties": {
"CODE_PIN": {
"type": "string",
"title": "Le code pin de la carte SIM",
"examples": [
"1234"
]
},
"DTMF_CODE": {
"type": "string",
"title": "Le code DTMF a envoyer par le module GSM",
"examples": [
"*"
]
},
"DTMF_DURATION": {
"type": "integer",
"title": "La duree du code DTMF a envoyer par le module GSM",
"examples": [
10
]
},
"HORAIRES": {
"type": "object",
"title": "Les horaires d'ouverture et de fermeture du module GSM",
"required": [
"Friday",
"Monday",
"Saturday",
"Sunday",
"Thursday",
"Tuesday",
"Wednesday"
],
"properties": {
"Friday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Vendredi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Monday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Lundi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Saturday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Samedi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Sunday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Dimanche",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Thursday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Jeudi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Tuesday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Mardi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
},
"Wednesday": {
"type": "array",
"title": "Les horaires pour le jour de la semaine: Mercredi",
"items": {
"type": "object",
"title": "A Schema",
"required": [
"name",
"state"
],
"properties": {
"name": {
"type": "string",
"title": "Les tranches horaires par pas de 1/2 heure"
},
"state": {
"type": "integer",
"title": "L'etat d'ouverture (1) ou fermeture(0) du module GSM",
"examples": [
0,
1
]
}
}
}
}
}
},
"INFOS": {
"type": "object",
"title": "Les infos du module GSM",
"required": [
"control",
"manufacturer"
],
"properties": {
"control": {
"type": "object",
"title": "The control Schema",
"required": [
"call_ready",
"operator",
"service_provider",
"signal_dbm",
"signal_qos",
"sim_inserted"
],
"properties": {
"call_ready": {
"type": "boolean",
"default": false,
"title": "The call_ready Schema",
"examples": [
true,
false
]
},
"operator": {
"type": "string",
"default": "",
"title": "The operator Schema",
"examples": [
"SFR"
]
},
"service_provider": {
"type": "string",
"default": "",
"title": "The service_provider Schema",
"examples": [
"La poste mobile"
]
},
"signal_dbm": {
"type": "string",
"default": "",
"title": "The signal_dbm Schema",
"examples": [
"-75"
]
},
"signal_qos": {
"type": "string",
"default": "",
"title": "The signal_qos Schema",
"examples": [
"excellent"
]
},
"sim_inserted": {
"type": "boolean",
"default": false,
"title": "The sim_inserted Schema",
"examples": [
true,
false
]
}
}
},
"manufacturer": {
"type": "object",
"title": "The manufacturer Schema",
"required": [
"hardware_rev",
"identification",
"model",
"serial_number"
],
"properties": {
"hardware_rev": {
"type": "string",
"title": "The hardware_rev Schema",
"examples": [
"1418B02SIM868M32_BT_EAT"
]
},
"identification": {
"type": "string",
"title": "The identification Schema",
"examples": [
"SIMCOM_Ltd"
]
},
"model": {
"type": "string",
"title": "The model Schema",
"examples": [
"SIMCOM_SIM868"
]
},
"serial_number": {
"type": "string",
"title": "The serial_number Schema",
"examples": [
"864866057705260"
]
}
}
}
}
},
"NUM_AUTORISE": {
"type": "string",
"title": "The NUM_AUTORISE Schema",
"examples": [
"670100036"
]
},
"OPERATION": {
"type": "string",
"title": "The OPERATION Schema",
"examples": [
"Horaires"
]
},
"PIN_ACTIF": {
"type": "boolean",
"title": "The PIN_ACTIF Schema",
"examples": [
true,
false
]
},
"TONE_DURATION": {
"type": "integer",
"title": "The TONE_DURATION Schema",
"examples": [
2
]
},
"utilisateur": {
"type": "object",
"title": "L'utilisateur du configurateur",
"required": [
"id",
"password"
],
"properties": {
"id": {
"type": "string",
"title": "The id Schema",
"examples": [
"admin"
]
},
"password": {
"type": "string",
"title": "The password Schema",
"examples": [
"9ac564e9a29c952a3ddeffd8635adb0c252dbd1d58f3efde265e028f7f808aa9"
]
}
}
}
}
}
+12
View File
@@ -0,0 +1,12 @@
[Unit]
Description=Démarrage du processus KineIntercom
[Service]
Type=simple
User=pi
Group=pi
ExecStart=/usr/bin/python3 /usr/local/lib/python3.9/dist-packages/kineintercom/src/intercom.py
[Install]
WantedBy=multi-user.target
+4
View File
@@ -0,0 +1,4 @@
RPi.GPIO==0.7.0
jsonschema==4.17.0
pyserial==3.5
APScheduler==3.9.1
+38
View File
@@ -0,0 +1,38 @@
import io, os
from setuptools import find_packages, setup
def read(*paths, **kwargs):
"""Read the contents of a text file safely.
>>> read("project_name", "VERSION")
'0.1.0'
>>> read("README.md")
...
"""
content = ""
with io.open(
os.path.join(os.path.dirname(__file__), *paths),
encoding=kwargs.get("encoding", "utf8"),
) as open_file:
content = open_file.read().strip()
return content
def read_requirements(path):
ret = []
with open(path, "r") as f:
ret = f.read().splitlines()
return ret
setup(
name='kineintercom',
version=read("src", "VERSION"),
author='vincent.benoit',
author_email='vincent.benoit@benserv.fr',
description='Processus d\'envoi de code DTMF via le module GSM',
long_description=read("README.md"),
long_description_content_type="text/markdown",
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=read_requirements("requirements.txt")
)
-71
View File
@@ -1,71 +0,0 @@
{
"CODE_PIN": 1234,
"NUM_AUTORISE": "0607297154",
"DTMF_CODE": "*",
"DTMF_DURATION": 1,
"HORAIRES": {
"Monday":{
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Tuesday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Wednesday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Thursday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Friday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":1,"06h30":1,
"07h00":1,"07h30":1,"08h00":1,"08h30":1,"09h00":1,"09h30":1,"10h00":1,
"10h30":1,"11h00":1,"11h30":1,"12h00":1,"12h30":1,"13h00":1,"13h30":1,
"14h00":1,"14h30":1,"15h00":1,"15h30":1,"16h00":1,"16h30":1,"17h00":1,
"17h30":1,"18h00":1,"18h30":1,"19h00":1,"19h30":1,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Saturday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":0,"06h30":0,
"07h00":0,"07h30":0,"08h00":0,"08h30":0,"09h00":0,"09h30":0,"10h00":0,
"10h30":0,"11h00":0,"11h30":0,"12h00":0,"12h30":0,"13h00":0,"13h30":0,
"14h00":0,"14h30":0,"15h00":0,"15h30":0,"16h00":0,"16h30":0,"17h00":0,
"17h30":0,"18h00":0,"18h30":0,"19h00":0,"19h30":0,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
},
"Sunday": {
"00h00":0,"00h30":0,"01h00":0,"01h30":0,"02h00":0,"02h30":0,"03h00":0,
"03h30":0,"04h00":0,"04h30":0,"05h00":0,"05h30":0,"06h00":0,"06h30":0,
"07h00":0,"07h30":0,"08h00":0,"08h30":0,"09h00":0,"09h30":0,"10h00":0,
"10h30":0,"11h00":0,"11h30":0,"12h00":0,"12h30":0,"13h00":0,"13h30":0,
"14h00":0,"14h30":0,"15h00":0,"15h30":0,"16h00":0,"16h30":0,"17h00":0,
"17h30":0,"18h00":0,"18h30":0,"19h00":0,"19h30":0,"20h00":0,"20h30":0,
"21h00":0,"21h30":0,"22h00":0,"22h30":0,"23h00":0,"23h30":0
}
}
}
+1
View File
@@ -0,0 +1 @@
1.0.0
+25 -26
View File
@@ -19,7 +19,6 @@ import json
import jsonschema import jsonschema
import socket import socket
import shutil import shutil
from signal import signal, SIGINT
from threading import Thread from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@@ -51,7 +50,7 @@ def validate_json(json_data={}, logger=None):
except FileNotFoundError as e: except FileNotFoundError as e:
logger.error("Impossible d'ouvrir le fichier de validation ({})".format(e)) logger.error("Impossible d'ouvrir le fichier de validation ({})".format(e))
ret = False ret = False
try: try:
jsonschema.validate(instance=json_data, schema=schema) jsonschema.validate(instance=json_data, schema=schema)
except jsonschema.exceptions.ValidationError as e: except jsonschema.exceptions.ValidationError as e:
@@ -97,7 +96,7 @@ def get_conf(logger=None):
logger.error("Impossible de charger les données de configuration ({})".format(e)) logger.error("Impossible de charger les données de configuration ({})".format(e))
except FileNotFoundError as e: except FileNotFoundError as e:
logger.error("Impossible d'ouvrir le fichier de configuation ({})".format(e)) logger.error("Impossible d'ouvrir le fichier de configuation ({})".format(e))
return config return config
def send_at_cmd(cmd='', timeout=0.0, serObj=None, logger=None): def send_at_cmd(cmd='', timeout=0.0, serObj=None, logger=None):
@@ -141,7 +140,7 @@ def send_at_cmd(cmd='', timeout=0.0, serObj=None, logger=None):
out = '' out = ''
outlst = [] outlst = []
while serObj.in_waiting > 0: while serObj.in_waiting > 0:
# remove \r and \n chars from out string # remove \r and \n chars from out string
out += serObj.read_until().decode('utf-8', 'replace').replace('\r','').replace('\n','') out += serObj.read_until().decode('utf-8', 'replace').replace('\r','').replace('\n','')
if out != '': if out != '':
outlst.append(out) outlst.append(out)
@@ -239,10 +238,10 @@ def init_gsm_com(serObj=None, config={}, logger=None):
''' Init GSM Communication ''' Init GSM Communication
source : SIM800_Series_AT_command Manual_v1.09 source : SIM800_Series_AT_command Manual_v1.09
AT : test command AT : test command
ATE1 : ATE1 :
AT+CMEE=2 : AT+CMEE=2 :
AT+CLTS=1 : AT+CLTS=1 :
AT+CMGF=1 : Set the format of messages to Text mode AT+CMGF=1 : Set the format of messages to Text mode
AT+CLIP=1 : The calling line identifty (CLI) of calling party when AT+CLIP=1 : The calling line identifty (CLI) of calling party when
receiving a mobile terminated call receiving a mobile terminated call
AT+VTD=1 : Tone Duration (in 1/10 seconds) AT+VTD=1 : Tone Duration (in 1/10 seconds)
@@ -368,7 +367,7 @@ def info_gsm_com(serObj=None, config={}, logger=None):
else: else:
logger.debug('cmd: {} - rsp: {}'.format(cmd, rsp)) logger.debug('cmd: {} - rsp: {}'.format(cmd, rsp))
if cmd['cmd'] == 'AT+CGMI': if cmd['cmd'] == 'AT+CGMI':
# Request Manufacturer Identification # Request Manufacturer Identification
config['INFOS'][cmd['obj']][cmd['item']] = rsp[1] config['INFOS'][cmd['obj']][cmd['item']] = rsp[1]
elif cmd['cmd'] == 'AT+CGMM': elif cmd['cmd'] == 'AT+CGMM':
# Request Model Identification # Request Model Identification
@@ -446,7 +445,7 @@ SIGNAL = [{"val":2, "dbm":"-109", 'condition':'Marginal'},
def verify_caller(buf="", num="", logger=None): def verify_caller(buf="", num="", logger=None):
''' Verify phone number of caller ''' Verify phone number of caller
example : +CLIP: "0607297154",129,"",0,"",0 example : +CLIP: "0607297154",129,"",0,"",0
:param buf: :param buf:
Serial input buffer Serial input buffer
@@ -475,7 +474,7 @@ def verify_caller(buf="", num="", logger=None):
if not phone_number.endswith(num): if not phone_number.endswith(num):
logger.warning("phone number not match ! {}/{}".format(phone_number, num)) logger.warning("phone number not match ! {}/{}".format(phone_number, num))
return False, phone_number return False, phone_number
return True, phone_number return True, phone_number
def listener(sock, logger): def listener(sock, logger):
''' Thread socket listener ''' Thread socket listener
@@ -521,7 +520,7 @@ def listener(sock, logger):
continue continue
if not data: if not data:
break break
logger.debug("Fin du serveur de communication") logger.debug("Fin du serveur de communication")
return return
@@ -709,7 +708,7 @@ def main():
logger = log.getLogger("Intercom") logger = log.getLogger("Intercom")
logger.setLevel(log.DEBUG) logger.setLevel(log.DEBUG)
fl = log.StreamHandler() fl = log.StreamHandler()
hl = log.FileHandler(os.path.join('/var/log/KineIntercom','Intercom.log')) hl = log.FileHandler(os.path.join('/var/log/kineintercom','Intercom.log'))
fl.setLevel(log.DEBUG) fl.setLevel(log.DEBUG)
hl.setLevel(log.INFO) hl.setLevel(log.INFO)
formatter = log.Formatter('%(asctime)s - %(funcName)s - %(levelname)s - %(message)s') formatter = log.Formatter('%(asctime)s - %(funcName)s - %(levelname)s - %(message)s')
@@ -723,9 +722,9 @@ def main():
global FLAG_CONF_UPDATE global FLAG_CONF_UPDATE
global FLAG_HORAIRE_UPDATE global FLAG_HORAIRE_UPDATE
global FLAG_TH_CLOSE global FLAG_TH_CLOSE
# Configuration loader # Configuration loader
config = get_conf(logger) config = get_conf(logger)
if config is None: if config is None:
logger.error("Impossible de charger la configuration") logger.error("Impossible de charger la configuration")
sys.exit(1) sys.exit(1)
@@ -737,7 +736,7 @@ def main():
sys.exit(1) sys.exit(1)
# Serial configuration # Serial configuration
ser = serial.Serial('/dev/ttyAMA0', ser = serial.Serial('/dev/ttyAMA0',
baudrate=115200, baudrate=115200,
parity=serial.PARITY_NONE, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, stopbits=serial.STOPBITS_ONE,
@@ -746,7 +745,7 @@ def main():
xonxoff=False, xonxoff=False,
rtscts=False, rtscts=False,
dsrdtr=False) dsrdtr=False)
# Test si le port série est ouvert # Test si le port série est ouvert
if ser.isOpen(): if ser.isOpen():
logger.info("Le port série avec le module GSM est ouvert") logger.info("Le port série avec le module GSM est ouvert")
@@ -838,7 +837,7 @@ def main():
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Bind the socket to the port # Bind the socket to the port
sock.bind(server_addr) sock.bind(server_addr)
sock.settimeout(1) # Timeout for accept sock.settimeout(1) # Timeout for accept
# Listen for incoming connections # Listen for incoming connections
sock.listen(1) sock.listen(1)
thread = Thread(target=listener, args=(sock, logger,)) thread = Thread(target=listener, args=(sock, logger,))
@@ -847,10 +846,10 @@ def main():
# Scheduler opened hours # Scheduler opened hours
sched = BackgroundScheduler(daemon=True) sched = BackgroundScheduler(daemon=True)
sched.add_job(func=cron_verify_hours, sched.add_job(func=cron_verify_hours,
args=(config['OPERATION'], config['HORAIRES'], logger), args=(config['OPERATION'], config['HORAIRES'], logger),
trigger='cron', trigger='cron',
minute='*', minute='*',
id="job_id") id="job_id")
sched.start() sched.start()
@@ -870,10 +869,10 @@ def main():
logger.info("Restart scheduler ...") logger.info("Restart scheduler ...")
# Stop job scheduler to restart it # Stop job scheduler to restart it
sched.remove_job('job_id') sched.remove_job('job_id')
sched.add_job(func=cron_verify_hours, sched.add_job(func=cron_verify_hours,
args=(config['OPERATION'], config['HORAIRES'], logger), args=(config['OPERATION'], config['HORAIRES'], logger),
trigger='cron', trigger='cron',
minute='*', minute='*',
id="job_id") id="job_id")
FLAG_HORAIRE_UPDATE = False FLAG_HORAIRE_UPDATE = False
FLAG_CONF_UPDATE = False FLAG_CONF_UPDATE = False
@@ -896,7 +895,7 @@ def main():
# While the number of bytes in the input buffer > 0 # While the number of bytes in the input buffer > 0
if ser.in_waiting > 0: if ser.in_waiting > 0:
# remove \r and \n chars from out string # remove \r and \n chars from out string
out += ser.read_until().decode('utf-8').replace('\r','').replace('\n','') out += ser.read_until().decode('utf-8').replace('\r','').replace('\n','')
if len(out) > 0 : if len(out) > 0 :
logger.debug("out: {}".format(out)) logger.debug("out: {}".format(out))
-121
View File
@@ -1,121 +0,0 @@
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
# @author: benoit.vince84@free.fr
# @date: Septembre 2022
# @brief: Programme Pwrkey pour le GNSS HAT
###################################################################
# Importation de modules externes #
import sys, os, re
import serial
import RPi.GPIO as GPIO
import time
import logging as log
import time
from datetime import datetime, date
import calendar
import json
import socket
###################################################################
# Class et Methods #
def get_conf(logger=None):
''' Get configuration
:return dict:
Configuration dictionnary
'''
config = None
try:
with open(os.path.join("/home/pi/KineIntercom/src", "KineIntercom.json"), 'r') as f:
try:
config = json.load(f)
except json.decoder.JSONDecodeError as e:
logger.error("Impossible de charger les données de configuration ({})".format(e))
except FileNotFoundError as e:
logger.error("Impossible d'ouvrir le fichier de configuation ({})".format(e))
return config
def verify_open_hours(conf=None, log=None):
''' Verify if GSM HAT must be opened with conf hours
:param conf:
configuration object
:param log:
logger object
:return bool:
True if authorized, False otherwise
'''
flag = False
my_date = date.today()
day = calendar.day_name[my_date.weekday()]
now = datetime.now()
for k,v in conf[day].items():
time_conf = int(k.split('h')[0])*60 + int(k.split('h')[1])
current_time = now.hour*60 + now.minute
if current_time >= time_conf:
if v == 1:
flag = True
elif v == 0:
flag = False
log.debug('Jour: {} - Temps courant: {} - Ouverture: {}'.format(day, now.strftime('%Hh%M'), flag))
return flag
def init_module():
''' initialisation of GNSS/GPS/GSM HAT Module
'''
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
return
def setup_module():
''' Setup module (Set/Reset)
'''
while True:
GPIO.output(7, GPIO.LOW)
time.sleep(2)
GPIO.output(7, GPIO.HIGH)
break
GPIO.cleanup()
def main():
''' main function
'''
logger = log.getLogger("pwrkey")
logger.setLevel(log.DEBUG)
fl = log.StreamHandler()
fl.setLevel(log.DEBUG)
formatter = log.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fl.setFormatter(formatter)
logger.addHandler(fl)
# get config dictionnary
config = get_conf(logger)
if not config:
exit(1)
# create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_addr = '/tmp/uds_socket'
try:
sock.connect(server_addr)
except socket.error as e:
logger.error("Erreur de connexion avec le serveur: {}".format(e))
sys.exit(1)
opened = verify_open_hours(conf=config['HORAIRES'], log=logger)
sock.sendall(str(opened))
sock.close()
#init_module()
#setup_module()
if __name__ == '__main__':
main()
+5
View File
@@ -0,0 +1,5 @@
#PACKAGE# (#VERSION#-1) stable; urgency=medium
* Initial release
-- #USERNAME# <#EMAIL#> #DATE#
+1
View File
@@ -0,0 +1 @@
11
+12
View File
@@ -0,0 +1,12 @@
Source: #PACKAGE#
Section: misc
Priority: optional
Maintainer: #USERNAME# <#EMAIL#>
Build-Depends: #BUILD_DEPS#
Standards-Version: #POLICY#
Homepage: https://git.nas.benserv.fr/vincent/KineIntercom
Package: #PACKAGE#
Architecture: all
Depends: ${misc:Depends}
Description: Installation des fichiers nécessaires au fonctionnement du processus KineIntercom
+3
View File
@@ -0,0 +1,3 @@
db.json.schema /usr/share/kineintercom/
database_origin.json /usr/share/kineintercom/
kineintercom.service /lib/systemd/system/
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
# postinst script for sclesignrestfulmisc
#
# see: dh_installdeb(1)
set -e
user="root"
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
userpi="pi"
dirname="kineintercom"
# create conf directory
/usr/bin/mkdir -p /etc/$dirname
/usr/bin/chown -R $user:$userpi /etc/$dirname
/usr/bin/chmod -R 770 /etc/$dirname
# create log directory
/usr/bin/mkdir -p /var/log/$dirname
/usr/bin/chown -R $user:$userpi /var/log/$dirname
# Restart service
/usr/bin/systemctl restart kineintercom.service
Executable
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
#RULES_START_TEXT#
%:
dh $@#DH_ADDON#
override_dh_auto_install:
#RULES_END_TEXT#