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);
55 result = OCStartPresence(0);
56 if (result != OC_STACK_OK)
58 OIC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
63 PIPlugin* plugin = NULL;
64 OIC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
65 result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
66 if (result != OC_STACK_OK)
68 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
72 if (signal(SIGINT, processCancel) == SIG_ERR)
74 OIC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
78 OIC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
80 while (!processSignal(false) && result == OC_STACK_OK)
83 if (result != OC_STACK_OK)
85 OIC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
89 result = PIProcess(plugin);
90 if (result != OC_STACK_OK)
92 OIC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
97 OIC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
98 result = PIStopPlugin(plugin);
99 if (result != OC_STACK_OK)
101 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
103 OIC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
106 OIC_LOG(INFO, TAG, "Stopping IoTivity...");
108 if (result != OC_STACK_OK)
110 OIC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
114 OIC_LOG(INFO, TAG, "Application Completed Successfully");
118 OCStackResult SetPlatformInfo()
120 static const OCPlatformInfo platformInfo =
122 .platformID = "IoTivityZigbeeID",
123 .manufacturerName = "IoTivity",
124 .manufacturerUrl = "http://iotivity.org",
125 .modelNumber = "T1000",
126 .dateOfManufacture = "January 14th, 2015",
127 .platformVersion = "0.9.2",
128 .operatingSystemVersion = "7",
129 .hardwareVersion = "0.5",
130 .firmwareVersion = "0",
131 .supportUrl = "http://iotivity.org",
135 return OCSetPlatformInfo(platformInfo);
138 OCStackResult SetDeviceInfo()
140 static OCDeviceInfo deviceInfo =
142 .deviceName = "IoTivity/Zigbee Server Sample",
143 .specVersion = "IoTivity/Zigbee Device Spec Version",
145 char *dmv = OICStrdup("IoTivity/Zigbee Data Model Version");
146 deviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
147 deviceInfo.dataModelVersions->value = dmv;
148 char *dup = OICStrdup("oic.wk.d");
149 deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL));
150 deviceInfo.types->value = dup;
151 return OCSetDeviceInfo(deviceInfo);
154 bool processSignal(bool set)
156 static sig_atomic_t signal = 0;
165 void processCancel(int signal)