Procházet zdrojové kódy

Changed call location of "serverCallback" to call it every messageloop cycle

FlorianPalm před 10 roky
rodič
revize
68df7888c1

+ 5 - 1
examples/src/networklayer.c

@@ -91,14 +91,18 @@ UA_Int32 NL_msgLoop(NL_data* nl, struct timeval *tv, UA_Int32(*worker)(void*), v
 			default:
 				DBG_VERBOSE(printf("UA_Stack_msgLoop - errno={%d,%s}\n", errno, strerror(errno)));
 				DBG_VERBOSE(printf("UA_Stack_msgLoop - call worker\n"));
-				worker(arg);
+
 				DBG_VERBOSE(printf("UA_Stack_msgLoop - return from worker\n"));
 			}
 		} else { // activity on listener or client ports
 			DBG_VERBOSE(printf("UA_Stack_msgLoop - activities on %d handles\n",result));
 			UA_list_iteratePayload(&(nl->connections),NL_checkFdSet);
+
 		}
+		worker(arg);
+
 	}
+
 	return UA_SUCCESS;
 }
 #endif

+ 7 - 42
examples/src/opcuaServer.c

@@ -19,16 +19,12 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include "raspberrypi_io.h"
+#ifdef RASPI
+	#include "raspberrypi_io.h"
+#endif
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #define MAXMYMEM 4
-void readTemp1(float *temp)
-{
-	*temp = *temp + 0.3772f;
-
-}
-
 
 
 
@@ -45,14 +41,6 @@ UA_Int32 serverCallback(void * arg) {
 		((UA_ServerStatusDataType*)(((UA_VariableNode*)node)->value.data))->currentTime = UA_DateTime_now();
 	}
 
-
-	//FIXME: add the I/O code for raspberry pi here
-//#ifdef RASPI
-
-
-
-
-
 	const UA_Node *foundNode = UA_NULL;
 	Namespace_Entry_Lock *lock;
 	//node which should be filled with data (float value)
@@ -63,36 +51,13 @@ UA_Int32 serverCallback(void * arg) {
 	tmpNodeId.namespace =  0;
 
 	if(Namespace_get(ns0,&tmpNodeId, &foundNode,&lock) == UA_SUCCESS){
-		int shID;
-		char *myPtr;
-		int processId;
-
-		shID = shmget(2404, MAXMYMEM, IPC_CREAT | 0666);
-		if (shID >= 0) {
-			myPtr = shmat(shID, 0, 0);
-			if(myPtr!=(void*)-1)
-			{
-				((UA_VariableNode *)foundNode)->value.data = myPtr;
-				if((processId = fork()) < 0) {
-					printf("serverCallback - ERROR: process not created");
-				}
-				else if(processId == 0) {
-
-					while(1){
-						(*(float*)myPtr) = (*(float*)myPtr) + 0.3312f;
 	#ifdef RASPI
-						readTemp((float*)myPtr);
+		readTemp((float*)((UA_VariableNode *)foundNode)->value.data);
+	#else
+		*((float*)((UA_VariableNode *)foundNode)->value.data) = *((float*)((UA_VariableNode *)foundNode)->value.data) + 0.2f;
 	#endif
-						sleep(100);
-					}
-				}
-			}
-		} else {
-			printf("serverCallback - ERROR: no shared memory allocated");
-		}
-	}
-
 
+	}
 
 	return UA_SUCCESS;
 }

+ 5 - 2
examples/src/raspberrypi_io.c

@@ -6,6 +6,9 @@
  */
 
 #include "raspberrypi_io.h"
