Welcome to mirror list, hosted at ThFree Co, Russian Federation.

appli_light_lc.c « app « STM32_WPAN « BLE_Mesh_ThermometerSensor « BLE « Applications « STM32WB5MM-DK « Projects - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1d53e1ec4e0bf9a49e024920004cc980d22d613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/**
  ******************************************************************************
  * @file    appli_light_lc.c
  * @author  BLE Mesh Team
  * @brief   Application interface for light LC Mesh Models 
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2020-2021 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "hal_common.h"
#include "types.h"
#include "appli_generic.h"
#include "appli_light.h"
#include "common.h"
#include "mesh_cfg_usr.h"
#include "appli_light_lc.h"

/** @addtogroup ST_BLE_Mesh
*  @{
*/

/** @addtogroup Application_Mesh_Models
*  @{
*/

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variable ----------------------------------------------------------*/

__attribute__((aligned(4)))const light_lc_cb_t AppliLightLc_cb = 
{ 
  Appli_LightLCs_ModeGet,
  Appli_LightLCs_ModeSet,
  Appli_LightLCs_ModeSetUnack,
  Appli_LightLCs_ModeStatus,
  Appli_LightLCs_OmGet,
  Appli_LightLCs_OmSet,
  Appli_LightLCs_OmSetUnack,
  Appli_LightLCs_OmStatus,
  Appli_LightLCs_OnOffGet,
  Appli_LightLCs_OnOffSet,
  Appli_LightLCs_OnOffSetUnack,
  Appli_LightLCs_OnOffStatus,
  Appli_LightLCs_PropertyGet,
  Appli_LightLCs_PropertySet,
  Appli_LightLCs_PropertySetUnack,
  Appli_LightLCs_PropertyStatus
};

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
  * @brief  Callback corresponding to LightLCs_ModeGet_cb
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_ModeGet(MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}

  
/**
  * @brief  Callback corresponding to LightLCs_ModeSet_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_ModeSet(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}


/**
  * @brief  Callback corresponding to LightLCs_ModeSetUnack_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_ModeSetUnack(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}


/**
  * @brief  Callback corresponding to LightLCs_ModeSatus_cb
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_ModeStatus(MOBLEUINT8 const* pLightLCMode_status,
                               MOBLEUINT32 plength, 
                               MOBLEUINT16 dstPeer, 
                               MOBLEUINT8 elementIndex)
{                              
  MOBLEUINT8 i;
  TRACE_M(TF_LIGHT_LC,"LightLCs_ModeStatus callback received for element %d \r\n", elementIndex);
  TRACE_M(TF_SERIAL_CTRL,"#8294!\r\n");
  
  for(i = 0; i < plength; i++)
  {
    if(i == 0)
      TRACE_M(TF_SERIAL_CTRL,"Light LC Mode value: %d\n\r", 
              pLightLCMode_status[i]);
  }
}


/**
  * @brief  Callback corresponding to LightLCs_OmGet_cb
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_OmGet(MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}
  

/**
  * @brief  Callback corresponding to LightLCs_OmSet_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_OmSet(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}


/**
  * @brief  Callback corresponding to LightLCs_OmSetUnack_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_OmSetUnack(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}
  
  
/**
  * @brief  Callback corresponding to LightLCs_OmStatus_cb
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_OmStatus(MOBLEUINT8 const* pLightLCOccupancyMode_status,
                             MOBLEUINT32 plength, 
                             MOBLEUINT16 dstPeer, 
                             MOBLEUINT8 elementIndex)
{                              
  MOBLEUINT8 i;
  TRACE_M(TF_LIGHT_LC,"LightLCs_OmStatus callback received for element %d \r\n", elementIndex);
  TRACE_M(TF_SERIAL_CTRL,"#8298!\r\n");
  
  for(i = 0; i < plength; i++)
  {
    if(i == 0)
      TRACE_M(TF_SERIAL_CTRL,"Light LC OM value: %d\n\r", 
              pLightLCOccupancyMode_status[i]);
  }
}


/**
  * @brief  Callback corresponding to LightLCs_OnOffGet_cb
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_OnOffGet(MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}


/**
  * @brief  Callback corresponding to LightLC_OnOffSet_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_OnOffSet(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{  
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}
  

/**
  * @brief  Callback corresponding to LightLCs_OnOffSetUnack_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_OnOffSetUnack(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}  


/**
  * @brief  Callback corresponding to LightLCs_OnOffStatus_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_OnOffStatus(MOBLEUINT8 const* pLightLCOnOff_status,
                                MOBLEUINT32 plength, 
                                MOBLEUINT16 dstPeer, 
                                MOBLEUINT8 elementIndex)
{                              
  MOBLEUINT8 i;
  TRACE_M(TF_LIGHT_LC,"LightLCs_OnOffStatus callback received for element %d \r\n", elementIndex);
  TRACE_M(TF_SERIAL_CTRL,"#829C!\r\n");
  
  for(i = 0; i < plength; i++)
  {
    if(i == 0)
      TRACE_M(TF_SERIAL_CTRL,"Light LC OnOff status: %d\n\r", 
              pLightLCOnOff_status[i]);
  }
}


/**
  * @brief  Callback corresponding to LightLCs_PropertyGet_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_PropertyGet(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}  


/**
  * @brief  Callback corresponding to LightLCs_PropertySet_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_PropertySet(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
{
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
}

  
/**
  * @brief  Callback corresponding to LightLCs_PropertySetUnack_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
  */
