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
d90af97d
Commit
d90af97d
authored
Jan 31, 2022
by
Balakrishna Balakrishna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inclusion of MOD IO Analog inputs
Test: Program is tested locally with laptop. modified: server.c
parent
455e5a1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
489 additions
and
44 deletions
+489
-44
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+489
-44
No files found.
coupler/opc-ua-server/server.c
View file @
d90af97d
...
@@ -216,6 +216,258 @@ static int getDigitalInputState(int i2c_addr, char **digital_input)
...
@@ -216,6 +216,258 @@ static int getDigitalInputState(int i2c_addr, char **digital_input)
close
(
file
);
close
(
file
);
}
}
static
int
getAnalogInputStateAIN0
(
int
i2c_addr
,
int
**
analog_input
)
{
/*
* get digital input state over I2C
*/
int
file
;
char
filename
[
20
];
if
(
I2C_VIRTUAL_MODE
)
{
// we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing
return
0
;
}
// step 1: open device
file
=
open
(
I2C_BLOCK_DEVICE_NAME
,
O_RDWR
);
if
(
file
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error opening i2c device (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 2: address the slave by its address
if
(
ioctl
(
file
,
I2C_SLAVE
,
i2c_addr
)
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error addressing i2c slave (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 3: write command over I2c
__u8
read_reg
=
0x30
;
/* Device register to access */
char
read_buf
[
10
];
read_buf
[
0
]
=
read_reg
;
if
(
write
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error writing to i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
if
(
read
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error reading analog input from i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
else
{
/* Since read_buf[0] is (LSB:MSB) we need to convert it to (MSB:LSB). To swap bits one by one do
the following */
int
analog_data
=
0
;
for
(
int
index
=
0
;
index
<
8
;
index
++
)
{
analog_data
|=
((
read_buf
[
0
]
&
0x80
)
?
1
:
0
)
<<
index
;
read_buf
[
0
]
<<=
1
;
}
/* Now add the high 2 bit to the value */
analog_data
|=
((
read_buf
[
1
]
&
0x02
)
?
1
:
0
)
<<
8
;
analog_data
|=
((
read_buf
[
1
]
&
0x01
)
?
1
:
0
)
<<
9
;
*
analog_input
=
&
analog_data
;
}
close
(
file
);
}
static
int
getAnalogInputStateAIN1
(
int
i2c_addr
,
int
**
analog_input
)
{
/*
* get digital input state over I2C
*/
int
file
;
char
filename
[
20
];
if
(
I2C_VIRTUAL_MODE
)
{
// we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing
return
0
;
}
// step 1: open device
file
=
open
(
I2C_BLOCK_DEVICE_NAME
,
O_RDWR
);
if
(
file
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error opening i2c device (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 2: address the slave by its address
if
(
ioctl
(
file
,
I2C_SLAVE
,
i2c_addr
)
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error addressing i2c slave (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 3: write command over I2c
__u8
read_reg
=
0x31
;
/* Device register to access */
char
read_buf
[
10
];
read_buf
[
0
]
=
read_reg
;
if
(
write
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error writing to i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
if
(
read
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error reading Analog input from i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
else
{
/* Since read_buf[0] is (LSB:MSB) we need to convert it to (MSB:LSB). To swap bits one by one do
the following */
int
analog_data
=
0
;
for
(
int
index
=
0
;
index
<
8
;
index
++
)
{
analog_data
|=
((
read_buf
[
0
]
&
0x80
)
?
1
:
0
)
<<
index
;
read_buf
[
0
]
<<=
1
;
}
/* Now add the high 2 bit to the value */
analog_data
|=
((
read_buf
[
1
]
&
0x02
)
?
1
:
0
)
<<
8
;
analog_data
|=
((
read_buf
[
1
]
&
0x01
)
?
1
:
0
)
<<
9
;
*
analog_input
=
&
analog_data
;
}
close
(
file
);
}
static
int
getAnalogInputStateAIN2
(
int
i2c_addr
,
int
**
analog_input
)
{
/*
* get digital input state over I2C
*/
int
file
;
char
filename
[
20
];
if
(
I2C_VIRTUAL_MODE
)
{
// we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing
return
0
;
}
// step 1: open device
file
=
open
(
I2C_BLOCK_DEVICE_NAME
,
O_RDWR
);
if
(
file
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error opening i2c device (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 2: address the slave by its address
if
(
ioctl
(
file
,
I2C_SLAVE
,
i2c_addr
)
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error addressing i2c slave (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 3: write command over I2c
__u8
read_reg
=
0x32
;
/* Device register to access */
char
read_buf
[
10
];
read_buf
[
0
]
=
read_reg
;
if
(
write
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error writing to i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
if
(
read
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error reading Analog input from i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
else
{
/* Since read_buf[0] is (LSB:MSB) we need to convert it to (MSB:LSB). To swap bits one by one do
the following */
int
analog_data
=
0
;
for
(
int
index
=
0
;
index
<
8
;
index
++
)
{
analog_data
|=
((
read_buf
[
0
]
&
0x80
)
?
1
:
0
)
<<
index
;
read_buf
[
0
]
<<=
1
;
}
/* Now add the high 2 bit to the value */
analog_data
|=
((
read_buf
[
1
]
&
0x02
)
?
1
:
0
)
<<
8
;
analog_data
|=
((
read_buf
[
1
]
&
0x01
)
?
1
:
0
)
<<
9
;
*
analog_input
=
&
analog_data
;
}
close
(
file
);
}
static
int
getAnalogInputStateAIN3
(
int
i2c_addr
,
int
**
analog_input
)
{
/*
* get digital input state over I2C
*/
int
file
;
char
filename
[
20
];
if
(
I2C_VIRTUAL_MODE
)
{
// we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing
return
0
;
}
// step 1: open device
file
=
open
(
I2C_BLOCK_DEVICE_NAME
,
O_RDWR
);
if
(
file
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error opening i2c device (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 2: address the slave by its address
if
(
ioctl
(
file
,
I2C_SLAVE
,
i2c_addr
)
<
0
)
{
/* ERROR HANDLING; you can check errno to see what went wrong */
printf
(
"Error addressing i2c slave (0x%x).
\n
"
,
i2c_addr
);
exit
(
1
);
}
// step 3: write command over I2c
__u8
read_reg
=
0x33
;
/* Device register to access */
char
read_buf
[
10
];
read_buf
[
0
]
=
read_reg
;
if
(
write
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error writing to i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
if
(
read
(
file
,
read_buf
,
1
)
!=
1
)
{
/* ERROR HANDLING: i2c transaction failed */
printf
(
"Error reading Analog input from i2c slave (0x%x).
\n
"
,
i2c_addr
);
}
else
{
/* Since read_buf[0] is (LSB:MSB) we need to convert it to (MSB:LSB). To swap bits one by one do
the following */
int
analog_data
=
0
;
for
(
int
index
=
0
;
index
<
8
;
index
++
)
{
analog_data
|=
((
read_buf
[
0
]
&
0x80
)
?
1
:
0
)
<<
index
;
read_buf
[
0
]
<<=
1
;
}
/* Now add the high 2 bit to the value */
analog_data
|=
((
read_buf
[
1
]
&
0x02
)
?
1
:
0
)
<<
8
;
analog_data
|=
((
read_buf
[
1
]
&
0x01
)
?
1
:
0
)
<<
9
;
*
analog_input
=
&
analog_data
;
}
close
(
file
);
}
void
addIntegerVariableNode
(
UA_Server
*
server
,
char
*
node_id
,
char
*
node_description
)
void
addIntegerVariableNode
(
UA_Server
*
server
,
char
*
node_id
,
char
*
node_description
)
{
{
UA_Int32
myInteger
=
0
;
UA_Int32
myInteger
=
0
;
...
@@ -235,6 +487,25 @@ void addIntegerVariableNode(UA_Server *server, char *node_id, char *node_descrip
...
@@ -235,6 +487,25 @@ void addIntegerVariableNode(UA_Server *server, char *node_id, char *node_descrip
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_BASEDATAVARIABLETYPE
),
attr0
,
NULL
,
NULL
);
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_BASEDATAVARIABLETYPE
),
attr0
,
NULL
,
NULL
);
}
}
void
addUIntegerVariableReadNode
(
UA_Server
*
server
,
char
*
node_id
,
char
*
node_description
)
{
UA_UInt32
myInteger
=
0
;
UA_NodeId
parentNodeId
=
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_OBJECTSFOLDER
);
UA_NodeId
parentReferenceNodeId
=
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_ORGANIZES
);
UA_VariableAttributes
attr0
=
UA_VariableAttributes_default
;
UA_Variant_setScalar
(
&
attr0
.
value
,
&
myInteger
,
&
UA_TYPES
[
UA_TYPES_UINT32
]);
attr0
.
description
=
UA_LOCALIZEDTEXT
(
"en-US"
,
node_description
);
attr0
.
displayName
=
UA_LOCALIZEDTEXT
(
"en-US"
,
node_description
);
attr0
.
dataType
=
UA_TYPES
[
UA_TYPES_UINT32
].
typeId
;
attr0
.
accessLevel
=
UA_ACCESSLEVELMASK_READ
;
UA_NodeId
myIntegerNodeId0
=
UA_NODEID_STRING
(
1
,
node_id
);
UA_QualifiedName
myIntegerName0
=
UA_QUALIFIEDNAME
(
1
,
node_description
);
UA_Server_addVariableNode
(
server
,
myIntegerNodeId0
,
parentNodeId
,
parentReferenceNodeId
,
myIntegerName0
,
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_BASEDATAVARIABLETYPE
),
attr0
,
NULL
,
NULL
);
}
void
addBooleanVariableReadNode
(
UA_Server
*
server
,
char
*
node_id
,
char
*
node_description
)
void
addBooleanVariableReadNode
(
UA_Server
*
server
,
char
*
node_id
,
char
*
node_description
)
{
{
UA_Boolean
myBoolean
=
false
;
UA_Boolean
myBoolean
=
false
;
...
@@ -271,6 +542,10 @@ static void addVariable(UA_Server *server)
...
@@ -271,6 +542,10 @@ static void addVariable(UA_Server *server)
addBooleanVariableReadNode
(
server
,
"i2c0.in1"
,
"I2C0 / Digital Input 1"
);
addBooleanVariableReadNode
(
server
,
"i2c0.in1"
,
"I2C0 / Digital Input 1"
);
addBooleanVariableReadNode
(
server
,
"i2c0.in2"
,
"I2C0 / Digital Input 2"
);
addBooleanVariableReadNode
(
server
,
"i2c0.in2"
,
"I2C0 / Digital Input 2"
);
addBooleanVariableReadNode
(
server
,
"i2c0.in3"
,
"I2C0 / Digital Input 3"
);
addBooleanVariableReadNode
(
server
,
"i2c0.in3"
,
"I2C0 / Digital Input 3"
);
addUIntegerVariableReadNode
(
server
,
"i2c0.ain0"
,
"I2C0 / Analog Input 0"
);
addUIntegerVariableReadNode
(
server
,
"i2c0.ain1"
,
"I2C0 / Analog Input 1"
);
addUIntegerVariableReadNode
(
server
,
"i2c0.ain2"
,
"I2C0 / Analog Input 2"
);
addUIntegerVariableReadNode
(
server
,
"i2c0.ain3"
,
"I2C0 / Analog Input 3"
);
}
}
if
(
length
>=
2
)
if
(
length
>=
2
)
{
{
...
@@ -283,6 +558,10 @@ static void addVariable(UA_Server *server)
...
@@ -283,6 +558,10 @@ static void addVariable(UA_Server *server)
addBooleanVariableReadNode
(
server
,
"i2c1.in1"
,
"I2C1 / Digital Input 1"
);
addBooleanVariableReadNode
(
server
,
"i2c1.in1"
,
"I2C1 / Digital Input 1"
);
addBooleanVariableReadNode
(
server
,
"i2c1.in2"
,
"I2C1 / Digital Input 2"
);
addBooleanVariableReadNode
(
server
,
"i2c1.in2"
,
"I2C1 / Digital Input 2"
);
addBooleanVariableReadNode
(
server
,
"i2c1.in3"
,
"I2C1 / Digital Input 3"
);
addBooleanVariableReadNode
(
server
,
"i2c1.in3"
,
"I2C1 / Digital Input 3"
);
addUIntegerVariableReadNode
(
server
,
"i2c1.ain0"
,
"I2C1 / Analog Input 0"
);
addUIntegerVariableReadNode
(
server
,
"i2c1.ain1"
,
"I2C1 / Analog Input 1"
);
addUIntegerVariableReadNode
(
server
,
"i2c1.ain2"
,
"I2C1 / Analog Input 2"
);
addUIntegerVariableReadNode
(
server
,
"i2c1.ain3"
,
"I2C1 / Analog Input 3"
);
}
}
}
}
...
@@ -295,6 +574,116 @@ static void beforeReadTime(UA_Server *server,
...
@@ -295,6 +574,116 @@ static void beforeReadTime(UA_Server *server,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
{
}
}
static
void
beforeReadTimeI2C0Ain0
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
*
data_input
=
0
;
getAnalogInputStateAIN0
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C0Ain1
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
*
data_input
=
0
;
getAnalogInputStateAIN1
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C0Ain2
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
*
data_input
=
0
;
getAnalogInputStateAIN2
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C0Ain3
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
*
data_input
=
0
;
getAnalogInputStateAIN3
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C1Ain0
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
int
*
data_input
=
0
;
getAnalogInputStateAIN0
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C1Ain1
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
int
*
data_input
=
0
;
getAnalogInputStateAIN1
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C1Ain2
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
int
*
data_input
=
0
;
getAnalogInputStateAIN2
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C1Ain3
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
int
*
data_input
=
0
;
getAnalogInputStateAIN3
(
addr
,
&
data_input
);
if
(
data
->
value
.
type
==
&
UA_TYPES
[
UA_TYPES_UINT32
])
{
*
(
UA_UInt32
*
)
data
->
value
.
data
=
*
data_input
;
}
}
static
void
beforeReadTimeI2C0In0
(
UA_Server
*
server
,
static
void
beforeReadTimeI2C0In0
(
UA_Server
*
server
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
sessionId
,
void
*
sessionContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
...
@@ -395,7 +784,7 @@ static void beforeReadTimeI2C1In0(UA_Server *server,
...
@@ -395,7 +784,7 @@ static void beforeReadTimeI2C1In0(UA_Server *server,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
char
*
data_input
=
0
;
char
*
data_input
=
0
;
getDigitalInputState
(
addr
,
&
data_input
);
getDigitalInputState
(
addr
,
&
data_input
);
if
((
*
data_input
)
&
(
1UL
<<
0
))
if
((
*
data_input
)
&
(
1UL
<<
0
))
...
@@ -419,7 +808,7 @@ static void beforeReadTimeI2C1In1(UA_Server *server,
...
@@ -419,7 +808,7 @@ static void beforeReadTimeI2C1In1(UA_Server *server,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
char
*
data_input
=
0
;
char
*
data_input
=
0
;
getDigitalInputState
(
addr
,
&
data_input
);
getDigitalInputState
(
addr
,
&
data_input
);
if
((
*
data_input
)
&
(
1UL
<<
1
))
if
((
*
data_input
)
&
(
1UL
<<
1
))
...
@@ -443,7 +832,7 @@ static void beforeReadTimeI2C1In2(UA_Server *server,
...
@@ -443,7 +832,7 @@ static void beforeReadTimeI2C1In2(UA_Server *server,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
char
*
data_input
=
0
;
char
*
data_input
=
0
;
getDigitalInputState
(
addr
,
&
data_input
);
getDigitalInputState
(
addr
,
&
data_input
);
if
((
*
data_input
)
&
(
1UL
<<
2
))
if
((
*
data_input
)
&
(
1UL
<<
2
))
...
@@ -467,7 +856,7 @@ static void beforeReadTimeI2C1In3(UA_Server *server,
...
@@ -467,7 +856,7 @@ static void beforeReadTimeI2C1In3(UA_Server *server,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NodeId
*
nodeid
,
void
*
nodeContext
,
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
const
UA_NumericRange
*
range
,
const
UA_DataValue
*
data
)
{
{
int
addr
=
I2C_SLAVE_ADDR_LIST
[
0
];
int
addr
=
I2C_SLAVE_ADDR_LIST
[
1
];
char
*
data_input
=
0
;
char
*
data_input
=
0
;
getDigitalInputState
(
addr
,
&
data_input
);
getDigitalInputState
(
addr
,
&
data_input
);
if
((
*
data_input
)
&
(
1UL
<<
3
))
if
((
*
data_input
)
&
(
1UL
<<
3
))
...
@@ -733,64 +1122,120 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
...
@@ -733,64 +1122,120 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
callback7
.
onWrite
=
afterWriteTime
;
callback7
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId7
,
callback7
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId7
,
callback7
);
// Analog input 0
UA_NodeId
currentNodeId8
=
UA_NODEID_STRING
(
1
,
"i2c0.ain0"
);
UA_ValueCallback
callback8
;
callback8
.
onRead
=
beforeReadTimeI2C0Ain0
;
callback8
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId8
,
callback8
);
// Analog input 1
UA_NodeId
currentNodeId9
=
UA_NODEID_STRING
(
1
,
"i2c0.ain1"
);
UA_ValueCallback
callback9
;
callback9
.
onRead
=
beforeReadTimeI2C0Ain1
;
callback9
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId9
,
callback9
);
// Analog input 2
UA_NodeId
currentNodeId10
=
UA_NODEID_STRING
(
1
,
"i2c0.ain2"
);
UA_ValueCallback
callback10
;
callback10
.
onRead
=
beforeReadTimeI2C0Ain2
;
callback10
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId10
,
callback10
);
// Analog input 3
UA_NodeId
currentNodeId11
=
UA_NODEID_STRING
(
1
,
"i2c0.ain3"
);
UA_ValueCallback
callback11
;
callback11
.
onRead
=
beforeReadTimeI2C0Ain3
;
callback11
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId11
,
callback11
);
if
(
length
>
1
)
if
(
length
>
1
)
{
{
// I2C1
// I2C1
// relay 0
// relay 0
UA_NodeId
currentNodeId
8
=
UA_NODEID_STRING
(
1
,
"i2c1.relay0"
);
UA_NodeId
currentNodeId
12
=
UA_NODEID_STRING
(
1
,
"i2c1.relay0"
);
UA_ValueCallback
callback
8
;
UA_ValueCallback
callback
12
;
callback
8
.
onRead
=
beforeReadTime
;
callback
12
.
onRead
=
beforeReadTime
;
callback
8
.
onWrite
=
afterWriteTimeI2C1_0
;
callback
12
.
onWrite
=
afterWriteTimeI2C1_0
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
8
,
callback8
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
12
,
callback12
);
// relay 1
// relay 1
UA_NodeId
currentNodeId
9
=
UA_NODEID_STRING
(
1
,
"i2c1.relay1"
);
UA_NodeId
currentNodeId
13
=
UA_NODEID_STRING
(
1
,
"i2c1.relay1"
);
UA_ValueCallback
callback
9
;
UA_ValueCallback
callback
13
;
callback
9
.
onRead
=
beforeReadTime
;
callback
13
.
onRead
=
beforeReadTime
;
callback
9
.
onWrite
=
afterWriteTimeI2C1_1
;
callback
13
.
onWrite
=
afterWriteTimeI2C1_1
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
9
,
callback9
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
13
,
callback13
);
// relay 2
// relay 2
UA_NodeId
currentNodeId1
0
=
UA_NODEID_STRING
(
1
,
"i2c1.relay2"
);
UA_NodeId
currentNodeId1
4
=
UA_NODEID_STRING
(
1
,
"i2c1.relay2"
);
UA_ValueCallback
callback1
0
;
UA_ValueCallback
callback1
4
;
callback1
0
.
onRead
=
beforeReadTime
;
callback1
4
.
onRead
=
beforeReadTime
;
callback1
0
.
onWrite
=
afterWriteTimeI2C1_2
;
callback1
4
.
onWrite
=
afterWriteTimeI2C1_2
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
6
,
callback10
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId
14
,
callback14
);
// relay 2
// relay 2
UA_NodeId
currentNodeId1
1
=
UA_NODEID_STRING
(
1
,
"i2c1.relay3"
);
UA_NodeId
currentNodeId1
5
=
UA_NODEID_STRING
(
1
,
"i2c1.relay3"
);
UA_ValueCallback
callback1
1
;
UA_ValueCallback
callback1
5
;
callback1
1
.
onRead
=
beforeReadTime
;
callback1
5
.
onRead
=
beforeReadTime
;
callback1
1
.
onWrite
=
afterWriteTimeI2C1_3
;
callback1
5
.
onWrite
=
afterWriteTimeI2C1_3
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
1
,
callback11
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
5
,
callback15
);
// Digital input 0
// Digital input 0
UA_NodeId
currentNodeId1
2
=
UA_NODEID_STRING
(
1
,
"i2c1.in0"
);
UA_NodeId
currentNodeId1
6
=
UA_NODEID_STRING
(
1
,
"i2c1.in0"
);
UA_ValueCallback
callback1
2
;
UA_ValueCallback
callback1
6
;
callback1
2
.
onRead
=
beforeReadTimeI2C1In0
;
callback1
6
.
onRead
=
beforeReadTimeI2C1In0
;
callback1
2
.
onWrite
=
afterWriteTime
;
callback1
6
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
2
,
callback12
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
6
,
callback16
);
// Digital input 1
// Digital input 1
UA_NodeId
currentNodeId1
3
=
UA_NODEID_STRING
(
1
,
"i2c1.in1"
);
UA_NodeId
currentNodeId1
7
=
UA_NODEID_STRING
(
1
,
"i2c1.in1"
);
UA_ValueCallback
callback1
3
;
UA_ValueCallback
callback1
7
;
callback1
3
.
onRead
=
beforeReadTimeI2C1In1
;
callback1
7
.
onRead
=
beforeReadTimeI2C1In1
;
callback1
3
.
onWrite
=
afterWriteTime
;
callback1
7
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
3
,
callback13
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
7
,
callback17
);
// Digital input 2
// Digital input 2
UA_NodeId
currentNodeId1
4
=
UA_NODEID_STRING
(
1
,
"i2c1.in2"
);
UA_NodeId
currentNodeId1
8
=
UA_NODEID_STRING
(
1
,
"i2c1.in2"
);
UA_ValueCallback
callback1
4
;
UA_ValueCallback
callback1
8
;
callback1
4
.
onRead
=
beforeReadTimeI2C1In2
;
callback1
8
.
onRead
=
beforeReadTimeI2C1In2
;
callback1
4
.
onWrite
=
afterWriteTime
;
callback1
8
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
4
,
callback14
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId1
8
,
callback18
);
// Digital input 3
// Digital input 3
UA_NodeId
currentNodeId15
=
UA_NODEID_STRING
(
1
,
"i2c1.in3"
);
UA_NodeId
currentNodeId19
=
UA_NODEID_STRING
(
1
,
"i2c1.in3"
);
UA_ValueCallback
callback15
;
UA_ValueCallback
callback19
;
callback15
.
onRead
=
beforeReadTimeI2C1In3
;
callback19
.
onRead
=
beforeReadTimeI2C1In3
;
callback15
.
onWrite
=
afterWriteTime
;
callback19
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId15
,
callback15
);
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId19
,
callback19
);
// Analog input 0
UA_NodeId
currentNodeId20
=
UA_NODEID_STRING
(
1
,
"i2c1.ain0"
);
UA_ValueCallback
callback20
;
callback20
.
onRead
=
beforeReadTimeI2C1Ain0
;
callback20
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId20
,
callback20
);
// Analog input 1
UA_NodeId
currentNodeId21
=
UA_NODEID_STRING
(
1
,
"i2c1.ain1"
);
UA_ValueCallback
callback21
;
callback21
.
onRead
=
beforeReadTimeI2C1Ain1
;
callback21
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId21
,
callback21
);
// Analog input 2
UA_NodeId
currentNodeId22
=
UA_NODEID_STRING
(
1
,
"i2c1.ain2"
);
UA_ValueCallback
callback22
;
callback22
.
onRead
=
beforeReadTimeI2C1Ain2
;
callback22
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId22
,
callback22
);
// Analog input 3
UA_NodeId
currentNodeId23
=
UA_NODEID_STRING
(
1
,
"i2c1.ain3"
);
UA_ValueCallback
callback23
;
callback23
.
onRead
=
beforeReadTimeI2C1Ain3
;
callback23
.
onWrite
=
afterWriteTime
;
UA_Server_setVariableNode_valueCallback
(
server
,
currentNodeId23
,
callback23
);
}
}
}
}
...
...
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