Wirepas SDK
app_persistent/app.c
/* Copyright 2021 Wirepas Ltd. All Rights Reserved.
*
* See file LICENSE.txt for full license details.
*
*/
/*
* \file app.c
* \brief This file is an example on how to use the application
* persistent library and test it in trivial cases.
* - Read to see if content is valid
* - Write
* - Read it back
* - Check content
*/
#include <stdlib.h>
#include <string.h>
#include "api.h"
#include "led.h"
#include "app_persistent.h"
#define DEBUG_LOG_MODULE_NAME "APP_PERS"
#define DEBUG_LOG_MAX_LEVEL LVL_INFO
#include "debug_log.h"
static char my_data[500];
#define PATTERN_BYTE 0xAB
void App_init(const app_global_functions_t * functions)
{
(void) functions;
// Basic configuration of the node with a unique node address
{
// Could not configure the node
// It should not happen except if one of the config value is invalid
return;
}
Led_set(0, true);
LOG(LVL_INFO, "App_persistent example started\n");
res = App_Persistent_read((uint8_t *) my_data, sizeof(my_data));
{
LOG(LVL_INFO, "First initialization\n");
}
{
LOG(LVL_ERROR, "Persistent unitialized => Data area not present\n");
}
// Fill our data with PATTERN_BYTE
memset(my_data, PATTERN_BYTE, sizeof(my_data));
res = App_Persistent_write((uint8_t *) my_data, sizeof(my_data));
{
LOG(LVL_ERROR, "Cannot write\n");
}
// Reset our data in Ram
memset(my_data, 0, sizeof(my_data));
// Read it back
res = App_Persistent_read((uint8_t *) my_data, sizeof(my_data));
{
LOG(LVL_ERROR, "Cannot read back %d\n", res);
}
// Check data
for (uint16_t i = 0; i < sizeof(my_data); i++)
{
if (my_data[i] != PATTERN_BYTE)
{
LOG(LVL_ERROR, "Data at index %d is wrong\n", i);
}
}
LOG(LVL_INFO, "After Read back: %x\n", my_data[0]);
// Start the stack
lib_state->startStack();
}
LVL_INFO
#define LVL_INFO
Definition: debug_log.h:83
Led_set
led_res_e Led_set(uint8_t led_id, bool state)
Turn the given LED on or off.
LVL_ERROR
#define LVL_ERROR
Definition: debug_log.h:85
node_configuration.h
APP_RES_OK
@ APP_RES_OK
Definition: wms_app.h:204
App_Persistent_write
app_persistent_res_e App_Persistent_write(uint8_t *data, size_t len)
Write to persistent.
APP_PERSISTENT_RES_INVALID_CONTENT
@ APP_PERSISTENT_RES_INVALID_CONTENT
Definition: app_persistent.h:46
APP_PERSISTENT_RES_OK
@ APP_PERSISTENT_RES_OK
Definition: app_persistent.h:38
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
debug_log.h
app_persistent.h
app_persistent_res_e
app_persistent_res_e
List of return code.
Definition: app_persistent.h:35
led.h
Board-independent LED functions.
configureNodeFromBuildParameters
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
Definition: node_configuration.h:224
LOG_INIT
#define LOG_INIT()
Definition: debug_log.h:66
LOG
#define LOG(level, fmt,...)
Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition: debug_log.h:173
APP_PERSISTENT_RES_UNINITIALIZED
@ APP_PERSISTENT_RES_UNINITIALIZED
Definition: app_persistent.h:42
App_Persistent_read
app_persistent_res_e App_Persistent_read(uint8_t *data, size_t len)
Read from persistent.
api.h