Skip to content

Commit 0343005

Browse files
Merge pull request #11 from nikhil-zinjurde-imgtec/master
Merge dev to master
2 parents fbf67f0 + 44a2f33 commit 0343005

File tree

3 files changed

+332
-1
lines changed

3 files changed

+332
-1
lines changed

Makefile.libobjects

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
libobjects_src = lwm2m-client-flow-object.c lwm2m-client-flow-access-object.c lwm2m-client-device-object.c \
2-
lwm2m-client-ipso-digital-input.c lwm2m-client-ipso-light-control.c
2+
lwm2m-client-ipso-digital-input.c lwm2m-client-ipso-light-control.c \
3+
lwm2m-client-ipso-presence-sensor.c
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
/**
2+
* @file
3+
* LightWeightM2M LWM2M Presence Sensor object.
4+
*
5+
* @author Imagination Technologies
6+
*
7+
* @copyright Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group
8+
* companies and/or licensors.
9+
*
10+
* All rights reserved.
11+
*
12+
* Redistribution and use in source and binary forms, with or without modification, are permitted
13+
* provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
16+
* and the following disclaimer.
17+
*
18+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
19+
* conditions and the following disclaimer in the documentation and/or other materials provided
20+
* with the distribution.
21+
*
22+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
23+
* endorse or promote products derived from this software without specific prior written
24+
* permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
27+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28+
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
33+
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
/***************************************************************************************************
37+
* Includes
38+
**************************************************************************************************/
39+
40+
#include <stdio.h>
41+
#include <stdint.h>
42+
#include <stdbool.h>
43+
#include <string.h>
44+
#include <awa/static.h>
45+
#include "lwm2m-client-ipso-presence-sensor.h"
46+
47+
/***************************************************************************************************
48+
* Typedefs
49+
**************************************************************************************************/
50+
51+
typedef struct
52+
{
53+
AwaBoolean State;
54+
AwaInteger Counter;
55+
char SensorType[128];
56+
AwaInteger BusyToClearDelay;
57+
AwaInteger ClearToBusyDelay;
58+
} IPSOPresenceSensor;
59+
60+
/***************************************************************************************************
61+
* Globals
62+
**************************************************************************************************/
63+
64+
static IPSOPresenceSensor presenceSensors[PRESENCE_SENSORS];
65+
66+
/***************************************************************************************************
67+
* Implementation
68+
**************************************************************************************************/
69+
70+
static AwaResult PresenceSensorHandler(AwaStaticClient *client, AwaOperation operation, AwaObjectID objectID, AwaObjectInstanceID objectInstanceID,
71+
AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID, void **dataPointer, size_t *dataSize, bool *changed)
72+
{
73+
AwaResult result = AwaResult_InternalError;
74+
if (!((objectID == IPSO_PRESENCE_OBJECT) && (objectInstanceID >= 0) && (objectInstanceID < PRESENCE_SENSORS)))
75+
{
76+
printf("Incorrect object data\n");
77+
return result;
78+
}
79+
80+
switch (operation)
81+
{
82+
case AwaOperation_DeleteObjectInstance:
83+
result = AwaResult_SuccessDeleted;
84+
memset(&presenceSensors[objectInstanceID], 0, sizeof(presenceSensors[objectInstanceID]));
85+
break;
86+
87+
case AwaOperation_CreateObjectInstance:
88+
result = AwaResult_SuccessCreated;
89+
memset(&presenceSensors[objectInstanceID], 0, sizeof(presenceSensors[objectInstanceID]));
90+
break;
91+
92+
case AwaOperation_CreateResource:
93+
result = AwaResult_SuccessCreated;
94+
break;
95+
96+
case AwaOperation_Execute:
97+
if (resourceID == IPSO_DIGITAL_INPUT_COUNTER_RESET)
98+
{
99+
presenceSensors[objectInstanceID].Counter = 0;
100+
AwaStaticClient_ResourceChanged(client, IPSO_PRESENCE_OBJECT, objectInstanceID, IPSO_DIGITAL_INPUT_COUNTER);
101+
result = AwaResult_Success;
102+
}
103+
else
104+
{
105+
printf("\n Invalid resource ID for PresenceSensor execute operation");
106+
result = AwaResult_InternalError;
107+
}
108+
break;
109+
110+
case AwaOperation_Read:
111+
result = AwaResult_SuccessContent;
112+
switch (resourceID)
113+
{
114+
case IPSO_DIGITAL_INPUT_STATE:
115+
*dataPointer = &presenceSensors[objectInstanceID].State;
116+
*dataSize = sizeof(presenceSensors[objectInstanceID].State);
117+
break;
118+
119+
case IPSO_DIGITAL_INPUT_COUNTER:
120+
*dataPointer = &presenceSensors[objectInstanceID].Counter;
121+
*dataSize = sizeof(presenceSensors[objectInstanceID].Counter);
122+
break;
123+
124+
case IPSO_SENSOR_TYPE:
125+
*dataPointer = presenceSensors[objectInstanceID].SensorType;
126+
*dataSize = strlen(presenceSensors[objectInstanceID].SensorType);
127+
break;
128+
129+
case IPSO_BUSY_TO_CLEAR_DELAY:
130+
*dataPointer = &presenceSensors[objectInstanceID].BusyToClearDelay;
131+
*dataSize = sizeof(presenceSensors[objectInstanceID].BusyToClearDelay);
132+
break;
133+
134+
case IPSO_CLEAR_TO_BUSY_DELAY:
135+
*dataPointer = &presenceSensors[objectInstanceID].ClearToBusyDelay;
136+
*dataSize = sizeof(presenceSensors[objectInstanceID].ClearToBusyDelay);
137+
break;
138+
139+
default:
140+
printf("\n Invalid resource ID for PresenceSensor read operation");
141+
result = AwaResult_InternalError;
142+
break;
143+
}
144+
break;
145+
146+
case AwaOperation_Write:
147+
*changed = true;
148+
result = AwaResult_SuccessChanged;
149+
switch (resourceID)
150+
{
151+
case IPSO_DIGITAL_INPUT_STATE:
152+
presenceSensors[objectInstanceID].State = *((AwaBoolean *)*dataPointer);
153+
break;
154+
155+
case IPSO_DIGITAL_INPUT_COUNTER:
156+
presenceSensors[objectInstanceID].Counter = *((AwaInteger *)*dataPointer);
157+
break;
158+
159+
case IPSO_SENSOR_TYPE:
160+
if(*dataSize < sizeof(presenceSensors[objectInstanceID].SensorType))
161+
{
162+
memcpy(presenceSensors[objectInstanceID].SensorType, *dataPointer, *dataSize);
163+
presenceSensors[objectInstanceID].SensorType[*dataSize] = '\0';
164+
}
165+
else
166+
{
167+
result = AwaResult_BadRequest;
168+
}
169+
break;
170+
171+
case IPSO_BUSY_TO_CLEAR_DELAY:
172+
presenceSensors[objectInstanceID].BusyToClearDelay = *((AwaInteger *)*dataPointer);
173+
break;
174+
175+
case IPSO_CLEAR_TO_BUSY_DELAY:
176+
presenceSensors[objectInstanceID].ClearToBusyDelay = *((AwaInteger *)*dataPointer);
177+
break;
178+
179+
default:
180+
printf("\n Invalid resource ID for DigitalInput write operation");
181+
result = AwaResult_InternalError;
182+
break;
183+
}
184+
break;
185+
default:
186+
printf("DigitalInput - unknown operation\n");
187+
break;
188+
}
189+
return result;
190+
}
191+
192+
int DefinePresenceSensorObject(AwaStaticClient *awaClient)
193+
{
194+
AwaError error;
195+
int i;
196+
197+
error = AwaStaticClient_DefineObjectWithHandler(awaClient, "PresenceSensor", IPSO_PRESENCE_OBJECT, 0, PRESENCE_SENSORS, PresenceSensorHandler);
198+
if (error != AwaError_Success)
199+
{
200+
printf("Failed to register flow access object\n");
201+
return 1;
202+
}
203+
204+
error = AwaStaticClient_DefineResourceWithHandler(awaClient, "State", IPSO_PRESENCE_OBJECT, IPSO_DIGITAL_INPUT_STATE, AwaResourceType_Boolean, 1, 1, AwaResourceOperations_ReadOnly, PresenceSensorHandler);
205+
if (error != AwaError_Success)
206+
{
207+
printf("Failed to define State resource\n");
208+
return 1;
209+
}
210+
211+
error = AwaStaticClient_DefineResourceWithHandler(awaClient, "Counter", IPSO_PRESENCE_OBJECT, IPSO_DIGITAL_INPUT_COUNTER, AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadOnly, PresenceSensorHandler);
212+
if (error != AwaError_Success)
213+
{
214+
printf("Failed to define Counter resource\n");
215+
return 1;
216+
}
217+
218+
error = AwaStaticClient_DefineResourceWithHandler(awaClient, "SensorType", IPSO_PRESENCE_OBJECT , IPSO_SENSOR_TYPE, AwaResourceType_String, 0, 1, AwaResourceOperations_ReadOnly, PresenceSensorHandler);
219+
if (error != AwaError_Success)
220+
{
221+
printf("Failed to define SensorType resource\n");
222+
return 1;
223+
}
224+
225+
error = AwaStaticClient_DefineResourceWithHandler(awaClient, "BusyToClearDelay", IPSO_PRESENCE_OBJECT, IPSO_BUSY_TO_CLEAR_DELAY, AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadOnly, PresenceSensorHandler);
226+
if (error != AwaError_Success)
227+
{
228+
printf("Failed to define BusyToClearDelay resource\n");
229+
return 1;
230+
}
231+
232+
error = AwaStaticClient_DefineResourceWithHandler(awaClient, "ClearToBusyDelay", IPSO_PRESENCE_OBJECT, IPSO_CLEAR_TO_BUSY_DELAY, AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadOnly, PresenceSensorHandler);
233+
if (error != AwaError_Success)
234+
{
235+
printf("Failed to define ClearToBusyDelay resource\n");
236+
return 1;
237+
}
238+
239+
error = AwaStaticClient_DefineResourceWithHandler(awaClient, "CounterReset", IPSO_PRESENCE_OBJECT , IPSO_DIGITAL_INPUT_COUNTER_RESET, AwaResourceType_Opaque, 0, 1, AwaResourceOperations_Execute, PresenceSensorHandler);
240+
if (error != AwaError_Success)
241+
{
242+
printf("Failed to define CounterReset resource\n");
243+
return 1;
244+
}
245+
246+
for (i = 0; i < PRESENCE_SENSORS; i++)
247+
{
248+
AwaStaticClient_CreateObjectInstance(awaClient, IPSO_PRESENCE_OBJECT, i);
249+
AwaStaticClient_CreateResource(awaClient, IPSO_PRESENCE_OBJECT, i, IPSO_DIGITAL_INPUT_COUNTER);
250+
}
251+
return 0;
252+
}
253+
254+
255+
int PresenceSensor_IncrementCounter(AwaStaticClient *awaClient, AwaObjectInstanceID objectInstanceID)
256+
{
257+
if ((awaClient != NULL) && (objectInstanceID >= 0) && (objectInstanceID < PRESENCE_SENSORS))
258+
{
259+
presenceSensors[objectInstanceID].Counter += 1;
260+
AwaStaticClient_ResourceChanged(awaClient, IPSO_PRESENCE_OBJECT, objectInstanceID, IPSO_DIGITAL_INPUT_COUNTER);
261+
return 0;
262+
}
263+
else
264+
{
265+
printf("Invalid arguments passed to %s", __func__);
266+
return 1;
267+
}
268+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @file
3+
* LightWeightM2M LWM2M Presence Sensor object.
4+
*
5+
* @author Imagination Technologies
6+
*
7+
* @copyright Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated group
8+
* companies and/or licensors.
9+
*
10+
* All rights reserved.
11+
*
12+
* Redistribution and use in source and binary forms, with or without modification, are permitted
13+
* provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
16+
* and the following disclaimer.
17+
*
18+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
19+
* conditions and the following disclaimer in the documentation and/or other materials provided
20+
* with the distribution.
21+
*
22+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
23+
* endorse or promote products derived from this software without specific prior written
24+
* permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
27+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28+
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
33+
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
#ifndef LWM2M_CLIENT_IPSO_PRESENCE_SENSOR_H_
37+
#define LWM2M_CLIENT_IPSO_PRESENCE_SENSOR_H_
38+
39+
#include "awa/static.h"
40+
41+
/***************************************************************************************************
42+
* Macros
43+
**************************************************************************************************/
44+
45+
#define IPSO_PRESENCE_OBJECT 3302
46+
#define IPSO_DIGITAL_INPUT_STATE 5500
47+
#define IPSO_DIGITAL_INPUT_COUNTER 5501
48+
#define IPSO_DIGITAL_INPUT_COUNTER_RESET 5505
49+
#define IPSO_SENSOR_TYPE 5751
50+
#define IPSO_BUSY_TO_CLEAR_DELAY 5903
51+
#define IPSO_CLEAR_TO_BUSY_DELAY 5904
52+
53+
#define PRESENCE_SENSORS 1
54+
55+
/***************************************************************************************************
56+
* Functions
57+
**************************************************************************************************/
58+
59+
int DefinePresenceSensorObject(AwaStaticClient *awaClient);
60+
int PresenceSensor_IncrementCounter(AwaStaticClient *awaClient, AwaObjectInstanceID objectInstanceID);
61+
62+
#endif /* LWM2M_CLIENT_IPSO_PRESENCE_SENSOR_H_ */

0 commit comments

Comments
 (0)