Commit f650aebf authored by Kishen Maloor's avatar Kishen Maloor

Removed unused sample apps

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent 1928aebe
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed 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 "oc_api.h"
static bool got_discovery_response = false;
static int
app_init(void)
{
int ret = oc_init_platform("Apple", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.phone", "Kishen's IPhone", "1.0", "1.0",
NULL, NULL);
return ret;
}
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_endpoint_t *light_server;
static bool light_state = false;
static oc_event_callback_retval_t
stop_observe(void *data)
{
(void)data;
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, light_server);
return OC_EVENT_DONE;
}
static void
post_light(oc_client_response_t *data)
{
PRINT("POST_light:\n");
if (data->code == OC_STATUS_CHANGED)
PRINT("POST response OK\n");
else
PRINT("POST response code %d\n", data->code);
}
static void
observe_light(oc_client_response_t *data)
{
PRINT("OBSERVE_light:\n");
oc_rep_t *rep = data->payload;
while (rep != NULL) {
PRINT("key %s, value ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
PRINT("%d\n", rep->value.boolean);
light_state = rep->value.boolean;
break;
default:
break;
}
rep = rep->next;
}
if (oc_init_post(light_1, light_server, NULL, &post_light, LOW_QOS, NULL)) {
oc_rep_start_root_object();
oc_rep_set_boolean(root, state, !light_state);
oc_rep_end_root_object();
if (oc_do_post())
PRINT("Sent POST request\n");
else
PRINT("Could not send POST\n");
} else
PRINT("Could not init POST\n");
}
static oc_discovery_flags_t
discovery(const char *anchor, const char *uri, oc_string_array_t types,
oc_interface_mask_t iface_mask, oc_endpoint_t *endpoint,
oc_resource_properties_t bm, void *user_data)
{
(void)anchor;
(void)iface_mask;
(void)user_data;
(void)bm;
int i;
int uri_len = strlen(uri);
uri_len = (uri_len >= MAX_URI_LENGTH) ? MAX_URI_LENGTH - 1 : uri_len;
for (i = 0; i < oc_string_array_get_allocated_size(types); i++) {
char *t = oc_string_array_get_item(types, i);
if (strlen(t) == 11 && strncmp(t, "oic.r.light", 11) == 0) {
light_server = endpoint;
strncpy(light_1, uri, uri_len);
light_1[uri_len] = '\0';
oc_do_observe(light_1, light_server, NULL, &observe_light, LOW_QOS, NULL);
oc_set_delayed_callback(NULL, &stop_observe, 30);
got_discovery_response = true;
return OC_STOP_DISCOVERY;
}
}
return OC_CONTINUE_DISCOVERY;
}
static oc_event_callback_retval_t
do_discovery(void *data)
{
(void)data;
if (got_discovery_response) {
return OC_EVENT_DONE;
}
oc_do_ip_discovery("oic.r.light", &discovery, NULL);
return OC_EVENT_CONTINUE;
}
static void
issue_requests(void)
{
oc_set_delayed_callback(NULL, &do_discovery, 10);
}
#include "contiki.h"
PROCESS(sample_client_process, "OCF client sample");
AUTOSTART_PROCESSES(&sample_client_process);
static void
signal_event_loop(void)
{
process_post(&sample_client_process, PROCESS_EVENT_TIMER, NULL);
}
PROCESS_THREAD(sample_client_process, ev, data)
{
static struct etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
static oc_clock_time_t next_event;
PROCESS_BEGIN();
int init = oc_main_init(&handler);
if (init < 0)
return init;
while (ev != PROCESS_EVENT_EXIT) {
next_event = oc_main_poll();
if (next_event != 0) {
next_event -= oc_clock_time();
etimer_set(&et, next_event);
}
PROCESS_YIELD();
}
PROCESS_END();
}
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed 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 "oc_api.h"
#include "pthread_cond.h"
#include "thread.h"
static int quit;
static mutex_t mutex;
static pthread_cond_t cv;
static struct timespec ts;
static bool got_discovery_response = false;
static void
set_device_custom_property(void *data)
{
(void)data;
oc_set_custom_device_property(purpose, "operate lamp");
}
static int
app_init(void)
{
int ret = oc_init_platform("Apple", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.phone", "Kishen's IPhone", "1.0", "1.0",
set_device_custom_property, NULL);
return ret;
}
#define MAX_URI_LENGTH (30)
static char light_1[MAX_URI_LENGTH];
static oc_endpoint_t *light_server;
static bool light_state = false;
static oc_event_callback_retval_t
stop_observe(void *data)
{
(void)data;
PRINT("Stopping OBSERVE\n");
oc_stop_observe(light_1, light_server);
return OC_EVENT_DONE;
}
static void
post_light(oc_client_response_t *data)
{
PRINT("POST_light:\n");
if (data->code == OC_STATUS_CHANGED)
PRINT("POST response OK\n");
else
PRINT("POST response code %d\n", data->code);
}
static void
observe_light(oc_client_response_t *data)
{
PRINT("OBSERVE_light:\n");
oc_rep_t *rep = data->payload;
while (rep != NULL) {
PRINT("key %s, value ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
PRINT("%d\n", rep->value.boolean);
light_state = rep->value.boolean;
break;
default:
break;
}
rep = rep->next;
}
if (oc_init_post(light_1, light_server, NULL, &post_light, LOW_QOS, NULL)) {
oc_rep_start_root_object();
oc_rep_set_boolean(root, state, !light_state);
oc_rep_end_root_object();
if (oc_do_post())
PRINT("Sent POST request\n");
else
PRINT("Could not send POST\n");
} else
PRINT("Could not init POST\n");
}
static oc_discovery_flags_t
discovery(const char *anchor, const char *uri, oc_string_array_t types,
oc_interface_mask_t iface_mask, oc_endpoint_t *endpoint,
oc_resource_properties_t bm, void *user_data)
{
(void)anchor;
(void)iface_mask;
(void)user_data;
(void)bm;
int i;
int uri_len = strlen(uri);
uri_len = (uri_len >= MAX_URI_LENGTH) ? MAX_URI_LENGTH - 1 : uri_len;
for (i = 0; i < (int)oc_string_array_get_allocated_size(types); i++) {
char *t = oc_string_array_get_item(types, i);
if (strlen(t) == 11 && strncmp(t, "oic.r.light", 11) == 0) {
light_server = endpoint;
strncpy(light_1, uri, uri_len);
light_1[uri_len] = '\0';
oc_do_observe(light_1, light_server, NULL, &observe_light, LOW_QOS, NULL);
oc_set_delayed_callback(NULL, &stop_observe, 30);
got_discovery_response = true;
return OC_STOP_DISCOVERY;
}
}
return OC_CONTINUE_DISCOVERY;
}
static oc_event_callback_retval_t
do_discovery(void *data)
{
(void)data;
if (got_discovery_response) {
return OC_EVENT_DONE;
}
oc_do_ip_discovery("oic.r.light", &discovery, NULL);
return OC_EVENT_CONTINUE;
}
static void
issue_requests(void)
{
oc_set_delayed_callback(NULL, &do_discovery, 10);
}
static void
signal_event_loop(void)
{
mutex_lock(&mutex);
pthread_cond_signal(&cv);
mutex_unlock(&mutex);
}
static char _oc_main_stack[THREAD_STACKSIZE_MAIN];
void *
oc_main_thread(void *arg)
{
(void)arg;
pthread_cond_init(&cv, NULL);
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.requests_entry = issue_requests };
if (oc_main_init(&handler) < 0) {
PRINT("client_riot: failed to initialize stack\n");
return NULL;
}
oc_clock_time_t next_event;
while (quit == 0) {
next_event = oc_main_poll();
mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else if (oc_clock_time() < next_event) {
ts.tv_sec = (next_event / OC_CLOCK_SECOND);
ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
pthread_cond_timedwait(&cv, &mutex, &ts);
}
mutex_unlock(&mutex);
}
oc_main_shutdown();
return NULL;
}
int
main(void)
{
thread_create(_oc_main_stack, sizeof(_oc_main_stack), 2, 0, oc_main_thread,
NULL, "OCF event thread");
fgetc(stdin);
quit = 1;
signal_event_loop();
return 0;
}
......@@ -31,7 +31,7 @@
static const size_t DEVICE = 0;
// define application specific values.
static const char *spec_version = "ocf.2.1.1";
static const char *spec_version = "ocf.2.0.5";
static const char *data_model_version = "ocf.res.1.3.0,ocf.sh.1.3.0";
static const char *deivce_uri = "/oic/d";
......
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed 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 "oc_api.h"
static bool light_state = false;
static int
app_init(void)
{
int ret = oc_init_platform("Intel", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.light", "Kishen's light", "1.0", "1.0",
NULL, NULL);
return ret;
}
static void
get_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)user_data;
PRINT("GET_light:\n");
oc_rep_start_root_object();
switch (iface_mask) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
case OC_IF_RW:
oc_rep_set_boolean(root, state, light_state);
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
PRINT("Light state %d\n", light_state);
}
static void
post_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)iface_mask;
(void)user_data;
PRINT("POST_light:\n");
bool state = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
PRINT("key: %s ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
state = rep->value.boolean;
PRINT("value: %d\n", state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
break;
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
light_state = state;
}
static void
put_light(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
post_light(request, iface_mask, user_data);
}
static void
register_resources(void)
{
oc_resource_t *res = oc_new_resource("lightbulb", "/light/1", 1, 0);
oc_resource_bind_resource_type(res, "oic.r.light");
oc_resource_bind_resource_interface(res, OC_IF_RW);
oc_resource_set_default_interface(res, OC_IF_RW);
oc_resource_set_discoverable(res, true);
oc_resource_set_periodic_observable(res, 1);
oc_resource_set_request_handler(res, OC_GET, get_light, NULL);
oc_resource_set_request_handler(res, OC_POST, post_light, NULL);
oc_resource_set_request_handler(res, OC_PUT, put_light, NULL);
oc_add_resource(res);
}
#include "contiki.h"
PROCESS(sample_server_process, "OCF server sample");
AUTOSTART_PROCESSES(&sample_server_process);
static void
signal_event_loop(void)
{
process_post(&sample_server_process, PROCESS_EVENT_TIMER, NULL);
}
PROCESS_THREAD(sample_server_process, ev, data)
{
static struct etimer et;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
static oc_clock_time_t next_event;
PROCESS_BEGIN();
int init = oc_main_init(&handler);
if (init < 0)
return init;
while (ev != PROCESS_EVENT_EXIT) {
next_event = oc_main_poll();
if (next_event != 0) {
next_event -= oc_clock_time();
etimer_set(&et, next_event);
}
PROCESS_YIELD();
}
PROCESS_END();
}
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed 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 "oc_api.h"
static bool light_state = false;
static int
app_init(void)
{
int ret = oc_init_platform("Intel", NULL, NULL);
ret |= oc_add_device("/oic/d", "oic.d.light", "Kishen's light", "1.0", "1.0",
NULL, NULL);
return ret;
}
static void
get_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)user_data;
PRINT("GET_light:\n");
oc_rep_start_root_object();
switch (iface_mask) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
case OC_IF_RW:
oc_rep_set_boolean(root, state, light_state);
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
PRINT("Light state %d\n", light_state);
}
static void
post_light(oc_request_t *request, oc_interface_mask_t iface_mask, void *user_data)
{
(void)iface_mask;
(void)user_data;
PRINT("POST_light:\n");
bool state = false;
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
PRINT("key: %s ", oc_string(rep->name));
switch (rep->type) {
case OC_REP_BOOL:
state = rep->value.boolean;
PRINT("value: %d\n", state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
break;
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
light_state = state;
}
static void
put_light(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
post_light(request, iface_mask, user_data);
}
static void
register_resources(void)
{
oc_resource_t *res = oc_new_resource("lightbulb", "/light/1", 1, 0);
oc_resource_bind_resource_type(res, "oic.r.light");
oc_resource_bind_resource_interface(res, OC_IF_RW);
oc_resource_set_default_interface(res, OC_IF_RW);
oc_resource_set_discoverable(res, true);
oc_resource_set_periodic_observable(res, 1);
oc_resource_set_request_handler(res, OC_GET, get_light, NULL);
oc_resource_set_request_handler(res, OC_POST, post_light, NULL);
oc_resource_set_request_handler(res, OC_PUT, put_light, NULL);
oc_add_resource(res);
}
#include "pthread_cond.h"
#include "thread.h"
static int quit;
static mutex_t mutex;
static pthread_cond_t cv;
static struct timespec ts;
static void
signal_event_loop(void)
{
mutex_lock(&mutex);
pthread_cond_signal(&cv);
mutex_unlock(&mutex);
}
static char _oc_main_stack[THREAD_STACKSIZE_MAIN];
void *
oc_main_thread(void *arg)
{
(void)arg;
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources };
if (oc_main_init(&handler) < 0) {
PRINT("server_riot: failed to initialize stack\n");
return NULL;
}
oc_clock_time_t next_event;
while (!quit) {
next_event = oc_main_poll();
mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else {
ts.tv_sec = (next_event / OC_CLOCK_SECOND);
ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
pthread_cond_timedwait(&cv, &mutex, &ts);
}
mutex_unlock(&mutex);
}
oc_main_shutdown();
return NULL;
}
int
main(void)
{
thread_create(_oc_main_stack, sizeof(_oc_main_stack), 2, 0, oc_main_thread,
NULL, "OCF event thread");
fgetc(stdin);
quit = 1;
signal_event_loop();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment