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"
31 #define VERIFY_SUCCESS(op) \
33 if (op != OC_STACK_OK) \
35 OIC_LOG_V(FATAL, TAG, "%s failed!!", #op); \
42 OIC_LOG(INFO, TAG, "Initializing IoTivity...");
43 OCStackResult result = OCInit(NULL, 0, OC_SERVER);
44 if (result != OC_STACK_OK)
46 OIC_LOG_V(ERROR, TAG, "OCInit Failed %d", result);
50 result = SetPlatformInfo();
51 if (result != OC_STACK_OK)
53 OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed %d", result);
57 result = SetDeviceInfo();
58 if (result != OC_STACK_OK)
60 OIC_LOG_V(ERROR, TAG, "SetPlatformInfo Failed: %d", result);
64 result = OCStartPresence(0);
65 if (result != OC_STACK_OK)
67 OIC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
72 PIPlugin* plugin = NULL;
73 OIC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
74 result = PIStartPlugin(defaultComPort, PLUGIN_ZIGBEE, &plugin);
75 if (result != OC_STACK_OK)
77 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Start Failed: %d", result);
81 if (signal(SIGINT, processCancel) == SIG_ERR)
83 OIC_LOG(ERROR, TAG, "Unable to catch SIGINT, terminating...");
87 OIC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
89 while (!processSignal(false) && result == OC_STACK_OK)
92 if (result != OC_STACK_OK)
94 OIC_LOG_V(ERROR, TAG, "OCProcess Failed: %d", result);
98 result = PIProcess(plugin);
99 if (result != OC_STACK_OK)
101 OIC_LOG_V(ERROR, TAG, "PIProcess Failed: %d", result);
106 OIC_LOG(INFO, TAG, "Stopping Zigbee Plugin...");
107 result = PIStopPlugin(plugin);
108 if (result != OC_STACK_OK)
110 OIC_LOG_V(ERROR, TAG, "Zigbee Plugin Stop Failed: %d", result);
112 OIC_LOG(INFO, TAG, "Zigbee Plugin Stopped");
115 OIC_LOG(INFO, TAG, "Stopping IoTivity...");
117 if (result != OC_STACK_OK)
119 OIC_LOG_V(ERROR, TAG, "OCStop Failed: %d", result);
123 OIC_LOG(INFO, TAG, "Application Completed Successfully");
127 OCStackResult SetPlatformInfo()
129 static const OCPlatformInfo platformInfo =
131 .platformID = "IoTivityZigbeeID",
132 .manufacturerName = "IoTivity",
133 .manufacturerUrl = "http://iotivity.org",
134 .modelNumber = "T1000",
135 .dateOfManufacture = "January 14th, 2015",
136 .platformVersion = "0.9.2",
137 .operatingSystemVersion = "7",
138 .hardwareVersion = "0.5",
139 .firmwareVersion = "0",
140 .supportUrl = "http://iotivity.org",
144 return OCSetPlatformInfo(platformInfo);
147 OCStackResult SetDeviceInfo()
149 VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME,
150 "IoTivity/Zigbee Server Sample"));
152 VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION,
153 "IoTivity/Zigbee Device Spec Version"));
155 VERIFY_SUCCESS(OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION,
156 "IoTivity/Zigbee Data Model Version"));
158 OIC_LOG(INFO, TAG, "Device information initialized successfully.");
162 return OC_STACK_ERROR;
166 bool processSignal(bool set)
168 static sig_atomic_t signal = 0;
177 void processCancel(int signal)