Start implement router
This commit is contained in:
parent
5a1600e24f
commit
4b9fccc756
8 changed files with 238 additions and 112 deletions
|
@ -56,7 +56,7 @@ void init_byte_stuffer(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void recv_byte(uint8_t link, uint8_t data) {
|
||||
void byte_stuffer_recv_byte(uint8_t link, uint8_t data) {
|
||||
byte_stuffer_state_t* state = &states[link];
|
||||
// Start of a new frame
|
||||
if (state->next_zero == 0) {
|
||||
|
@ -112,7 +112,7 @@ static void send_block(uint8_t link, uint8_t* start, uint8_t* end, uint8_t num_n
|
|||
}
|
||||
}
|
||||
|
||||
void send_frame(uint8_t link, uint8_t* data, uint16_t size) {
|
||||
void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) {
|
||||
const uint8_t zero = 0;
|
||||
if (size > 0) {
|
||||
uint16_t num_non_zero = 1;
|
||||
|
|
|
@ -23,5 +23,5 @@ SOFTWARE.
|
|||
*/
|
||||
|
||||
void init_byte_stuffer(void);
|
||||
void recv_byte(uint8_t link, uint8_t data);
|
||||
void send_frame(uint8_t link, uint8_t* data, uint16_t size);
|
||||
void byte_stuffer_recv_byte(uint8_t link, uint8_t data);
|
||||
void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size);
|
||||
|
|
33
serial_link/protocol/frame_router.c
Normal file
33
serial_link/protocol/frame_router.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Fred Sundvik
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "protocol/frame_router.h"
|
||||
|
||||
void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
|
||||
validator_send_frame(DOWN_LINK, data, size);
|
||||
}
|
||||
|
||||
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
|
||||
validator_send_frame(DOWN_LINK, data, size);
|
||||
}
|
|
@ -22,4 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#define UP_LINK 0
|
||||
#define DOWN_LINK 1
|
||||
|
||||
void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size);
|
||||
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size);
|
||||
|
|
|
@ -116,5 +116,5 @@ void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) {
|
|||
void validator_send_frame(uint8_t link, uint8_t* data, uint16_t size) {
|
||||
uint32_t crc = crc32_byte(data, size);
|
||||
memcpy(data + size, &crc, 4);
|
||||
send_frame(link, data, size + 4);
|
||||
byte_stuffer_send_frame(link, data, size + 4);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue