Commit 66755185 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

pubsub: use message instead of checkpoint

parent a2430d79
...@@ -5,11 +5,23 @@ ...@@ -5,11 +5,23 @@
#include "mavsdk_wrapper.h" #include "mavsdk_wrapper.h"
#include "pubsub.h" #include "pubsub.h"
struct messageNode {
char *message;
struct messageNode *next;
};
typedef struct {
struct messageNode *head;
struct messageNode *tail;
} MessageQueue;
UA_Double latitude = 0; UA_Double latitude = 0;
UA_Double longitude = 0; UA_Double longitude = 0;
UA_Float altitude_abs = 0; UA_Float altitude_abs = 0;
UA_Float altitude_rel = 0; UA_Float altitude_rel = 0;
UA_UInt32 last_checkpoint = 0; UA_String message = {
.length = 0,
.data = NULL,
};
VariableData droneVariableArray[] = { VariableData droneVariableArray[] = {
{ {
...@@ -45,12 +57,12 @@ VariableData droneVariableArray[] = { ...@@ -45,12 +57,12 @@ VariableData droneVariableArray[] = {
.getter.getFloat = mavsdk_getAltitudeRel, .getter.getFloat = mavsdk_getAltitudeRel,
}, },
{ {
.name = "last_checkpoint", .name = "message",
.description = "Last checkpoint flown over", .description = "Message to send to the other drones",
.value = &last_checkpoint, .value = &message,
.type = UA_TYPES_UINT32, .type = UA_TYPES_STRING,
.builtInType = UA_NS0ID_UINT32, .builtInType = UA_NS0ID_STRING,
.getter.getUint32 = getLastCheckpoint .getter.getString = get_message
}, },
}; };
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#define DATA_SET_WRITER_ID 1 #define DATA_SET_WRITER_ID 1
#define WRITER_GROUP_ID 1 #define WRITER_GROUP_ID 1
#define MAX_MESSAGE_SIZE 1024
typedef struct { typedef struct {
UA_UInt16 id; UA_UInt16 id;
UA_Double latitude; UA_Double latitude;
...@@ -23,8 +25,8 @@ typedef struct { ...@@ -23,8 +25,8 @@ typedef struct {
UA_UInt32 altitudeAbsId; UA_UInt32 altitudeAbsId;
UA_Float altitudeRel; UA_Float altitudeRel;
UA_UInt32 altitudeRelId; UA_UInt32 altitudeRelId;
UA_UInt32 lastCheckpoint; char message[MAX_MESSAGE_SIZE];
UA_UInt32 lastCheckpointId; UA_UInt32 messageId;
} JSDroneData; } JSDroneData;
typedef struct { typedef struct {
...@@ -34,10 +36,11 @@ typedef struct { ...@@ -34,10 +36,11 @@ typedef struct {
int type; int type;
UA_Byte builtInType; UA_Byte builtInType;
union { union {
UA_UInt32 (*getUint32)(void);
UA_Float (*getFloat)(void);
UA_Double (*getDouble)(void);
UA_DateTime (*getTimestamp)(void); UA_DateTime (*getTimestamp)(void);
UA_Double (*getDouble)(void);
UA_Float (*getFloat)(void);
UA_String (*getString)(void);
UA_UInt32 (*getUint32)(void);
} getter; } getter;
} VariableData; } VariableData;
...@@ -45,7 +48,7 @@ typedef struct { ...@@ -45,7 +48,7 @@ typedef struct {
int subscribeOnly(UA_String *transportProfile, int subscribeOnly(UA_String *transportProfile,
UA_NetworkAddressUrlDataType *networkAddressUrl, UA_NetworkAddressUrlDataType *networkAddressUrl,
VariableData *variableArray, size_t nbVariable, VariableData *variableArray, size_t nbVariable,
UA_UInt32 id, UA_UInt32 nbReader, UA_UInt32 id, UA_UInt32 nbReader, UA_Duration interval,
void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic), void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic),
UA_UInt16 (*get_reader_id)(UA_UInt32 nb), UA_UInt16 (*get_reader_id)(UA_UInt32 nb),
void (*update)(UA_UInt32 id, const UA_DataValue*), void (*update)(UA_UInt32 id, const UA_DataValue*),
...@@ -54,14 +57,14 @@ int subscribeOnly(UA_String *transportProfile, ...@@ -54,14 +57,14 @@ int subscribeOnly(UA_String *transportProfile,
int runPubsub(UA_String *transportProfile, int runPubsub(UA_String *transportProfile,
UA_NetworkAddressUrlDataType *networkAddressUrl, UA_NetworkAddressUrlDataType *networkAddressUrl,
VariableData *variableArray, size_t nbVariable, VariableData *variableArray, size_t nbVariable,
UA_UInt32 id, UA_UInt32 nbReader, UA_UInt32 id, UA_UInt32 nbReader, UA_Duration interval,
void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic), void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic),
UA_UInt16 (*get_reader_id)(UA_UInt32 nb), UA_UInt16 (*get_reader_id)(UA_UInt32 nb),
VariableData (*get_value)(UA_String identifier), VariableData (*get_value)(UA_String identifier),
void (*update)(UA_UInt32 id, const UA_DataValue*), void (*update)(UA_UInt32 id, const UA_DataValue*),
UA_Boolean *running); UA_Boolean *running);
UA_UInt32 getLastCheckpoint(void); UA_String get_message(void);
UA_UInt16 get_drone_id(UA_UInt32 nb); UA_UInt16 get_drone_id(UA_UInt32 nb);
...@@ -73,8 +76,6 @@ void pubsub_print_coordinates(UA_UInt32 id, const UA_DataValue *var); ...@@ -73,8 +76,6 @@ void pubsub_print_coordinates(UA_UInt32 id, const UA_DataValue *var);
VariableData pubsub_get_value(UA_String identifier); VariableData pubsub_get_value(UA_String identifier);
void stop_pubsub(void);
DLL_PUBLIC JSModuleDef *js_init_module(JSContext *ctx, const char *module_name); DLL_PUBLIC JSModuleDef *js_init_module(JSContext *ctx, const char *module_name);
#endif /* __PUBSUB_H__ */ #endif /* __PUBSUB_H__ */
...@@ -135,13 +135,13 @@ addDataSetField(UA_Server *server, VariableData varDetails) { ...@@ -135,13 +135,13 @@ addDataSetField(UA_Server *server, VariableData varDetails) {
* The WriterGroup (WG) is part of the connection and contains the primary * The WriterGroup (WG) is part of the connection and contains the primary
* configuration parameters for the message creation. */ * configuration parameters for the message creation. */
static void static void
addWriterGroup(UA_Server *server) { addWriterGroup(UA_Server *server, UA_Duration publishingInterval) {
/* Now we create a new WriterGroupConfig and add the group to the existing /* Now we create a new WriterGroupConfig and add the group to the existing
* PubSubConnection. */ * PubSubConnection. */
UA_WriterGroupConfig writerGroupConfig; UA_WriterGroupConfig writerGroupConfig;
memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig)); memset(&writerGroupConfig, 0, sizeof(UA_WriterGroupConfig));
writerGroupConfig.name = UA_STRING("Demo WriterGroup"); writerGroupConfig.name = UA_STRING("Demo WriterGroup");
writerGroupConfig.publishingInterval = 100; writerGroupConfig.publishingInterval = publishingInterval;
writerGroupConfig.enabled = UA_FALSE; writerGroupConfig.enabled = UA_FALSE;
writerGroupConfig.writerGroupId = WRITER_GROUP_ID; writerGroupConfig.writerGroupId = WRITER_GROUP_ID;
writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP; writerGroupConfig.encodingMimeType = UA_PUBSUB_ENCODING_UADP;
...@@ -245,7 +245,8 @@ dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitoredItemId, ...@@ -245,7 +245,8 @@ dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitoredItemId,
* Set SubscribedDataSet type to TargetVariables data type. * Set SubscribedDataSet type to TargetVariables data type.
* Add subscribedvariables to the DataSetReader */ * Add subscribedvariables to the DataSetReader */
static UA_StatusCode static UA_StatusCode
addSubscribedVariables(UA_Server *server, UA_NodeId dataSetReaderId, UA_UInt32 nb, addSubscribedVariables(UA_Server *server, UA_NodeId dataSetReaderId,
UA_UInt32 nb, UA_Duration samplingInterval,
void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic)) { void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic)) {
if(server == NULL) if(server == NULL)
return UA_STATUSCODE_BADINTERNALERROR; return UA_STATUSCODE_BADINTERNALERROR;
...@@ -302,6 +303,7 @@ addSubscribedVariables(UA_Server *server, UA_NodeId dataSetReaderId, UA_UInt32 n ...@@ -302,6 +303,7 @@ addSubscribedVariables(UA_Server *server, UA_NodeId dataSetReaderId, UA_UInt32 n
/*monitor variable*/ /*monitor variable*/
UA_MonitoredItemCreateRequest monRequest = UA_MonitoredItemCreateRequest_default(newNode); UA_MonitoredItemCreateRequest monRequest = UA_MonitoredItemCreateRequest_default(newNode);
init_node_id(newNode.identifier.numeric, nb, i); init_node_id(newNode.identifier.numeric, nb, i);
monRequest.requestedParameters.samplingInterval = samplingInterval;
UA_Server_createDataChangeMonitoredItem(server, UA_TIMESTAMPSTORETURN_SOURCE, UA_Server_createDataChangeMonitoredItem(server, UA_TIMESTAMPSTORETURN_SOURCE,
monRequest, NULL, dataChangeNotificationCallback); monRequest, NULL, dataChangeNotificationCallback);
...@@ -375,7 +377,7 @@ setServer(UA_String *transportProfile, ...@@ -375,7 +377,7 @@ setServer(UA_String *transportProfile,
static UA_StatusCode static UA_StatusCode
subscribe(UA_Server *server, subscribe(UA_Server *server,
VariableData *variableArray, size_t nbVariable, VariableData *variableArray, size_t nbVariable,
UA_UInt32 id, UA_UInt32 nbReader, UA_UInt32 id, UA_UInt32 nbReader, UA_Duration interval,
void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic), void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic),
UA_UInt16 (*get_reader_id)(UA_UInt32 nb), UA_UInt16 (*get_reader_id)(UA_UInt32 nb),
void (*update)(UA_UInt32 id, const UA_DataValue*)) { void (*update)(UA_UInt32 id, const UA_DataValue*)) {
...@@ -405,7 +407,7 @@ subscribe(UA_Server *server, ...@@ -405,7 +407,7 @@ subscribe(UA_Server *server,
return EXIT_FAILURE; return EXIT_FAILURE;
/* Add SubscribedVariables to the created DataSetReader */ /* Add SubscribedVariables to the created DataSetReader */
retval = addSubscribedVariables(server, readerIdent, i, init_node_id); retval = addSubscribedVariables(server, readerIdent, i, interval, init_node_id);
if (retval != UA_STATUSCODE_GOOD) if (retval != UA_STATUSCODE_GOOD)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -416,7 +418,7 @@ subscribe(UA_Server *server, ...@@ -416,7 +418,7 @@ subscribe(UA_Server *server,
int subscribeOnly(UA_String *transportProfile, int subscribeOnly(UA_String *transportProfile,
UA_NetworkAddressUrlDataType *networkAddressUrl, UA_NetworkAddressUrlDataType *networkAddressUrl,
VariableData *variableArray, size_t nbVariable, VariableData *variableArray, size_t nbVariable,
UA_UInt32 id, UA_UInt32 nbReader, UA_UInt32 id, UA_UInt32 nbReader, UA_Duration interval,
void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic), void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic),
UA_UInt16 (*get_reader_id)(UA_UInt32 nb), UA_UInt16 (*get_reader_id)(UA_UInt32 nb),
void (*update)(UA_UInt32 id, const UA_DataValue*), void (*update)(UA_UInt32 id, const UA_DataValue*),
...@@ -426,8 +428,8 @@ int subscribeOnly(UA_String *transportProfile, ...@@ -426,8 +428,8 @@ int subscribeOnly(UA_String *transportProfile,
server = setServer(transportProfile, networkAddressUrl, id); server = setServer(transportProfile, networkAddressUrl, id);
subscribe(server, variableArray, nbVariable, id, nbReader, init_node_id, subscribe(server, variableArray, nbVariable, id, nbReader, interval,
get_reader_id, update); init_node_id, get_reader_id, update);
retval = UA_Server_run(server, running); retval = UA_Server_run(server, running);
UA_Server_delete(server); UA_Server_delete(server);
...@@ -437,7 +439,7 @@ int subscribeOnly(UA_String *transportProfile, ...@@ -437,7 +439,7 @@ int subscribeOnly(UA_String *transportProfile,
int runPubsub(UA_String *transportProfile, int runPubsub(UA_String *transportProfile,
UA_NetworkAddressUrlDataType *networkAddressUrl, UA_NetworkAddressUrlDataType *networkAddressUrl,
VariableData *variableArray, size_t nbVariable, VariableData *variableArray, size_t nbVariable,
UA_UInt32 id, UA_UInt32 nbReader, UA_UInt32 id, UA_UInt32 nbReader, UA_Duration interval,
void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic), void (*init_node_id)(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic),
UA_UInt16 (*get_reader_id)(UA_UInt32 nb), UA_UInt16 (*get_reader_id)(UA_UInt32 nb),
VariableData (*get_value)(UA_String identifier), VariableData (*get_value)(UA_String identifier),
...@@ -460,15 +462,15 @@ int runPubsub(UA_String *transportProfile, ...@@ -460,15 +462,15 @@ int runPubsub(UA_String *transportProfile,
addDataSetField(server, variableArray[i]); addDataSetField(server, variableArray[i]);
} }
addWriterGroup(server); addWriterGroup(server, interval);
retval = addDataSetWriter(server); retval = addDataSetWriter(server);
if (retval != UA_STATUSCODE_GOOD) if (retval != UA_STATUSCODE_GOOD)
return EXIT_FAILURE; return EXIT_FAILURE;
/* Subscribing */ /* Subscribing */
subscribe(server, variableArray, nbVariable, id, nbReader, init_node_id, subscribe(server, variableArray, nbVariable, id, nbReader, interval,
get_reader_id, update); init_node_id, get_reader_id, update);
retval = UA_Server_run(server, running); retval = UA_Server_run(server, running);
UA_Server_delete(server); UA_Server_delete(server);
......
This diff is collapsed.
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