Skip to content

Commit 9dc221b

Browse files
authored
Merge pull request #274 from HyperloopUPV-H8/development
v2.4.0
2 parents cd96ee1 + eaffd1a commit 9dc221b

16 files changed

Lines changed: 216 additions & 60 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ file(GLOB_RECURSE SOURCE_H ${CMAKE_SOURCE_DIR}/ *.h)
1212
file(GLOB_RECURSE SOURCE_HPP ${CMAKE_SOURCE_DIR}/ *.hpp)
1313

1414
add_library(${LIBRARY} STATIC
15-
${SOURCE_C}
16-
${SOURCE_CPP}
1715
${SOURCE_H}
16+
${SOURCE_C}
17+
${SOURCE_HPP}
1818
${SOURCE_CPP}
1919
)
2020

Inc/HALAL/Models/Concepts/Concepts.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,32 @@ concept NotContainer = !Container<T>;
6363

6464
template <class T, class... U>
6565
concept PackDerivesFrom = (std::derived_from<T, U> && ...);
66+
67+
68+
template<class... Types> struct has_container;
69+
70+
template<class Type, class... Types>
71+
struct has_container<Type, Types...>{
72+
public:
73+
static constexpr bool value = Container<Type> || has_container<Types...>::value;
74+
};
75+
76+
template<>
77+
struct has_container<>{
78+
public:
79+
static constexpr bool value = false;
80+
};
81+
82+
template<class... Types> struct total_sizeof;
83+
84+
template<class Type, class... Types>
85+
struct total_sizeof<Type,Types...>{
86+
public:
87+
static constexpr size_t value = sizeof(Type) + total_sizeof<Types...>::value;
88+
};
89+
90+
template<>
91+
struct total_sizeof<>{
92+
public:
93+
static constexpr size_t value = 0;
94+
};

Inc/HALAL/Models/Packets/Packet.hpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,33 +147,6 @@ class StackPacket<0> : public Packet{
147147
}
148148
};
149149

150-
template<class... Types> struct has_container;
151-
152-
template<class Type, class... Types>
153-
struct has_container<Type, Types...>{
154-
public:
155-
static constexpr bool value = Container<Type> || has_container<Types...>::value;
156-
};
157-
158-
template<>
159-
struct has_container<>{
160-
public:
161-
static constexpr bool value = false;
162-
};
163-
164-
template<class... Types> struct total_sizeof;
165-
166-
template<class Type, class... Types>
167-
struct total_sizeof<Type,Types...>{
168-
public:
169-
static constexpr size_t value = sizeof(Type) + total_sizeof<Types...>::value;
170-
};
171-
172-
template<>
173-
struct total_sizeof<>{
174-
public:
175-
static constexpr size_t value = 0;
176-
};
177150

178151
#if __cpp_deduction_guides >= 201606
179152
template<class... Types>

Inc/HALAL/Services/Communication/SNTP/SNTP.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
#pragma once
99

10+
#include "sntp.h"
11+
#include "IPV4/IPV4.hpp"
12+
#include "Time/Time.hpp"
1013
#include "C++Utilities/CppUtils.hpp"
1114

12-
class SNTP{
15+
class SNTP {
1316
public:
1417
static void sntp_update(uint8_t address_head, uint8_t address_second, uint8_t address_third, uint8_t address_last);
1518
static void sntp_update(string ip);

Inc/HALAL/Services/Flash/Flash.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "C++Utilities/CppUtils.hpp"
1414
#include "ErrorHandler/ErrorHandler.hpp"
1515

16+
#define FLASH_32BITS_WORLD ((uint8_t) 4U)
1617
#define FLASHWORD 8
1718
#define FLASH_START_ADDRESS 0x08000000
1819
#define FLASH_SECTOR0_START_ADDRESS 0x08000000
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
#include "C++Utilities/CppUtils.hpp"
4+
#include "Concepts/Concepts.hpp"
5+
#include "ErrorHandler/ErrorHandler.hpp"
6+
#include "Flash/Flash.hpp"
7+
#include "FlashVariable.hpp"
8+
9+
#define FLASH_STORER_MAX_SIZE ((uint32_t)(1028*64))
10+
#define FLASH_STORER_START_ADDRESS (FLASH_STORER_MAX_ADDRESS - FLASH_STORER_MAX_SIZE)
11+
#define FLASH_STORER_MAX_ADDRESS ((uint32_t)0x080DFFF0U)
12+
13+
14+
class FlashStorer{
15+
16+
public:
17+
static vector<FlashVariable> variable_list;
18+
static uint32_t total_size;
19+
20+
template<class... Type>
21+
static bool add_variables(Type&... var);
22+
static void read(void);
23+
static bool store_all(void);
24+
template<class Type>
25+
static bool store(Type& var);
26+
template<class... Type> requires requires{requires sizeof...(Type) != 1;}
27+
static bool store(Type&... var);
28+
29+
private:
30+
template<class Type>
31+
static void add_size(Type& var);//?Mirar, si no hace falta borrar
32+
};
33+
34+
template<class Type>
35+
bool FlashStorer::store(Type& var) {
36+
uint32_t number_of_words = ((FlashStorer::total_size + FLASH_32BITS_WORLD - 1) / FLASH_32BITS_WORLD); //Fast ceiling the dvision result
37+
38+
uint32_t* data = (uint32_t*)malloc(number_of_words * FLASH_32BITS_WORLD);
39+
Flash::read(FLASH_STORER_START_ADDRESS, (uint32_t*)data, number_of_words);
40+
41+
uint32_t offset = 0;
42+
for(FlashVariable& v: FlashStorer::variable_list){
43+
if (v.get_pointer() == &var) {
44+
memcpy((((uint8_t*)data) + offset), v.get_pointer(), v.get_size());
45+
}
46+
47+
offset += v.get_size();
48+
}
49+
50+
if(not Flash::write(data, FLASH_STORER_START_ADDRESS, number_of_words)){
51+
return false;
52+
}
53+
54+
free(data);
55+
return true;
56+
}
57+
58+
template<class... Type> requires requires{requires sizeof...(Type) != 1;}
59+
bool FlashStorer::store(Type&... var){
60+
return (FlashStorer::store(var) & ...);
61+
}
62+
63+
template<class... Type>
64+
bool FlashStorer::add_variables(Type&... var){
65+
(FlashStorer::variable_list.push_back(FlashVariable(var)), ...);
66+
FlashStorer::total_size = total_sizeof<Type...>::value;
67+
68+
return FlashStorer::total_size >= FLASH_STORER_MAX_SIZE;
69+
}
70+
71+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include "C++Utilities/CppUtils.hpp"
4+
#include "ErrorHandler/ErrorHandler.hpp"
5+
6+
class FlashVariable{
7+
private:
8+
void* v_pointer;
9+
size_t size;
10+
public:
11+
template<class T>
12+
FlashVariable(T& value);
13+
void* get_pointer();
14+
size_t get_size();
15+
};
16+
17+
template<class T>
18+
FlashVariable::FlashVariable(T& value){
19+
FlashVariable::v_pointer = (void*)&value;
20+
FlashVariable::size = sizeof(T);
21+
}

Inc/ST-LIB_HIGH/ST-LIB_HIGH.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
#include "Control/Blocks/PID.hpp"
2222
#include "Control/Blocks/Saturator.hpp"
2323
#include "Control/ControlSystem.hpp"
24-
24+
#include "FlashStorer/FlashStorer.hpp"

Middlewares/Third_Party/LwIP/src/include/lwip/apps/sntp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* Author: Frédéric Bernon, Simon Goldschmidt
3535
*
3636
*/
37+
3738
#ifndef LWIP_HDR_APPS_SNTP_H
3839
#define LWIP_HDR_APPS_SNTP_H
3940

Middlewares/Third_Party/LwIP/src/include/lwip/apps/sntp_opts.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@
4141
#include "lwip/prot/iana.h"
4242

4343
#ifdef __cplusplus
44-
#define EXTERNC extern "C"
45-
#else
46-
#define EXTERNC
47-
#endif
4844

49-
EXTERNC void set_time(uint32_t sec, uint32_t us);
50-
EXTERNC void set_rtc(uint16_t counter, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint16_t year);
51-
EXTERNC u32_t get_rtc_s();
52-
EXTERNC u32_t get_rtc_us();
45+
extern "C" void set_time(uint32_t sec, uint32_t us);
46+
extern "C" void set_rtc(uint16_t counter, uint8_t second, uint8_t minute, uint8_t hour, uint8_t day, uint8_t month, uint16_t year);
47+
extern "C" u32_t get_rtc_s();
48+
extern "C" u32_t get_rtc_us();
49+
50+
#endif
5351

5452
#define SNTP_STARTUP_DELAY 0
5553
#define SNTP_SET_SYSTEM_TIME_US(sec,us) set_time(sec,us)
@@ -58,15 +56,7 @@ EXTERNC u32_t get_rtc_us();
5856
#define SNTP_COMP_ROUNDTRIP 1
5957
#define SNTP_UPDATE_DELAY 60000
6058

61-
void set_time(uint32_t sec, uint32_t us){
62-
struct timeval tv;
63-
tv.tv_sec = sec;
64-
tv.tv_usec = us;
65-
time_t nowtime = sec;
66-
struct tm *nowtm = localtime(&nowtime);
67-
uint32_t subsecond = (uint32_t)(TRANSFORMATION_FACTOR * tv.tv_usec);
68-
set_rtc(subsecond, nowtm->tm_sec, nowtm->tm_min, nowtm->tm_hour, nowtm->tm_mday, 1+nowtm->tm_mon, 1900+(nowtm->tm_year));
69-
}
59+
7060

7161
#define SNTP_GET_SYSTEM_TIME(sec, us) do {(sec) = get_rtc_s(); (us) = get_rtc_us(); } while (0)
7262

0 commit comments

Comments
 (0)