Commit c761d241 authored by Ivan Tyagov's avatar Ivan Tyagov

Tsn

See merge request !19
parents ab8807f9 c8f469b0
#!/bin/bash
OPEN62541_SR=/usr/local/lib
rm -f server
# build OPC UA server which publishes msgs
gcc -o server -I /usr/local/include/ -std=c99 server.c -l:libopen62541.so -L/usr/local/lib -lmbedcrypto -lmbedx509 -I ~/open62541/src/pubsub/ -I ~/open62541/deps/
gcc -o server -I /usr/local/include/ -std=c99 server.c -l:libopen62541.so -L$OPEN62541_SR/lib -lmbedcrypto -lmbedx509 -I ~/open62541/src/pubsub/ -I ~/open62541/deps/
#!/bin/bash
./server -m 1 -b 1 -i 1 -l 2,3 -t 100 -o 10000
COUPLER_SR=.
$COUPLER_SR/server -m 1 -b 1 -i 1 -l 2 -t 1000 -o 5000 -n opc.udp://224.0.0.22:4840/
#!/bin/bash
./server -p 4841 -m 1 -b 1 -i 2 -l 1,3 -t 100 -o 10000
COUPLER_SR=.
$COUPLER_SR/server -p 4841 -m 1 -b 1 -i 2 -l 1 -t 1000 -o 5000 -n opc.udp://224.0.0.22:4840/
#!/bin/bash
./server -p 4842 -m 1 -b 1 -i 3 -l 1,2 -t 100 -o 10000
COUPLER_SR=.
$COUPLER_SR/server -p 4842 -m 1 -b 1 -i 3 -l 1,2 -t 1000 -o 5000
......@@ -5,7 +5,7 @@ char *NETWORK_ADDRESS_URL_DATA_TYPE = "opc.udp://224.0.0.22:4840/";
// global HEART BEATs of coupler
static unsigned int HEART_BEATS = 0;
// the heart beat interval$$
// the heart beat interval (in ms)
const int DEFAULT_HEART_BEAT_INTERVAL = 250;
static int HEART_BEAT_INTERVAL = DEFAULT_HEART_BEAT_INTERVAL;
......
......@@ -141,7 +141,25 @@ void callbackTicHeartBeat()
// set OPC UA's heat_beat node value
UA_NodeId myFloatNodeId = UA_NODEID_STRING(1, "heart_beat");
UA_Float myFloat = HEART_BEATS;
// XXX: implement heart_beat like <ID>.<heart_beats>
int len = snprintf(NULL, 0, "%d", HEART_BEATS);
char *result1 = malloc(len + 1);
snprintf(result1, len + 1, "%d", HEART_BEATS);
int len1 = snprintf(NULL, 0, "%d", COUPLER_ID);
char *result2 = malloc(len1 + 1);
snprintf(result2, len1 + 1, "%d", COUPLER_ID);
// concat
strcat(result2, ".");
strcat(result2, result1);
char * end_ptr;
float final_result = strtof(result2, &end_ptr );
//printf( "final_result: %f\n", final_result );
UA_Float myFloat = final_result;
UA_Variant myVar;
UA_Variant_init(&myVar);
UA_Variant_setScalar(&myVar, &myFloat, &UA_TYPES[UA_TYPES_FLOAT]);
......
......@@ -25,16 +25,18 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
void *monitoredItemContext, const UA_NodeId *nodeId,
void *nodeContext, UA_UInt32 attributeId,
const UA_DataValue *var) {
unsigned long int milli_seconds_now = getMilliSecondsSinceEpoch();
unsigned long int milli_seconds_now;
unsigned int coupler_id;
// filter out ID from Data Set
/*
if(UA_Variant_hasScalarType(&var->value, &UA_TYPES[UA_TYPES_UINT32])) {
unsigned int coupler_id = *(UA_UInt32*) var->value.data;
coupler_id = *(UA_UInt32*) var->value.data;
// care for other coupler_id NOT ourselves
if (coupler_id!=COUPLER_ID) {
//UA_LOG_INFO(UA_Log_Stdout, \
// UA_LOGCATEGORY_USERLAND, \
// "HEART BEAT: %d", coupler_id);
UA_LOG_INFO(UA_Log_Stdout, \
UA_LOGCATEGORY_USERLAND, \
"HEART BEAT: %d", coupler_id);
// convert coupler_id to str
char* coupler_id_str = convertInt2Str(coupler_id);
......@@ -44,14 +46,31 @@ 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);
}
}
*/
// filter out heart_beat from Data Set
if(UA_Variant_hasScalarType(&var->value, &UA_TYPES[UA_TYPES_FLOAT])) {
float heart_beat = *(UA_Float*) var->value.data;
//UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "heart_beat = %f", heart_beat);
milli_seconds_now = getMilliSecondsSinceEpoch();
// split <ID>.<heart_beats>, just converting to int is enough
coupler_id = (int) heart_beat;
if (coupler_id!=COUPLER_ID) {
UA_LOG_INFO(UA_Log_Stdout, \
UA_LOGCATEGORY_USERLAND, \
"HEART BEAT: %d", coupler_id);
// convert coupler_id to str
char* coupler_id_str = convertInt2Str(coupler_id);
// convert micro seconds to str
char* milli_seconds_now_str = convertLongInt2Str(milli_seconds_now);
// Add to our local linked list
addItem(&SUBSCRIBER_DICT, coupler_id_str, milli_seconds_now_str);
}
}
}
......@@ -198,7 +217,8 @@ static UA_StatusCode addSubscribedVariables(UA_Server *server, UA_NodeId dataSet
/*monitor variable*/
if (ENABLE_HEART_BEAT_CHECK) {
UA_MonitoredItemCreateRequest monRequest = UA_MonitoredItemCreateRequest_default(newNode);
UA_Server_createDataChangeMonitoredItem(server, UA_TIMESTAMPSTORETURN_SOURCE,
//monRequest.requestedParameters.samplingInterval = 100.0; /* 100 ms interval */
UA_Server_createDataChangeMonitoredItem(server, UA_TIMESTAMPSTORETURN_NEITHER,
monRequest, NULL, dataChangeNotificationCallback);
}
/* For creating Targetvariables */
......
#!/bin/bash
chrt -f 97 ptp4l -s -S -i eth0 --step_threshold=1 -m &> ptp4l_eth0.log &
#!/bin/sh
# Pin ethernet IRQ bottom half to CPU1
echo 2 > /proc/irq/56/smp_affinity
# Get PID for ethernet IRQ
irq56_pid=$(pgrep "irq/56-eth0")
# Pin ethernet IRQ upper half to CPU1
taskset -p 2 $irq56_pid
# Get PID for ksoftirqd1
ksoftirq1_pid=$(pgrep "ksoftirqd/1")
# Set high priority for ksoftirqd/1
chrt -f -p 97 $ksoftirq1_pid
#!/bin/bash
chrt -f 97 ptp4l -s -S -i eth0 --step_threshold=1 -m &> ptp4l_eth0.log &
#!/bin/bash
# kill all
pkill -f "ptp4l"
pkill -f "phc2sys"
#!/bin/bash
chrt -f 97 ptp4l -H -i enp6s0 --step_threshold=1 -m &> ptp4l_enp6s0.log &
pmc -u -b 0 -i enp6s0 "SET GRANDMASTER_SETTINGS_NP clockClass 248 clockAccuracy 0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 timeTraceable 1 frequencyTraceable 0 timeSource 0xa0"
chrt -f 95 phc2sys -m -c enp6s0 -s CLOCK_REALTIME --step_threshold=1 -w &> phc2sys_enp6s0.log &
#!/bin/bash
chrt -f 97 ptp4l -H -i enp7s0 --step_threshold=1 -m &> ptp4l_enp7s0.log &
pmc -u -b 0 -i enp7s0 "SET GRANDMASTER_SETTINGS_NP clockClass 248 clockAccuracy 0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 1 ptpTimescale 1 timeTraceable 1 frequencyTraceable 0 timeSource 0xa0"
chrt -f 95 phc2sys -m -c enp7s0 -s CLOCK_REALTIME --step_threshold=1 -w &> phc2sys_enp7s0.log &
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