#endif
} CloudLoginInfo;
-
+bool g_auto_publish;
bool bSignin;
bool isExit;
uint16_t g_cred_id = 0;
else if(!strcmp(mode, "wb"))
mode = strdup("w");
+ printf("path [%s], mode[%s]", path, mode);
return fopen(OC_CONTROLEE_DAT_FILE_PATH, mode);
}
OCDeviceInfo devInfoAirConditioner;
OCStringLL deviceType;
- deviceType.value = "oic.d.airconditioner";
+#ifdef _USE_WWST_
+ deviceType.value = g_strdup("oic.d.switch");
+#else
+ deviceType.value = g_strdup("oic.d.airconditioner");
+#endif
+
deviceType.next = NULL;
- devInfoAirConditioner.deviceName = "FAC_2016";
+ devInfoAirConditioner.deviceName = g_strdup("FAC_2016");
devInfoAirConditioner.types = &deviceType;
devInfoAirConditioner.specVersion = NULL;
devInfoAirConditioner.dataModelVersions = NULL;
bSignin = true;
printf("Sign-In Success!!!\n");
+ sleep(1);
+ if (g_auto_publish) {
+ if (_publish_fw_res_to_rd() != 0)
+ printf("publish failed!!!\n");
+ }
+
#ifdef _USE_WWST_
pthread_t pingThread;
pthread_mutex_lock(&pingcycle_mutex);
int _signin()
{
char uri[MAX_URI_LENGTH] = { 0 };
- snprintf(uri, MAX_URI_LENGTH, "%s%s%s",
- CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
+ snprintf(uri, MAX_URI_LENGTH, "%s%s%s?rt=%s;if=%s",
+ CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI, CLOUD_SESSION_RES_TYPE, OC_RSRVD_INTERFACE_DEFAULT);
printf("server uri=[%s]\n", uri);
OCCallbackData cbData;
_set_auth_cert_info();
char uri[MAX_URI_LENGTH] = { 0 };
- snprintf(uri, MAX_URI_LENGTH, "%s%s%s",
- CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
+ snprintf(uri, MAX_URI_LENGTH, "%s%s%s?rt=%s;if=%s",
+ CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI, CLOUD_ACCOUNT_RES_TYPE, OC_RSRVD_INTERFACE_DEFAULT);
printf("server uri=[%s]\n", uri);
OCCallbackData cbData;
{
OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
- if (!input) {
- printf("Failed to parse\n");
- return NULL;
- }
-
if (OC_REST_PUT == ehRequest->method || OC_REST_POST == ehRequest->method) {
/* Get pointer to query */
bool power;
return NULL;
}
+ printf("Client Set payload Power : %d\n", switch_power);
OCRepPayloadSetPropBool(payload, "value", switch_power);
return payload;
OCEntityHandlerRequest *entityHandlerRequest,
void *callbackParam)
{
+ printf("_handle_oc_entity\n");
OCEntityHandlerResult ehRet = OC_EH_OK;
OCEntityHandlerResponse response = { 0, 0, OC_EH_ERROR, 0, 0, \
{ }, { 0 }, false };
printf("Received OC_REST_GET request\n");
ehRet = _handle_get_request(entityHandlerRequest, &payload);
} else if (OC_REST_PUT == entityHandlerRequest->method) {
- printf("Received OC_REST_PUT request, nothing to do\n");
+ printf("Received OC_REST_PUT request, from client\n");
+ ehRet = _handle_post_request(entityHandlerRequest, &payload);
} else if (OC_REST_POST == entityHandlerRequest->method) {
printf("Received OC_REST_POST from client\n");
ehRet = _handle_post_request(entityHandlerRequest, &payload);
+ } else {
+ //OC_REST_DISCOVER, OC_REST_PRESENCE, OC_REST_OBSERVE_ALL, OC_REST_OBSERVE, OC_REST_DELETE, OC_REST_NOMETHOD
+ printf("Received unsupported method %d from client\n", entityHandlerRequest->method);
+ ehRet = OC_EH_ERROR;
}
-
- if (ehRet == OC_EH_OK) {
+ if (!((ehRet == OC_EH_ERROR) || (ehRet == OC_EH_FORBIDDEN))) {
response.requestHandle = entityHandlerRequest->requestHandle;
response.resourceHandle = entityHandlerRequest->resource;
response.ehResult = ehRet;
response.payload = (OCPayload*)payload;
response.persistentBufferFlag = 0;
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof(response.sendVendorSpecificHeaderOptions));
+ memset(response.resourceUri, 0, sizeof(response.resourceUri));
+
// Send the response
if (OCDoResponse(&response) != OC_STACK_OK) {
printf("Error sending response\n");
}
if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG)) {
- printf("Flag includes OC_OBSERVE_FLAG");
+ printf("Flag includes OC_OBSERVE_FLAG\n");
if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action) {
- printf("Received OC_OBSERVE_REGISTER from client");
+ printf("Received OC_OBSERVE_REGISTER from client\n");
} else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action) {
- printf("Received OC_OBSERVE_DEREGISTER from client");
+ printf("Received OC_OBSERVE_DEREGISTER from client\n");
}
}
+ OCPayloadDestroy(response.payload);
return ehRet;
}
{
/* Debug */
if (clientResponse) {
- printf("RD resource response received, code: %d\n", clientResponse->result);
+ printf("RD resource response received, code: [%d]\n", clientResponse->result);
+ printf("############## Publish resource response received [%s]\n", clientResponse->resourceUri);
}
- _cond_signal();
+// _cond_signal();
return OC_STACK_KEEP_TRANSACTION;
}
/* Debug */
if (clientResponse) {
printf("RD resource response received, code: %d\n", clientResponse->result);
+ printf("############## Publish resource response received [%s]\n", clientResponse->resourceUri);
}
- _cond_signal();
+// _cond_signal();
return OC_STACK_KEEP_TRANSACTION;
}
#endif
/* Create air conditioner resource handle */
- if (OCCreateResource(&res_handle[0], "x.com.samsung.da.device",
+ if (OCCreateResource(&res_handle[0],
+#ifdef _USE_WWST_
+ "oic.r.switch.binary",
+ "oic.if.baseline",
+ "/capability/switch/0",
+ _handle_oc_entity, NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE) != OC_STACK_OK) {
+#else
+ "x.com.samsung.da.device",
OC_RSRVD_INTERFACE_DEFAULT,
"/sec/aircon/0",
_handle_oc_entity, NULL,
OC_DISCOVERABLE) != OC_STACK_OK) {
+#endif
printf("OCCreateResource() failed\n");
return -1;
}
+/* oic.if.b, oic.if.ll */
+/*
if (OCBindResourceInterfaceToResource(res_handle[0], OC_RSRVD_INTERFACE_BATCH) != OC_STACK_OK) {
printf("OCBindResourceInterfaceToResource() [%s] failed\n", OC_RSRVD_INTERFACE_BATCH);
}
if (OCBindResourceInterfaceToResource(res_handle[0], OC_RSRVD_INTERFACE_LL) != OC_STACK_OK) {
printf("OCBindResourceInterfaceToResource() [%s] failed\n", OC_RSRVD_INTERFACE_LL);
}
+*/
// if (OCBindResource(aircon_handle, binary_switch_handle) != OC_STACK_OK) {
// printf("OCBindResource() failed\n");
snprintf(uri, MAX_URI_LENGTH, "%s%s", CLOUD_PROTOCOL, CLOUD_STG_SERVER);
#ifdef _USE_WWST_
- if (OCRDPublish(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
- NULL, 0,
- &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
- printf("OCRDPublish() failed\n");
+// if (OCRDPublish(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
+// NULL, 0,
+// &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
+// printf("OCRDPublish() failed\n");
+// return -1;
+// }
+//
+//// _lock_and_wait();
+//
+// if (OCRDPublish(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
+// res_handle, 2,
+// &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
+// printf("OCRDPublish() failed\n");
+// return -1;
+// }
+
+ int ocResult = OC_STACK_OK;
+ ocResult = OCRDPublish(NULL, uri, (CT_ADAPTER_TCP | CT_IP_USE_V4), NULL, 0, &cb_data, OC_LOW_QOS);
+ if (ocResult != OC_STACK_OK) {
+ printf("Publish Resource with null handle failed");
return -1;
}
- _lock_and_wait();
+ ocResult = OCRDPublish(NULL, uri, (CT_ADAPTER_TCP | CT_IP_USE_V4), &res_handle[0], 1, &cb_data, OC_LOW_QOS);
+ if (ocResult != OC_STACK_OK) {
+ printf("Publish Resource failed [%d]", ocResult);
+ return -1;
+ }
- if (OCRDPublish(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
- res_handle, 2,
- &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
- printf("OCRDPublish() failed\n");
+ ocResult = OCRDPublish(NULL, uri, (CT_ADAPTER_TCP | CT_IP_USE_V4), &res_handle[1], 1, &cb_data, OC_LOW_QOS);
+ if (ocResult != OC_STACK_OK) {
+ printf("Publish firmware Resource failed [%d]", ocResult);
return -1;
}
+
+
#else
if (OCRDPublish(uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
NULL, 0,
return -1;
}
- _lock_and_wait();
+// _lock_and_wait();
if (OCRDPublish(uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
res_handle, 2,
}
#endif
- _lock_and_wait();
+// _lock_and_wait();
controlee_check_firmware_upgraded();
}
#endif
- _lock_and_wait();
+// _lock_and_wait();
return 0;
}
printf("============================================\n");
printf("=== Controlee firmware resource test app ===\n");
printf("============================================\n");
- printf(" [A] Sign Up/In\n");
- printf(" [Z] Sign Out\n");
+ printf(" [A] Create Resource & Sign Up/In & publish\n");
+ printf(" [U] Sign Up/In\n");
+ printf(" [O] Sign Out\n");
printf(" [1] Create default resource\n");
printf(" [2] Create firmware resource\n");
printf(" [3] Publish resources to RD\n");
switch (str_ret[0]) {
case 'A' :
case 'a' :
+ rv = _init_default_test_res();
+ rv = _create_fw_res();
+ g_auto_publish = true;
+ rv = _signup();
+ break;
+ case 'U' :
+ case 'u' :
+ g_auto_publish = false;
rv = _signup();
break;
- case 'Z' :
- case 'z' :
+ case 'O' :
+ case 'o' :
rv = _signout();
break;
case '1':
bSignin = false;
isExit = false;
ps = NULL;
+ switch_power = true;
mainloop = g_main_loop_new(NULL, false);