Friendly LWM2M client
ConnectivityMonitoring.cpp
Go to the documentation of this file.
1 /*
2  * ConnectivityMonitoring
3  * Generated on: 2023-11-02 16:57:15
4  * Created by: Sinai RnD
5  */
6 
8 
9 #include "Resource.h"
10 #include "ItemOp.h"
11 #include "WppTypes.h"
12 #include "WppLogs.h"
13 #include "WppClient.h"
14 
15 /* --------------- Code_cpp block 0 start --------------- */
16 #define NTWRK_BRR_MIN 0
17 #define NTWRK_BRR_MAX 50
18 #define AVLB_NTWRK_BRR_MIN 0
19 #define AVLB_NTWRK_BRR_MAX 50
20 #define LINK_QUALITY_IEEE_802_15_4_MIN 0
21 #define LINK_QUALITY_IEEE_802_15_4_MAX 255
22 #define LINK_QUALITY_GSM_MIN 0
23 #define LINK_QUALITY_GSM_MAX 7
24 #if RES_4_6
25 #define LINK_UTLZTN_MIN 0
26 #define LINK_UTLZTN_MAX 100
27 #endif
28 #define CELL_ID_GSM_MIN 0
29 #define CELL_ID_GSM_MAX 65535
30 #define CELL_ID_WCDMA_MIN 0
31 #define CELL_ID_WCDMA_MAX 268435455
32 #if RES_4_9
33 #define SMNC_MIN 0
34 #define SMNC_MAX 999
35 #endif
36 #if RES_4_10
37 #define SMCC_MIN 0
38 #define SMCC_MAX 999
39 #endif
40 /* --------------- Code_cpp block 0 end --------------- */
41 
42 #define TAG "ConnectivityMonitoring"
43 
44 namespace wpp {
45 
46 ConnectivityMonitoring::ConnectivityMonitoring(lwm2m_context_t &context, const OBJ_LINK_T &id): Instance(context, id) {
47 
48  /* --------------- Code_cpp block 1 start --------------- */
49  /* --------------- Code_cpp block 1 end --------------- */
50 
51  resourcesCreate();
52  resourcesInit();
53 
54  /* --------------- Code_cpp block 2 start --------------- */
55  /* --------------- Code_cpp block 2 end --------------- */
56 }
57 
59  /* --------------- Code_cpp block 3 start --------------- */
60  /* --------------- Code_cpp block 3 end --------------- */
61 }
62 
64  return ctx.registry().connectivityMonitoring();
65 }
66 
68  Instance *inst = ctx.registry().connectivityMonitoring().instance(instId);
69  if (!inst) return NULL;
70  return static_cast<ConnectivityMonitoring*>(inst);
71 }
72 
75  if (!inst) return NULL;
76  return static_cast<ConnectivityMonitoring*>(inst);
77 }
78 
80  return ctx.registry().connectivityMonitoring().remove(instId);
81 }
82 
84  /* --------------- Code_cpp block 4 start --------------- */
85  /* --------------- Code_cpp block 4 end --------------- */
86 
87  operationNotify(*this, resLink, type);
88 
89  /* --------------- Code_cpp block 5 start --------------- */
90  /* --------------- Code_cpp block 5 end --------------- */
91 }
92 
94  if (type == ItemOp::WRITE || type == ItemOp::DELETE) notifyResChanged(resLink.resId, resLink.resInstId);
95 
96  /* --------------- Code_cpp block 6 start --------------- */
97  /* --------------- Code_cpp block 6 end --------------- */
98 }
99 
100 void ConnectivityMonitoring::resourcesCreate() {
101  std::vector<Resource> resources = {
105  #if RES_4_3
106  {LINK_QUALITY_3, ItemOp(ItemOp::READ), IS_SINGLE::SINGLE, IS_MANDATORY::OPTIONAL, TYPE_ID::INT },
107  #endif
109  #if RES_4_5
110  {ROUTER_IP_ADDRESSES_5, ItemOp(ItemOp::READ), IS_SINGLE::MULTIPLE, IS_MANDATORY::OPTIONAL, TYPE_ID::STRING },
111  #endif
112  #if RES_4_6
113  {LINK_UTILIZATION_6, ItemOp(ItemOp::READ), IS_SINGLE::SINGLE, IS_MANDATORY::OPTIONAL, TYPE_ID::INT },
114  #endif
115  #if RES_4_7
117  #endif
118  #if RES_4_8
120  #endif
121  #if RES_4_9
123  #endif
124  #if RES_4_10
126  #endif
127  #if RES_4_11
129  #endif
130  #if RES_4_12
132  #endif
133  #if RES_4_13
134  {COVERAGE_ENHANCEMENT_LEVEL_13, ItemOp(ItemOp::READ), IS_SINGLE::SINGLE, IS_MANDATORY::OPTIONAL, TYPE_ID::INT },
135  #endif
136  };
137  setupResources(std::move(resources));
138 }
139 
140 void ConnectivityMonitoring::resourcesInit() {
141  /* --------------- Code_cpp block 7 start --------------- */
142 
144  resource(NETWORK_BEARER_0)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return GSM <= value && value < NTWRK_BRR_MAX; });
145 
146  resource(AVAILABLE_NETWORK_BEARER_1)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return AVLB_NTWRK_BRR_MIN <= value && value <= AVLB_NTWRK_BRR_MAX; });
147 
149 
150  #if RES_4_3
151  resource(LINK_QUALITY_3)->set<INT_T>(0);
152  resource(LINK_QUALITY_3)->setDataVerifier((VERIFY_INT_T)[this](const INT_T& value) { return this->checkLinkQuality(value); });
153  #endif
154 
155  #if RES_4_6
156  resource(LINK_UTILIZATION_6)->set<INT_T>(LINK_UTLZTN_MIN);
157  resource(LINK_UTILIZATION_6)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return LINK_UTLZTN_MIN <= value && value <= LINK_UTLZTN_MAX; });
158  #endif
159 
160  #if RES_4_8
161  resource(CELL_ID_8)->set<INT_T>(0);
162  resource(CELL_ID_8)->setDataVerifier((VERIFY_INT_T)[this](const INT_T& value) { return this->checkCellId(value); });
163  #endif
164 
165  #if RES_4_9
166  resource(SMNC_9)->set<INT_T>(SMNC_MIN);
167  resource(SMNC_9)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return SMNC_MIN <= value && value <= SMNC_MAX; });
168  #endif
169 
170  #if RES_4_10
171  resource(SMCC_10)->set<INT_T>(SMCC_MIN);
172  resource(SMCC_10)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return SMCC_MIN <= value && value <= SMCC_MAX; });
173  #endif
174 
175  #if RES_4_11
176  resource(SIGNALSNR_11)->set<INT_T>(0);
177  #endif
178 
179  #if RES_4_12
180  resource(LAC_12)->set<INT_T>(0);
181  #endif
182 
183  #if RES_4_13
184  resource(COVERAGE_ENHANCEMENT_LEVEL_13)->set<INT_T>(CVRG_ENHNCMNT_LVL_MAX);
185  resource(COVERAGE_ENHANCEMENT_LEVEL_13)->setDataVerifier((VERIFY_INT_T)[](const INT_T& value) { return MISSING <= value && value < CVRG_ENHNCMNT_LVL_MAX; });
186  #endif
187 
188  /* --------------- Code_cpp block 7 end --------------- */
189 }
190 
191 /* --------------- Code_cpp block 8 start --------------- */
192 bool ConnectivityMonitoring::checkLinkQuality(uint8_t linkQuality) {
193  INT_T networkBearer = resource(NETWORK_BEARER_0)->get<INT_T>();
194  switch (networkBearer) {
195  case GSM:
196  return LINK_QUALITY_GSM_MIN <= linkQuality && linkQuality <= LINK_QUALITY_GSM_MAX;
197  case IEEE_802_15_4:
198  return LINK_QUALITY_IEEE_802_15_4_MIN <= linkQuality && linkQuality <= LINK_QUALITY_IEEE_802_15_4_MAX;
199  case LTE_TDD:
200  case LTE_FDD:
201  case NB_IOT:
202  // TODO: the RSRQ used in the first 2 cases and NRSRQ in third. But measures in dB
203  // TODO: not understund the range of available values
204  return true;
205  default:
206  // return true as for as resource not used in the another cases
207  return true;
208  }
209 }
210 
211 bool ConnectivityMonitoring::checkCellId(uint32_t cellId) {
212  INT_T networkBearer = resource(NETWORK_BEARER_0)->get<INT_T>();
213  switch (networkBearer) {
214  case GSM:
215  return CELL_ID_GSM_MIN <= cellId && cellId <= CELL_ID_GSM_MAX;
216  case WCDMA:
217  case TD_SCDMA:
218  return CELL_ID_WCDMA_MIN <= cellId && cellId <= CELL_ID_WCDMA_MAX;
219  default:
220  // return true as for as resource not used in the another cases
221  return true;
222  }
223 }
224 /* --------------- Code_cpp block 8 end --------------- */
225 
226 } /* namespace wpp */
#define CELL_ID_WCDMA_MAX
#define LINK_QUALITY_IEEE_802_15_4_MIN
#define CELL_ID_WCDMA_MIN
#define LINK_QUALITY_GSM_MAX
#define AVLB_NTWRK_BRR_MAX
#define CELL_ID_GSM_MAX
#define AVLB_NTWRK_BRR_MIN
#define LINK_QUALITY_IEEE_802_15_4_MAX
#define LINK_QUALITY_GSM_MIN
#define CELL_ID_GSM_MIN
static ConnectivityMonitoring * createInst(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Creates an instance of the object.
ConnectivityMonitoring(lwm2m_context_t &context, const OBJ_LINK_T &id)
void userOperationNotifier(ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
void serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
static ConnectivityMonitoring * instance(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Gets an instance of the object.
static bool removeInst(WppClient &ctx, ID_T instId)
Removes an instance of the object.
static Object & object(WppClient &ctx)
Gets the Object reference.
bool checkLinkQuality(uint8_t linkQuality)
void operationNotify(Instance &inst, const ResLink &resLink, ItemOp::TYPE type)
Notifies the observers about an operation on an instance resource.
Definition: InstSubject.h:78
Instance is interface class that implements manipulation with derived class resources....
Definition: Instance.h:40
void notifyResChanged(ID_T resId, ID_T resInstId=ID_T_MAX_VAL)
Notify server about resource value change.
Definition: Instance.cpp:17
The Object class implements manipulation with Instance interface class and its inheritors.
Definition: Object.h:32
Instance * instance(ID_T instanceID=ID_T_MAX_VAL)
Gets an instance of the object.
Definition: Object.cpp:102
virtual Instance * createInstance(ID_T instanceID=ID_T_MAX_VAL)=0
Creates an instance of the object.
bool remove(ID_T instanceID)
Removes an instance of the object.
Definition: Object.cpp:82
void setupResources(const std::vector< Resource > &resources)
This methods setup resources list.
Resource * resource(ID_T resId)
This method return resource ptr if it exists. If resources does not exist then return NULL.
std::vector< Resource > & resources()
This method return list with all resources that has been defined.
bool set(const T &value, ID_T resInstId=SINGLE_INSTANCE_ID)
Set data value by copy for the resource (instance)
Definition: Resource.h:253
bool setDataVerifier(const DATA_VERIFIER_T &verifier)
Set data verifier for the resource.
Definition: Resource.cpp:164
const T & get(ID_T resInstId=SINGLE_INSTANCE_ID)
Definition: Resource.h:290
Represents a client interface for Wpp library.
Definition: WppClient.h:37
WppRegistry & registry()
Gets the WppRegistry associated with the WppClient.
Definition: WppClient.cpp:93
Object & connectivityMonitoring()
Definition: WppRegistry.cpp:94
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
int64_t INT_T
Definition: WppTypes.h:41
uint16_t ID_T
Definition: WppTypes.h:15
std::function< bool(const INT_T &)> VERIFY_INT_T
Data validation function types.
Definition: WppTypes.h:94
The ItemOp struct represents the operations that can be performed on a instance/resource.
Definition: ItemOp.h:24
TYPE
Enum representing the different types of operations.
Definition: ItemOp.h:29
@ DELETE
Definition: ItemOp.h:36