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"
26 #define TAG "IoTivityZigbeeServer"
27 #define defaultComPort "/dev/ttyUSB0"
30 OIC_LOG(INFO, TAG, "Initializing IoTivity...");
31 OCStackResult result = OCInit(NULL, 0, OC_SERVER);
32 if (result != OC_STACK_OK)
34 OIC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
38 result = SetPlatformInfo();
39 if (result != OC_STACK_OK)
41 OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
45 result = SetDeviceInfo();
46 if (result != OC_STACK_OK)
48 OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
52 result = OCStartPresence(0);
53 if (result != OC_STACK_OK)
55 OIC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
60 PIPlugin* plugin = NULL;
61 OIC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
62 result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
63 if (result != OC_STACK_OK)
65 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
69 if (signal(SIGINT, processCancel) == SIG_ERR)
71 OIC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
75 OIC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
77 while (!processSignal(false) && result == OC_STACK_OK)
80 if (result != OC_STACK_OK)
82 OIC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
86 result = PIProcess(plugin);
87 if (result != OC_STACK_OK)
89 OIC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
94 OIC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
95 result = PIStopPlugin(plugin);
96 if (result != OC_STACK_OK)
98 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
100 OIC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
103 OIC_LOG(INFO, TAG, "Stopping IoTivity...");
105 if (result != OC_STACK_OK)
107 OIC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
111 OIC_LOG(INFO, TAG, "Application Completed Successfully");
115 OCStackResult SetPlatformInfo()
117 static const OCPlatformInfo platformInfo =
119 .platformID = "IoTivityZigbeeID",
120 .manufacturerName = "IoTivity",
121 .manufacturerUrl = "http://iotivity.org",
122 .modelNumber = "T1000",
123 .dateOfManufacture = "January 14th, 2015",
124 .platformVersion = "0.9.2",
125 .operatingSystemVersion = "7",
126 .hardwareVersion = "0.5",
127 .firmwareVersion = "0",
128 .supportUrl = "http://iotivity.org",
132 return OCSetPlatformInfo(platformInfo);
135 OCStackResult SetDeviceInfo()
137 static const OCDeviceInfo deviceInfo =
139 .deviceName = "IoTivity/Zigbee Server Sample"
142 return OCSetDeviceInfo(deviceInfo);
145 bool processSignal(bool set)
147 static sig_atomic_t signal = 0;
156 void processCancel(int signal)