7070/** Maximum size of a single rule in bytes */
7171#define VSCP_DM_NG_RULE_MAX_SIZE 40
7272
73+ /** Decision matrix NG location: Page */
74+ #define VSCP_DM_NG_START_PAGE VSCP_CONFIG_DM_NG_PAGE
75+
76+ /** Number of pages which are overspaned by the decision matrix NG, without considering the offset. */
77+ #define VSCP_DM_NG_PAGES (VSCP_CONFIG_DM_NG_RULE_SET_SIZE / 256)
78+
79+ /** Last page of the decision matrix NG */
80+ #define VSCP_DM_NG_LAST_PAGE (VSCP_DM_NG_START_PAGE + VSCP_DM_NG_PAGES)
81+
82+ /** Last offset in the last page of the decision matrix NG. */
83+ #define VSCP_DM_NG_LAST_PAGE_OFFSET ((0 < (VSCP_CONFIG_DM_NG_RULE_SET_SIZE % 256)) ? (VSCP_CONFIG_DM_NG_RULE_SET_SIZE % 256 - 1) : 255)
84+
7385/*******************************************************************************
7486 MACROS
7587*******************************************************************************/
@@ -188,7 +200,7 @@ extern void vscp_dm_ng_init(void)
188200 */
189201extern void vscp_dm_ng_restoreFactoryDefaultSettings (void )
190202{
191- uint8_t index = 0 ;
203+ uint16_t index = 0 ;
192204
193205 /* Clear decision matrix next generation */
194206 for (index = 0 ; index < VSCP_CONFIG_DM_NG_RULE_SET_SIZE ; ++ index )
@@ -199,6 +211,94 @@ extern void vscp_dm_ng_restoreFactoryDefaultSettings(void)
199211 return ;
200212}
201213
214+ /**
215+ * This function check if the given page and address are part of the
216+ * decision matrix.
217+ *
218+ * @param[in] page Page
219+ * @param[in] addr Register address
220+ * @return Is part of the decision matrix or not.
221+ * @retval FALSE Is not part of the decision matrix.
222+ * @retval TRUE Is part of the decision matrix.
223+ */
224+ extern BOOL vscp_dm_ng_isDecisionMatrix (uint16_t page , uint8_t addr )
225+ {
226+ BOOL status = FALSE;
227+
228+ /* Decision matrix NG is not empty? */
229+ if (0 < VSCP_CONFIG_DM_NG_RULE_SET_SIZE )
230+ {
231+ /* Page is inside? */
232+ if ((VSCP_DM_NG_START_PAGE <= page ) &&
233+ (VSCP_DM_NG_LAST_PAGE >= page ))
234+ {
235+ /* Page is equal to the last decision matrix NG page? */
236+ if (VSCP_DM_NG_LAST_PAGE == page )
237+ {
238+ /* Address is lower or equal than the last decision matrix NG offset? */
239+ if (VSCP_DM_NG_LAST_PAGE_OFFSET >= addr )
240+ {
241+ status = TRUE;
242+ }
243+ }
244+ /* Address is inside */
245+ else
246+ {
247+ status = TRUE;
248+ }
249+ }
250+ }
251+
252+ return status ;
253+ }
254+
255+ /**
256+ * Read register and return its value.
257+ *
258+ * @param[in] page Page
259+ * @param[in] addr Register address
260+ * @return Register value
261+ */
262+ extern uint8_t vscp_dm_ng_readRegister (uint16_t page , uint8_t addr )
263+ {
264+ uint8_t value = 0 ;
265+ uint8_t index = 0 ;
266+
267+ if (VSCP_DM_NG_START_PAGE <= page )
268+ {
269+ index = (page - VSCP_DM_NG_START_PAGE ) * 256 + addr ;
270+
271+ value = vscp_ps_readDMNextGeneration (index );
272+ }
273+
274+ return value ;
275+ }
276+
277+ /**
278+ * Write to register.
279+ *
280+ * @param[in] page Page
281+ * @param[in] addr Register address
282+ * @param[in] value Value to write
283+ * @return Register value
284+ */
285+ extern uint8_t vscp_dm_ng_writeRegister (uint16_t page , uint8_t addr , uint8_t value )
286+ {
287+ uint8_t index = 0 ;
288+
289+ if (VSCP_DM_NG_START_PAGE <= page )
290+ {
291+ index = (page - VSCP_DM_NG_START_PAGE ) * 256 + addr ;
292+
293+ vscp_ps_writeDMNextGeneration (index , value );
294+
295+ /* Read value back */
296+ value = vscp_ps_readDMNextGeneration (index );
297+ }
298+
299+ return value ;
300+ }
301+
202302/**
203303 * This function process all configured rules and if any action regarding the
204304 * received message takes place, it will call the corresponding action.
0 commit comments