+
+
+
 #ifdef RASPI
 int readTemp(float *temp){
 	FILE *ptr_file;
@@ -24,9 +27,9 @@ int readTemp(float *temp){
 
 	fgets(buf, 1000, ptr_file);
 
-	ptr_temp = strtok(buf, (int) delimiter);
+	ptr_temp = strtok(buf, (char*)delimiter);
 
-	ptr_temp = strtok((void*)0, (int) delimiter);
+	ptr_temp = strtok((void*)0, (char*)delimiter);
 
 	temperaturInmC = atol(ptr_temp);
 

+ 4 - 3
examples/src/raspberrypi_io.h

@@ -7,12 +7,13 @@
 
 #ifndef RASPBERRYPI_IO_H_
 #define RASPBERRYPI_IO_H_
-#ifdef RASPI
-	#include <wiringPi.h>
-#endif
+
+#include <wiringPi.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "string.h"
 int readTemp(float *temp);
 int writeLEDred(int state);
 

+ 11 - 33
src/ua_application.c

@@ -556,19 +556,19 @@ void appMockup_init() {
 UA_ExpandedNodeId ObjId_led1 = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 110}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
 
 // LED1
-UA_VariableNode *led1;
-UA_VariableNode_new(&led1);
-led1->nodeId = ObjId_led1.nodeId;
-led1->nodeClass = UA_NODECLASS_VARIABLE;
-led1->browseName = UA_QUALIFIEDNAME_STATIC("led1");
-led1->displayName = UA_LOCALIZEDTEXT_STATIC("led1");
-led1->description = UA_LOCALIZEDTEXT_STATIC("led1");
+UA_VariableNode *temperature1;
+UA_VariableNode_new(&temperature1);
+temperature1->nodeId = ObjId_led1.nodeId;
+temperature1->nodeClass = UA_NODECLASS_VARIABLE;
+temperature1->browseName = UA_QUALIFIEDNAME_STATIC("temperature1");
+temperature1->displayName = UA_LOCALIZEDTEXT_STATIC("temperature1");
+temperature1->description = UA_LOCALIZEDTEXT_STATIC("temperature1");
 
 //Set node value
 UA_Variant *tmpNodeValue;
 UA_Float *tmpFloat;
 UA_Float_new(&tmpFloat);
-*tmpFloat = 0;
+*tmpFloat = -133.2f;
 UA_Variant_new(&tmpNodeValue);
 tmpNodeValue->arrayDimensionsLength = 0;
 tmpNodeValue->arrayLength = 1;
@@ -576,40 +576,18 @@ tmpNodeValue->data = (void*)tmpFloat;
 
 tmpNodeValue->vt = &UA_.types[UA_FLOAT];
 
-UA_Variant_copy(tmpNodeValue, &led1->value);
+UA_Variant_copy(tmpNodeValue, &temperature1->value);
 
 //FIXME: these two give - "Browse failed with error 'UncertainNotAllNodesAvailable'."
 //AddReference((UA_Node*)led1, &(UA_ReferenceNode){RefTypeId_Organizes, UA_TRUE, NS0EXPANDEDNODEID(84)}, ns0);
 AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_led1}, ns0);
 
 //FIXME: this give no error, but also also does not show the node
-AddReference((UA_Node*)led1, &(UA_ReferenceNode){RefTypeId_Organizes, UA_TRUE, NS0EXPANDEDNODEID(84)}, ns0);
+AddReference((UA_Node*)temperature1, &(UA_ReferenceNode){RefTypeId_Organizes, UA_TRUE, NS0EXPANDEDNODEID(84)}, ns0);
 
-Namespace_insert(ns0,(UA_Node*)led1);
+Namespace_insert(ns0,(UA_Node*)temperature1);
 
-/* NOT WORKING
 
-UA_ExpandedNodeId ObjId_led1 = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 1, .identifier.numeric = 110}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
-
-// LED1
-UA_VariableNode *led1;
-UA_VariableNode_new(&led1);
-led1->nodeId = ObjId_led1.nodeId;
-led1->nodeClass = UA_NODECLASS_VARIABLE;
-led1->browseName = UA_QUALIFIEDNAME_STATIC("led1");
-led1->displayName = UA_LOCALIZEDTEXT_STATIC("led1");
-led1->description = UA_LOCALIZEDTEXT_STATIC("led1");
-
-//FIXME: these two give - "Browse failed with error 'UncertainNotAllNodesAvailable'."
-//AddReference((UA_Node*)led1, &(UA_ReferenceNode){RefTypeId_Organizes, UA_TRUE, NS0EXPANDEDNODEID(84)}, ns0);
-AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_led1}, local);
-
-//FIXME: this give no error, but also also does not show the node
-AddReference((UA_Node*)led1, &(UA_ReferenceNode){RefTypeId_Organizes, UA_TRUE, NS0EXPANDEDNODEID(84)}, ns0);
-
-Namespace_insert(local,(UA_Node*)led1);
-
-*/
 
 #if defined(DEBUG) && defined(VERBOSE)
 	uint32_t i;