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

models_if.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: 377f8fb30e4d2c9cfc1632787c9d4b634859b6d0 (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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
/**
  ******************************************************************************
  * @file    models_if.c
  * @author  BLE Mesh Team
  * @brief   Mesh Modes interface file of the application
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "hal_common.h"
#include "appli_mesh.h"
#include "appli_nvm.h"
#include "ble_hci_le.h"
#include "models_if.h"

#include "common.h"
#include "generic.h"
#include "light.h"
#include "light_lc.h"
#include "time_scene.h"
#include "sensors.h"
#include "vendor.h"
#include "appli_generic.h"
#include "appli_light.h"
#include "appli_light_lc.h"
#include "appli_sensor.h"
#include "appli_vendor.h"
#include "config_client.h"
#include "generic_client.h"
#include "light_client.h"
#include "sensors_client.h"
#include "appli_generic_client.h"
#include "appli_light_client.h"
#include "appli_sensors_client.h"

#include "PWM_config.h"
#include "PWM_handlers.h"

/** @addtogroup ST_BLE_Mesh
*  @{
*/

/** @addtogroup Application_Mesh_Models
*  @{
*/
/* Private variables ---------------------------------------------------------*/
MOBLEUINT8 Led_Value = 0;

MOBLEUINT8 ButtonIndex_Value = 0;

/* Private typedef -----------------------------------------------------------*/
#pragma pack(push, 1)

typedef struct
{
  MOBLE_ADDRESS peer;
  MOBLE_ADDRESS dst;
  MOBLEUINT8 command;
  MOBLEUINT8 elementIndex;
  MOBLEUINT8 appKeyOffset;
  MOBLEUINT8 netKeyOffset;
  MOBLEUINT8 data[DATA_BUFFER_LENGTH]; /* 8-Bytes response packet */
  MOBLEUINT32 length;
} APPLI_SEND_RESPONSE_MODULE;


typedef struct
{
  MOBLEUINT8 packet_count;
  MOBLEUINT32 send_time;
  APPLI_SEND_RESPONSE_MODULE* head;
  MOBLEUINT8 head_index;
  APPLI_SEND_RESPONSE_MODULE packet[MAX_PENDING_PACKETS_QUE_SIZE];
} APPLI_PENDING_PACKETS;

#pragma pack(pop)
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/


/* Private variables ---------------------------------------------------------*/

MOBLEUINT8 pGeneric_OnOffParam[sizeof(Generic_OnOffParam_t)];
MOBLEUINT8 pGeneric_LevelParam[sizeof(Generic_LevelParam_t)];
MOBLEUINT8 pGeneric_DeltaLevelParam[sizeof(Generic_DeltaLevelParam_t)];
MOBLEUINT8 pGeneric_MoveLevelParam[sizeof(Generic_LevelMoveParam_t)];
MOBLEUINT8 pGeneric_PowerOnOffParam[sizeof(Generic_PowerOnOffParam_t)];
MOBLEUINT8 pGeneric_DefaultTransitionTimeParam[sizeof(Generic_DefaultTransitionParam_t)];

MOBLEUINT8 pLightnessParam[sizeof(Light_LightnessParam_t)];
MOBLEUINT8 pLightnessRangeParam[sizeof(Light_LightnessRangeParam_t)];

MOBLEUINT8 pLightCtlParam[sizeof(Light_CtlParam_t)];
MOBLEUINT8 pLightCtlTemperatureParam[sizeof(Light_CtlTemperatureParam_t)];
MOBLEUINT8 pLightCtlTemperatureRangeParam[sizeof(Light_CtlTemperatureRangeParam_t)];
MOBLEUINT8 pLightCtlDefaultParam[sizeof(Light_CtlDefaultParam_t)];

MOBLEUINT8 pLightHslParam[sizeof(Light_HslParam_t)];
MOBLEUINT8 pLightHslRangeParam[sizeof(Light_HslRangeParam_t)];
MOBLEUINT8 pLightHslHueParam[sizeof(Light_HslHueParam_t)];
MOBLEUINT8 pLightHslSaturationParam[sizeof(Light_HslSaturationParam_t)];

MOBLEUINT8 pLightLCModeParam[sizeof(Light_LC_ModeParam_t)];
MOBLEUINT8 pLightLCOccupancyModeParam[sizeof(Light_LC_ModeParam_t)];
MOBLEUINT8 pLightLCOnOffParam[sizeof(Light_LC_OnOffParam_t)];
MOBLEUINT8 pLightLCPropertyParam[6];

MOBLEUINT8 pSensorsCadenceParam[sizeof(sensor_CadenceCbParam_t)];
MOBLEUINT8 pSensorsSettingParam[sizeof(sensor_SettingCbParams_t)];

APPLI_PENDING_PACKETS Appli_PendingPackets = {0};

__attribute__((aligned(4)))const MOBLE_VENDOR_CB_MAP vendor_cb = 
{
  Vendor_WriteLocalDataCb,
  Vendor_ReadLocalDataCb,
  Vendor_OnResponseDataCb
};

__attribute__((aligned(4)))const Appli_Vendor_cb_t VendorAppli_cb = 
{
  /*Vendor Commads*/
  Appli_Vendor_LEDControl,              /// Vendor_WriteLocalDataCb with command = APPLI_LED_CONTROL_STATUS_CMD 
  Appli_Vendor_DeviceInfo,              /// Vendor_WriteLocalDataCb with command = APPLI_DEVICE_INFO_CMD
  Appli_Vendor_Test,                    /// Vendor_WriteLocalDataCb with command = APPLI_TEST_CMD
  Appli_LedCtrl,                        /// Vendor_ReadLocalDataCb with command  = APPLI_LED_CONTROL_STATUS_CMD
  Appli_GetTestValue,                   /// Vendor_ReadLocalDataCb with command  = APPLI_TEST_CMD
  Appli_Vendor_Data_write               /// Vendor_WriteLocalDataCb with command = APPLI_DATA_CNTRL_CMD 
};

__attribute__((aligned(4)))const Appli_Generic_cb_t GenericAppli_cb = 
{
  /* Generic OnOff callbacks */
  Appli_Generic_OnOff_Set,
  /* Generic OnOff Status callbacks */
  Appli_Generic_OnOff_Status,
  /* Generic Level callbacks */
  Appli_Generic_Level_Set,
  Appli_Generic_Delta_Set,
  Appli_Generic_Move_Set,
  /* Generic Level Status callbacks */ 
  Appli_Generic_Level_Status,
  /* Generic Power on off callbacks */
  Appli_Generic_PowerOnOff_Set,
  /* Generic Power on off callbacks */
  Appli_Generic_PowerOnOff_Status,
    
  /* Generic Default transition time callbacks */  
  Appli_Generic_DefaultTransitionTime_Set,
  /* Generic Default transition time callbacks */
  Appli_Generic_DefaultTransitionTime_Status
};

__attribute__((aligned(4)))const Appli_Generic_State_cb_t Appli_GenericState_cb =
{
  
  /* Generic Get On Off status */
  Appli_Generic_GetOnOffStatus,
  Appli_Generic_GetOnOffValue,
  /* Generic Get level status */
  Appli_Generic_GetLevelStatus,
 /* Generic Get Power on off status */
  Appli_Generic_GetPowerOnOffStatus, 
 /* Generic Get Default transition time status */
  Appli_Generic_GetDefaultTransitionStatus
};

__attribute__((aligned(4)))const Appli_Light_GetStatus_cb_t Appli_Light_GetStatus_cb = 
{
  Appli_Light_GetLightnessStatus,
  Appli_Light_GetLightnessLinearStatus,
  Appli_Light_GetLightnessDefaultStatus,
  Appli_Light_GetLightnessLastStatus,
  Appli_Light_GetLightnessRangeStatus,
  Appli_Light_GetCtlLightStatus,
  Appli_Light_GetCtlTargetStatus,
  Appli_Light_GetCtlTemperatureStatus,
  Appli_Light_GetCtlTemperatureRange,
  Appli_Light_GetCtlDefaultStatus,
  Appli_Light_GetHslStatus,
  Appli_Light_GetHslTargetStatus,
  Appli_Light_GetHslHueStatus,
  Appli_Light_GetHslSaturationStatus,
  Appli_Light_GetHslHueRange,
  Appli_Light_GetHslSatRange,
  Appli_Light_GetHslDefaultStatus  
};


__attribute__((aligned(4)))const Appli_Light_cb_t LightAppli_cb = 
{
  /* Light Lightness callbacks */
  Appli_Light_Lightness_Set,
  Appli_Light_Lightness_Status,
  
  Appli_Light_Lightness_Linear_Set,
  Appli_Light_Lightness_Linear_Status,
  
  Appli_Light_Lightness_Default_Set,
  Appli_Light_Lightness_Default_Status,
  
  Appli_Light_Lightness_Last_Set,
  Appli_Light_Lightness_Last_Status,

  Appli_Light_Lightness_Range_Set,
  Appli_Light_Lightness_Range_Status,
  
  Appli_Light_Ctl_Set,
  Appli_Light_Ctl_Status,
  
  Appli_Light_CtlTemperature_Set,
  Appli_Light_CtlTemperature_Status,
  
  Appli_Light_CtlTemperature_Range_Set,
  Appli_Light_CtlTemperature_Range_Status,
  
  Appli_Light_CtlDefault_Set,
  Appli_Light_CtlDefault_Status,
  
  Appli_Light_Hsl_Set,
  Appli_Light_Hsl_Status,
  
  Appli_Light_HslHue_Set,
  Appli_Light_HslHue_Status,
  
  Appli_Light_HslSaturation_Set,
  Appli_Light_HslSaturation_Status,
  
  Appli_Light_HslDefault_Set,
  Appli_Light_HslDefault_Status,
  
  Appli_Light_HslRange_Set,
  Appli_Light_HslRange_Status
};

/*#ifdef ENABLE_SENSOR_MODEL_CLIENT*/
__attribute__((aligned(4))) const sensor_client_cb_t SensorAppli_cb = 
{
  Appli_Sensor_Descriptor_Status,
  Appli_Sensor_Cadence_Status,
  Appli_Sensor_Settings_Status,
  Appli_Sensor_Setting_Status,
  Appli_Sensor_Status,
  Appli_Sensor_Column_Status,
  Appli_Sensor_Series_Status
};
/*#endif*/

__attribute__((aligned(4)))const MODEL_SIG_cb_t Model_SIG_cb[] = 
{
#ifdef ENABLE_GENERIC_MODEL_SERVER  
  {
    GenericModelServer_GetOpcodeTableCb,
    GenericModelServer_GetStatusRequestCb,
    GenericModelServer_ProcessMessageCb
  },
#endif
  
#ifdef ENABLE_LIGHT_MODEL_SERVER
  {
    LightModelServer_GetOpcodeTableCb,
    LightModelServer_GetStatusRequestCb,
    LightModelServer_ProcessMessageCb
  },
#endif
  
#ifdef ENABLE_SENSOR_MODEL_SERVER
{
  SensorModelServer_GetOpcodeTableCb,
  SensorModelServer_GetStatusRequestCb,
  SensorModelServer_ProcessMessageCb
  },
#endif
  
#ifdef ENABLE_TIME_SCENE_MODEL_SERVER
  {
    Time_SceneModelServer_GetOpcodeTableCb,
    Time_SceneModelServer_GetStatusRequestCb,
    Time_SceneModelServer_ProcessMessageCb
  },
#endif
  
#ifdef ENABLE_LIGHT_MODEL_SERVER_LC
  {
    LightLcServer_GetOpcodeTableCb,
    LightLcServer_GetStatusRequestCb,
    LightLcServer_ProcessMessageCb
  },
#endif
  
#ifdef ENABLE_GENERIC_MODEL_CLIENT
  {
    GenericModelClient_GetOpcodeTableCb,
    GenericModelClient_GetStatusRequestCb,
    GenericModelClient_ProcessMessageCb
  },
#endif  
  
#ifdef ENABLE_CONFIG_MODEL_CLIENT
  {
    ConfigClientModel_GetOpcodeTableCb,
    ConfigClientModel_GetStatusRequestCb,
    ConfigClientModel_ProcessMessageCb
  },
#endif
#ifdef ENABLE_LIGHT_MODEL_CLIENT
  {
    LightModelClient_GetOpcodeTableCb,
    LightModelClient_GetStatusRequestCb,
    LightModelClient_ProcessMessageCb
  },
#endif  
  
#ifdef ENABLE_SENSOR_MODEL_CLIENT
  {
    SensorsModelClient_GetOpcodeTableCb,
    SensorsModelClient_GetStatusRequestCb,
    SensorsModelClient_ProcessMessageCb
  },
#endif  
  
  { 
    0, 0, 0 
  }
};

__attribute__((aligned(4)))const APPLI_SAVE_MODEL_STATE_CB SaveModelState_cb = AppliNvm_SaveModelState;

#if 0
__attribute__((aligned(4)))const APPLI_SAVE_MODEL_TEST_STATE_CB SaveModelTestState_cb = AppliNVM_Save_FlashTesting;
__attribute__((aligned(4)))const APPLI_RETRIEVE_MODEL_TEST_STATE_CB RetrieveModelTestState_cb = AppliNVM_Retrieve_FlashTesting;
#endif

#define MODEL_SIG_COUNT ( ( sizeof(Model_SIG_cb)/sizeof(Model_SIG_cb[0]) - 1 ))
                                   
__attribute__((aligned(4)))const MODEL_Vendor_cb_t Model_Vendor_cb[] = 
{
#ifdef ENABLE_VENDOR_MODEL_SERVER  
  {
    VendorModel_PID1_GetOpcodeTableCb,
    VendorModel_PID1_GetStatusRequestCb,
    VendorModel_PID1_ProcessMessageCb
  },
#endif  
  { 0, 0,0 }
};

#define MODEL_VENDOR_COUNT ( ( sizeof(Model_Vendor_cb)/sizeof(Model_Vendor_cb[0]) - 1 ))

extern MOBLEUINT8 NumberOfElements;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

void GetApplicationVendorModels(const MODEL_Vendor_cb_t** pModelsTable, MOBLEUINT32* VendorModelscount)
{
  *pModelsTable = Model_Vendor_cb       ;
  *VendorModelscount = MODEL_VENDOR_COUNT;
  
   TRACE_M(TF_VENDOR_M, "GetApplicationVendorModels \r\n");
}

/**
* @brief  Initialization Commands for Models
* @param  void
* @retval void
*/    
void BLEMesh_ModelsInit(void)
{
  
#ifdef ENABLE_SAVE_MODEL_STATE_NVM
  
  MOBLEUINT16 modelStateLoad_Size;
  MOBLEUINT8 modelStateLoadBuff[APP_NVM_MODEL_SIZE];    
  
#ifdef CLIENT
  MOBLEUINT8 PrvnStateLoad_Size;
  MOBLEUINT8 PrvnlStateLoadBuff[16]; 
#endif
  
#if 0
#ifdef ENABLE_NVM_TEST	
  /* Testing of flash code */
  Device_FlashTesting();
#endif	
#endif
  
  /* Inintialise the light model range states with default values */
  Light_ModelRangeInit();
  
  /* Callbacks used by BlueNRG-Mesh Models */
  BLEMesh_SetSIGModelsCbMap(Model_SIG_cb, MODEL_SIG_COUNT);
 
#if defined ENABLE_SENSOR_MODEL_SERVER && !defined CUSTOM_BOARD_PWM_SELECTION  
  /* Initialization of sensors */
  Appli_Sensor_Init();
#endif  

  Appli_Light_LCs_Init();
#endif  
  
  /* Load generic model states from nvm */
  AppliNvm_LoadModelState(modelStateLoadBuff, &modelStateLoad_Size);
  if (modelStateLoad_Size != 0)
  {
    /* update states of generic model */
    Model_RestoreStates(modelStateLoadBuff, modelStateLoad_Size);
  }
  
#ifdef CLIENT
  AppliPrvnNvm_LoadData(PrvnlStateLoadBuff,&PrvnStateLoad_Size);
#endif
  
}

/**
* @brief  Process Commands for Models
* @param  void
* @retval void
*/    
void BLEMesh_ModelsProcess(void)
{
#ifdef ENABLE_GENERIC_MODEL_SERVER  
  Generic_Process();
#endif

#ifdef ENABLE_LIGHT_MODEL_SERVER  
  Lighting_Process();
#endif

#ifdef ENABLE_VENDOR_MODEL_SERVER  
  Vendor_Process();
#endif  
/* Define this Macro to enable the publication of sensors data.*/ 
#if defined ENABLE_SENSOR_MODEL_SERVER 
  Sensor_Process();
#endif  

#if ENABLE_APPLI_TEST  
  Test_Process();
#endif   

#ifdef ENABLE_SAVE_MODEL_STATE_NVM  
  ModelSave_Process();
#endif
  
#ifdef ENABLE_LIGHT_MODEL_SERVER_LC   
  Light_LC_Process();
#endif
}

/**
* @brief  Publish Command for Models
* @param  void
* @retval void
*/    
void BLEMesh_ModelsCommand(void)
{
#ifdef VENDOR_CLIENT_MODEL_PUBLISH     
  Appli_Vendor_Publish(BLEMesh_GetAddress());
#endif
  
#if defined(GENERIC_CLIENT_MODEL_PUBLISH) || defined(LIGHT_CLIENT_MODEL_PUBLISH) 
  Led_Value ^= APPLI_LED_ON;
  pGeneric_OnOffParam[0] = Led_Value;    /* OnOff parameter byte 0 : The target value of the Generic Onoff state */  
  
  pLightLCModeParam[0] = Led_Value;
  pLightLCOccupancyModeParam[0] = Led_Value;
  pLightLCOnOffParam[0] = Led_Value;
  
  /*This Switch-case allows to quickly set the different Models Messages parameters in order to demonstrate Client APIs functionning */
  switch (ButtonIndex_Value){
  case 0:
    ButtonIndex_Value=0x1;
    
    pGeneric_LevelParam[0]= 0xE8;           /* Level parameter byte 0 : The target value of the Generic Level state */
    pGeneric_LevelParam[1]= 0x03;           /* Level parameter byte 1 : The target value of the Generic Level state */
    
    pGeneric_DeltaLevelParam[0]= 0xE8;      /* Delta Level parameter byte 0 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[1]= 0x03;      /* Delta Level parameter byte 1 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[2]= 0x00;      /* Delta Level parameter byte 2 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[3]= 0x00;      /* Delta Level parameter byte 3 : The Delta change of the Generic Level state */
    
    pGeneric_MoveLevelParam[0]= 0xE8;       /*Move Delta Level parameter byte 0 : The Delta Level step to calculate Move speed for the Generic Level state */
    pGeneric_MoveLevelParam[1]= 0x03;       /*Move Delta  Level parameter byte 1 : The Delta Level step to calculate Move speed for the Generic Level state */
    
    pGeneric_DefaultTransitionTimeParam[0]=0x0F;    /*Transition time parameter byte 0 : The value of the Generic Default Transition Time state */
    
    pGeneric_PowerOnOffParam[0]=0x1;        /*OnPowerUp parameter byte 0 : The value of the Generic OnPowerUp state */
    
    pLightnessParam[0] = 0xE8;              /*Lightness parameter byte 0 : The target value of the Light Lightness Actual/Linear/Default state */
    pLightnessParam[1] = 0x03;              /*Lightness parameter byte 1 : The target value of the Light Lightness Actual/Linear/Default state */
    
    pLightnessRangeParam[0] = 0xE8;         /*Lightness Range Min parameter byte 0 : The value of the Lightness Range Min field of the Light Lightness Range state */
    pLightnessRangeParam[1] = 0x03;         /*Lightness Range Min parameter byte 1 : The value of the Lightness Range Min field of the Light Lightness Range state */
    pLightnessRangeParam[2] = 0x88;         /*Lightness Range Max parameter byte 0 : The value of the Lightness Range Max field of the Light Lightness Range state */
    pLightnessRangeParam[3] = 0x13;         /*Lightness Range Max parameter byte 1 : The value of the Lightness Range Max field of the Light Lightness Range state */
    
    pLightCtlParam[0] = 0xE8;               /*CTL Lightness parameter byte 0 : The target value of the Light CTL Lightness state */
    pLightCtlParam[1] = 0x03;               /*CTL Lightness parameter byte 1 : The target value of the Light CTL Lightness state */
    pLightCtlParam[2] = 0xE8;               /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature state */
    pLightCtlParam[3] = 0x03;               /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature state */
    pLightCtlParam[4] = 0xE8;               /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV state */
    pLightCtlParam[5] = 0x03;               /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV state */
    
    pLightCtlTemperatureParam[0] = 0xE8;    /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature state */
    pLightCtlTemperatureParam[1] = 0x03;    /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature state */
    pLightCtlTemperatureParam[2] = 0xE8;    /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV state */
    pLightCtlTemperatureParam[3] = 0x03;    /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV state */
    
    pLightCtlTemperatureRangeParam[0] = 0xE8;       /*Temperature Range Min parameter byte 0 : The value of the Temperature Range Min field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[1] = 0x03;       /*Temperature Range Min parameter byte 1 : The value of the Temperature Range Min field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[2] = 0x88;       /*Temperature Range Max parameter byte 0 : The value of the Temperature Range Max field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[3] = 0x13;       /*Temperature Range Max parameter byte 1 : The value of the Temperature Range Max field of the Light CTL Temperature Range state */
    
    pLightCtlDefaultParam[0] = 0xE8;        /*CTL Lightness parameter byte 0 : The target value of the Light CTL Lightness Default state*/
    pLightCtlDefaultParam[1] = 0x03;        /*CTL Lightness parameter byte 1 : The target value of the Light CTL Lightness Default state*/
    pLightCtlDefaultParam[2] = 0xE8;        /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature Default state*/
    pLightCtlDefaultParam[3] = 0x03;        /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature Default state*/
    pLightCtlDefaultParam[4] = 0xE8;        /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV Default state*/
    pLightCtlDefaultParam[5] = 0x03;        /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV Default state*/
    /** Red color **/    
    pLightHslParam[0] = 0x44;               /*HSL Lightness parameter byte 0 : The target value of the Light HSL Lightness state*/
    pLightHslParam[1] = 0x44;               /*HSL Lightness parameter byte 1 : The target value of the Light HSL Lightness state*/
    pLightHslParam[2] = 0x64;               /*HSL Hue parameter byte 0 : The target value of the Light HSL Hue state*/
    pLightHslParam[3] = 0x04;               /*HSL Hue parameter byte 1 : The target value of the Light HSL Hue state*/
    pLightHslParam[4] = 0xff;               /*HSL Saturation parameter byte 0 : The target value of the Light HSL Saturation state*/
    pLightHslParam[5] = 0xff;               /*HSL Saturation parameter byte 1 : The target value of the Light HSL Saturation state*/
        
    pLightHslRangeParam[0] = 0xE8;          /*HSL Hue Range Min parameter byte 0 : The value of the Hue Range Min field of the Light HSL Hue Range state*/
    pLightHslRangeParam[1] = 0x03;          /*HSL Hue Range Min parameter byte 1 : The value of the Hue Range Min field of the Light HSL Hue Range state*/
    pLightHslRangeParam[2] = 0x88;          /*HSL Hue Range Max parameter byte 0 : The value of the Hue Range Max field of the Light HSL Hue Range state*/
    pLightHslRangeParam[3] = 0x13;          /*HSL Hue Range Max parameter byte 1 : The value of the Hue Range Max field of the Light HSL Hue Range state*/
    pLightHslRangeParam[4] = 0x88;          /*HSL Saturation Min parameter byte 0 : The value of the Saturation Range Min field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[5] = 0x13;          /*HSL Saturation Min parameter byte 1 : The value of the Saturation Range Min field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[6] = 0x70;          /*HSL Saturation Max parameter byte 0 : The value of the Saturation Range Max field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[7] = 0x17;          /*HSL Saturation Max parameter byte 1 : The value of the Saturation Range Max field of the Light HSL Saturation Range state*/
    
    pLightHslHueParam[0] = 0xE8;            /*HSL Hue parameter byte 0 : The target value of the Light HSL Hue state*/
    pLightHslHueParam[1] = 0x03;            /*HSL Hue parameter byte 1 : The target value of the Light HSL Hue state*/
    
    pLightHslSaturationParam[0] = 0xE8;     /*HSL Saturation parameter byte 0 : The target value of the Light HSL Saturation state*/
    pLightHslSaturationParam[1] = 0x03;     /*HSL Saturation parameter byte 1 : The target value of the Light HSL Saturation state*/
    
    /*LIGHT_CONTROL_AMBIENT_LUXLEVEL_ON_PID  : 0x002B*/
    pLightLCPropertyParam[0]= 0x2B;           /* Property ID byte 0 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[1]= 0x00;           /* Property ID byte 1 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[2]= 0x44;           /* Property ID byte 0 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[3]= 0x44;           /* Property ID byte 1 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[4]= 0x44;           /* Property ID byte 2 : Property ID identifying a Light LC Property.*/
    break;
    
  case 1:
    ButtonIndex_Value=0x2;
    
    pGeneric_LevelParam[0]= 0xff;           /* Level parameter byte 0 : The target value of the Generic Level state */
    pGeneric_LevelParam[1]= 0x7f;           /* Level parameter byte 1 : The target value of the Generic Level state */
    
    pGeneric_DeltaLevelParam[0]= 0x10;      /* Delta Level parameter byte 0 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[1]= 0x27;      /* Delta Level parameter byte 1 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[2]= 0x00;      /* Delta Level parameter byte 2 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[3]= 0x00;      /* Delta Level parameter byte 3 : The Delta change of the Generic Level state */
    
    pGeneric_MoveLevelParam[0]= 0xff;       /*Move Delta Level parameter byte 0 : The Delta Level step to calculate Move speed for the Generic Level state */
    pGeneric_MoveLevelParam[1]= 0x7f;       /*Move Delta  Level parameter byte 1 : The Delta Level step to calculate Move speed for the Generic Level state */
    
    pGeneric_DefaultTransitionTimeParam[0]=0x10;    /*Transition time parameter byte 0 : The value of the Generic Default Transition Time state */
    
    pGeneric_PowerOnOffParam[0]=0x2;        /*OnPowerUp parameter byte 0 : The value of the Generic OnPowerUp state. */
    
    pLightnessParam[0] = 0xff;              /*Lightness parameter byte 0 : The target value of the Light Lightness Actual/Linear/Default state */
    pLightnessParam[1] = 0xff;              /*Lightness parameter byte 1 : The target value of the Light Lightness Actual/Linear/Default state */
    
    pLightnessRangeParam[0] = 0x00;         /*Lightness Range Min parameter byte 0 : The value of the Lightness Range Min field of the Light Lightness Range state */
    pLightnessRangeParam[1] = 0x00;         /*Lightness Range Min parameter byte 1 : The value of the Lightness Range Min field of the Light Lightness Range state */
    pLightnessRangeParam[2] = 0xff;         /*Lightness Range Max parameter byte 0 : The value of the Lightness Range Max field of the Light Lightness Range state */
    pLightnessRangeParam[3] = 0xff;         /*Lightness Range Max parameter byte 1 : The value of the Lightness Range Max field of the Light Lightness Range state */
    
    pLightCtlParam[0] = 0xff;               /*CTL Lightness parameter byte 0 : The target value of the Light CTL Lightness state */
    pLightCtlParam[1] = 0xff;               /*CTL Lightness parameter byte 1 : The target value of the Light CTL Lightness state */
    pLightCtlParam[2] = 0x20;               /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature state */
    pLightCtlParam[3] = 0x4e;               /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature state */
    pLightCtlParam[4] = 0xff;               /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV state */
    pLightCtlParam[5] = 0x7f;               /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV state */
    
    pLightCtlTemperatureParam[0] = 0x20;    /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature state */
    pLightCtlTemperatureParam[1] = 0x4e;    /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature state */
    pLightCtlTemperatureParam[2] = 0xff;    /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV state */
    pLightCtlTemperatureParam[3] = 0x7f;    /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV state */
    
    pLightCtlTemperatureRangeParam[0] = 0x19;       /*Temperature Range Min parameter byte 0 : The value of the Temperature Range Min field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[1] = 0x4e;       /*Temperature Range Min parameter byte 1 : The value of the Temperature Range Min field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[2] = 0x20;       /*Temperature Range Max parameter byte 0 : The value of the Temperature Range Max field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[3] = 0x4e;       /*Temperature Range Max parameter byte 1 : The value of the Temperature Range Max field of the Light CTL Temperature Range state */
    
    pLightCtlDefaultParam[0] = 0xff;        /*CTL Lightness parameter byte 0 : The target value of the Light CTL Lightness Default state*/
    pLightCtlDefaultParam[1] = 0xff;        /*CTL Lightness parameter byte 1 : The target value of the Light CTL Lightness Default state*/
    pLightCtlDefaultParam[2] = 0x20;        /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature Default state*/
    pLightCtlDefaultParam[3] = 0x4e;        /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature Default state*/
    pLightCtlDefaultParam[4] = 0xff;        /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV Default state*/
    pLightCtlDefaultParam[5] = 0x7f;        /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV Default state*/
    /** Green color **/      
    pLightHslParam[0] = 0xc6;               /*HSL Lightness parameter byte 0 : The target value of the Light HSL Lightness state*/
    pLightHslParam[1] = 0x46;               /*HSL Lightness parameter byte 1 : The target value of the Light HSL Lightness state*/
    pLightHslParam[2] = 0x19;               /*HSL Hue parameter byte 0 : The target value of the Light HSL Hue state*/
    pLightHslParam[3] = 0x51;               /*HSL Hue parameter byte 1 : The target value of the Light HSL Hue state*/
    pLightHslParam[4] = 0xd7;               /*HSL Saturation parameter byte 0 : The target value of the Light HSL Saturation state*/
    pLightHslParam[5] = 0xed;               /*HSL Saturation parameter byte 1 : The target value of the Light HSL Saturation state*/
        
    pLightHslRangeParam[0] = 0x00;          /*HSL Hue Range Min parameter byte 0 : The value of the Hue Range Min field of the Light HSL Hue Range state*/
    pLightHslRangeParam[1] = 0xf0;          /*HSL Hue Range Min parameter byte 1 : The value of the Hue Range Min field of the Light HSL Hue Range state*/
    pLightHslRangeParam[2] = 0xff;          /*HSL Hue Range Max parameter byte 0 : The value of the Hue Range Max field of the Light HSL Hue Range state*/
    pLightHslRangeParam[3] = 0xff;          /*HSL Hue Range Max parameter byte 1 : The value of the Hue Range Max field of the Light HSL Hue Range state*/
    pLightHslRangeParam[4] = 0x00;          /*HSL Saturation Min parameter byte 0 : The value of the Saturation Range Min field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[5] = 0xe0;          /*HSL Saturation Min parameter byte 1 : The value of the Saturation Range Min field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[6] = 0xff;          /*HSL Saturation Max parameter byte 0 : The value of the Saturation Range Max field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[7] = 0xef;          /*HSL Saturation Max parameter byte 1 : The value of the Saturation Range Max field of the Light HSL Saturation Range state*/
    
    pLightHslHueParam[0] = 0xff;            /*HSL Hue parameter byte 0 : The target value of the Light HSL Hue state*/
    pLightHslHueParam[1] = 0xff;            /*HSL Hue parameter byte 1 : The target value of the Light HSL Hue state*/
    
    pLightHslSaturationParam[0] = 0xff;     /*HSL Saturation parameter byte 0 : The target value of the Light HSL Saturation state*/
    pLightHslSaturationParam[1] = 0xff;     /*HSL Saturation parameter byte 1 : The target value of the Light HSL Saturation state*/
    
    /*LIGHT_CONTROL_AMBIENT_LUXLEVEL_ON_PID  : 0x002B*/
    pLightLCPropertyParam[0]= 0x2B;           /* Property ID byte 0 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[1]= 0x00;           /* Property ID byte 1 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[2]= 0x01;           /* Property ID byte 0 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[3]= 0x00;           /* Property ID byte 1 : Property ID identifying a Light LC Property.*/   
    pLightLCPropertyParam[4]= 0x10;           /* Property ID byte 2 : Property ID identifying a Light LC Property.*/
    break;
    
  case 2:
    ButtonIndex_Value=0x0;
    
    pGeneric_LevelParam[0]= 0x00;           /* Level parameter byte 0 : The target value of the Generic Level state */ 
    pGeneric_LevelParam[1]= 0x00;           /* Level parameter byte 1 : The target value of the Generic Level state */
    
    pGeneric_DeltaLevelParam[0]= 0x00;      /* Delta Level parameter byte 0 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[1]= 0x00;      /* Delta Level parameter byte 1 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[2]= 0x00;      /* Delta Level parameter byte 2 : The Delta change of the Generic Level state */
    pGeneric_DeltaLevelParam[3]= 0x00;      /* Delta Level parameter byte 3 : The Delta change of the Generic Level state */
    
    pGeneric_MoveLevelParam[0]= 0x00;       /*Move Delta Level parameter byte 0 : The Delta Level step to calculate Move speed for the Generic Level state */
    pGeneric_MoveLevelParam[1]= 0x00;       /*Move Delta  Level parameter byte 1 : The Delta Level step to calculate Move speed for the Generic Level state */
    
    pGeneric_DefaultTransitionTimeParam[0]=0x00;    /*Transition time parameter byte 0 : The value of the Generic Default Transition Time state */
    
    pGeneric_PowerOnOffParam[0]=0x0;        /*OnPowerUp parameter byte 0 : The value of the Generic OnPowerUp state. */
    
    pLightnessParam[0] = 0x00;              /*Lightness parameter byte 0 : The target value of the Light Lightness Actual/Linear/Default state */
    pLightnessParam[1] = 0x00;              /*Lightness parameter byte 1 : The target value of the Light Lightness Actual/Linear/Default state */
    
    pLightnessRangeParam[0] = 0x00;         /*Lightness Range Min parameter byte 0 : The value of the Lightness Range Min field of the Light Lightness Range state */
    pLightnessRangeParam[1] = 0x00;         /*Lightness Range Min parameter byte 1 : The value of the Lightness Range Min field of the Light Lightness Range state */
    pLightnessRangeParam[2] = 0x00;         /*Lightness Range Max parameter byte 0 : The value of the Lightness Range Max field of the Light Lightness Range state */
    pLightnessRangeParam[3] = 0x10;         /*Lightness Range Max parameter byte 1 : The value of the Lightness Range Max field of the Light Lightness Range state */
    
    pLightCtlParam[0] = 0x00;               /*CTL Lightness parameter byte 0 : The target value of the Light CTL Lightness state */
    pLightCtlParam[1] = 0x00;               /*CTL Lightness parameter byte 1 : The target value of the Light CTL Lightness state */
    pLightCtlParam[2] = 0x20;               /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature state */
    pLightCtlParam[3] = 0x03;               /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature state */
    pLightCtlParam[4] = 0x00;               /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV state */
    pLightCtlParam[5] = 0x00;               /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV state */
    
    pLightCtlTemperatureParam[0] = 0x20;    /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature state */
    pLightCtlTemperatureParam[1] = 0x03;    /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature state */
    pLightCtlTemperatureParam[2] = 0x00;    /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV state */
    pLightCtlTemperatureParam[3] = 0x00;    /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV state */
    
    pLightCtlTemperatureRangeParam[0] = 0x20;       /*Temperature Range Min parameter byte 0 : The value of the Temperature Range Min field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[1] = 0x03;       /*Temperature Range Min parameter byte 1 : The value of the Temperature Range Min field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[2] = 0x21;       /*Temperature Range Max parameter byte 0 : The value of the Temperature Range Max field of the Light CTL Temperature Range state */
    pLightCtlTemperatureRangeParam[3] = 0x03;       /*Temperature Range Max parameter byte 1 : The value of the Temperature Range Max field of the Light CTL Temperature Range state */
    
    pLightCtlDefaultParam[0] = 0x00;        /*CTL Lightness parameter byte 0 : The target value of the Light CTL Lightness Default state */
    pLightCtlDefaultParam[1] = 0x00;        /*CTL Lightness parameter byte 1 : The target value of the Light CTL Lightness Default state */
    pLightCtlDefaultParam[2] = 0x20;        /*CTL Temperature parameter byte 0 : The target value of the Light CTL Temperature Default state */
    pLightCtlDefaultParam[3] = 0x03;        /*CTL Temperature parameter byte 1 : The target value of the Light CTL Temperature Default state */
    pLightCtlDefaultParam[4] = 0x00;        /*CTL Delta UV parameter byte 0 : The target value of the Light CTL Delta UV Default state */
    pLightCtlDefaultParam[5] = 0x00;        /*CTL Delta UV parameter byte 1 : The target value of the Light CTL Delta UV Default state */
    
    pLightHslParam[0] = 0x00;               /*HSL Lightness parameter byte 0 : The target value of the Light HSL Lightness state */
    pLightHslParam[1] = 0x00;               /*HSL Lightness parameter byte 1 : The target value of the Light HSL Lightness state */
    pLightHslParam[2] = 0x00;               /*HSL Hue parameter byte 0 : The target value of the Light HSL Hue state */
    pLightHslParam[3] = 0x00;               /*HSL Hue parameter byte 1 : The target value of the Light HSL Hue state */
    pLightHslParam[4] = 0x00;               /*HSL Saturation parameter byte 0 : The target value of the Light HSL Saturation state */
    pLightHslParam[5] = 0x00;               /*HSL Saturation parameter byte 1 : The target value of the Light HSL Saturation state */
    
    pLightHslRangeParam[0] = 0x00;          /*HSL Hue Range Min parameter byte 0 : The value of the Hue Range Min field of the Light HSL Hue Range state*/
    pLightHslRangeParam[1] = 0x00;          /*HSL Hue Range Min parameter byte 1 : The value of the Hue Range Min field of the Light HSL Hue Range state*/
    pLightHslRangeParam[2] = 0x00;          /*HSL Hue Range Max parameter byte 0 : The value of the Hue Range Max field of the Light HSL Hue Range state*/
    pLightHslRangeParam[3] = 0x10;          /*HSL Hue Range Max parameter byte 1 : The value of the Hue Range Max field of the Light HSL Hue Range state*/
    pLightHslRangeParam[4] = 0x00;          /*HSL Saturation Min parameter byte 0 : The value of the Saturation Range Min field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[5] = 0x00;          /*HSL Saturation Min parameter byte 1 : The value of the Saturation Range Min field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[6] = 0x00;          /*SL Saturation Max parameter byte 0 : The value of the Saturation Range Max field of the Light HSL Saturation Range state*/
    pLightHslRangeParam[7] = 0x20;          /*HSL Saturation Max parameter byte 1 : The value of the Saturation Range Max field of the Light HSL Saturation Range state*/
    
    pLightHslHueParam[0] = 0x00;            /*HSL Hue parameter byte 0 : The target value of the Light HSL Hue state */
    pLightHslHueParam[1] = 0x00;            /*HSL Hue parameter byte 1 : The target value of the Light HSL Hue state */
    
    pLightHslSaturationParam[0] = 0x00;     /*HSL Saturation parameter byte 0 : The target value of the Light HSL Saturation state*/
    pLightHslSaturationParam[1] = 0x00;     /*HSL Saturation parameter byte 1 : The target value of the Light HSL Saturation state*/
    
    /*LIGHT_CONTROL_AMBIENT_LUXLEVEL_ON_PID  : 0x002B */
    pLightLCPropertyParam[0]= 0x2B;           /* Property ID byte 0 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[1]= 0x00;           /* Property ID byte 1 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[2]= 0x00;           /* Property ID byte 0 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[3]= 0x00;           /* Property ID byte 1 : Property ID identifying a Light LC Property.*/
    pLightLCPropertyParam[4]= 0x00;           /* Property ID byte 2 : Property ID identifying a Light LC Property.*/
    break;
    
  default:
    break;
  }
      
      
#ifdef GENERIC_CLIENT_MODEL_PUBLISH  
  /** GENERIC ONOFF **/  
/*      TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API ONOFF SET ACK ------------- \r\n");
        Appli_GenericClient_API(0, GENERIC_ON_OFF_SET_ACK, pGeneric_OnOffParam); 
 */
      TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API ONOFF SET UNACK ------------- \r\n");
      Appli_GenericClient_API(0, GENERIC_ON_OFF_SET_UNACK, pGeneric_OnOffParam);  
      
  /** GENERIC LEVEL **/  
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API LEVEL SET ACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_LEVEL_SET_ACK, pGeneric_LevelParam); */ 
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API LEVEL SET UNACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_LEVEL_SET_UNACK, pGeneric_LevelParam);  */
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API DELTA LEVEL SET ACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_DELTA_SET, pGeneric_DeltaLevelParam);*/  
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API DELTA LEVEL SET UNACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_DELTA_SET_UNACK, pGeneric_DeltaLevelParam); */ 
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API MOVE DELTA LEVEL SET ACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_MOVE_SET, pGeneric_MoveLevelParam); */ 
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API MOVE DELTA LEVEL SET UNACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_MOVE_SET_UNACK, pGeneric_MoveLevelParam);  */
      
  /** GENERIC POWER ONOFF **/  
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API POWER ON OFF SET ACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_POWER_ON_OFF_SET, pGeneric_PowerOnOffParam); */ 
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API POWER ON OFF SET UNACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_POWER_ON_OFF_SET_UNACK, pGeneric_PowerOnOffParam); */ 
      
  /** GENERIC TRANSITION TIME **/  
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API DEFAULT TRANSITION TIME SET ACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_DEFAULT_TRANSITION_TIME_SET, pGeneric_DefaultTransitionTimeParam);  */
/*  */
/*  TRACE_M(TF_GENERIC_CLIENT_M, "----------- Generic API DEFAULT TRANSITION TIME SET UNACK ------------- \r\n");*/
/*  Appli_GenericClient_API(0, GENERIC_DEFAULT_TRANSITION_TIME_SET_UNACK, pGeneric_DefaultTransitionTimeParam);  */
#endif
      
