Skip to content

Commit c3be618

Browse files
author
Michał Narajowski
authored
Merge pull request apache#17 from michal-narajowski/mesh-models
Mesh models fixes
2 parents 706fd6d + 336dd31 commit c3be618

File tree

14 files changed

+326
-273
lines changed

14 files changed

+326
-273
lines changed

nimble/host/mesh/include/mesh/cfg_srv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
6262
BT_MESH_MODEL(BT_MESH_MODEL_ID_CFG_SRV, \
6363
bt_mesh_cfg_srv_op, NULL, srv_data)
6464

65+
6566
/**
6667
* @}
6768
*/

nimble/host/mesh/src/model_srv.h renamed to nimble/host/mesh/include/mesh/model_srv.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ extern const struct bt_mesh_model_op gen_level_srv_op[];
2929
BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_LEVEL_SRV, \
3030
gen_level_srv_op, pub, srv)
3131

32-
int pwm_init(void);
32+
struct bt_mesh_light_lightness_srv_cb {
33+
int (*get)(struct bt_mesh_model *model, s16_t *level);
34+
int (*set)(struct bt_mesh_model *model, s16_t level);
35+
};
36+
37+
extern const struct bt_mesh_model_op light_lightness_srv_op[];
38+
39+
#define BT_MESH_MODEL_LIGHT_LIGHTNESS_SRV(srv, pub) \
40+
BT_MESH_MODEL(BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, \
41+
light_lightness_srv_op, pub, srv)
42+
43+
44+
void bt_mesh_set_gen_onoff_srv_cb(struct bt_mesh_gen_onoff_srv_cb *gen_onoff_cb);
45+
void bt_mesh_set_gen_level_srv_cb(struct bt_mesh_gen_level_srv_cb *gen_level_cb);
46+
void bt_mesh_set_light_lightness_srv_cb(struct bt_mesh_light_lightness_srv_cb *light_lightness_cb);
3347

3448
#endif

nimble/host/mesh/include/mesh/testing.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ void bt_test_cb_register(struct bt_test_cb *cb);
5757
*/
5858
void bt_test_cb_unregister(struct bt_test_cb *cb);
5959

60+
u8_t mod_bind(struct bt_mesh_model *model, u16_t key_idx);
61+
u8_t mod_unbind(struct bt_mesh_model *model, u16_t key_idx);
62+
int cmd_init(int argc, char *argv[]);
63+
64+
int bt_test_shell_init(void);
65+
int bt_test_bind_app_key_to_model(struct bt_mesh_model *model, u16_t key_idx, u16_t id);
66+
6067
/**
6168
* @}
6269
*/

nimble/host/mesh/src/access.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "access.h"
2424
#include "foundation.h"
2525
#if MYNEWT_VAL(BLE_MESH_SHELL_MODELS)
26-
#include "model_cli.h"
26+
#include "mesh/model_cli.h"
2727
#endif
2828

2929
static const struct bt_mesh_comp *dev_comp;

nimble/host/mesh/src/cfg_srv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static u8_t _mod_pub_set(struct bt_mesh_model *model, u16_t pub_addr,
298298
return STATUS_SUCCESS;
299299
}
300300

301-
static u8_t mod_bind(struct bt_mesh_model *model, u16_t key_idx)
301+
u8_t mod_bind(struct bt_mesh_model *model, u16_t key_idx)
302302
{
303303
int i;
304304

@@ -325,7 +325,7 @@ static u8_t mod_bind(struct bt_mesh_model *model, u16_t key_idx)
325325
return STATUS_INSUFF_RESOURCES;
326326
}
327327

328-
static u8_t mod_unbind(struct bt_mesh_model *model, u16_t key_idx)
328+
u8_t mod_unbind(struct bt_mesh_model *model, u16_t key_idx)
329329
{
330330
int i;
331331

nimble/host/mesh/src/light_model.c

Lines changed: 8 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,17 @@
11

22
#include "syscfg/syscfg.h"
33

4-
#if MYNEWT_VAL(BLE_MESH_SHELL_MODELS)
5-
64
#include "mesh/mesh.h"
7-
#include "bsp.h"
8-
#include "pwm/pwm.h"
5+
#include "console/console.h"
96
#include "light_model.h"
107

11-
struct pwm_dev *pwm0;
12-
struct pwm_dev *pwm1;
13-
struct pwm_dev *pwm2;
14-
struct pwm_dev *pwm3;
15-
static uint16_t top_val;
168

179
static u8_t gen_onoff_state;
1810
static s16_t gen_level_state;
1911

20-
static void light_set_lightness(u8_t percentage)
21-
{
22-
int rc;
23-
24-
uint16_t pwm_val = (uint16_t) (percentage * top_val / 100);
25-
26-
rc = pwm_enable_duty_cycle(pwm0, 0, pwm_val);
27-
assert(rc == 0);
28-
rc = pwm_enable_duty_cycle(pwm1, 0, pwm_val);
29-
assert(rc == 0);
30-
rc = pwm_enable_duty_cycle(pwm2, 0, pwm_val);
31-
assert(rc == 0);
32-
rc = pwm_enable_duty_cycle(pwm3, 0, pwm_val);
33-
assert(rc == 0);
34-
}
35-
3612
static void update_light_state(void)
3713
{
38-
int level = gen_level_state;
39-
40-
if (level > 100) {
41-
level = 100;
42-
}
43-
if (level < 0) {
44-
level = 0;
45-
}
46-
47-
if (gen_onoff_state == 0) {
48-
level = 0;
49-
}
50-
51-
light_set_lightness((uint8_t) level);
14+
console_printf("Light state: onoff=%d lvl=0x%04x\n", gen_onoff_state, (u16_t)gen_level_state);
5215
}
5316

5417
int light_model_gen_onoff_get(struct bt_mesh_model *model, u8_t *state)
@@ -73,102 +36,23 @@ int light_model_gen_level_get(struct bt_mesh_model *model, s16_t *level)
7336
int light_model_gen_level_set(struct bt_mesh_model *model, s16_t level)
7437
{
7538
gen_level_state = level;
76-
if (gen_level_state > 0) {
39+
if ((u16_t)gen_level_state > 0x0000) {
7740
gen_onoff_state = 1;
7841
}
79-
if (gen_level_state <= 0) {
42+
if ((u16_t)gen_level_state == 0x0000) {
8043
gen_onoff_state = 0;
8144
}
8245
update_light_state();
8346
return 0;
8447
}
8548

86-
static struct pwm_dev_interrupt_cfg led1_conf = {
87-
.cfg = {
88-
.pin = LED_1,
89-
.inverted = true,
90-
.n_cycles = 0,
91-
.interrupts_cfg = true,
92-
},
93-
.int_prio = 3,
94-
};
95-
96-
static struct pwm_dev_interrupt_cfg led2_conf = {
97-
.cfg = {
98-
.pin = LED_2,
99-
.inverted = true,
100-
.n_cycles = 0,
101-
.interrupts_cfg = true,
102-
},
103-
.int_prio = 3,
104-
};
105-
106-
static struct pwm_dev_interrupt_cfg led3_conf = {
107-
.cfg = {
108-
.pin = LED_3,
109-
.inverted = true,
110-
.n_cycles = 0,
111-
.interrupts_cfg = true,
112-
},
113-
.int_prio = 3,
114-
};
115-
116-
static struct pwm_dev_interrupt_cfg led4_conf = {
117-
.cfg = {
118-
.pin = LED_4,
119-
.inverted = true,
120-
.n_cycles = 0,
121-
.interrupts_cfg = true,
122-
},
123-
.int_prio = 3,
124-
};
125-
126-
int pwm_init(void)
49+
int light_model_light_lightness_get(struct bt_mesh_model *model, s16_t *lightness)
12750
{
128-
int rc;
129-
130-
led1_conf.seq_end_data = &led1_conf;
131-
led2_conf.seq_end_data = &led2_conf;
132-
led3_conf.seq_end_data = &led3_conf;
133-
led4_conf.seq_end_data = &led4_conf;
134-
135-
pwm0 = (struct pwm_dev *) os_dev_open("pwm0", 0, NULL);
136-
assert(pwm0);
137-
pwm1 = (struct pwm_dev *) os_dev_open("pwm1", 0, NULL);
138-
assert(pwm1);
139-
pwm2 = (struct pwm_dev *) os_dev_open("pwm2", 0, NULL);
140-
assert(pwm2);
141-
pwm3 = (struct pwm_dev *) os_dev_open("pwm3", 0, NULL);
142-
assert(pwm3);
143-
144-
/* set the PWM frequency */
145-
pwm_set_frequency(pwm0, 1000);
146-
pwm_set_frequency(pwm1, 1000);
147-
pwm_set_frequency(pwm2, 1000);
148-
pwm_set_frequency(pwm3, 1000);
149-
top_val = (uint16_t) pwm_get_top_value(pwm0);
150-
151-
rc = pwm_chan_config(pwm0, 0, (struct pwm_chan_cfg*) &led1_conf);
152-
assert(rc == 0);
153-
rc = pwm_chan_config(pwm1, 0, (struct pwm_chan_cfg*) &led2_conf);
154-
assert(rc == 0);
155-
rc = pwm_chan_config(pwm2, 0, (struct pwm_chan_cfg*) &led3_conf);
156-
assert(rc == 0);
157-
rc = pwm_chan_config(pwm3, 0, (struct pwm_chan_cfg*) &led4_conf);
158-
assert(rc == 0);
159-
160-
update_light_state();
161-
162-
return rc;
51+
return light_model_gen_level_get(model, lightness);
16352
}
164-
#endif
16553

166-
int light_model_init(void)
54+
int light_model_light_lightness_set(struct bt_mesh_model *model, s16_t lightness)
16755
{
168-
#if MYNEWT_VAL(BLE_MESH_SHELL_MODELS)
169-
return pwm_init();
170-
#else
171-
return 0;
172-
#endif
56+
return light_model_gen_level_set(model, lightness);
17357
}
17458

nimble/host/mesh/src/light_model.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,11 @@
99
#include "syscfg/syscfg.h"
1010
#include "mesh/mesh.h"
1111

12-
#if MYNEWT_VAL(BLE_MESH_SHELL_MODELS)
1312
int light_model_gen_onoff_get(struct bt_mesh_model *model, u8_t *state);
1413
int light_model_gen_onoff_set(struct bt_mesh_model *model, u8_t state);
1514
int light_model_gen_level_get(struct bt_mesh_model *model, s16_t *level);
1615
int light_model_gen_level_set(struct bt_mesh_model *model, s16_t level);
17-
int light_model_init(void);
18-
#else
19-
static inline int light_model_gen_onoff_get(struct bt_mesh_model *model, u8_t *state) { return 0; }
20-
static inline int light_model_gen_onoff_set(struct bt_mesh_model *model, u8_t state) { return 0; }
21-
static inline int light_model_gen_level_get(struct bt_mesh_model *model, s16_t *level) { return 0; }
22-
static inline int light_model_gen_level_set(struct bt_mesh_model *model, s16_t level) { return 0; }
23-
static inline int light_model_init(void) { return 0; }
24-
#endif
16+
int light_model_light_lightness_get(struct bt_mesh_model *model, s16_t *lightness);
17+
int light_model_light_lightness_set(struct bt_mesh_model *model, s16_t lightness);
2518

2619
#endif

nimble/host/mesh/src/mesh_priv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
#define OP_GEN_LEVEL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x08)
2727
#define OP_GEN_DELTA_SET BT_MESH_MODEL_OP_2(0x82, 0x09)
2828
#define OP_GEN_DELTA_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0a)
29-
#define OP_GEN_MOVE_SET BT_MESH_MODEL_OP_2(0x82, 0x0b)
29+
#define OP_GEN_MOVE_SET BT_MESH_MODEL_OP_2(0x82, 0x0b)
3030
#define OP_GEN_MOVE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0c)
31+
#define OP_LIGHT_LIGHTNESS_GET BT_MESH_MODEL_OP_2(0x82, 0x4b)
32+
#define OP_LIGHT_LIGHTNESS_SET BT_MESH_MODEL_OP_2(0x82, 0x4c)
33+
#define OP_LIGHT_LIGHTNESS_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x4d)
3134

3235
bool bt_mesh_is_provisioned(void);
3336

nimble/host/mesh/src/model_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <mesh/mesh.h>
88

99
#define BT_DBG_ENABLED (MYNEWT_VAL(BLE_MESH_DEBUG_MODEL))
10-
#include "model_cli.h"
10+
#include "mesh/model_cli.h"
1111
#include "mesh_priv.h"
1212

1313
static s32_t msg_timeout = K_SECONDS(5);

0 commit comments

Comments
 (0)