Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
33acc0d
Modify pulse init value with duty_cycle instead of 0
Sagah123 Oct 16, 2026
6683848
Fix PWM duty cycle being overwritten on init
Sagah123 Oct 17, 2026
33beac9
Add changeset and apply clangformat
Sagah123 Oct 17, 2026
6f8c60b
Implement get_ccrx and add it to .Pulse initialization in pwm and dua…
Sagah123 Oct 17, 2026
0de3a89
Update TimerWrapper.hpp
Sagah123 Oct 17, 2026
8936ec3
Change method's name and location
Sagah123 Oct 17, 2026
17dc11c
resolve merge conflict
Sagah123 Oct 17, 2026
420c280
Merge branch 'development' of https://github.com/Hyperloop-UPV/ST-LIB…
Sagah123 Oct 21, 2026
0c77e89
Initial commit
Sagah123 Oct 21, 2026
ac73f61
a lot of stuff to do
Sagah123 Oct 21, 2026
484556f
feat: add ProtectionMessage over raw lwIP TCP
Sagah123 Oct 21, 2026
d1d8c14
Delete useless pointer
Sagah123 Oct 22, 2026
0e6e526
Add subseconds and comments
Sagah123 Oct 22, 2026
95fcee2
Merge remote-tracking branch 'origin/development' into feat/adjv3-pro…
Sagah123 Oct 22, 2026
5086b87
Add comments and subseconds'
Sagah123 Oct 22, 2026
367603f
Change IP to the recommended one
Sagah123 Oct 23, 2026
7fb805f
Modify hardcoded IP and Port to argumentos of a function. Add better …
Sagah123 Oct 23, 2026
c040c24
Add changeset for ADJV3 protections
Sagah123 Oct 23, 2026
41a53e5
Revert c_cpp_properties and add inline to template
Sagah123 Oct 23, 2026
60e4734
Add make raw make() private (FoolProof) and read value at send time
Sagah123 Oct 23, 2026
c31f790
test
Sagah123 Oct 23, 2026
13fc4b7
Change make implementation and modify structure names
Sagah123 Oct 28, 2026
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
2 changes: 2 additions & 0 deletions .changesets/adjv3-protections-tcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: minor
summary: Add ProtectionADJV3Packet TCP client with IP passed as an argument, plus improved error handling
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ set(STLIB_LOW_CPP_NO_ETH

set(STLIB_HIGH_C_ETH)

set(STLIB_HIGH_CPP_ETH)
set(STLIB_HIGH_CPP_ETH
${CMAKE_CURRENT_LIST_DIR}/Src/ST-LIB_HIGH/Protections/ProtectionMessages.cpp
)

set(STLIB_HIGH_C_NO_ETH)

Expand Down
48 changes: 48 additions & 0 deletions Inc/ST-LIB_HIGH/Protections/ProtectionMessages.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once
/*
* ProtectionMessages.hpp
* "Hello there"
* Created on: Oct 22, 2026
* Author: Aleks
*/
#include "ST-LIB_HIGH/Protections/SampleSource.hpp"
#include "HALAL/Services/Diagnostics/Diagnostics.hpp"
#include "ST-LIB_HIGH/Protections/FaultController.hpp"
#include "ST-LIB_HIGH/Protections/Protection.hpp"
#include "ST-LIB_HIGH/Protections/ProtectionTypes.hpp"
#include <cstdint>
#include <cstddef>
#include <cstring>

struct tcp_pcb;

namespace ST_LIB {
struct ProtectionADJv3Packet {

struct Data {
uint16_t id;
uint8_t hours;
uint8_t minutes;
uint8_t seconds;
Comment thread
Sagah123 marked this conversation as resolved.
uint8_t subseconds;
uint16_t reserved; // Just to not forget about it exists
};

struct Package {
size_t packageSize;
Data data;
// Maximum is 8 bytes, not all will be sent always
uint8_t value[8];
};

public:
static Package
make(uint16_t measurement_id, Protections::RuleKind protection, size_t value_size);
static bool tcp_client_init(const char* ip, uint16_t port);
static bool tcp_client_send(Package& pack, const void* value);

static struct tcp_pcb* tpcb;
static bool is_connected;
};

} // namespace ST_LIB
88 changes: 88 additions & 0 deletions Src/ST-LIB_HIGH/Protections/ProtectionMessages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* ProtectionMessages.cpp
* "Hello there"
* Created on: Oct 22, 2026
* Author: Aleks
*/
#include "ST-LIB_HIGH/Protections/ProtectionMessages.hpp"
#include "HALAL/Services/Time/RTC.hpp"
#include "lwip/tcp.h"

namespace ST_LIB {

struct tcp_pcb* ProtectionADJv3Packet::tpcb = nullptr;
bool ProtectionADJv3Packet::is_connected = false;

ProtectionADJv3Packet::Package
ProtectionADJv3Packet::make(uint16_t measurement_id, Protections::RuleKind prot, size_t valueSize) {
Package pack = {.packageSize = sizeof(Data) + valueSize, .data = {}};
// Bit packing of protection into 3 most significant bits of id (Look adjv3 format)
pack.data.id = (measurement_id & 0x1FFF) | (static_cast<uint16_t>(prot) << 13);
pack.data.hours = 0;
pack.data.minutes = 0;
pack.data.seconds = 0;
pack.data.subseconds = 0;
pack.data.reserved = 0;
return pack;
}

static err_t tcp_client_connected_callback(void* arg, struct tcp_pcb* pcb, err_t err) {
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(pcb);
if (err == ERR_OK) {
ProtectionADJv3Packet::is_connected = true;
}
return ERR_OK;
}
static void tcp_client_err_callback(void* arg, err_t err) {
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
ProtectionADJv3Packet::tpcb = nullptr; // lwip already has freed the tpcb, only pointer is left
ProtectionADJv3Packet::is_connected = false;
}

bool ProtectionADJv3Packet::tcp_client_init(const char* ip, uint16_t port) {
if (tpcb != nullptr) { // it means we already have one tpcb initialized
return false;
}
ip_addr_t destIPADDR;
if (!ip4addr_aton(ip, &destIPADDR)) {
return false; // ip was not converted
}
tpcb = tcp_new();
if (tpcb == nullptr) {
return false; // tpcb was not initialized
}
tcp_err(tpcb, tcp_client_err_callback);
err_t err = tcp_connect(tpcb, &destIPADDR, port, tcp_client_connected_callback);
if (err != ERR_OK) { // we got an error while connecting
tcp_abort(tpcb);
tpcb = nullptr;
return false;
}
return true;
}
bool ProtectionADJv3Packet::tcp_client_send(
ProtectionADJv3Packet::Package& pack,
const void* value
) {
if (tpcb == nullptr || !is_connected) {
return false;
}

memcpy(pack.value, value, pack.packageSize - sizeof(Data));
#if defined(HAL_RTC_MODULE_ENABLED) && !defined(SIM_ON)
RTCData rtc = Global_RTC::get_rtc_timestamp();
pack.data.hours = rtc.hour;
pack.data.minutes = rtc.minute;
pack.data.seconds = rtc.second;
pack.data.subseconds = static_cast<uint8_t>((rtc.counter * 256) / (RTC_MAX_COUNTER + 1));
#endif // if HAL_RTC was not enabled all values were initialized before to 0
err_t err = tcp_write(tpcb, &pack.data, pack.packageSize, TCP_WRITE_FLAG_COPY);
if (err != ERR_OK) {
return false;
}
return tcp_output(tpcb) == ERR_OK;
}

} // namespace ST_LIB
Loading