void Appli_LightLCs_PropertySetUnack(MOBLEUINT8 const* pRxData, MODEL_MessageHeader_t *pmsgParam)
  {    
  TRACE_M(TF_LIGHT_LC, "Element index %d peer addr %X dst peer %X\r\n",
          pmsgParam->elementIndex, pmsgParam->peer_addr, pmsgParam->dst_peer);
    }


/**
  * @brief  Callback corresponding to LightLCs_PropertyStatus_cb
  * @param  Data
  * @param  Message parameters
  * @retval None
*/ 
void Appli_LightLCs_PropertyStatus(MOBLEUINT8 const* pLightLCProperty_status,
                                   MOBLEUINT32 plength, 
                                   MOBLEUINT16 dstPeer, 
                                   MOBLEUINT8 elementIndex)
{                              
  MOBLEUINT8 i;
  TRACE_M(TF_LIGHT_LC,"LightLCs_PropertyStatus callback received for element %d \r\n", elementIndex);
  TRACE_M(TF_SERIAL_CTRL,"#64!\r\n");
  
  for(i = 0; i < plength; i++)
  {
    if(i == 0)
      TRACE_M(TF_SERIAL_CTRL,"Light LC Property status: %d\n\r", 
              pLightLCProperty_status[i]);
  }
}


/**
  * @brief  
  * @param  
  * @retval 
  */
__weak MOBLE_RESULT Appli_Light_LCs_Init(void)
{
  MOBLE_RESULT result = MOBLE_RESULT_FAIL;
  MOBLEUINT8 lcsElementIndex = 0;
  
  /* Extract element index of LC server */
  result = ExtractLcServerElementIndex(&lcsElementIndex,
#ifdef APPLICATION_NUMBER_OF_ELEMENTS
                                       APPLICATION_NUMBER_OF_ELEMENTS,
#else
                                       0,
#endif
#ifdef ENABLE_LIGHT_MODEL_SERVER_LC
                                       ENABLE_LIGHT_MODEL_SERVER_LC,
                                       ENABLE_LIGHT_MODEL_SERVER_LC_SETUP,
#else
                                       0,
                                       0,
#endif
#ifdef ENABLE_GENERIC_MODEL_SERVER_ONOFF
                                       ENABLE_GENERIC_MODEL_SERVER_ONOFF,
#else
                                       0,
#endif
#ifdef ENABLE_GENERIC_MODEL_SERVER_POWER_ONOFF
                                       ENABLE_GENERIC_MODEL_SERVER_POWER_ONOFF,
#else
                                       0,
#endif
#ifdef ENABLE_LIGHT_MODEL_SERVER_LIGHTNESS
                                       ENABLE_LIGHT_MODEL_SERVER_LIGHTNESS);
#else
                                       0);
#endif
      
  if(MOBLE_SUCCEEDED(result))
  {
    result = Light_LCs_Init(&BufferLcServer, lcsElementIndex, &AppliLightLc_cb, SIZE_OF_LC_SERVER_T);
  }
  
  if(MOBLE_FAILED(result))
  {
    TRACE_M(TF_LIGHT_LC, "Light LC Server init failed\r\n");
  }
  
  return result; 
}


/**
  * @brief  
  * @param  
  * @retval 
  */
__weak MOBLE_RESULT Appli_Light_LC_SensorPropertyUpdate(MOBLEUINT8 elementIndex,
                                                 MOBLEUINT16 propertyId,
                                                 MOBLEUINT32 value)
{
  return Light_LC_SensorPropertyUpdate(elementIndex,
                                       propertyId,
                                       value);
}

#ifdef ENABLE_LIGHT_MODEL_SERVER_LC
/**
  * @brief  Handling of serial inputs to LC model
  * @param  serial string
  * @param  serial string size
  * @retval void
  */
void Appli_Light_LC_SerialCmd(char *rcvdStringBuff, uint16_t rcvdStringSize)
{
  MOBLE_RESULT result = MOBLE_RESULT_INVALIDARG;
  
  if (!strncmp(rcvdStringBuff+6, "TR0", 3))
  {    
    if (rcvdStringSize == 9)
    {
      /* call to function corresponding MMDL/SR/LLC/BV-03-C */
      result = Light_LC_SetTransitionTimeZero(1);
    }
    else
    {
      result = MOBLE_RESULT_FAIL;
      BLEMesh_PrintStringCb("Invalid size of string\r\n");
    }
  }
  else if (!strncmp(rcvdStringBuff+6, "OCCUPANCY", 9)) /* occupancy detect */
  {
    if (rcvdStringSize == 15)
    {
      /* occupancy detected for element index 0 */
      Appli_Light_LC_SensorPropertyUpdate(0,
                                          PRESENCE_DETECTED_PID,
                                          1);
      result = MOBLE_RESULT_SUCCESS;
    }
    else
    {
      result = MOBLE_RESULT_FAIL;
      BLEMesh_PrintStringCb("Invalid size of string\r\n");
    }
  }
  else
  {
    result = MOBLE_RESULT_FAIL;
  }
  
  /* Check the result of command processing */
  if(result == MOBLE_RESULT_SUCCESS)
  {
    BLEMesh_PrintStringCb("Success\r\n");
  }
  else if(result == MOBLE_RESULT_OUTOFMEMORY)
  {
    BLEMesh_PrintStringCb("Fail Out of memory\r\n");  
  }
  else if(result == MOBLE_RESULT_INVALIDARG)
  {
    BLEMesh_PrintStringCb("Fail Invalid Argument\r\n");  
  }
  else
  {
    BLEMesh_PrintStringCb("Fail\r\n");   
  }
}
#endif


/**
* @}
*/

/**
* @}
*/