Repository navigation
Feat/adjv3 protections #692
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
Open
Sagah123
wants to merge
22
commits into
development
Choose a base branch
from
feat/adjv3-protections
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 6683848
Fix PWM duty cycle being overwritten on init
Sagah123 33beac9
Add changeset and apply clangformat
Sagah123 6f8c60b
Implement get_ccrx and add it to .Pulse initialization in pwm and dua…
Sagah123 0de3a89
Update TimerWrapper.hpp
Sagah123 8936ec3
Change method's name and location
Sagah123 17dc11c
resolve merge conflict
Sagah123 420c280
Merge branch 'development' of https://github.com/Hyperloop-UPV/ST-LIB…
Sagah123 0c77e89
Initial commit
Sagah123 ac73f61
a lot of stuff to do
Sagah123 484556f
feat: add ProtectionMessage over raw lwIP TCP
Sagah123 d1d8c14
Delete useless pointer
Sagah123 0e6e526
Add subseconds and comments
Sagah123 95fcee2
Merge remote-tracking branch 'origin/development' into feat/adjv3-pro…
Sagah123 5086b87
Add comments and subseconds'
Sagah123 367603f
Change IP to the recommended one
Sagah123 7fb805f
Modify hardcoded IP and Port to argumentos of a function. Add better …
Sagah123 c040c24
Add changeset for ADJV3 protections
Sagah123 41a53e5
Revert c_cpp_properties and add inline to template
Sagah123 60e4734
Add make raw make() private (FoolProof) and read value at send time
Sagah123 c31f790
test
Sagah123 13fc4b7
Change make implementation and modify structure names
Sagah123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.