...
 
......@@ -6,7 +6,6 @@ project(toolkit_test_server)
add_definitions (-DS2OPC_CLIENTSERVER_ONLY=1)
add_definitions (-DWITH_STATIC_SECURITY_DATA=1 -DPUBSUB_STATIC_CONFIG=1 -DWITH_NANO_EXTENDED=1)
add_definitions (-DMY_IP_MASK="255.255.255.0" -DMY_IP_ETH0="192.0.2.10" -DMY_IP_GW="192.0.2.2" -DMY_IP6_ETH0="2001:db8::2" -DMY_IP6_MASK="ffff:ffff:")
# Add TEST include directory
......
......@@ -35,12 +35,11 @@ CONFIG_TEST_RANDOM_GENERATOR=y
# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.10"
CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.1"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
# MbedTLS
CONFIG_MBEDTLS=y
......
/*
* network_init.c
* Licensed to Systerel under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Systerel licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain
* a copy of the License at
*
* Created on: 17 f�vr. 2020
* Author: nottin
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "network_init.h"
......@@ -31,16 +43,20 @@
#define MY_IP_LB ((const char*) ("127.0.0.1"))
#endif
#ifndef MY_IP_ETH0
#define MY_IP_ETH0 ((const char*) ("192.168.1.102"))
#ifndef MY_IP_LB_MASK
#define MY_IP_LB_MASK ((const char*) ("255.255.255.0"))
#endif
#ifndef CONFIG_NET_CONFIG_MY_IPV4_ADDR
#define CONFIG_NET_CONFIG_MY_IPV4_ADDR ((const char*) ("192.168.1.102"))
#endif
#ifndef MY_IP_MASK
#define MY_IP_MASK ((const char*) ("255.255.255.0"))
#ifndef CONFIG_NET_CONFIG_MY_IPV4_NETMASK
#define CONFIG_NET_CONFIG_MY_IPV4_NETMASK ((const char*) ("255.255.255.0"))
#endif
#ifndef MY_IP_GW
#define MY_IP_GW ((const char*) ("192.168.1.111"))
#ifndef CONFIG_NET_CONFIG_MY_IPV4_GW
#define CONFIG_NET_CONFIG_MY_IPV4_GW ((const char*) ("192.168.1.111"))
#endif
typedef enum E_NETWORK_CONFIG_STATUS
......@@ -88,11 +104,11 @@ bool Network_Initialize(void)
struct in_addr addressInterfaceEthMask;
struct in_addr addressInterfaceEthGtw;
net_addr_pton(AF_INET, MY_IP_LB, (void*) &addressLoopBack);
net_addr_pton(AF_INET, MY_IP_MASK, (void*) &addressLoopBackNetMask);
net_addr_pton(AF_INET, MY_IP_LB_MASK, (void*) &addressLoopBackNetMask);
net_addr_pton(AF_INET, MY_IP_ETH0, (void*) &addressInterfaceEth);
net_addr_pton(AF_INET, MY_IP_MASK, (void*) &addressInterfaceEthMask);
net_addr_pton(AF_INET, MY_IP_GW, (void*) &addressInterfaceEthGtw);
net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_ADDR, (void*) &addressInterfaceEth);
net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_NETMASK, (void*) &addressInterfaceEthMask);
net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_GW, (void*) &addressInterfaceEthGtw);
if (NULL == net_if_ipv4_addr_lookup(&addressLoopBack, &ptrNetIf))
{
#if defined(CONFIG_NET_L2_DUMMY)
......
......@@ -44,6 +44,7 @@
#include "sopc_raw_sockets.h"
#include "sopc_threads.h"
#include "sopc_time.h"
#include "sopc_udp_sockets.h"
#include <assert.h>
#include <errno.h>
......@@ -54,6 +55,54 @@
#include <stdlib.h> /* getenv, exit */
#include <string.h>
#define LIBC_STDOUT_BUFFER_HOOK 0
/****************************************/
#if LIBC_STDOUT_BUFFER_HOOK == 1
extern void __stdout_buffer_hook_install(void (*fn)(const char*, int));
extern void __stdout_hook_install(int (*fn)(int));
K_MUTEX_DEFINE(my_mutex);
char gBuffer[256];
static void _zephyr_callback_log_buffer_hook(const char* buffer, int size)
{
//SOPC_LogServer_Print(0, buffer, size, false);
k_mutex_lock(&my_mutex,K_FOREVER);
size = size > 256 ? 256 : size;
memset(gBuffer,0,256);
memcpy(gBuffer,buffer,size);
gBuffer[size-1]=0;
(void)printk("%s\r\n",(char*)gBuffer);
k_mutex_unlock(&my_mutex);
return;
}
static int _zephyr_callback_log_hook(int character)
{
if (character == '\r')
{
return character;
}
return character;
}
static int _zephyr_add_log_hook(struct device* d)
{
ARG_UNUSED(d);
__stdout_hook_install(_zephyr_callback_log_hook);
__stdout_buffer_hook_install(_zephyr_callback_log_buffer_hook);
return 0;
}
#endif
/****************************************/
#include "opcua_identifiers.h"
#include "opcua_statuscodes.h"
#include "sopc_atomic.h"
......@@ -833,10 +882,141 @@ static void Launch_Server(void)
return;
}
static void* cbS2OPC_Thread_UDP_Socket_API_LB(void* ptr)
{
SOPC_ReturnStatus res = SOPC_STATUS_OK;
SOPC_Socket_Network_Initialize();
SOPC_Buffer* pBuffer;
SOPC_Socket_AddressInfo* adresseM;
adresseM = NULL;
Socket sockR = -1;
pBuffer = SOPC_Buffer_Create(256);
SOPC_Buffer_Write(pBuffer, (const uint8_t*) "Hello world !!!\r\n", (uint32_t) strlen("Hello world !!!\r\n"));
SOPC_Buffer_SetPosition(pBuffer, 0);
adresseM = SOPC_UDP_SocketAddress_Create(false, "239.0.1.2", "20481");
assert(adresseM != NULL);
assert(SOPC_UDP_Socket_CreateToReceive(adresseM, true, &sockR) == SOPC_STATUS_OK);
assert(SOPC_UDP_Socket_AddMembership(sockR, adresseM, NULL) == SOPC_STATUS_OK);
SOPC_SocketSet rdset;
SOPC_SocketSet wrset;
SOPC_SocketSet exset;
SOPC_SocketSet_Clear(&rdset);
SOPC_SocketSet_Clear(&wrset);
SOPC_SocketSet_Clear(&exset);
SOPC_SocketSet_Add(sockR, &rdset);
SOPC_SocketSet_Add(sockR, &wrset);
SOPC_SocketSet_Add(sockR, &exset);
// bool bDropMemberShip = true;
uint32_t cpt = 0;
while (cpt < 60)
{
{
SOPC_SocketSet_Clear(&rdset);
SOPC_SocketSet_Clear(&wrset);
SOPC_SocketSet_Clear(&exset);
SOPC_SocketSet_Add(sockR, &rdset);
SOPC_SocketSet_Add(sockR, &wrset);
SOPC_SocketSet_Add(sockR, &exset);
if (SOPC_Socket_WaitSocketEvents(&rdset, NULL, NULL, 1000) > 0)
{
res = SOPC_UDP_Socket_ReceiveFrom(sockR, pBuffer);
if (pBuffer->length > 0)
{
pBuffer
->data[pBuffer->length < (pBuffer->maximum_size - 2) ? pBuffer->length : pBuffer->length - 1] =
'\r';
pBuffer->data[pBuffer->length < (pBuffer->maximum_size - 2) ? pBuffer->length + 1
: pBuffer->length - 1] = '\n';
pBuffer->data[pBuffer->length < (pBuffer->maximum_size - 2) ? pBuffer->length + 2
: pBuffer->length - 1] = 0;
printk("\r\nThread 1 : %s\r\n", (const char*) pBuffer->data);
}
else
{
printk("\r\nThread 1 No data\r\n");
}
}
else
{
printk("\r\nThread 1 No events\r\n");
}
cpt++;
// if ((cpt % 10) == 0)
// {
// if (bDropMemberShip)
// {
// printk("\r\nThread 1 Drop MCAST !!!\r\n");
// assert(SOPC_UDP_Socket_DropMembership(sockR, adresseM, NULL) == SOPC_STATUS_OK);
// }
// else
// {
// printk("\r\nThread 1 Join MCAST !!!\r\n");
// assert(SOPC_UDP_Socket_AddMembership(sockR, adresseM, NULL) == SOPC_STATUS_OK);
// }
//
// bDropMemberShip = !bDropMemberShip;
// }
}
}
SOPC_Buffer_Delete(pBuffer);
SOPC_UDP_SocketAddress_Delete(&adresseM);
SOPC_UDP_Socket_Close(&sockR);
printk("\r\nThread 1 exit\r\n");
return NULL;
}
void TEST_S2OPC_UDP_SOCKET_API_LB(void)
{
SOPC_ReturnStatus result;
bool netInit = Network_Initialize();
assert(netInit == true);
Thread sopcThreadHandle1 = NULL;
printk("\r\n********Test high level SOCKET (wait 5s)*************\r\n");
printk("\r\n*Create infinite loop waiting for MCAST string and display on UART received value\r\n");
printk("\r\n*A drop and join are called each 10s\r\n");
SOPC_Sleep(5000);
result = SOPC_Thread_Create(&sopcThreadHandle1, cbS2OPC_Thread_UDP_Socket_API_LB, NULL, NULL);
assert(SOPC_STATUS_OK == result);
SOPC_Thread_Join(sopcThreadHandle1);
return;
}
void main(void)
{
Launch_Server();
#if LIBC_STDOUT_BUFFER_HOOK == 1
_zephyr_add_log_hook(NULL);
#endif
//Decommenter pour tester les socket udp mutlicast
//TEST_S2OPC_UDP_SOCKET_API_LB();
Launch_Server();
while(true)
{
printf("\r\nThread quit, error and go to idle...\r\n");
......
......@@ -5,7 +5,6 @@ include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(pubsub_test_server)
add_definitions (-DWITH_STATIC_SECURITY_DATA=1 -DPUBSUB_STATIC_CONFIG=1 -DWITH_NANO_EXTENDED=1)
add_definitions (-DMY_IP_MASK="255.255.255.0" -DMY_IP_ETH0="192.0.2.10" -DMY_IP_GW="192.0.2.2" -DMY_IP6_ETH0="2001:db8::2" -DMY_IP6_MASK="ffff:ffff:")
add_definitions (-DPUBLISHER_ADDRESS="232.1.2.100:4840" -DSUBSCRIBER_ADDRESS="232.1.2.101:4840")
add_definitions (-DPUBLISH_PERIOD=1000 -DSUBSCRIBE_PERIOD=1000)
......
......@@ -35,7 +35,6 @@ CONFIG_TEST_RANDOM_GENERATOR=y
# Network address config
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_NEED_IPV4=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.10"
......
/*
* network_init.c
* Licensed to Systerel under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Systerel licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain
* a copy of the License at
*
* Created on: 17 f�vr. 2020
* Author: nottin
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "network_init.h"
......@@ -31,16 +43,20 @@
#define MY_IP_LB ((const char*) ("127.0.0.1"))
#endif
#ifndef MY_IP_ETH0
#define MY_IP_ETH0 ((const char*) ("192.168.1.102"))
#ifndef MY_IP_LB_MASK
#define MY_IP_LB_MASK ((const char*) ("255.255.255.0"))
#endif
#ifndef CONFIG_NET_CONFIG_MY_IPV4_ADDR
#define CONFIG_NET_CONFIG_MY_IPV4_ADDR ((const char*) ("192.168.1.102"))
#endif
#ifndef MY_IP_MASK
#define MY_IP_MASK ((const char*) ("255.255.255.0"))
#ifndef CONFIG_NET_CONFIG_MY_IPV4_NETMASK
#define CONFIG_NET_CONFIG_MY_IPV4_NETMASK ((const char*) ("255.255.255.0"))
#endif
#ifndef MY_IP_GW
#define MY_IP_GW ((const char*) ("192.168.1.111"))
#ifndef CONFIG_NET_CONFIG_MY_IPV4_GW
#define CONFIG_NET_CONFIG_MY_IPV4_GW ((const char*) ("192.168.1.111"))
#endif
typedef enum E_NETWORK_CONFIG_STATUS
......@@ -88,11 +104,11 @@ bool Network_Initialize(void)
struct in_addr addressInterfaceEthMask;
struct in_addr addressInterfaceEthGtw;
net_addr_pton(AF_INET, MY_IP_LB, (void*) &addressLoopBack);
net_addr_pton(AF_INET, MY_IP_MASK, (void*) &addressLoopBackNetMask);
net_addr_pton(AF_INET, MY_IP_LB_MASK, (void*) &addressLoopBackNetMask);
net_addr_pton(AF_INET, MY_IP_ETH0, (void*) &addressInterfaceEth);
net_addr_pton(AF_INET, MY_IP_MASK, (void*) &addressInterfaceEthMask);
net_addr_pton(AF_INET, MY_IP_GW, (void*) &addressInterfaceEthGtw);
net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_ADDR, (void*) &addressInterfaceEth);
net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_NETMASK, (void*) &addressInterfaceEthMask);
net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_GW, (void*) &addressInterfaceEthGtw);
if (NULL == net_if_ipv4_addr_lookup(&addressLoopBack, &ptrNetIf))
{
#if defined(CONFIG_NET_L2_DUMMY)
......
/* Copyright (C) Systerel SAS 2019, all rights reserved. */
/*
* Licensed to Systerel under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Systerel licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "pubsub_config_static.h"
......
......@@ -27,7 +27,6 @@
#include "sopc_pub_scheduler.h"
#include "sopc_sub_scheduler.h"
#include "sopc_udp_sockets.h"
#include "sopc_xml_loader.h"
#include "config.h"
#include "pubsub.h"
......
/*
* network_init.c
* Licensed to Systerel under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Systerel licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain
* a copy of the License at
*
* Created on: 17 f�vr. 2020
* Author: nottin
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <assert.h>
......
......@@ -6,8 +6,7 @@ zephyr_interface_library_named(S2OPC)
add_definitions (-DSOPC_PTR_SIZE=4)
add_definitions (-DS2OPC_CLIENTSERVER_ONLY=1)
add_definitions (-DWITH_STATIC_SECURITY_DATA=1 -DPUBSUB_STATIC_CONFIG=1 -DUSE_RTOS=1 -DWITH_NANO_EXTENDED=1)
add_definitions (-DMY_IP_MASK="255.255.255.0" -DMY_IP_ETH0="192.0.2.10" -DMY_IP_GW="192.0.2.1" -DMY_IP6_ETH0="2001:db8::2" -DMY_IP6_MASK="ffff:ffff:")
add_definitions (-DWITH_STATIC_SECURITY_DATA=1 -DPUBSUB_STATIC_CONFIG=1 -DWITH_NANO_EXTENDED=1)
# Add S2OPC includes directories
zephyr_include_directories(
......@@ -28,7 +27,6 @@ zephyr_include_directories(
../src/Common/opcua_types
../src/PubSub
../src/PubSub/common
../src/PubSub/config_loaders/xml_expat
../src/PubSub/dataset
../src/PubSub/network
../src/PubSub/protocol
......@@ -244,7 +242,6 @@ zephyr_library_sources(
../src/ClientServer/secure_channels/sopc_secure_channels_api.c
../src/PubSub/common/sopc_pubsub_helpers.c
../src/PubSub/common/sopc_pubsub_conf.c
../src/PubSub/config_loaders/xml_expat/sopc_xml_loader.c
../src/PubSub/real_time_api/sopc_rt_subscriber.c
../src/PubSub/real_time_api/sopc_msgbox.c
../src/PubSub/real_time_api/sopc_rt_publisher.c
......