From 041dae8e41e27537b46896d04cd88a030fe48b2f Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Wed, 9 May 2018 04:09:38 +0200 Subject: [PATCH] =?UTF-8?q?S=C3=A9curit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chef/Makefile | 2 +- chef/src/securite.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ chef/src/securite.h | 16 +++++++++++ chef/src/testSecu.c | 24 +++++++++++++++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 chef/src/securite.c create mode 100644 chef/src/securite.h create mode 100644 chef/src/testSecu.c diff --git a/chef/Makefile b/chef/Makefile index 042796f..1563198 100644 --- a/chef/Makefile +++ b/chef/Makefile @@ -11,7 +11,7 @@ CFLAGS_CUSTOM += -g ## Générateurs de drapeaux pour les bibliothèques PKG_CONFIG=pkg-config ## Nom des objets communs -OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position +OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position securite OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS))) # VARIABLES AUTOMATIQUES diff --git a/chef/src/securite.c b/chef/src/securite.c new file mode 100644 index 0000000..09d174e --- /dev/null +++ b/chef/src/securite.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +#include "debug.h" +#include "securite.h" + +// Globales +pthread_t tSecurite; +pthread_mutex_t secPolling; +pthread_mutex_t secData; +struct F2CI_CAPTs secRaw; +float secFront, secBack; + +void onF2CI_CAPT() +{ + readCF(&secRaw, sizeof(struct F2CI_CAPTs)); + pthread_mutex_unlock(&secPolling); +} + +void* TaskSecurite(void* pData) +{ + (void)pData; + + for (;;) { + pthread_mutex_lock(&secPolling); + sendCF(F2CI_CAPT, NULL, 0); + // Waiting for reception + pthread_mutex_lock(&secPolling); + pthread_mutex_unlock(&secPolling); + + pthread_mutex_lock(&secData); + secFront = (float)secRaw.front * SOUND_MM_P_MS; + secBack = (float)secRaw.back * SOUND_MM_P_MS; + pthread_mutex_unlock(&secData); + + usleep(SENSOR_SAMPLING_INTERVAL * 1000); + } + + return NULL; +} + +void getDistance(float* front, float* back) +{ + pthread_mutex_lock(&secData); + *front = secFront; + *back = secBack; + pthread_mutex_unlock(&secData); +} + +void configureSecurite() +{ + pthread_mutex_init(&secPolling, NULL); + pthread_mutex_init(&secData, NULL); + registerRxHandlerCF(F2CI_CODER, onF2CI_CAPT); + registerDebugVar("secFront", ld, &secFront); + registerDebugVar("secBack", ld, &secBack); + pthread_create(&tSecurite, NULL, TaskSecurite, NULL); +} + +void deconfigureSecurite() +{ + pthread_cancel(tSecurite); +} + diff --git a/chef/src/securite.h b/chef/src/securite.h new file mode 100644 index 0000000..11b51a7 --- /dev/null +++ b/chef/src/securite.h @@ -0,0 +1,16 @@ +#ifndef __SECURITE_H_ +#define __SECURITE_H_ + +#include "CF.h" +#include + +#define SOUND_MM_P_MS 0.3312 +#define SENSOR_SAMPLING_INTERVAL 60 + +// Fonctions +void configureSecurite(); +void deconfigureSecurite(); +void getDistance(float* avant, float* arriere); + +#endif + diff --git a/chef/src/testSecu.c b/chef/src/testSecu.c new file mode 100644 index 0000000..afbb587 --- /dev/null +++ b/chef/src/testSecu.c @@ -0,0 +1,24 @@ +#include +#include +#include + +#include "CF.h" +#include "securite.h" + +int main(int argc, char* argv[]) +{ + + (void)argc; + (void)argv; + + configureCF(); + configureSecurite(); + + float f, b; + + for (;;) { + getDistance(&f, &b); + printf("Av: %6f Ar: %6f\n", f, b); + sleep(1); + } +}