Byggern
Socket Class Reference

A socket which defines the communication in a CAN channel. More...

#include <socket.h>

Inheritance diagram for Socket:
Stream

Public Member Functions

 Socket (const Socket &)=delete
 
 Socket (uint8_t id)
 
void Initialize (CAN *can)
 
void Write (uint8_t *string, uint16_t size)
 
void WriteByte (uint8_t byte)
 
- Public Member Functions inherited from Stream
 Stream (uint16_t input_stream_size, uint16_t output_stream_size)
 
virtual uint16_t Read (uint8_t *string, uint16_t size)
 
virtual bool ReadByte (uint8_t &byte)
 
virtual uint8_t GetAvailableWriteBytes ()
 
virtual uint8_t GetAvailableReadBytes ()
 
virtual bool CheckInputOverflowFlag ()
 
virtual bool CheckOutputOverflowFlag ()
 
virtual uint16_t GetInputBufferLength ()
 
virtual uint16_t GetOutputBufferLength ()
 
virtual void FlushInputBuffer ()
 
virtual void FlushOutputBuffer ()
 

Static Public Member Functions

static SocketGetInstance (uint8_t id=0)
 
static void HandleDataFromLowerLevel (CanMessage &message)
 

Public Attributes

CANcan
 

Private Attributes

uint8_t id
 

Additional Inherited Members

- Protected Member Functions inherited from Stream
virtual uint16_t ReadFromBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, uint8_t *string, uint16_t &string_size)
 
virtual void WriteToBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, bool &overflow_flag, uint8_t *string, uint16_t &string_size, void(*cb)(Stream *stream))
 
virtual bool ReadByteFromBuffer (uint8_t &byte, uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty)
 
virtual void WriteByteToBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, bool &overflow_flag, uint8_t &byte, void(*cb)(Stream *stream))
 
virtual void WriteByteToInputStream (uint8_t &byte)
 
virtual bool ReadByteFromOutputStream (uint8_t &byte)
 
virtual void WriteToInputStream (uint8_t *string, uint16_t size)
 
virtual uint16_t ReadFromOutputStream (uint8_t *string, uint16_t size)
 
virtual uint16_t CalculateLength (uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty)
 
virtual void FlushStream (uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty)
 
- Protected Attributes inherited from Stream
uint8_t * input_buffer
 
uint8_t * output_buffer
 
uint16_t input_buffer_start_index = 0
 
uint16_t output_buffer_start_index = 0
 
uint16_t input_buffer_stop_index
 
uint16_t output_buffer_stop_index
 
uint16_t input_buffer_size
 
uint16_t output_buffer_size
 
void(* event_input_buffer_not_empty )(Stream *stream) = nullptr
 
void(* event_output_buffer_not_empty )(Stream *stream) = nullptr
 
bool input_buffer_empty = true
 
bool output_buffer_empty = true
 
bool input_buffer_overflowed = false
 
bool output_buffer_overflowed = false
 

Detailed Description

A socket which defines the communication in a CAN channel.

It uses an ID to identify which channel it is listening and sending on. This interface consists of two sockets , although it is flexible to increase the amount of sockets. See GetInstance() for more information regarding extending the number of sockets. The lower the socket identifier, the higher the priority.

Constructor & Destructor Documentation

§ Socket() [1/2]

Socket::Socket ( const Socket )
delete

Because of singleton, make sure it is not deleted

§ Socket() [2/2]

Socket::Socket ( uint8_t  id)
inline

The initializer. Not used by end user due to singleton

Parameters
idThe socket ID

Member Function Documentation

§ GetInstance()

static Socket& Socket::GetInstance ( uint8_t  id = 0)
inlinestatic

A Singleton implementation of this class. In order to have support for more than two sockets, this if else statement has to bee extended to the amount of sockets you wish to support.

Parameters
idThe socket ID

§ HandleDataFromLowerLevel()

static void Socket::HandleDataFromLowerLevel ( CanMessage message)
inlinestatic

Called when a new CAN_MESSAGE from the can controller has arrived. Puts the message into the stream

Parameters
messageThe received CAN_MESSAGE

§ Initialize()

void Socket::Initialize ( CAN can)
inline

Initializes the socket.

Parameters
canA can controller which implements the interface defined in the can class in this project
target_idThe target node id

§ Write()

void Socket::Write ( uint8_t *  string,
uint16_t  size 
)
virtual

Creates the required number of can messages and sends the data to the targeted id

Parameters
stringData to be sent
sizeSize of the data

Reimplemented from Stream.

§ WriteByte()

void Socket::WriteByte ( uint8_t  byte)
virtual

Creates a can message and sends the byte to the targeted id

Parameters
byte

Reimplemented from Stream.

Member Data Documentation

§ id

uint8_t Socket::id
private

This sockets identifier


The documentation for this class was generated from the following files: