Skip to content

Commit 5030467

Browse files
Merge pull request #293 from HyperloopUPV-H8/development
v2.6.0
2 parents 6127ddb + be15b59 commit 5030467

25 files changed

Lines changed: 421 additions & 105 deletions

File tree

Inc/C++Utilities/CppUtils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ using std::vector;
6666
using std::queue;
6767
using std::map;
6868
using std::stringstream;
69+
using std::move;

Inc/HALAL/Models/Packets/Order.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Order : public Packet{
2727
orders[id]->process();
2828
}
2929
}
30+
3031
protected:
3132
static map<uint16_t,Order*> orders;
3233
};

Inc/HALAL/Models/Packets/OrderProtocol.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ class OrderProtocol{
77
public:
88
virtual bool send_order(Order& order) = 0;
99
static vector<OrderProtocol*> sockets;
10+
11+
friend class ServerSocket;
12+
friend class Socket;
1013
};

Inc/HALAL/Services/Communication/Ethernet/TCP/ServerSocket.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
#pragma once
88

99
#include "Communication/Ethernet/EthernetNode.hpp"
10+
#include "Communication/Ethernet/Ethernet.hpp"
1011
#include "Packets/Packet.hpp"
1112
#include "Packets/Order.hpp"
1213
#include "Packets/OrderProtocol.hpp"
1314
#ifdef HAL_ETH_MODULE_ENABLED
1415

1516
#define PBUF_POOL_MEMORY_DESC_POSITION 8
1617

