1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "IotivityandZigbeeServer.h"
25 #include "oic_string.h"
26 #include "oic_malloc.h"
28 #define TAG "IoTivityZigbeeServer"
29 #define defaultComPort "/dev/ttyUSB0"
32 OIC_LOG(INFO, TAG, "Initializing IoTivity...");
33 OCStackResult result = OCInit(NULL, 0, OC_SERVER);
34 if (result != OC_STACK_OK)
36 OIC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
40 result = SetPlatformInfo();
41 if (result != OC_STACK_OK)
43 OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
47 result = SetDeviceInfo();
48 if (result != OC_STACK_OK)
50 OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
54 result = OCStartPresence(0);
55 if (result != OC_STACK_OK)
57 OIC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
62 PIPlugin* plugin = NULL;
63 OIC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
64 result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
65 if (result != OC_STACK_OK)
67 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
71 if (signal(SIGINT, processCancel) == SIG_ERR)
73 OIC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
77 OIC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
79 while (!processSignal(false) && result == OC_STACK_OK)
82 if (result != OC_STACK_OK)
84 OIC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
88 result = PIProcess(plugin);
89 if (result != OC_STACK_OK)
91 OIC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
96 OIC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
97 result = PIStopPlugin(plugin);
98 if (result != OC_STACK_OK)
100 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
102 OIC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
105 OIC_LOG(INFO, TAG, "Stopping IoTivity...");
107 if (result != OC_STACK_OK)
109 OIC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
113 OIC_LOG(INFO, TAG, "Application Completed Successfully");
117 OCStackResult SetPlatformInfo()
119 static const OCPlatformInfo platformInfo =
121 .platformID = "IoTivityZigbeeID",
122 .manufacturerName = "IoTivity",
123 .manufacturerUrl = "http://iotivity.org",
124 .modelNumber = "T1000",
125 .dateOfManufacture = "January 14th, 2015",
126 .platformVersion = "0.9.2",
127 .operatingSystemVersion = "7",
128 .hardwareVersion = "0.5",
129 .firmwareVersion = "0",
130 .supportUrl = "http://iotivity.org",
134 return OCSetPlatformInfo(platformInfo);
137 OCStackResult SetDeviceInfo()
139 static OCDeviceInfo deviceInfo =
141 .deviceName = "IoTivity/Zigbee Server Sample",
143 char *dup = OICStrdup("oic.wk.d");
144 deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
145 deviceInfo.types->value = dup;
147 return OCSetDeviceInfo(deviceInfo);
150 bool processSignal(bool set)
152 static sig_atomic_t signal = 0;
161 void processCancel(int signal)