Previously we had hard coded WIFI to be the default interface.
Added code to allow users to pass adapter type as a command line argument.
Change-Id: Id9e0cadf10746bd665212b79d36f7557ed5993d2
Signed-off-by: omkar <omkar.m.hegde@intel.com>
static std::string coapServerPort = "5683";
static std::string coapServerResource = "/a/led";
+#ifdef CA_INT
+//The following variable determines the interface (wifi, ethernet etc.)
+//to be used for sending unicast messages. Default set to WIFI.
+static OCConnectivityType CA_CONNTYPE = OC_WIFI;
+static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
+#endif
+
int gQuitFlag = 0;
namespace {
static void PrintUsage()
{
+#ifdef CA_INT
+ OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2|3>");
+#else
OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>");
+#endif
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
+#ifdef CA_INT
+ OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send unicast messages over Ethernet, WIFI, EDR or LE");
+#endif
OC_LOG(INFO, TAG, "-t 1 : Discover Resources");
OC_LOG(INFO, TAG, "-t 2 : Discover Resources and"
" Initiate Nonconfirmable Get/Put/Post Requests");
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
(method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL,
- OC_WIFI, qos, &cbData, options, numOptions);
+ CA_CONNTYPE, qos, &cbData, options, numOptions);
#else
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
(method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL,
}
else
{
+#ifdef CA_INT
+ strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
+#else
strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
+#endif
}
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to all but should be configurable - add as API param
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI),
- OC_LOW_QOS, &cbData, NULL, 0);
+ if (UNICAST_DISCOVERY)
+ {
+ ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (CA_CONNTYPE),
+ OC_LOW_QOS, &cbData, NULL, 0);
+ }
+ else
+ {
+ ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
+ OC_LOW_QOS, &cbData, NULL, 0);
+ }
#else
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
#endif
uint8_t ifname[] = "eth0";
int opt;
+#ifdef CA_INT
+ while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
+#else
while ((opt = getopt(argc, argv, "u:t:")) != -1)
+#endif
{
switch(opt)
{
case 't':
TEST_CASE = atoi(optarg);
break;
+ #ifdef CA_INT
+ case 'c':
+ CA_CONNTYPE = OCConnectivityType(atoi(optarg));
+ break;
+ #endif
default:
PrintUsage();
return -1;
static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}";
+#ifdef CA_INT
+//The following variable determines the interface (wifi, ethernet etc.)
+//to be used for sending unicast messages. Default set to WIFI.
+static OCConnectivityType CA_CONNTYPE = OC_WIFI;
+static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
+#endif
+
// The handle for the observe registration
OCDoHandle gObserveDoHandle;
// After this crosses a threshold client deregisters for further observations
void PrintUsage()
{
+#ifdef CA_INT
+ OC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case> -c <CA connectivity Type>");
+ OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send messages over Ethernet, WIFI, EDR or LE");
+#else
OC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case>");
+#endif
OC_LOG(INFO, TAG, "Test Case 1 : Discover Resources && Initiate GET Request on an"\
"available resource using default interface.");
OC_LOG(INFO, TAG, "Test Case 2 : Discover Resources && Initiate GET Request on an"\
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, (OC_WIFI), OC_LOW_QOS,
+ ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, CA_CONNTYPE, OC_LOW_QOS,
&cbData, NULL, 0);
#else
ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
OC_LOG_V(INFO, TAG, "OBSERVE payload from client = %s ", putPayload.c_str());
#ifdef CA_INT
- // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param
- ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_WIFI, OC_LOW_QOS,
- &cbData, NULL, 0);
+ ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, CA_CONNTYPE,
+ OC_LOW_QOS, &cbData, NULL, 0);
#else
ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_LOW_QOS,
&cbData, NULL, 0);
OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
#ifdef CA_INT
- // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param
ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
- OC_WIFI, OC_LOW_QOS, &cbData, NULL, 0);
+ CA_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0);
#else
ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
OC_LOW_QOS, &cbData, NULL, 0);
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_WIFI, OC_LOW_QOS,
+ ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, CA_CONNTYPE, OC_LOW_QOS,
&cbData, NULL, 0);
#else
ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
/* Start a discovery query*/
char szQueryUri[64] = { 0 };
+#ifdef CA_INT
+ strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
+#else
strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
+#endif
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to all but should be configurable - add as API param
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI),
+ ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
OC_LOW_QOS,
&cbData, NULL, 0);
#else
uint8_t ifname[] = "eth0";
int opt;
+#ifdef CA_INT
+ while ((opt = getopt(argc, argv, "t:c:")) != -1)
+#else
while ((opt = getopt(argc, argv, "t:")) != -1)
+#endif
{
switch(opt)
{
case 't':
TEST = atoi(optarg);
break;
+ #ifdef CA_INT
+ case 'c':
+ CA_CONNTYPE = OCConnectivityType(atoi(optarg));
+ break;
+ #endif
default:
PrintUsage();
return -1;
static std::string coapServerPort = "5683";
static std::string coapServerResource = "/a/led";
+#ifdef CA_INT
+//The following variable determines the interface (wifi, ethernet etc.)
+//to be used for sending unicast messages. Default set to WIFI.
+static OCConnectivityType CA_CONNTYPE = OC_WIFI;
+static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
+#endif
+
int gQuitFlag = 0;
/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
static void PrintUsage()
{
+#ifdef CA_INT
+ OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1|2|3>");
+ OC_LOG(INFO, TAG, "-c <0|1|2|3> : Send unicast messages over Ethernet, WIFI, EDR or LE");
+#else
OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>");
+#endif
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
OC_LOG(INFO, TAG, "-t 1 : Discover Resources");
OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request");
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to WiFi but should be configurable - add as API param
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
- NULL, OC_WIFI, qos, &cbData, options, numOptions);
+ NULL, CA_CONNTYPE, qos, &cbData, options, numOptions);
#else
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
NULL, qos, &cbData, options, numOptions);
}
else
{
+#ifdef CA_INT
+ strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
+#else
strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
+#endif
}
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
#ifdef CA_INT
- // TODO-CA: The adapter type is set to all but should be configurable - add as API param
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ETHERNET | OC_WIFI),
- OC_LOW_QOS, &cbData, NULL, 0);
+ if(UNICAST_DISCOVERY)
+ {
+ ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, CA_CONNTYPE,
+ OC_LOW_QOS, &cbData, NULL, 0);
+ }
+ else
+ {
+ ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
+ OC_LOW_QOS, &cbData, NULL, 0);
+ }
#else
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
#endif
uint8_t ifname[] = "eth0";
int opt;
+#ifdef CA_INT
+ while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
+#else
while ((opt = getopt(argc, argv, "u:t:")) != -1)
+#endif
{
switch(opt)
{
case 't':
TEST_CASE = atoi(optarg);
break;
+ #ifdef CA_INT
+ case 'c':
+ CA_CONNTYPE = OCConnectivityType(atoi(optarg));
+ break;
+ #endif
default:
PrintUsage();
return -1;