#ifdef  LIGHT_CLIENT_MODEL_PUBLISH
  /** LIGHT LIGHTNESS **/    
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_SET, pLightnessParam); */
/*  */
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_SET_UNACK, pLightnessParam); */   
      
  /** LIGHT LIGHTNESS LINEAR **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS SET LINEAR ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_LINEAR_SET, pLightnessParam); */ 
      
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS SET LINEAR UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_LINEAR_SET_UNACK, pLightnessParam); */   
      
  /** LIGHT LIGHTNESS DEFAULT **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS DEFAULT SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_DEFAULT_SET, pLightnessParam);  */
 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS DEFAULT SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_DEFAULT_SET_UNACK, pLightnessParam); */   
      
  /** LIGHT LIGHTNESS RANGE **/       
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS RANGE SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_RANGE_SET, pLightnessRangeParam);*/  
 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LIGHTNESS RANGE SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LIGHTNESS_RANGE_SET_UNACK, pLightnessRangeParam);*/    
      
  /** LIGHT LIGHTNESS CTL **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_SET, pLightCtlParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_SET_UNACK, pLightCtlParam);*/
      
  /** LIGHT LIGHTNESS CTL TEMPERATURE**/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL TEMPERATURE SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_TEMPERATURE_SET, pLightCtlTemperatureParam);*/  
      
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL TEMPERATURE SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_TEMPERATURE_SET_UNACK, pLightCtlTemperatureParam);*/
      
  /** LIGHT LIGHTNESS CTL TEMPERATURE RANGE**/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL TEMPERATURE RANGE SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_TEMPERATURE_RANGE_SET, pLightCtlTemperatureRangeParam);*/  
      
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL TEMPERATURE RANGE SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK, pLightCtlTemperatureRangeParam);*/
      
  /** LIGHT LIGHTNESS CTL DEFAULT**/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL DEFAULT SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_DEFAULT_SET, pLightCtlDefaultParam);*/  
      
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT CTL DEFAULT SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_CTL_DEFAULT_SET_UNACK, pLightCtlDefaultParam);*/
      
  /** LIGHT LIGHTNESS HSL **/
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_SET, pLightHslParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_SET_UNACK, pLightHslParam);*/
  
  /** LIGHT LIGHTNESS HSL DEFAULT **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL DEFAULT SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_DEFAULT_SET, pLightHslParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL DEFAULT SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_DEFAULT_SET_UNACK, pLightHslParam);*/
  
  /** LIGHT LIGHTNESS HSL RANGE **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL RANGE SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_RANGE_SET, pLightHslRangeParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL RANGE SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_RANGE_SET_UNACK, pLightHslRangeParam);*/
  
  /** LIGHT LIGHTNESS HSL HUE **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL HUE SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_HUE_SET, pLightHslHueParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL HUE SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_HUE_SET_UNACK, pLightHslHueParam);*/
  
  /** LIGHT LIGHTNESS HSL SATURATION **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL SATURATION SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_SATURATION_SET, pLightHslSaturationParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT HSL SATURATION SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_HSL_SATURATION_SET_UNACK, pLightHslSaturationParam);*/
  
  /** LIGHT LC MODE **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC MODE SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_MODE_SET, pLightLCModeParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC MODE SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_MODE_SET_UNACK, pLightLCModeParam);*/
  
  /** LIGHT LC OM **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC OM SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_OM_SET, pLightLCOccupancyModeParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC OM SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_OM_SET_UNACK, pLightLCOccupancyModeParam);*/
  
  /** LIGHT LC ONOFF **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC ONOFF SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_ON_OFF_SET, pLightLCOnOffParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC ONOFF SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_ON_OFF_SET_UNACK, pLightLCOnOffParam);*/   
  
  /** LIGHT LC PROPERTY **/ 
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC PROPERTY SET ACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_PROPERTY_SET, pLightLCPropertyParam);*/  
  
