Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Manchev
osie
Commits
bd7df765
Commit
bd7df765
authored
May 03, 2023
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Plain Diff
Use a dedicated module for GPIO measurements.
See merge request
nexedi/osie!29
parents
adbb6f91
bac363ca
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
61 deletions
+63
-61
coupler/gpio.h
coupler/gpio.h
+60
-0
coupler/keep_alive.h
coupler/keep_alive.h
+1
-12
coupler/keep_alive_publisher.h
coupler/keep_alive_publisher.h
+0
-2
coupler/keep_alive_subscriber.h
coupler/keep_alive_subscriber.h
+0
-47
coupler/server.c
coupler/server.c
+2
-0
No files found.
coupler/gpio.h
0 → 100644
View file @
bd7df765
#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
;
}
coupler/keep_alive.h
View file @
bd7df765
...
@@ -17,17 +17,6 @@ const int STATE_NO_INITIAL_HEART_BEAT = 2;
...
@@ -17,17 +17,6 @@ const int STATE_NO_INITIAL_HEART_BEAT = 2;
// number of times the coupler was in SAFE mode
// number of times the coupler was in SAFE mode
static
unsigned
int
SAFE_MODE_STATE_COUNTER
=
0
;
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)
// the heart beat interval (in ms)
const
int
DEFAULT_HEART_BEAT_INTERVAL
=
250
;
const
int
DEFAULT_HEART_BEAT_INTERVAL
=
250
;
static
int
HEART_BEAT_INTERVAL
=
DEFAULT_HEART_BEAT_INTERVAL
;
static
int
HEART_BEAT_INTERVAL
=
DEFAULT_HEART_BEAT_INTERVAL
;
...
@@ -36,7 +25,7 @@ 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
;
const
int
DEFAULT_HEART_BEAT_TIMEOUT_INTERVAL
=
4
*
DEFAULT_HEART_BEAT_INTERVAL
;
static
int
HEART_BEAT_TIMEOUT_INTERVAL
=
DEFAULT_HEART_BEAT_TIMEOUT_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!
// XXX: assume ONLY 8 couplers!
unsigned
int
HEART_BEAT_ID_LIST
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
unsigned
int
HEART_BEAT_ID_LIST
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
...
...
coupler/keep_alive_publisher.h
View file @
bd7df765
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
Keep alive implementation for couplers based on OPC UA's pub/sub mechanism
Keep alive implementation for couplers based on OPC UA's pub/sub mechanism
*/
*/
#include "keep_alive.h"
UA_NodeId
connectionIdent
,
publishedDataSetIdent
,
writerGroupIdent
;
UA_NodeId
connectionIdent
,
publishedDataSetIdent
,
writerGroupIdent
;
static
void
addPubSubConnection
(
UA_Server
*
server
,
UA_String
*
transportProfile
,
static
void
addPubSubConnection
(
UA_Server
*
server
,
UA_String
*
transportProfile
,
...
...
coupler/keep_alive_subscriber.h
View file @
bd7df765
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>
UA_NodeId
connectionIdentifier
;
UA_NodeId
connectionIdentifier
;
UA_NodeId
readerGroupIdentifier
;
UA_NodeId
readerGroupIdentifier
;
...
@@ -20,52 +19,6 @@ UA_DataSetReaderConfig readerConfig;
...
@@ -20,52 +19,6 @@ UA_DataSetReaderConfig readerConfig;
static
void
fillTestDataSetMetaData
(
UA_DataSetMetaDataType
*
pMetaData
);
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 */
/* callback to handle change notifications */
static
void
dataChangeNotificationCallback
(
UA_Server
*
server
,
UA_UInt32
monitoredItemId
,
static
void
dataChangeNotificationCallback
(
UA_Server
*
server
,
UA_UInt32
monitoredItemId
,
void
*
monitoredItemContext
,
const
UA_NodeId
*
nodeId
,
void
*
monitoredItemContext
,
const
UA_NodeId
*
nodeId
,
...
...
coupler/server.c
View file @
bd7df765
...
@@ -53,6 +53,8 @@ char *PASSWORD;
...
@@ -53,6 +53,8 @@ char *PASSWORD;
char
*
X509_KEY_FILENAME
;
char
*
X509_KEY_FILENAME
;
char
*
X509_CERTIFICATE_FILENAME
;
char
*
X509_CERTIFICATE_FILENAME
;
#include "gpio.h"
#include "keep_alive.h"
#include "keep_alive_publisher.h"
#include "keep_alive_publisher.h"
#include "keep_alive_subscriber.h"
#include "keep_alive_subscriber.h"
#include "cli.h"
#include "cli.h"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment