2020-08-27 18:52:06 +02:00
|
|
|
/*
|
|
|
|
* NimBLEMeshModel.h
|
|
|
|
*
|
|
|
|
* Created: on Aug 25 2020
|
|
|
|
* Author H2zero
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MAIN_NIMBLE_MESH_MODEL_H_
|
|
|
|
#define MAIN_NIMBLE_MESH_MODEL_H_
|
|
|
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#if defined(CONFIG_BT_ENABLED)
|
|
|
|
#include "nimconfig.h"
|
|
|
|
|
|
|
|
#include "NimBLEMeshElement.h"
|
|
|
|
|
|
|
|
class NimBLEMeshModelCallbacks;
|
|
|
|
|
|
|
|
class NimBLEMeshModel {
|
|
|
|
public:
|
|
|
|
NimBLEMeshModel(NimBLEMeshModelCallbacks* pCallbacks);
|
2020-09-01 16:43:58 +02:00
|
|
|
virtual ~NimBLEMeshModel();
|
2020-08-27 18:52:06 +02:00
|
|
|
|
2020-09-01 16:43:58 +02:00
|
|
|
bt_mesh_model_op* m_opList;
|
2020-08-27 18:52:06 +02:00
|
|
|
|
2020-09-01 16:43:58 +02:00
|
|
|
bt_mesh_model_pub m_opPub;
|
2020-08-27 18:52:06 +02:00
|
|
|
NimBLEMeshModelCallbacks* m_callbacks;
|
2020-08-30 15:48:24 +02:00
|
|
|
int extractTransTimeDelay(os_mbuf *buf);
|
|
|
|
bool checkRetransmit(uint8_t tid, bt_mesh_msg_ctx *ctx);
|
|
|
|
void sendMessage(bt_mesh_model *model, bt_mesh_msg_ctx *ctx, os_mbuf *msg);
|
|
|
|
void startTdTimer(ble_npl_time_t timerMs);
|
2020-09-01 16:43:58 +02:00
|
|
|
void publish();
|
|
|
|
virtual void setPubMsg();
|
2020-08-30 15:48:24 +02:00
|
|
|
|
|
|
|
uint8_t m_lastTid;
|
|
|
|
uint16_t m_lastSrcAddr;
|
|
|
|
uint16_t m_lastDstAddr;
|
|
|
|
time_t m_lastMsgTime;
|
|
|
|
uint8_t m_transTime;
|
|
|
|
uint8_t m_delayTime;
|
|
|
|
uint8_t m_onOffValue;
|
|
|
|
uint8_t m_onOffTarget;
|
|
|
|
int16_t m_levelValue;
|
|
|
|
int16_t m_levelTarget;
|
|
|
|
int16_t m_transStep;
|
2020-09-01 16:43:58 +02:00
|
|
|
|
2020-08-30 15:48:24 +02:00
|
|
|
ble_npl_callout m_tdTimer;
|
2020-09-01 16:43:58 +02:00
|
|
|
ble_npl_callout m_pubTimer;
|
2020-08-27 18:52:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class NimBLEGenOnOffSrvModel : NimBLEMeshModel {
|
|
|
|
friend class NimBLEMeshElement;
|
|
|
|
friend class NimBLEMeshNode;
|
|
|
|
|
|
|
|
NimBLEGenOnOffSrvModel(NimBLEMeshModelCallbacks* pCallbacks);
|
2020-09-01 16:43:58 +02:00
|
|
|
~NimBLEGenOnOffSrvModel(){};
|
2020-08-27 18:52:06 +02:00
|
|
|
|
|
|
|
static void getOnOff(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setOnOff(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setOnOffUnack(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
2020-08-30 15:48:24 +02:00
|
|
|
static void tdTimerCb(ble_npl_event *event);
|
2020-09-01 16:43:58 +02:00
|
|
|
|
|
|
|
static void pubTimerCb(ble_npl_event *event);
|
|
|
|
|
|
|
|
void setPubMsg() override;
|
2020-08-27 18:52:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class NimBLEGenLevelSrvModel : NimBLEMeshModel {
|
|
|
|
friend class NimBLEMeshElement;
|
|
|
|
friend class NimBLEMeshNode;
|
|
|
|
|
|
|
|
NimBLEGenLevelSrvModel(NimBLEMeshModelCallbacks* pCallbacks);
|
2020-09-01 16:43:58 +02:00
|
|
|
~NimBLEGenLevelSrvModel(){};
|
2020-08-27 18:52:06 +02:00
|
|
|
|
|
|
|
static void getLevel(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setLevel(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setLevelUnack(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setDelta(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setDeltaUnack(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setMove(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
|
|
|
static void setMoveUnack(bt_mesh_model *model,
|
|
|
|
bt_mesh_msg_ctx *ctx,
|
|
|
|
os_mbuf *buf);
|
2020-08-30 15:48:24 +02:00
|
|
|
static void tdTimerCb(ble_npl_event *event);
|
2020-09-01 16:43:58 +02:00
|
|
|
|
|
|
|
static void pubTimerCb(ble_npl_event *event);
|
|
|
|
|
|
|
|
void setPubMsg() override;
|
2020-08-27 18:52:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class NimBLEMeshModelCallbacks {
|
|
|
|
public:
|
|
|
|
virtual ~NimBLEMeshModelCallbacks();
|
|
|
|
virtual void setOnOff(uint8_t);
|
|
|
|
virtual uint8_t getOnOff();
|
|
|
|
virtual void setLevel(int16_t);
|
|
|
|
virtual int16_t getLevel();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CONFIG_BT_ENABLED
|
|
|
|
#endif // MAIN_NIMBLE_MESH_MODEL_H_
|