/*  TRACE_M(TF_LIGHT_CLIENT_M, "----------- API LIGHT LC PROPERTY SET UNACK ------------- \r\n");*/
/*  Appli_LightClient_API(0, LIGHT_LC_PROPERTY_SET_UNACK, pLightLCPropertyParam);*/   
#endif      
#endif  
      
 #ifdef ENABLE_SENSOR_MODEL_CLIENT    
  /** SENSOR CADENCE**/ 
  /* 
    PRESENT_AMBIENT_TEMPERATURE_PID : 0x004F
  */
  pSensorsCadenceParam[0]= 0x4F;           /* Property ID byte 0 : Property ID for the sensor.*/
  pSensorsCadenceParam[1]= 0x00;           /* Property ID byte 1 : Property ID for the sensor.*/
  
  pSensorsCadenceParam[2]= 0x81;           /* Fast Cadence Period Divisor bits 0-7: Divisor for the Publish Period.*/
                                           /* Status Trigger Type bit 8 : Defines the unit and format of the Status Trigger Delta fields.*/
  pSensorsCadenceParam[3]= 0x11;           /* Status Trigger Delta Down byte 0 : Delta down value that triggers a status message.*/
  pSensorsCadenceParam[4]= 0x11;           /* Status Trigger Delta Down byte 1 : Delta down value that triggers a status message.*/
  
  pSensorsCadenceParam[5]= 0x22;           /* Status Trigger Delta Up byte 0 : Delta down value that triggers a status message.*/
  pSensorsCadenceParam[6]= 0x22;           /* Status Trigger Delta Up byte 1 : Delta down value that triggers a status message.*/
  
  pSensorsCadenceParam[7]= 0x10;           /* Status Min Interval byte 0 : Minimum interval between two consecutive Status messages. */
  
  pSensorsCadenceParam[8]= 0x33;           /* Fast Cadence Low byte 0 : Low value for the fast cadence range.*/
  
  pSensorsCadenceParam[9]= 0x44;          /* Fast Cadence High byte 0 : High value for the fast cadence range.*/
  
