Add sending of small frames with no zeroes
This commit is contained in:
		
							parent
							
								
									26537474ae
								
							
						
					
					
						commit
						a089eaa868
					
				
					 4 changed files with 82 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -24,7 +24,7 @@ SOFTWARE.
 | 
			
		|||
 | 
			
		||||
#include "protocol/byte_stuffer.h"
 | 
			
		||||
#include "protocol/frame_validator.h"
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "protocol/physical.h"
 | 
			
		||||
 | 
			
		||||
// This implements the "Consistent overhead byte stuffing protocol"
 | 
			
		||||
// https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing
 | 
			
		||||
| 
						 | 
				
			
			@ -92,3 +92,13 @@ void recv_byte(byte_stuffer_state_t* state, uint8_t data) {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void send_frame(uint8_t* data, uint16_t size) {
 | 
			
		||||
    if (size > 0) {
 | 
			
		||||
        uint8_t numZeroes = size + 1;
 | 
			
		||||
        const uint8_t zero = 0;
 | 
			
		||||
        send_data(&numZeroes, 1);
 | 
			
		||||
        send_data(data, size);
 | 
			
		||||
        send_data(&zero, 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,3 +25,4 @@ SOFTWARE.
 | 
			
		|||
typedef struct byte_stuffer_state byte_stuffer_state_t;
 | 
			
		||||
void init_byte_stuffer_state(byte_stuffer_state_t* state);
 | 
			
		||||
void recv_byte(byte_stuffer_state_t* state, uint8_t data);
 | 
			
		||||
void send_frame(uint8_t* data, uint16_t size);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										25
									
								
								serial_link/protocol/physical.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								serial_link/protocol/physical.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
/*
 | 
			
		||||
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.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
void send_data(const uint8_t* data, uint16_t size);
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue