Pārlūkot izejas kodu

Merge branch 'master' of https://github.com/Stasik0/Open62541

Conflicts:
	OPCUAServer/src/opcua_binaryEncDec.c
MaximilianBauer 11 gadi atpakaļ
vecāks
revīzija
5188c451d2

+ 0 - 18
OPCUAServer/config.log

@@ -295,21 +295,3 @@ target_vendor='pc'
 #define VERSION "1.0"
 
 configure: exit 0
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by OPCUAServer config.status 1.0, which was
-generated by GNU Autoconf 2.68.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile depfiles
-
-on opcua-VirtualBox
-
-config.status:793: creating src/Makefile
-config.status:965: executing depfiles commands

+ 37 - 1
OPCUAServer/src/opcuaServer.c

@@ -51,7 +51,36 @@ void server_run()
 	int send_data = 1;
 	int new_client = 2;
 	int new_request = 3;
+	char buf[8192];
+	struct sockaddr_in self;
+	int sockfd;
+	int clientfd;
 
+	struct sockaddr_in client_addr;
+	int addrlen=sizeof(client_addr);
+
+	/*---Create streaming socket---*/
+    if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
+	{
+    	puts("socket error");
+	}
+	bzero(&self, sizeof(self));
+	self.sin_family = AF_INET;
+	self.sin_port = htons(4840);
+	self.sin_addr.s_addr = htonl(INADDR_ANY);
+
+
+	if(bind(sockfd, self, sizeof( self)) < 0) {
+	   //Fehler bei bind()
+	 }
+
+	/*---Make it a "listening socket"---*/
+	if ( listen(sockfd, 1) != 0 )
+	{
+		puts("listen error");
+	}
+	clientfd = accept(sockfd, (struct sockaddr*)&client_addr, &addrlen);
+	server_state = 0;
 	while(1)
 	{
 		//call recv (nonblocking)
@@ -62,13 +91,20 @@ void server_run()
 		//
 		UA_connection connection;
 		AD_RawMessage *rawMessage;
+		rawMessage->message = buf;
+		rawMessage->length = 0;
 		switch(server_state)
 		{
 
 			recv_data :
 			{
-				//call receive function
 
+				//call receive function
+				rawMessage->length = recv(sockfd,buf,8192,0);
+				if(rawMessage->length > 0)
+				{
+					server_state = new_client;
+				}
 				break;
 			}
 			send_data :

+ 27 - 5
OPCUAServer/src/opcua_binaryEncDec.c

@@ -79,13 +79,15 @@ Int64 convertToInt64(char* buf, int pos)
 	return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
 }
 
+
 Int64 convertToInt64_test(char* buf, int pos)
 {
 
 	printf("");
 }
 
-void convertToUAString(char* buf, int pos, UA_String* dstUAString)
+
+convertToUAString(char* buf, int pos,UA_String *dstUAString)
 {
 
 	dstUAString->Length = convertToInt32(buf,pos);
@@ -107,22 +109,30 @@ convertToUAGuid(char* buf, int pos,UA_Guid* dstGUID)
 	UInt32 i = 0;
 	for(i = 1; i <= 4; i++)
 	{
+
 		dstGUID->Data1[i] = convertToUInt32(*buf, pos+counter);
+
 		counter += sizeof(UInt32);
 	}
 	for(i = 1; i <= 2; i++)
 	{
+
 		dstGUID->Data2[i] = convertToUInt16(*buf, pos+counter);
+
 		counter += sizeof(UInt16);
 	}
 	for(i = 1; i <= 2; i++)
 	{
+
 		dstGUID->Data3[i] = convertToUInt16(*buf, pos+counter);
+
 		counter += sizeof(UInt16);
 	}
 	for(i = 1; i <= 8; i++)
 	{
+
 		dstGUID->Data4[i] = convertToByte(*buf, pos+counter);
+
 		counter += sizeof(Byte);
 	}
 }
@@ -165,6 +175,7 @@ UA_StatusCode convertToUAStatusCode(char* buf, int pos){
 void convertToUANodeId(char* buf, int pos, UA_NodeId* dstNodeId){
 
 	dstNodeId->EncodingByte = convertToInt32(buf, 0);
+
 	int counter = sizeof(UInt32);
 
 	UA_NodeIdEncodingValuesType encodingType = dstNodeId->EncodingByte;
@@ -173,44 +184,55 @@ void convertToUANodeId(char* buf, int pos, UA_NodeId* dstNodeId){
 	{
 		case NIEVT_TWO_BYTE:
 		{
+
 			dstNodeId->Identifier.Numeric = convertToInt32(buf, counter);
+
 			counter += sizeof(UInt16);
 			break;
 		}
 		case NIEVT_FOUR_BYTE:
 		{
+
 			dstNodeId->Identifier.Numeric = convertToInt32(buf, counter);
+
 			counter += sizeof(Int64);
 			break;
 		}
 		case NIEVT_NUMERIC:
 		{
+
 			dstNodeId->Identifier.Numeric = convertToInt32(buf, counter);
+
 			counter += sizeof(UInt32);
 			break;
 		}
 		case NIEVT_STRING:
 		{
+
+
 			convertToUAString(buf, counter,&dstNodeId->Identifier.String);
 			counter += sizeof(sizeof(UInt32) + dstNodeId->Identifier.String.Length);
+
 			break;
 		}
 		case NIEVT_GUID:
 		{
-			tmpUANodeId.Identifier.Guid = convertToUAGuid(buf, counter);
+
+
 			convertToUAGuid(buf, counter,&dstNodeId->Identifier.Guid);
+
 			counter += sizeof(UA_Guid);
 			break;
 		}
 		case NIEVT_BYTESTRING:
 		{
-			tmpUANodeId.Identifier.OPAQUE = convertToUAByteString(buf, counter);
+			dstNodeId->Identifier.OPAQUE = convertToUAByteString(buf, counter);
 			//If Length == -1 then the ByteString is null
-			if(tmpUANodeId.Identifier.OPAQUE.Length == -1)
+			if(dstNodeId->Identifier.OPAQUE.Length == -1)
 			{
 				counter += sizeof(Int32);
 			}else{
-				counter += sizeof(Int32)+sizeof(Byte)*tmpUANodeId.Identifier.OPAQUE.Length;
+				counter += sizeof(Int32)+sizeof(Byte)*dstNodeId->Identifier.OPAQUE.Length;
 			}
 			break;
 		}