/*  TRACE_M(TF_SENSOR_CLIENT_M, "----------- API SENSOR CADENCE SET ------------- \r\n");*/
/*  Appli_SensorsClient_API(0, SENSOR_CADENCE_SET, pSensorsCadenceParam);*/
  
/*  TRACE_M(TF_SENSOR_CLIENT_M, "----------- API SENSOR CADENCE SET UNACK ------------- \r\n");*/
/*  Appli_SensorsClient_API(0, SENSOR_CADENCE_SET_UNACK, pSensorsCadenceParam);*/  
  
  /** SENSOR SETTING**/ 
  /*      
      PRESENT_AMBIENT_TEMPERATURE_PID : 0x004F
      Second Property PID : 0x00AD
  */
  pSensorsSettingParam[0]= 0x4F;           /* Property ID byte 0 : Property ID for the sensor*/
  pSensorsSettingParam[1]= 0x00;           /* Property ID byte 1 : Property ID for the sensor*/
  pSensorsSettingParam[2]= 0xAD;           /* Sensor Setting Property ID byte 0 : Property ID for the sensor setting*/
  pSensorsSettingParam[3]= 0x00;           /* Sensor Setting Property ID byte 1 : Property ID for the sensor setting*/
  
  switch (ButtonIndex_Value){
  case 0:
    pSensorsSettingParam[4]= 0x10;           /* Sensor Setting Property ID byte 0 : Property ID for the sensor setting*/
    /*pSensorsSettingParam[5]= 0x10;*/           /* Sensor Setting Property ID byte 1 : Property ID for the sensor setting*/
    break;
  case 1:
    pSensorsSettingParam[4]= 0x20;           /* Sensor Setting Property ID byte 0 : Property ID for the sensor setting*/
    /*pSensorsSettingParam[5]= 0x20;*/           /* Sensor Setting Property ID byte 1 : Property ID for the sensor setting*/
    break;
  case 2:
    pSensorsSettingParam[4]= 0x0F;           /* Sensor Setting Property ID byte 0 : Property ID for the sensor setting*/
    /*pSensorsSettingParam[5]= 0x00;*/           /* Sensor Setting Property ID byte 1 : Property ID for the sensor setting*/
    break;
  default:
    break;
  }
/*  TRACE_M(TF_SENSOR_CLIENT_M, "----------- API SENSOR SETTING SET ------------- \r\n");*/
/*  Appli_SensorsClient_API(0, SENSOR_SETTING_SET, pSensorsSettingParam);*/
  
/*  TRACE_M(TF_SENSOR_CLIENT_M, "----------- API SENSOR SETTING SET UNACK ------------- \r\n");*/
/*  Appli_SensorsClient_API(0, SENSOR_SETTING_SET_UNACK, pSensorsSettingParam);*/  
#endif /* ENABLE_SENSOR_MODEL_CLIENT    */
  
      
/* if CLIENT and SERVER => Publish is already done in CLIENT */
#ifdef GENERIC_SERVER_MODEL_PUBLISH 
#ifndef GENERIC_CLIENT_MODEL_PUBLISH  
  Generic_Publish(BLEMesh_GetAddress());
#endif
#endif
}


/**
* @brief  Get the Element Number for selected Model 
* @param  dst_peer : Destination Address received
* @retval MOBLEUINT8 : elementNumber
*/ 
MOBLEUINT8 BLEMesh_ModelsGetElementNumber(MOBLE_ADDRESS dst_peer)
{
  
  MOBLE_ADDRESS nodeAddress;
  MOBLEUINT8 elementNumber;
  
  nodeAddress = BLEMesh_GetAddress();
  elementNumber = ((dst_peer - nodeAddress)+1);
  
  return elementNumber;
}

/**
* @brief  Get the Element Index for selected Model 
* @param  dst_peer : Destination Address received
* @retval MOBLEUINT8 : elementIndex
*/ 
MOBLEUINT8 BLEMesh_ModelsGetElementIndex(MOBLE_ADDRESS dst_peer)
{
  
  MOBLE_ADDRESS nodeAddress;
  MOBLEUINT8 elementIndex;
  
  nodeAddress = BLEMesh_GetAddress();
  elementIndex =(dst_peer - nodeAddress);
  
  return elementIndex;
}
  

/**
* @brief  Schedule a packet to be sent with randomized send timestamp  
*         If a que is empty, random timestamp is calculated
*         Subsequent packets are sent in sequence
* @param  *pmsgParam Pointer to structure of message header for parameters:
*          elementIndex, src, dst addresses, TTL, RSSI, NetKey & AppKey Offset
* @param  status:  Command status
* @param  data:    Data buffer.
* @param  length:  Length of data in bytes.
* @retval None
*/ 
void BLEMesh_ModelsDelayPacket(MODEL_MessageHeader_t *pmsgParams,
                               MOBLEUINT8 command, 
                               MOBLEUINT8 const * data, 
                               MOBLEUINT32 length)
{
  MOBLEUINT8 random_time[8];
  
  if (Appli_PendingPackets.packet_count == 0)
  {
    Appli_PendingPackets.packet_count = 1;
    hci_le_rand(random_time);
    Appli_PendingPackets.send_time = Clock_Time() + 
      DEFAULT_DELAY_PACKET_FROM + 
        (random_time[0] + random_time[1]*256)\
          %DEFAULT_DELAY_PACKET_RANDOM_TIME;    
    Appli_PendingPackets.head = Appli_PendingPackets.packet;
    Appli_PendingPackets.head_index = 0;
    TRACE_M(TF_MISC, "Randomized time: %ld\n\r", Appli_PendingPackets.send_time - Clock_Time());
  }
  else 
  {
    Appli_PendingPackets.packet_count += 1;
    Appli_PendingPackets.packet_count = (Appli_PendingPackets.packet_count)%\
      (MAX_PENDING_PACKETS_QUE_SIZE+1);
    
    if (Appli_PendingPackets.head != (Appli_PendingPackets.packet + \
      MAX_PENDING_PACKETS_QUE_SIZE - 1))
    {
      Appli_PendingPackets.head = Appli_PendingPackets.head +1;
      Appli_PendingPackets.head_index = Appli_PendingPackets.head_index+1;
    }
    else
    {
      Appli_PendingPackets.head = Appli_PendingPackets.packet;
      Appli_PendingPackets.head_index = 0;
    }
  }  
  
  Appli_PendingPackets.head->peer = pmsgParams->peer_addr;
  Appli_PendingPackets.head->dst = pmsgParams->dst_peer;
  Appli_PendingPackets.head->elementIndex = pmsgParams->elementIndex;
  Appli_PendingPackets.head->appKeyOffset = pmsgParams->rcvdAppKeyOffset;
  Appli_PendingPackets.head->netKeyOffset = pmsgParams->rcvdNetKeyOffset;
  Appli_PendingPackets.head->command = command;
  Appli_PendingPackets.head->length = length;
  for (MOBLEUINT8 count=0; count<length; count++)
    Appli_PendingPackets.head->data[count] = data[count];
}   


/**
* @brief  If send timestamp is reached and que is not empty, send all packets
* @param  None
* @retval None
*/
void BLEMesh_ModelsSendDelayedPacket(void)
{
  APPLI_SEND_RESPONSE_MODULE* ptr;
  MODEL_MessageHeader_t msgParam;
  MOBLEUINT8 temp_index;
  
  if ((Appli_PendingPackets.packet_count != 0) && 
      (Appli_PendingPackets.send_time <= Clock_Time()))
  {
    for (MOBLEUINT8 count=Appli_PendingPackets.packet_count; count!=0; count--)
    {
    TRACE_M(TF_MISC, "Sending randomized packets. Packet count: %d \n\r",\
        Appli_PendingPackets.packet_count - count + 1);
      temp_index = ((Appli_PendingPackets.head_index+MAX_PENDING_PACKETS_QUE_SIZE+1)\
        -count)%MAX_PENDING_PACKETS_QUE_SIZE;
      ptr = Appli_PendingPackets.packet + temp_index;
      
      /* Initialize the messageParam*/
      msgParam.dst_peer = ptr->dst;
      msgParam.peer_addr = ptr->peer;
      msgParam.elementIndex = 0;
      msgParam.rcvdAppKeyOffset = 0;
      msgParam.rcvdNetKeyOffset = 0;
      msgParam.rssi = 0;
      msgParam.ttl = 0;
      
      VendorModel_SendResponse(VENDOR_STMICRO_CID, 
                               &msgParam,
                               ptr->command,
                               ptr->data,
                               ptr->length);
    }
    
    Appli_PendingPackets.packet_count = 0;
  }
}

