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 OC_LOG(INFO, TAG, "Initializing IoTivity...");
31 OCStackResult result = OCInit(NULL, 0, OC_SERVER);
32 if (result != OC_STACK_OK)
34 OC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
38 result = SetPlatformInfo();
39 if (result != OC_STACK_OK)
41 OC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
45 result = SetDeviceInfo();
46 if (result != OC_STACK_OK)
48 OC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
52 result = OCStartPresence(0);
53 if (result != OC_STACK_OK)
55 OC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
60 PIPlugin* plugin = NULL;
61 OC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
62 result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
63 if (result != OC_STACK_OK)
65 OC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
69 if (signal(SIGINT, processCancel) == SIG_ERR)
71 OC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
75 OC_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 OC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
86 result = PIProcess(plugin);
87 if (result != OC_STACK_OK)
89 OC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
94 OC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
96 OC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
97 result = PIStopPlugin(plugin);
98 if (result != OC_STACK_OK)
100 OC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
105 OC_LOG(INFO, TAG, "Stopping IoTivity...");
107 if (result != OC_STACK_OK)
109 OC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
113 OC_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 const OCDeviceInfo deviceInfo =
141 .deviceName = "IoTivity/Zigbee Server Sample"
144 return OCSetDeviceInfo(deviceInfo);
147 bool processSignal(bool set)
149 static sig_atomic_t signal = 0;
158 void processCancel(int signal)