From d12ef314dfcd9bafd370669fc47e5ee443767b28 Mon Sep 17 00:00:00 2001 From: Robert Gustafsson Date: Sat, 14 Oct 2017 11:18:03 +0200 Subject: Rename midbropasad -> midbro in C impl.. * files in script/ are not changed --- broccoli/Makefile | 12 +++++------ broccoli/includes/midbro.h | 6 ++++++ broccoli/includes/midbropasad.h | 6 ------ broccoli/src/broevent.c | 4 ++-- broccoli/src/midbro.c | 48 +++++++++++++++++++++++++++++++++++++++++ broccoli/src/midbropasad.c | 47 ---------------------------------------- broccoli/test/midbro_test.c | 11 ++++++++++ broccoli/test/pasad_test.c | 11 ---------- 8 files changed, 73 insertions(+), 72 deletions(-) create mode 100644 broccoli/includes/midbro.h delete mode 100644 broccoli/includes/midbropasad.h create mode 100644 broccoli/src/midbro.c delete mode 100644 broccoli/src/midbropasad.c create mode 100644 broccoli/test/midbro_test.c delete mode 100644 broccoli/test/pasad_test.c diff --git a/broccoli/Makefile b/broccoli/Makefile index 8e39783..d50fb9e 100644 --- a/broccoli/Makefile +++ b/broccoli/Makefile @@ -4,19 +4,19 @@ CFLAGS =-c -DBROCCOLI INC =-I/usr/local/include -I/usr/local/include -I./includes LDFLAGS = -L/usr/local/lib -lbroccoli -pthread DEBUG = -SRC = midbropasad.c broevent.c fifoqueue.c +SRC = midbro.c broevent.c fifoqueue.c OBJ = $(patsubst %.c, build/%.o, $(SRC)) -all: dirs lib/midbropasad +all: dirs lib/midbro dirs: mkdir -p build bin lib -lib/midbropasad: $(OBJ) - $(CC) -shared $^ -o lib/libmidbropasad.so $(LDFLAGS) +lib/midbro: $(OBJ) + $(CC) -shared $^ -o lib/libmidbro.so $(LDFLAGS) -pasad_test: - $(CC) test/pasad_test.c -I./includes -o bin/pasad_test -L./lib -lmidbropasad +midbro_test: + $(CC) test/midbro_test.c -I./includes -o bin/midbro_test -L./lib -lmidbro build/%.o: src/%.c $(CC) $(LIBCFLAGS) $(DEBUG) $(INC) $< -o $@ diff --git a/broccoli/includes/midbro.h b/broccoli/includes/midbro.h new file mode 100644 index 0000000..3b3c59f --- /dev/null +++ b/broccoli/includes/midbro.h @@ -0,0 +1,6 @@ +#ifndef MIDBRO_H +#define MIDBRO_H +void request_n_values(int number, int arrayOfValues[]); +int request_value(); +void start_data_capture(); +#endif diff --git a/broccoli/includes/midbropasad.h b/broccoli/includes/midbropasad.h deleted file mode 100644 index 73e3bec..0000000 --- a/broccoli/includes/midbropasad.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MIDBROPASAD_H -#define MIDBROPASAD_H -void request_n_values(int number, int arrayOfValues[]); -int request_value(); -void start_data_capture(); -#endif diff --git a/broccoli/src/broevent.c b/broccoli/src/broevent.c index 206ce17..362ed5e 100644 --- a/broccoli/src/broevent.c +++ b/broccoli/src/broevent.c @@ -9,7 +9,7 @@ char *port_default = "47760"; Fifo_q * q; static void -pasad_register_received(BroConn *conn, void *data, BroRecord *record) +modbus_register_received(BroConn *conn, void *data, BroRecord *record) { int type = BRO_TYPE_COUNT; uint64 *address = NULL; @@ -56,7 +56,7 @@ bro_event_listener(void * args) bro_debug_messages = 0; bro_event_registry_add(bc, "pasad_register_received", - (BroEventFunc) pasad_register_received, NULL); + (BroEventFunc) modbus_register_received, NULL); if (! bro_conn_connect(bc)) { diff --git a/broccoli/src/midbro.c b/broccoli/src/midbro.c new file mode 100644 index 0000000..6c83207 --- /dev/null +++ b/broccoli/src/midbro.c @@ -0,0 +1,48 @@ +#include +#include +#include "fifoqueue.h" +#include "broevent.h" +#include "midbro.h" +#ifdef BROCCOLI +#include +#endif + +Fifo_q * queue; + + void +request_n_values(int number, int arrayOfValues[]) +{ + int i; + Sensor_t * sensor; + for(i=0; ivalue; + free(sensor); + } + printf("Release %d sensor data values\n", number); +} + int +request_value() +{ + int value; + Sensor_t * sensor; + sensor = pop_from_queue(queue); + value = sensor->value; + free(sensor); + printf("Release 1 sensor data value\n"); + return value; +} + + void +start_data_capture() +{ + int res; + queue = init_queue(500000); /* Initiate queue with fixed size */ + pthread_t event_listener; + /* Create producer thread that listen for bro events */ + res = pthread_create(&event_listener, NULL, bro_event_listener, queue); + if(res){ + perror("Unable to create thread"); + exit(-1); + } +} diff --git a/broccoli/src/midbropasad.c b/broccoli/src/midbropasad.c deleted file mode 100644 index a745091..0000000 --- a/broccoli/src/midbropasad.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include "fifoqueue.h" -#include "broevent.h" -#ifdef BROCCOLI -#include -#endif - -Fifo_q * queue; - - void -request_n_values(int number, int arrayOfValues[]) -{ - int i; - Sensor_t * sensor; - for(i=0; ivalue; - free(sensor); - } - printf("Release %d sensor data values\n", number); -} - int -request_value() -{ - int value; - Sensor_t * sensor; - sensor = pop_from_queue(queue); - value = sensor->value; - free(sensor); - printf("Release 1 sensor data value\n"); - return value; -} - - void -start_data_capture() -{ - int res; - queue = init_queue(500000); /* Initiate queue with fixed size */ - pthread_t event_listener; - /* Create producer thread that listen for bro events */ - res = pthread_create(&event_listener, NULL, bro_event_listener, queue); - if(res){ - perror("Unable to create thread"); - exit(-1); - } -} diff --git a/broccoli/test/midbro_test.c b/broccoli/test/midbro_test.c new file mode 100644 index 0000000..c0f4ba6 --- /dev/null +++ b/broccoli/test/midbro_test.c @@ -0,0 +1,11 @@ +#include "midbro.h" + + int +main(int argc, char **argv) +{ + start_data_capture(); + while(1){ + request_value(); + } + return 0; +} diff --git a/broccoli/test/pasad_test.c b/broccoli/test/pasad_test.c deleted file mode 100644 index 5ed3481..0000000 --- a/broccoli/test/pasad_test.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "midbropasad.h" - - int -main(int argc, char **argv) -{ - start_data_capture(); - while(1){ - request_value(); - } - return 0; -} -- cgit v1.2.3