-
Notifications
You must be signed in to change notification settings - Fork 0
Added TCP/IP and Packet Validation Examples #80
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
Draft
jorgesg82
wants to merge
9
commits into
main
Choose a base branch
from
robust-tcpip
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c1103d
feat(build): support example-targeted builds and packet codegen fixes
jorgesg82 5bb3d56
feat(tcpip): add hardware stress example and host test harness
jorgesg82 8f51aa1
feat(packets): add generated packet parsing example for TEST board
jorgesg82 12765df
docs: add example guides and TCP/IP test manuals
jorgesg82 6825dac
chore(packets): untrack generated packet headers and document schema …
jorgesg82 3f0959a
chore(network): remove the macOS host-link helper from the repo
jorgesg82 2bdc299
Erased generated chatty doc haha sorry
jorgesg82 a62b789
Pointing to proper stlib
jorgesg82 6bed414
Pointing to proper st-lib (again)
jorgesg82 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
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
Submodule JSON_ADE
updated
from ee857f to d0f7d8
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,233 @@ | ||
| #ifdef EXAMPLE_PACKETS | ||
|
|
||
| #include "Communications/Packets/DataPackets.hpp" | ||
| #include "Communications/Packets/OrderPackets.hpp" | ||
| #include "ST-LIB.hpp" | ||
| #include "main.h" | ||
|
|
||
| using namespace ST_LIB; | ||
|
|
||
| #ifndef STLIB_ETH | ||
| #error "EXAMPLE_PACKETS requires STLIB_ETH" | ||
| #endif | ||
|
|
||
| constexpr auto led = ST_LIB::DigitalOutputDomain::DigitalOutput(ST_LIB::PB0); | ||
|
|
||
| #if defined(USE_PHY_LAN8742) | ||
| constexpr auto eth = EthernetDomain::Ethernet( | ||
| EthernetDomain::PINSET_H10, | ||
| "00:80:e1:00:01:08", | ||
| "192.168.1.7", | ||
| "255.255.0.0" | ||
| ); | ||
| #elif defined(USE_PHY_LAN8700) | ||
| constexpr auto eth = EthernetDomain::Ethernet( | ||
| EthernetDomain::PINSET_H10, | ||
| "00:80:e1:00:01:08", | ||
| "192.168.1.7", | ||
| "255.255.0.0" | ||
| ); | ||
| #elif defined(USE_PHY_KSZ8041) | ||
| constexpr auto eth = EthernetDomain::Ethernet( | ||
| EthernetDomain::PINSET_H11, | ||
| "00:80:e1:00:01:08", | ||
| "192.168.1.7", | ||
| "255.255.0.0" | ||
| ); | ||
| #else | ||
| #error "No PHY selected for Ethernet pinset selection" | ||
| #endif | ||
|
|
||
| using ExamplePacketsBoard = ST_LIB::Board<eth, led>; | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr uint16_t ORDER_ID_SET_SMALL_PROFILE = 0x5001; | ||
| constexpr uint16_t ORDER_ID_SET_LARGE_PROFILE = 0x5002; | ||
| constexpr uint16_t ORDER_ID_SET_EXTREMES = 0x5003; | ||
| constexpr uint16_t ORDER_ID_BUMP_STATE = 0x5004; | ||
| constexpr uint16_t ORDER_ID_SET_STATE_CODE = 0x5005; | ||
|
|
||
| constexpr uint32_t HEARTBEAT_PERIOD_MS = 250; | ||
| constexpr uint32_t SOCKET_RECONNECT_PERIOD_MS = 1000; | ||
|
|
||
| constexpr char BOARD_IP[] = "192.168.1.7"; | ||
|
|
||
| bool enable_flag{false}; | ||
| uint8_t small_counter{0}; | ||
| uint16_t window_size{0}; | ||
| uint32_t magic_value{0}; | ||
| uint64_t big_counter{0}; | ||
| int8_t trim_value{0}; | ||
| int16_t offset_value{0}; | ||
| int32_t position_value{0}; | ||
| int64_t energy_value{0}; | ||
| float ratio_value{0.0f}; | ||
| double precise_value{0.0}; | ||
|
|
||
| uint32_t tcp_order_count{0}; | ||
| uint32_t udp_parse_count{0}; | ||
| uint32_t heartbeat_ticks{0}; | ||
| uint16_t last_order_code{0}; | ||
|
|
||
| OrderPackets::order_mode order_mode{OrderPackets::order_mode::IDLE}; | ||
| OrderPackets::order_state order_state{OrderPackets::order_state::BOOT}; | ||
| DataPackets::mirror_mode mirror_mode{DataPackets::mirror_mode::IDLE}; | ||
| DataPackets::mirror_state mirror_state{DataPackets::mirror_state::BOOT}; | ||
|
|
||
| uint32_t probe_seq{0}; | ||
| bool probe_toggle{false}; | ||
| uint16_t probe_window{0}; | ||
| float probe_ratio{0.0f}; | ||
| DataPackets::probe_mode probe_mode{DataPackets::probe_mode::LOW}; | ||
| uint32_t last_seen_probe_seq{0}; | ||
|
|
||
| void sync_mirror_enums() { | ||
| mirror_mode = static_cast<DataPackets::mirror_mode>(static_cast<uint8_t>(order_mode)); | ||
| mirror_state = static_cast<DataPackets::mirror_state>(static_cast<uint8_t>(order_state)); | ||
| } | ||
|
|
||
| void process_orders() { | ||
| if (OrderPackets::set_small_profile_flag) { | ||
| OrderPackets::set_small_profile_flag = false; | ||
| ++tcp_order_count; | ||
| last_order_code = ORDER_ID_SET_SMALL_PROFILE; | ||
| } | ||
|
|
||
| if (OrderPackets::set_large_profile_flag) { | ||
| OrderPackets::set_large_profile_flag = false; | ||
| ++tcp_order_count; | ||
| last_order_code = ORDER_ID_SET_LARGE_PROFILE; | ||
| } | ||
|
|
||
| if (OrderPackets::set_extremes_flag) { | ||
| OrderPackets::set_extremes_flag = false; | ||
| ++tcp_order_count; | ||
| last_order_code = ORDER_ID_SET_EXTREMES; | ||
| } | ||
|
|
||
| if (OrderPackets::bump_state_flag) { | ||
| OrderPackets::bump_state_flag = false; | ||
| ++tcp_order_count; | ||
| last_order_code = ORDER_ID_BUMP_STATE; | ||
| const uint8_t next_state = (static_cast<uint8_t>(order_state) + 1U) % 4U; | ||
| order_state = static_cast<OrderPackets::order_state>(next_state); | ||
| } | ||
|
|
||
| if (OrderPackets::set_state_code_flag) { | ||
| OrderPackets::set_state_code_flag = false; | ||
| ++tcp_order_count; | ||
| last_order_code = ORDER_ID_SET_STATE_CODE; | ||
| } | ||
|
|
||
| sync_mirror_enums(); | ||
| } | ||
|
|
||
| void process_probe_packet() { | ||
| if (probe_seq == last_seen_probe_seq) { | ||
| return; | ||
| } | ||
| last_seen_probe_seq = probe_seq; | ||
| ++udp_parse_count; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| int main(void) { | ||
| Hard_fault_check(); | ||
| ExamplePacketsBoard::init(); | ||
| Scheduler::start(); | ||
|
|
||
| OrderPackets::set_small_profile_init(enable_flag, small_counter, offset_value, order_mode); | ||
| OrderPackets::set_large_profile_init( | ||
| window_size, | ||
| magic_value, | ||
| position_value, | ||
| ratio_value, | ||
| precise_value | ||
| ); | ||
| OrderPackets::set_extremes_init(trim_value, energy_value, big_counter); | ||
| OrderPackets::bump_state_init(); | ||
| OrderPackets::set_state_code_init(order_state); | ||
|
|
||
| DataPackets::order_mirror_init( | ||
| tcp_order_count, | ||
| last_order_code, | ||
| enable_flag, | ||
| small_counter, | ||
| offset_value, | ||
| mirror_mode | ||
| ); | ||
| DataPackets::numeric_mirror_init( | ||
| window_size, | ||
| magic_value, | ||
| position_value, | ||
| ratio_value, | ||
| precise_value | ||
| ); | ||
| DataPackets::extremes_mirror_init(trim_value, energy_value, big_counter, mirror_state); | ||
| DataPackets::udp_probe_init(probe_seq, probe_toggle, probe_window, probe_ratio, probe_mode); | ||
| DataPackets::udp_probe_echo_init( | ||
| udp_parse_count, | ||
| probe_seq, | ||
| probe_toggle, | ||
| probe_window, | ||
| probe_ratio, | ||
| probe_mode | ||
| ); | ||
| DataPackets::heartbeat_snapshot_init( | ||
| heartbeat_ticks, | ||
| tcp_order_count, | ||
| udp_parse_count, | ||
| mirror_state | ||
| ); | ||
|
|
||
| DataPackets::start(); | ||
| OrderPackets::start(); | ||
|
|
||
| auto& eth_instance = ExamplePacketsBoard::instance_of<eth>(); | ||
| auto& led_instance = ExamplePacketsBoard::instance_of<led>(); | ||
|
|
||
| sync_mirror_enums(); | ||
|
|
||
| uint32_t last_heartbeat_ms = HAL_GetTick(); | ||
| uint32_t last_reconnect_ms = HAL_GetTick(); | ||
| bool led_state = false; | ||
|
|
||
| while (1) { | ||
| eth_instance.update(); | ||
| Scheduler::update(); | ||
|
|
||
| process_orders(); | ||
| process_probe_packet(); | ||
|
|
||
| const uint32_t now = HAL_GetTick(); | ||
| if ((now - last_reconnect_ms) >= SOCKET_RECONNECT_PERIOD_MS) { | ||
| last_reconnect_ms = now; | ||
| if (OrderPackets::control_test_client != nullptr && | ||
| !OrderPackets::control_test_client->is_connected()) { | ||
| OrderPackets::control_test_client->reconnect(); | ||
| } | ||
| if (OrderPackets::control_test_tcp != nullptr && | ||
| !OrderPackets::control_test_tcp->is_connected() && | ||
| !OrderPackets::control_test_tcp->is_listening()) { | ||
| delete OrderPackets::control_test_tcp; | ||
| OrderPackets::control_test_tcp = new ServerSocket(BOARD_IP, 41000); | ||
| } | ||
| } | ||
|
|
||
| if ((now - last_heartbeat_ms) >= HEARTBEAT_PERIOD_MS) { | ||
| last_heartbeat_ms = now; | ||
| ++heartbeat_ticks; | ||
| sync_mirror_enums(); | ||
| led_state = !led_state; | ||
| if (led_state) { | ||
| led_instance.turn_on(); | ||
| } else { | ||
| led_instance.turn_off(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif // EXAMPLE_PACKETS |
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.