Commit 17409606 authored by Ivan Tyagov's avatar Ivan Tyagov

Tsn evaluation

See merge request !25
parents d4237734 84653282
......@@ -196,5 +196,11 @@ void handleCLI(int argc, char **argv) {
}
printf("Heart beat check=%d\n", ENABLE_HEART_BEAT_CHECK);
// update current measurement mode
const char* s = getenv("CURRENT_GPIO_MODE");
if (s != NULL) CURRENT_GPIO_MODE = 1;
printf("GPIO measurement mode = %d\n", CURRENT_GPIO_MODE);
}
......@@ -17,6 +17,12 @@ 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 over GPIO
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;
......
......@@ -8,15 +8,65 @@
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>
UA_NodeId connectionIdentifier;
UA_NodeId readerGroupIdentifier;
UA_NodeId readerIdentifier;
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;
if(ioctl(led.fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data) < 0)
perror("Error setting GPIO to 1");
// debug
//UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, \
// "GPIO = %d", CURRENT_GPIO_STATE);
close(fd);
close(led.fd);
return 0;
}
/* callback to handle change notifications */
static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitoredItemId,
......@@ -45,6 +95,11 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
// Add to our local linked list
addItem(&SUBSCRIBER_DICT, coupler_id_str, milli_seconds_now_str);
// set GPIO so we can monitor using logical analyzer the work of
// keep-alive network system
if (CURRENT_GPIO_MODE) setGPIO();
}
}
}
......
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