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();
}
app_persistent_res_e App_Persistent_read(uint8_t *data, size_t len)
Read from persistent.
app_persistent_res_e
List of return code.
@ APP_PERSISTENT_RES_OK
@ APP_PERSISTENT_RES_UNINITIALIZED
@ APP_PERSISTENT_RES_INVALID_CONTENT
app_persistent_res_e App_Persistent_write(uint8_t *data, size_t len)
Write to persistent.
#define LOG_INIT()
Definition debug_log.h:91
#define LVL_INFO
Definition debug_log.h:110
#define LVL_ERROR
Definition debug_log.h:112
#define LOG(level, fmt,...)
Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition debug_log.h:206
Board-independent LED functions.
led_res_e Led_set(uint8_t led_id, bool state)
Turn the given LED on or off.
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
@ APP_RES_OK
Definition wms_app.h:204
List of global functions, passed to App_entrypoint()
Definition wms_app.h:158