/** \brief Set remote publication for the given Model ID & node Address
* User is responsible for serializing data into \a data buffer. Vendor_WriteLocalDataCb 
*                                  callback will be called on the remote device.
* @param modelId ID of the model. 
* @param elementIdx element index
* @param command vendor model commands 
* @param data Data buffer.
* @param length Length of data in bytes.
* @param response If 'MOBLE_TRUE', used to get the response. If 'MOBLE_FALSE', no response 
* @return MOBLE_RESULT_SUCCESS on success.
*/
MOBLE_RESULT MeshClient_SetRemotePublication(MOBLEUINT32 modelId, MOBLEUINT8 elementIdx,
                                              MOBLEUINT16 msg_opcode, MOBLEUINT8 const *msg_buff, 
                                              MOBLEUINT32 length, MOBLEBOOL ack_flag,
                                              MOBLEUINT8 isVendor)
{
    MOBLE_ADDRESS srcAddress;
      
    srcAddress = BLEMesh_GetAddress();
    srcAddress += elementIdx;  /* Get the Address to send in the message */
    
    return BLEMesh_SetRemotePublication(modelId, 
                                            srcAddress ,
                                            msg_opcode , 
                                            msg_buff, length,
                                            ack_flag, 
                                            MOBLE_FALSE);
}

/**
* @brief  Convert ASCII value into Character
* @param  tempValue : 8bit value for conversion
* @retval MOBLEUINT8 
*/         
MOBLEUINT8 BLEMesh_ModelsASCII_To_Char(MOBLEUINT8 tempValue)
{
  tempValue = tempValue - 0x30;
  return tempValue;
} 

__weak void Test_Process(void)
{
}
/**
* @}
*/

/**
* @}
*/

/******************* (C) COPYRIGHT 2020 STMicroelectronics *****END OF FILE****/