*
******************************************************************/
+//***************************************************************
+//
+// This file is for internal test only.
+// Do NOT use this file to test CA on Tizen.
+//
+//***************************************************************
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MOD_NAME "TizenSample"
-//Comment any below for blocking testing of specific adapters
-//#define WIFI_ADAPTER_TEST
-#define BT_ADAPTER_TEST
-//#define BLE_ADAPTER_TEST
-
#if defined(WIFI_ADAPTER_TEST)
#include "cawifiadapter.h"
-#include "caethernetadapter.h"
static u_thread_pool_t gWiFiThreadPool = NULL;
-#elif defined(BT_ADAPTER_TEST)
+#endif
+#if defined(BT_ADAPTER_TEST)
#include "caedradapter.h"
static u_thread_pool_t gBTThreadPool = NULL;
-#elif defined(BLE_ADAPTER_TEST)
+#endif
+#if defined(BLE_ADAPTER_TEST)
#include "caleadapter.h"
static u_thread_pool_t gLEThreadPool = NULL;
#endif
-static GMainLoop *mainloop;
-static GIOChannel *channel;
-static guint g_test_io_watch_id;
-static GError *g_err_Sample;
+static GMainLoop *mainloop = NULL;
+static GIOChannel *channel = NULL;
+static guint g_test_io_watch_id = 0;
+static GError *g_err_Sample = NULL;
-static CALocalConnectivity_t *localWifiEndpoint = NULL;
//Hardcoded coap data for Test
static char coapData[500] =
"{\"oc:\[{href\":\"/a/light\",\"ref\":{\"power\":\"20\",\"state\":\"true\"}}]}";
void initializeThreadPool(CAConnectivityType_t type)
{
#ifdef BT_ADAPTER_TEST
- if (CA_EDR == type && NULL == gBTThreadPool)
- {
+ if (CA_EDR == type && NULL == gBTThreadPool)
+ {
if (CA_STATUS_OK != u_thread_pool_init(3, &gBTThreadPool))
{
printf("Failed to create thread pool for BT adapter!\n");
return;
}
- }
+ }
#endif
#ifdef WIFI_ADAPTER_TEST
- if (CA_WIFI == type && NULL == gWiFiThreadPool)
- {
+ if (CA_WIFI == type && NULL == gWiFiThreadPool)
+ {
if (CA_STATUS_OK != u_thread_pool_init(3, &gWiFiThreadPool))
{
- printf("Failed to create thread pool for BT adapter!\n");
+ printf("Failed to create thread pool for WIFI adapter!\n");
return;
}
- }
+ }
#endif
#ifdef BLE_ADAPTER_TEST
- if (CA_LE == type && NULL == gLEThreadPool)
- {
- if (CA_STATUS_OK != u_thread_pool_init(3, &gLEThreadPool))
+ if (CA_LE == type && NULL == gLEThreadPool)
+ {
+ if (CA_STATUS_OK != u_thread_pool_init(5, &gLEThreadPool))
{
- printf("Failed to create thread pool for BT adapter!\n");
+ printf("Failed to create thread pool for BLE adapter!\n");
return;
}
- }
+ }
#endif
}
}
else if (CA_LE == object->connectivityType)
{
- printf(object->addressInfo.LE.leMacAddress);
+ printf(object->addressInfo.LE.leMacAddress);
}
else if (CA_WIFI == object->connectivityType || CA_ETHERNET == object->connectivityType)
{
printf(object->addressInfo.IP.ipAddress);
}
- printf("\nReceived Data [Length: %d]: %s\n",dataLength,(char *)data);
+ printf("\nReceived Data [Length: %d]: %s\n", dataLength, (char *)data);
printf("networkPacketHandler Exit in Sample\n");
}
case 2: //Listening server
startServer = tempConnectivityHandlers->handler.startListenServer;
break;
- case 3: //Notification server
- startServer = tempConnectivityHandlers->handler.startNotifyServer;
- break;
}
if (startServer)
printf("Invoking start server method\n");
startServer();
}
+ return 0;
}
int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
if (strlen(remoteIPAddress) == 0)
{
printf("Invalid device address\n");
- return;
+ return -1;
}
endpoint.connectivityType = CA_WIFI;
strncpy(endpoint.addressInfo.IP.ipAddress, remoteIPAddress, CA_IPADDR_SIZE);
- endpoint.addressInfo.IP.port = 5283; /* Send the corresponding port here */
+ endpoint.addressInfo.IP.port = 5683; /* Send the corresponding port here */
int sdatalen = tempConnectivityHandlers->handler.sendData(&endpoint, coapData,
strlen(coapData));
if (strlen(deviceaddress) == 0)
{
printf("Invlaid device address\n");
- return;
+ return -1;
}
endpoint.connectivityType = CA_EDR;
endpoint.resourceUri = NULL;
printf("Sent Unicast data to device: %s\n", endpoint.addressInfo.BT.btMacAddress);
- tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData)+1);
+ tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData) + 1);
}
else if (CA_LE == connType)
{
if (strlen(deviceaddress) == 0)
{
printf("Invlaid device address\n");
- return;
+ return -1;
}
//Get the service uuid from user
if (strlen(uuid) == 0)
{
printf("Invlaid service uuid\n");
- return;
+ return -1;
}
endpoint.connectivityType = CA_LE;
- strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
- endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ strncpy(endpoint.addressInfo.LE.leMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
+ endpoint.addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
endpoint.resourceUri = strdup(uuid);
tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData));
return 1;
}
-void interfaceSendNotification(CAConnectivityType_t connType)
-{
- ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
- if (NULL == tempConnectivityHandlers)
- {
- printf(" None of the interface is initialized \n");
- return;
- }
-
- while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
- {
- tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
- }
-
- if (NULL == tempConnectivityHandlers)
- {
- printf( "No interface handler for type %d\n", connType);
- return;
- }
-
- if (CA_WIFI == connType)
- {
- CARemoteEndpoint_t remoteEndpoint;
- tempConnectivityHandlers->handler.sendNotification(&remoteEndpoint, coapData, strlen(coapData));
- }
- else if (CA_EDR == connType)
- {
- //create endpoint
- CARemoteEndpoint_t endpoint;
-
- //Get the device address from user
- char deviceaddress[100] = {0};
- printf("Enter the device address: \n");
- scanf("%s", deviceaddress);
-
- if (strlen(deviceaddress) == 0)
- {
- printf("Invlaid device address\n");
- return;
- }
-
- //Get the service uuid from user
- char uuid[100] = {0};
- printf("Enter the service uuid: \n");
- scanf("%s", uuid);
-
- if (strlen(uuid) == 0)
- {
- printf("Invlaid service uuid\n");
- return;
- }
-
- endpoint.connectivityType = CA_EDR;
- strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
- endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
- endpoint.resourceUri = strdup(uuid);
-
- tempConnectivityHandlers->handler.sendNotification(&endpoint, coapData, strlen(coapData));
- printf("Sent Unicast data \n");
- free(endpoint.resourceUri);
- }
- else if (CA_LE == connType)
- {
- //create endpoint
- CARemoteEndpoint_t endpoint;
-
- //Get the device address from user
- char deviceaddress[100] = {0};
- printf("Enter the device address: \n");
- scanf("%s", deviceaddress);
-
- if (strlen(deviceaddress) == 0)
- {
- printf("Invlaid device address\n");
- return;
- }
-
- //Get the service uuid from user
- char uuid[100] = {0};
- printf("Enter the service uuid: \n");
- scanf("%s", uuid);
-
- if (strlen(uuid) == 0)
- {
- printf("Invlaid service uuid\n");
- return;
- }
-
- endpoint.connectivityType = CA_LE;
- strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
- endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
- endpoint.resourceUri = strdup(uuid);
-
- tempConnectivityHandlers->handler.sendNotification(&endpoint, coapData, strlen(coapData));
- printf("Sent Unicast data \n");
- free(endpoint.resourceUri);
- printf("Feature is not implemented !!\n");
- }
-}
-
int16_t interfaceSendMulticastData(CAConnectivityType_t connType)
{
ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
{
tempConnectivityHandlers->handler.sendDataToAll(coapData, strlen(coapData));
}
+ return 0;
}
void interfaceReadData(CAConnectivityType_t connType)
}
}
-void testSendNotification()
+void testSendMulticastData()
{
int16_t type = selectConnectivityType();
if (0 >= type || 3 < type)
#ifdef WIFI_ADAPTER_TEST
case 1: //WIFI
{
- interfaceSendNotification(CA_WIFI);
+ interfaceSendMulticastData(CA_WIFI);
}
break;
#endif
#ifdef BT_ADAPTER_TEST
case 2: //BT
{
- interfaceSendNotification(CA_EDR);
+ interfaceSendMulticastData(CA_EDR);
}
break;
#endif
#ifdef BLE_ADAPTER_TEST
case 3: //BLE
{
- interfaceSendNotification(CA_LE);
+ interfaceSendMulticastData(CA_LE);
}
break;
#endif
}
}
-void testSendMulticastData()
+void testReadData(void)
{
int16_t type = selectConnectivityType();
if (0 >= type || 3 < type)
#ifdef WIFI_ADAPTER_TEST
case 1: //WIFI
{
- interfaceSendMulticastData(CA_WIFI);
+ interfaceReadData(CA_WIFI);
}
break;
#endif
#ifdef BT_ADAPTER_TEST
case 2: //BT
{
- interfaceSendMulticastData(CA_EDR);
+ interfaceReadData(CA_EDR);
}
break;
#endif
#ifdef BLE_ADAPTER_TEST
case 3: //BLE
{
- interfaceSendMulticastData(CA_LE);
+ interfaceReadData(CA_LE);
}
break;
#endif
}
}
-void testReadData(void)
-{
- int16_t type = selectConnectivityType();
- if (0 >= type || 3 < type)
- {
- printf("Invalid selection...\n");
- return;
- }
-
- switch (type)
- {
-#ifdef WIFI_ADAPTER_TEST
- case 1: //WIFI
- {
- interfaceReadData(CA_WIFI);
- }
- break;
-#endif
-#ifdef BT_ADAPTER_TEST
- case 2: //BT
- {
- interfaceReadData(CA_EDR);
- }
- break;
-#endif
-#ifdef BLE_ADAPTER_TEST
- case 3: //BLE
- {
- interfaceReadData(CA_LE);
- }
- break;
-#endif
- default:
- printf("Feature is not enabled or not implemented\n");
- }
-}
-
void testGetNetworkInfo(void)
{
int16_t type = selectConnectivityType();
{
printf("Initiazing EDR\n");
- printf("Initializing BT Adapter threadpool\n");
- initializeThreadPool(CA_EDR);
+ printf("Initializing BT Adapter threadpool\n");
+ initializeThreadPool(CA_EDR);
//Start bluetooth communication adapter
CAResult_t err = CAInitializeEDR(interfaceRegisterCallback, networkPacketHandler,
- networkInterfaceCallback, gBTThreadPool);
+ networkInterfaceCallback, gBTThreadPool);
if (CA_STATUS_OK != err && CA_ADAPTER_NOT_ENABLED != err)
{
printf("Failed to initialize bluetooth communication adapter!\n");
printf( "Terminating BT Adapter thread pool");
u_thread_pool_free(gBTThreadPool);
+ gBTThreadPool = NULL;
}
#endif //BT_ADAPTER_TEST
{
printf("testInitializeWIFIInterface IN\n");
- printf("Initializing WIFI adapter threadpool\n");
- initializeThreadPool(CA_WIFI);
+ printf("Initializing WIFI adapter threadpool\n");
+ initializeThreadPool(CA_WIFI);
//Start Wifi communication adapter
if (0 != CAInitializeWifi(interfaceRegisterCallback, networkPacketHandler,
// Freeing threadpool for wifi communication adapter
printf( "Terminating WIFI Adapter thread pool");
u_thread_pool_free(gWiFiThreadPool);
+ gWiFiThreadPool = NULL;
//Terminate the Wifi communication adapter
CATerminateWIfI();
{
printf("testInitializeBLEInterface IN\n");
- printf("Initializing BLE adapter threadpool\n");
- initializeThreadPool(CA_LE);
+ printf("Initializing BLE adapter threadpool\n");
+ initializeThreadPool(CA_LE);
//Start bluetooth communication adapter
if (0 != CAInitializeLE(interfaceRegisterCallback, networkPacketHandler,
printf( "Terminating BLE Adapter thread pool");
u_thread_pool_free(gLEThreadPool);
+ gLEThreadPool = NULL;
printf("testTerminateBLEInterface OUT\n");
}
printf("| b - Stop adapter |\n");
printf("| sd- Start Discovery Server |\n");
printf("| sl- Start Listening Server |\n");
- printf("| sn- Start Notification Server |\n");
printf("| u - Send Unicast Data |\n");
printf("| m - Send Multicast Data |\n");
- printf("| n - Send Notification Data |\n");
printf("| g - Get Network Info |\n");
printf("| r - Read data synchronously |\n");
printf("| x - quit the test. |\n");
- printf("| h - Help menu. |\n");
+ printf("| h - Help menu. |\n");
printf(" =====================================================================\n");
}
gchar buf[10] = {'\0'};
gsize read = 0;
-
if (g_io_channel_read(channel, buf, 10, &read) != G_IO_ERROR_NONE)
{
printf("g_io_channel_read error!!!\n");
{
testStartServer(2);
}
- if (buf[1] == 'n')
- {
- testStartServer(3);
- }
}
break;
case 'u':
case 'm':
testSendMulticastData();
break;
- case 'n':
- testSendNotification();
- break;
case 'r':
testReadData();
break;