17-
class ServerSocket : OrderProtocol{
18+
class ServerSocket : public OrderProtocol{
1819
public:
1920

2021
enum ServerState{
@@ -36,9 +37,13 @@ class ServerSocket : OrderProtocol{
3637

3738

3839
ServerSocket();
40+
ServerSocket(ServerSocket&& other);
3941
ServerSocket(IPV4 local_ip, uint32_t local_port);
4042
ServerSocket(string local_ip, uint32_t local_port);
4143
ServerSocket(EthernetNode local_node);
44+
~ServerSocket();
45+
46+
void operator=(ServerSocket&& other);
4247

4348
void close();
4449

Inc/HALAL/Services/Communication/Ethernet/TCP/Socket.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
#pragma once
88

99
#include "Communication/Ethernet/EthernetNode.hpp"
10+
#include "Communication/Ethernet/Ethernet.hpp"
1011
#include "Packets/Packet.hpp"
1112
#include "Packets/Order.hpp"
1213
#include "Packets/OrderProtocol.hpp"
1314
#ifdef HAL_ETH_MODULE_ENABLED
1415

1516
#define PBUF_POOL_MEMORY_DESC_POSITION 8
1617

17-
class Socket : OrderProtocol{
18+
class Socket : public OrderProtocol{
1819
public:
1920
enum SocketState{
2021
INACTIVE,
@@ -32,11 +33,13 @@ class Socket : OrderProtocol{
3233
static unordered_map<EthernetNode,Socket*> connecting_sockets;
3334

3435
Socket();
36+
Socket(Socket&& other);
3537
Socket(IPV4 local_ip, uint32_t local_port, IPV4 remote_ip, uint32_t remote_port);
3638
Socket(string local_ip, uint32_t local_port, string remote_ip, uint32_t remote_port);
3739
Socket(EthernetNode local_node, EthernetNode remote_node);
40+
~Socket();
3841

39-
42+
void operator=(Socket&& other);
4043
void close();
4144

4245
void reconnect();
@@ -57,12 +60,12 @@ class Socket : OrderProtocol{
5760
}
5861

5962
uint8_t* order_buffer = order.build();
60-
if(order.size > tcp_sndbuf(socket_control_block)){
63+
if(order.get_size() > tcp_sndbuf(socket_control_block)){
6164
return false;
6265
}
6366

64-
struct pbuf* packet = pbuf_alloc(PBUF_TRANSPORT, order.size, PBUF_POOL);
65-
pbuf_take(packet, order_buffer, order.size);
67+
struct pbuf* packet = pbuf_alloc(PBUF_TRANSPORT, order.get_size(), PBUF_POOL);
68+
pbuf_take(packet, order_buffer, order.get_size());
6669
tx_packet_buffer.push(packet);
6770
send();
6871
return true;

Inc/HALAL/Services/Communication/Ethernet/UDP/DatagramSocket.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include "Communication/Ethernet/EthernetNode.hpp"
3+
#include "Communication/Ethernet/Ethernet.hpp"
34
#include "Packets/Packet.hpp"
45

56
#ifdef HAL_ETH_MODULE_ENABLED
@@ -15,10 +16,13 @@ class DatagramSocket{
1516
uint32_t remote_port;
1617

1718
DatagramSocket();
19+
DatagramSocket(DatagramSocket&& other);
1820
DatagramSocket(IPV4 local_ip, uint32_t local_port, IPV4 remote_ip, uint32_t remote_port);
1921
DatagramSocket(EthernetNode local_node, EthernetNode remote_node);
2022
~DatagramSocket();
2123

24+
void operator=(DatagramSocket&&);
25+
2226
bool send(Packet& packet){
2327
uint8_t* packet_buffer = packet.build();
2428

@@ -30,6 +34,8 @@ class DatagramSocket{
3034
return true;
3135
}
3236

37+
void reconnect();
38+
3339
void close();
3440

3541
private:

Inc/HALAL/Services/Time/Time.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private :
3838
TIM_HandleTypeDef* tim;
3939
function<void()> alarm;
4040
uint64_t offset;
41+
bool is_on = false;
4142
};
4243

4344
static constexpr uint32_t HIGH_PRECISION_MAX_ARR = 4294967295;
@@ -53,10 +54,14 @@ private :
5354
static unordered_map<uint8_t, Alarm> low_precision_alarms_by_id;
5455
static unordered_map<uint8_t, Alarm> mid_precision_alarms_by_id;
5556

57+
static stack<uint8_t> low_precision_erasable_ids;
58+
static stack<uint8_t> mid_precision_erasable_ids;
59+
5660
static void stop_timer(TIM_HandleTypeDef* htim);
5761
static void start_timer(TIM_HandleTypeDef* htim,uint32_t prescaler, uint32_t period);
5862
static void init_timer(TIM_TypeDef* tim, TIM_HandleTypeDef* htim,uint32_t prescaler, uint32_t period, IRQn_Type interrupt_channel);
5963
static void ConfigTimer(TIM_HandleTypeDef* tim, uint32_t period_in_us);
64+
static bool is_valid_timer(TIM_HandleTypeDef* tim);
6065

6166
public :
6267
static TIM_HandleTypeDef* global_timer;

Inc/ST-LIB_HIGH/Control/Blocks/MatrixMultiplier.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ class MatrixMultiplier<U,V,W> : public ControlBlock<float(*)[U][V], float(*)[U][
1313
}
1414

1515
void execute() override{
16-
for (int i = 0; i < U; i++) {
17-
for (int j = 0; j < W; j++) {
16+
for (size_t i = 0; i < U; i++) {
17+
for (size_t j = 0; j < W; j++) {
1818
result[i][j] = 0;
19-
for (int k = 0; k < V; k++)
19+
for (size_t k = 0; k < V; k++)
2020
result[i][j] += A[i][k] * B[k][j];
2121
}
2222
}
2323
}
2424

2525
void reset(){
26-
for (int i = 0; i < U; i++) {
27-
for (int j = 0; j < W; j++)
26+
for (size_t i = 0; i < U; i++) {
27+
for (size_t j = 0; j < W; j++)
2828
result[i][j] = 0.0;
2929
}
3030
}
@@ -46,15 +46,15 @@ class MatrixMultiplier<U,V,1> : public ControlBlock<float(*)[U][V], float(*)[U]>
4646
}
4747

4848
void execute() override{
49-
for (int i = 0; i < U; i++) {
49+
for (size_t i = 0; i < U; i++) {
5050
result[i] = 0;
51-
for (int k = 0; k < V; k++)
51+
for (size_t k = 0; k < V; k++)
5252
result[i] += A[i][k] * B[k];
5353
}
5454
}
5555

5656
void reset(){
57-
for(int i = 0; i < U; i++){
57+
for(size_t i = 0; i < U; i++){
5858
result[i] = 0.0;
5959
}
6060
}
@@ -76,15 +76,15 @@ class MatrixMultiplier<1,U,V> : public ControlBlock<float(*)[U], float(*)[V]>{
7676
}
7777

7878
void execute() override{
79-
for (int j = 0; j < V; j++) {
79+
for (size_t j = 0; j < V; j++) {
8080
result[j] = 0;
81-
for (int k = 0; k < U; k++)
81+
for (size_t k = 0; k < U; k++)
8282
result[j] += A[k] * B[k][j];
8383
}
8484
}
8585

8686
void reset(){
87-
for(int i = 0; i < V; i++){
87+
for(size_t i = 0; i < V; i++){
8888
result[i] = 0.0;
8989
}
9090
}
@@ -107,7 +107,7 @@ class MatrixMultiplier<1,U,1> : public ControlBlock<float(*)[U], float(*)>{
107107

108108
void execute() override{
109109
result = 0;
110-
for (int k = 0; k < U; k++)
110+
for (size_t k = 0; k < U; k++)
111111
result += A[k] * B[k];
112112
}
113113

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#pragma once
22

33
#include "../ControlBlock.hpp"
4+
#include "ErrorHandler/ErrorHandler.hpp"
45
template<size_t N>
56
class MeanCalculator : public ControlBlock<double,double>{
67
public:
78
int index = 0;
89
double mean = 0.0;
910
public:
10-
MeanCalculator():ControlBlock<double,double>(0.0){}
11+
MeanCalculator():ControlBlock<double,double>(0.0){
12+
output_value = 0.0;
13+
}
1114
void execute() override {
1215
mean += input_value/N;
1316
index++;
17+
if(index > N) ErrorHandler("MeanCalculator is receiving just 0");
1418
if(index == N) output_value = mean;
1519
else output_value = 0.0;
1620
return;
@@ -19,4 +23,4 @@ class MeanCalculator : public ControlBlock<double,double>{
1923
mean = 0.0;
2024
index = 0;
2125
}
22-
};
26+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
#include "../ControlBlock.hpp"
3+
#include "MeanCalculator.hpp"
4+
#include "Sensors/LinearSensor/LinearSensor.hpp"
5+
template<class Type, size_t Order>
6+
class Zeroing : public ControlBlock<Type,Type>{
7+
public:
8+
MeanCalculator<Order> mean_calculator;
9+
LinearSensor<Type>& sensor;
10+
Type max_value_offset;
11+
bool has_max_value = false;
12+
Zeroing(LinearSensor<Type>& sensor) : sensor(sensor), mean_calculator(){};
13+
Zeroing(LinearSensor<Type>& sensor, Type max_value_offset) : mean_calculator(), sensor(sensor), max_value_offset(max_value_offset), has_max_value(true){};
14+
void execute(){
15+
while(mean_calculator.output_value == 0){
16+
sensor.read();
17+
mean_calculator.input(*sensor.get_value_pointer());
18+
mean_calculator.execute();
19+
}
20+
if(has_max_value && abs(mean_calculator.output_value) > max_value_offset) ErrorHandler("Zeroing offset is calculated to be above specified maximum");
21+
else sensor.set_offset(sensor.get_offset() - mean_calculator.output_value);
22+
mean_calculator.reset();
23+
}
24+
};

0 commit comments

Comments
 (0)