Commit bd7df765 authored by Ivan Tyagov's avatar Ivan Tyagov

Use a dedicated module for GPIO measurements.

See merge request !29
parents adbb6f91 bac363ca
#include <linux/gpio.h>
// the current GPI state (used for debuging)
static unsigned int CURRENT_GPIO_STATE = 0;
/*
* variable representing the measurement mode over GPIO
* 0: disabled
* 1: enabled for keep-alive subsystem
* 2: enabled for first i2c0.relay0
*/
static unsigned int CURRENT_GPIO_MODE = 0;
static int setGPIO() {
/*
* Set GPIO state (useful for debuging with logical analyzer)
*/
int fd;
struct gpiohandle_request led;
struct gpiohandle_data data;
/* Schema for STMP15x-Shield
* GND : pin 2
* Channel 0 : pin 9
*/
fd = open("/dev/gpiochip1", O_RDWR);
if(fd < 0) {
perror("Error opening gpiochip");
return -1;
}
/* Setup GPIO to output */
led.flags = GPIOHANDLE_REQUEST_OUTPUT;
strcpy(led.consumer_label, "LED");
memset(led.default_values, 0, sizeof(led.default_values));
led.lines = 1;
led.lineoffsets[0] = 7;
if(ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &led) < 0) {
perror("Error setting GPIO to output");
close(fd);
return -1;
}
// revert previous state
if (CURRENT_GPIO_STATE) CURRENT_GPIO_STATE = 0;
else CURRENT_GPIO_STATE = 1;
// set actual GPI value
data.values[0] = CURRENT_GPIO_STATE;
if(ioctl(led.fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data) < 0)
perror("Error setting GPIO to 1");
close(fd);
close(led.fd);
return 0;
}
......@@ -17,17 +17,6 @@ const int STATE_NO_INITIAL_HEART_BEAT = 2;
// number of times the coupler was in SAFE mode
static unsigned int SAFE_MODE_STATE_COUNTER = 0;
// the current GPI state (used for debuging)
static unsigned int CURRENT_GPIO_STATE = 0;
/*
* variable representing the measurement mode over GPIO
* 0: disabled
* 1: enabled for keep-alive subsystem
* 2: enabled for first i2c0.relay0
*/
static unsigned int CURRENT_GPIO_MODE = 0;
// the heart beat interval (in ms)
const int DEFAULT_HEART_BEAT_INTERVAL = 250;
static int HEART_BEAT_INTERVAL = DEFAULT_HEART_BEAT_INTERVAL;
......@@ -36,7 +25,7 @@ static int HEART_BEAT_INTERVAL = DEFAULT_HEART_BEAT_INTERVAL;
const int DEFAULT_HEART_BEAT_TIMEOUT_INTERVAL = 4 * DEFAULT_HEART_BEAT_INTERVAL;
static int HEART_BEAT_TIMEOUT_INTERVAL = DEFAULT_HEART_BEAT_TIMEOUT_INTERVAL;
// the list of couplers onto which we depend for properly running$
// the list of couplers onto which we depend for properly running
// XXX: assume ONLY 8 couplers!
unsigned int HEART_BEAT_ID_LIST[] = {0, 0, 0, 0, 0, 0, 0, 0};
......
......@@ -2,8 +2,6 @@
Keep alive implementation for couplers based on OPC UA's pub/sub mechanism
*/
#include "keep_alive.h"
UA_NodeId connectionIdent, publishedDataSetIdent, writerGroupIdent;
static void addPubSubConnection(UA_Server *server, UA_String *transportProfile,
......
......@@ -11,7 +11,6 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>
UA_NodeId connectionIdentifier;
UA_NodeId readerGroupIdentifier;
......@@ -20,52 +19,6 @@ UA_DataSetReaderConfig readerConfig;
static void fillTestDataSetMetaData(UA_DataSetMetaDataType *pMetaData);
static int setGPIO() {
/*
* Set GPIO state (useful for debuging with logical analyzer
*/
int fd;
struct gpiohandle_request led;
struct gpiohandle_data data;
/* Schema for STMP15x-Shield
* GND : pin 2
* Channel 0 : pin 9
*/
fd = open("/dev/gpiochip1", O_RDWR);
if(fd < 0) {
perror("Error opening gpiochip");
return -1;
}
/* Setup GPIO to output */
led.flags = GPIOHANDLE_REQUEST_OUTPUT;
strcpy(led.consumer_label, "LED");
memset(led.default_values, 0, sizeof(led.default_values));
led.lines = 1;
led.lineoffsets[0] = 7;
if(ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &led) < 0) {
perror("Error setting GPIO to output");
close(fd);
return -1;
}
// revert previous state
if (CURRENT_GPIO_STATE) CURRENT_GPIO_STATE = 0;
else CURRENT_GPIO_STATE = 1;
// set actual GPI value
data.values[0] = CURRENT_GPIO_STATE;
if(ioctl(led.fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data) < 0)
perror("Error setting GPIO to 1");
close(fd);
close(led.fd);
return 0;
}
/* callback to handle change notifications */
static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitoredItemId,
void *monitoredItemContext, const UA_NodeId *nodeId,
......
......@@ -53,6 +53,8 @@ char *PASSWORD;
char *X509_KEY_FILENAME;
char *X509_CERTIFICATE_FILENAME;
#include "gpio.h"
#include "keep_alive.h"
#include "keep_alive_publisher.h"
#include "keep_alive_subscriber.h"
#include "cli.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment