Procházet zdrojové kódy

minimal write (write value of a node) implemented (alpha version)

FlorianPalm před 10 roky
rodič
revize
15b7b35773
3 změnil soubory, kde provedl 214 přidání a 3 odebrání
  1. 8 1
      src/ua_services.h
  2. 202 2
      src/ua_services_attribute.c
  3. 4 0
      src/ua_transport_binary_secure.c

+ 8 - 1
src/ua_services.h

@@ -183,7 +183,14 @@ UA_Int32 Service_TranslateBrowsePathsToNodeIds(SL_Channel *channel, const UA_Tra
  */
 UA_Int32 Service_Read(SL_Channel *channel, const UA_ReadRequest *request, UA_ReadResponse *response);
 // Service_HistoryRead
-// Service_Write
+/**
+ * @brief This Service is used to write one or more Attributes of one or more
+ *  Nodes. For constructed Attribute values whose elements are indexed, such as
+ *  an array, this Service allows Clients to write the entire set of indexed
+ *  values as a composite, to write individual elements or to write ranges of
+ *  elements of the composite.
+ */
+UA_Int32 Service_Write(SL_Channel *channel, const UA_WriteRequest *request,UA_WriteResponse *response);
 // Service_HistoryUpdate
 /** @} */
 

+ 202 - 2
src/ua_services_attribute.c

@@ -231,7 +231,7 @@ UA_Int32 Service_Read(SL_Channel *channel, const UA_ReadRequest *request,
 	if(channel->session == UA_NULL || channel->session->application == UA_NULL)
 		return UA_ERROR;    // TODO: Return error message
 
-	int readsize = request->nodesToReadSize;
+	UA_Int32 readsize = request->nodesToReadSize;
 	/* NothingTodo */
 	if(readsize <= 0) {
 		response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
@@ -241,7 +241,7 @@ UA_Int32 Service_Read(SL_Channel *channel, const UA_ReadRequest *request,
 
 	response->resultsSize = readsize;
 	UA_alloc((void **)&response->results, sizeof(UA_DataValue) * readsize);
-	for(int i = 0;i < readsize;i++) {
+	for(UA_Int32 i = 0;i < readsize;i++) {
 		DBG_VERBOSE(printf("service_read - attributeId=%d\n", request->nodesToRead[i].attributeId));
 		DBG_VERBOSE(UA_NodeId_printf("service_read - nodeId=", &(request->nodesToRead[i].nodeId)));
 		response->results[i] = service_read_node(channel->session->application,
@@ -251,3 +251,203 @@ UA_Int32 Service_Read(SL_Channel *channel, const UA_ReadRequest *request,
 	response->diagnosticInfosSize = 0;
 	return UA_SUCCESS;
 }
+
+UA_Int32 Service_Write_writeNode(Application *app, UA_WriteValue *writeValue,UA_StatusCode *result)
+{
+	UA_Int32 retval = UA_SUCCESS;
+	Namespace *ns = UA_indexedList_findValue(app->namespaces, writeValue->nodeId.namespace);
+	if(ns==UA_NULL)
+	{
+		*result = UA_STATUSCODE_BADNODEIDINVALID;
+		return UA_ERROR;
+	}
+	Namespace_Entry_Lock *lock;
+	const UA_Node *node;
+
+	if(Namespace_get(ns, &writeValue->nodeId,&node, &lock) != UA_SUCCESS){
+		return UA_ERROR;
+	}
+
+
+
+	switch(writeValue->attributeId) {
+	case UA_ATTRIBUTEID_NODEID:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){
+
+		}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_NODECLASS:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){
+
+		}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_BROWSENAME:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_DISPLAYNAME:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){
+		}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_DESCRIPTION:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_WRITEMASK:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		break;
+
+	case UA_ATTRIBUTEID_USERWRITEMASK:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_ISABSTRACT:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_SYMMETRIC:
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_INVERSENAME:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_EVENTNOTIFIER:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_VALUE:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){
+		// TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
+		/* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
+		/*                                     &((UA_VariableNode *)node)->value); */
+		retval |= UA_Variant_copy(&writeValue->value.value, &((UA_VariableNode *)node)->value);
+		*result = UA_STATUSCODE_GOOD;
+
+		}
+
+		break;
+
+	case UA_ATTRIBUTEID_DATATYPE:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_VALUERANK:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_ARRAYDIMENSIONS:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_ACCESSLEVEL:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_USERACCESSLEVEL:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+		return UA_ERROR;
+		break;
+
+	case UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_HISTORIZING:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_EXECUTABLE:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	case UA_ATTRIBUTEID_USEREXECUTABLE:
+
+		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){}
+		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+		break;
+
+	default:
+
+		*result      = UA_STATUSCODE_BADATTRIBUTEIDINVALID;
+		break;
+	}
+
+	Namespace_Entry_Lock_release(lock);
+	return retval;
+
+}
+UA_Int32 Service_Write(SL_Channel *channel, const UA_WriteRequest *request,
+                      UA_WriteResponse *response) {
+	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 i;
+	if(channel->session == UA_NULL || channel->session->application == UA_NULL)
+		return UA_ERROR;    // TODO: Return error message
+	response->resultsSize = request->nodesToWriteSize;
+
+	UA_Array_new((void**)&response->results,response->resultsSize,&UA_.types[UA_STATUSCODE]);
+	for(i=0; i < request->nodesToWriteSize; i++){
+		Service_Write_writeNode(channel->session->application ,&request->nodesToWrite[i], &response->results[i]);
+	}
+
+	return retval;
+}

+ 4 - 0
src/ua_transport_binary_secure.c

@@ -140,6 +140,10 @@ UA_Int32 SL_handleRequest(SL_Channel *channel, const UA_ByteString *msg, UA_UInt
 	}else if(serviceid == UA_READREQUEST_NS0) {
 		INVOKE_SERVICE(Read);
 		responsetype = UA_READRESPONSE_NS0;
+	}else if(serviceid == UA_WRITEREQUEST_NS0)
+	{
+		INVOKE_SERVICE(Write);
+		responsetype = UA_WRITERESPONSE_NS0;
 	}else if(serviceid == UA_TRANSLATEBROWSEPATHSTONODEIDSREQUEST_NS0) {
 		INVOKE_SERVICE(TranslateBrowsePathsToNodeIds);
 		responsetype = UA_TRANSLATEBROWSEPATHSTONODEIDSRESPONSE_NS0;