Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firmware/default_params: Adding Elements to save configuration in the… #308

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion firmware/default_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* @ingroup m4a-firmware
* @{
* @file
* @name Defaults params for the m4a firmware
* @author xkevin190 <[email protected]>
*/
Expand All @@ -25,16 +26,52 @@
#define DEFAULT_PARAMS_H

#include "storage.h"
#ifdef MODULE_NETDEV_DEFAULT
#include "net/netdev/ieee802154.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Data type to get a brew description of the sensors
*/
typedef struct {
uint8_t class_sensor : 1; /*!< class of the sensor, e.g TEMPERATURE (0), MOISTURE (1)*/
uint8_t sensor_type : 1; /*!< Soil(0) or Air(1)*/
uint8_t pin : 6; /*!< Input pin -> Max pin 63*/
} sensors_t;

/**
* @brief struct to save all data of the firmware Mesh4all
*/
typedef struct {
#if ((MODULE_RADIO) || (DOXYGEN))
int16_t radio_tx_power : 6; /*!< The transmit power from a radio interface*/
uint16_t subghz : 1; /*!< Represent if the interface is active in 2.4 sub-GHZ mode*/
uint16_t channel : 5; /*!< Channel of the radio */

#if ((MODULE_RPL_PROTOCOL) || (DOXYGEN))
uint16_t rpl_mode : 1; /*!< If the system has an RPL in mode `DAG` or `DODAG`*/
uint8_t rpl_instance; /*!< Number of instance of DODAG*/
uint16_t pan_id; /*!< The Personal Area Network where is located the RPL network*/
int16_t : 1; /*!< Empty bit (Boolean Expression Could be used)*/
#else
int16_t : 2;
#endif
#endif
/* peripherals */
uint8_t amount_sensors : 5; /*!< Amount of sensors referenced with the number of pins
(64 pins)*/
uint8_t wifi_subsys : 1; /*!< The Wifi-subsystem is connected*/
uint8_t uniqueid_mode : 2; /*!< The unique id mode STATIC(0), RANDOM(1), MANUAL(2)*/
sensors_t sensors[2]; /*!< Sensor set in the firmware*/
} storage_data_t;

/**
* @name storage address this address will be the storage keys
* @{
*/

/**
* @brief first address of the page this name is optional must be change in the future
*/
Expand Down
1 change: 0 additions & 1 deletion firmware/network/radio/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "net/netif.h"
#include "net/netdev/ieee802154.h"
#include "net/gnrc.h"
#include "uniqueid.h"
#include "net/netdev.h"
#include "radio.h"

Expand Down
8 changes: 8 additions & 0 deletions firmware/network/rpl_protocol/include/rpl_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@
extern "C" {
#endif

/**
* @brief Configuration to set "DAG" or "DODAG" mode
*
*/
#ifndef CONFIG_IS_DODAG
#define CONFIG_IS_DODAG (0)
#endif

/**
* @brief DODAG instance by Kconfig
*
*/
#ifndef CONFIG_DODAG_INSTANCE
#define CONFIG_DODAG_INSTANCE (1)
#endif
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.tests_common
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EXTERNAL_BOARD_DIRS ?= $(CURDIR)/../../boards
EXTERNAL_MODULE_DIRS += $(CURDIR)/../../firmware/peripherals
EXTERNAL_MODULE_DIRS += $(CURDIR)/../../firmware/network
EXTERNAL_MODULE_DIRS += $(CURDIR)/../../firmware/sys
CFLAGS += -I $(CURDIR)/../../firmware

SLIP_UART ?= 1
CFLAGS += "-DSLIPDEV_PARAM_UART=UART_DEV($(SLIP_UART))"
Expand Down
4 changes: 4 additions & 0 deletions tests/storage/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
menu "Test Kconfig Storage"
rsource "../../firmware/sys/uniqueid/Kconfig"
rsource "../../firmware/network/net_tools/Kconfig"
endmenu
2 changes: 2 additions & 0 deletions tests/storage/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ include ../Makefile.tests_common

USEMODULE += embunit
USEMODULE += storage
USEMODULE += radio
USEMODULE += rpl_protocol

include $(RIOTBASE)/Makefile.include
71 changes: 66 additions & 5 deletions tests/storage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include "default_params.h"
#include "embUnit.h"

#include "storage.h"
Expand Down Expand Up @@ -75,6 +75,66 @@ void test_load_data(void) {
}
printf("\n");
}

void test_save_firm_data(void) {
int ret = 0;
storage_data_t storage_test = {
.amount_sensors = 2,
.wifi_subsys = 0,
.uniqueid_mode = 0,
.sensors =
{
{
.class_sensor = 0,
.pin = 5,
.sensor_type = 0,
},
{
.class_sensor = 1,
.pin = 1,
.sensor_type = 1,
},
},
#ifdef MODULE_RADIO
.radio_tx_power = -30,
.subghz = true,
.channel = 11,
#endif
#ifdef MODULE_RPL_PROTOCOL
.rpl_mode = 0,
#endif
};
ret = mtd_save_compress(&storage_test, sizeof(storage_test));
TEST_ASSERT_EQUAL_INT(0, ret);
}

void test_load_firm_data(void) {
storage_data_t load_storage;
printf("\n\nLoading Firmware default data:\n\n");
mtd_load(&load_storage, sizeof(load_storage));
#ifdef MODULE_RADIO
printf("Tx_power: %d\n", load_storage.radio_tx_power);
printf("Sub_GHz: %s\n", load_storage.subghz ? "YES" : "NO");
printf("Channel: %u\n", load_storage.channel);
#endif
#ifdef MODULE_RPL_PROTOCOL
printf("\nRouting\n\nRpl_mode: %s\n", load_storage.rpl_mode ? "DODAG" : "DAG");
printf("RPL instance: %d\n", load_storage.rpl_instance);
printf("\nRouting\n\nRpl_mode: %d\n ", load_storage.pan_id);

#endif
printf("Wifi-subsys: %s\n", load_storage.wifi_subsys ? "YES" : "NO");
printf("Amount of sensors %d\n", load_storage.amount_sensors);
for (uint8_t i = 0; i < load_storage.amount_sensors; i++) {
printf("\nSensor Id %d \n", i + 1);
printf("Class of Sensor: %s SENSOR\n",
load_storage.sensors[i].class_sensor ? "TEMPERATURE" : "MOISTURE");
printf("Application Type of Sensor: %s SENSOR\n",
load_storage.sensors[i].sensor_type ? "AIR" : "SOIL");
printf("Input pin: %d\n", load_storage.sensors[i].pin);
}
printf("\n\n");
}
void test_write_string(void) {
int ret = mtd_write_string(ADDRESS, data);
TEST_ASSERT_EQUAL_INT(0, ret);
Expand Down Expand Up @@ -111,10 +171,11 @@ void test_erase_address(void) {

Test *tests_mtd_flashpage_tests(void) {
EMB_UNIT_TESTFIXTURES(fixtures){
new_TestFixture(test_init_mtd), new_TestFixture(test_save_data),
new_TestFixture(test_load_data), new_TestFixture(test_write_string),
new_TestFixture(test_read_string), new_TestFixture(test_write_u8),
new_TestFixture(test_read_u8), new_TestFixture(test_erase_address),
new_TestFixture(test_init_mtd), new_TestFixture(test_save_data),
new_TestFixture(test_load_data), new_TestFixture(test_save_firm_data),
new_TestFixture(test_load_firm_data), new_TestFixture(test_write_string),
new_TestFixture(test_read_string), new_TestFixture(test_write_u8),
new_TestFixture(test_read_u8), new_TestFixture(test_erase_address),
};

EMB_UNIT_TESTCALLER(mtd_flashpage_tests, NULL, NULL, fixtures);
Expand Down