AYAB Arduino Firmware 0.95
The goal of the AYAB project is to provide an alternative way to control the famous Brother KH-9xx range of knitting machines using a computer
Com Class Reference
Inheritance diagram for Com:
Inheritance graph
Collaboration diagram for Com:
Collaboration graph

Public Member Functions

void init () final
 Initialize serial communication.
 
void update () final
 Service the serial connection.
 
void send (uint8_t *payload, size_t length) const final
 Send a packet of data.
 
void sendMsg (AYAB_API_t id, const char *msg) final
 send initial msgid followed by null-terminated string
 
void send_reqLine (const uint8_t lineNumber, Err_t error=ErrorCode::success) const final
 Send reqLine message.
 
void send_indState (Carriage_t carriage, uint8_t position, Err_t error=ErrorCode::success) const final
 Send indState message.
 
void onPacketReceived (const uint8_t *buffer, size_t size) final
 Callback for PacketSerial.
 

Private Member Functions

void h_reqInit (const uint8_t *buffer, size_t size)
 Handle reqInit (request initialization) command.
 
void h_reqStart (const uint8_t *buffer, size_t size)
 Handle reqStart (start request) command.
 
void h_cnfLine (const uint8_t *buffer, size_t size)
 Handle cnfLine (configure line) command.
 
void h_reqInfo () const
 Handle reqInfo (request information) command.
 
void h_reqTest () const
 Handle reqTest (request hardware test) command.
 
void h_unrecognized () const
 Handle unrecognized command.
 
void send_cnfInfo () const
 Send cnfInfo message.
 
void send_cnfInit (Err_t error) const
 Send cnfInit message.
 
void send_cnfStart (Err_t error) const
 Send cnfStart message.
 
void send_cnfTest (Err_t error) const
 Send cnfTest message.
 
uint8_t CRC8 (const uint8_t *buffer, size_t len) const
 Calculate CRC8 of a buffer.
 

Private Attributes

PacketSerial_< SLIP, SLIP::END, MAX_MSG_BUFFER_LEN > m_packetSerial
 
uint8_t lineBuffer [MAX_LINE_BUFFER_LEN] = {0}
 
uint8_t msgBuffer [MAX_MSG_BUFFER_LEN] = {0}
 

Member Function Documentation

◆ CRC8()

uint8_t Com::CRC8 ( const uint8_t *  buffer,
size_t  len 
) const
private

Calculate CRC8 of a buffer.

Parameters
bufferA pointer to a data buffer.
lenThe number of bytes of data in the data buffer.

Based on https://www.leonardomiliani.com/en/2013/un-semplice-crc8-per-arduino/

CRC-8 - based on the CRC8 formulas by Dallas/Maxim code released under the therms of the GNU GPL 3.0 license

Faster code using a lookup table is available, if needed.

Here is the caller graph for this function:

◆ h_cnfLine()

void Com::h_cnfLine ( const uint8_t *  buffer,
size_t  size 
)
private

Handle cnfLine (configure line) command.

Parameters
bufferA pointer to a data buffer.
sizeThe number of bytes in the data buffer.
Todo:

sl: Handle CRC-8 error?

sl: Assert size? Handle error?

References CRC8().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ h_reqInfo()

void Com::h_reqInfo ( ) const
private

Handle reqInfo (request information) command.

Parameters
bufferA pointer to a data buffer.
sizeThe number of bytes in the data buffer.

References send_cnfInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ h_reqInit()

void Com::h_reqInit ( const uint8_t *  buffer,
size_t  size 
)
private

Handle reqInit (request initialization) command.

Parameters
bufferA pointer to a data buffer.
sizeThe number of bytes in the data buffer.

References CRC8(), and send_cnfInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ h_reqStart()

void Com::h_reqStart ( const uint8_t *  buffer,
size_t  size 
)
private

Handle reqStart (start request) command.

Parameters
bufferA pointer to a data buffer.
sizeThe number of bytes in the data buffer.

References CRC8(), and send_cnfStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ h_reqTest()

void Com::h_reqTest ( ) const
private

Handle reqTest (request hardware test) command.

Parameters
bufferA pointer to a data buffer.
sizeThe number of bytes in the data buffer.

References send_cnfTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void Com::init ( )
finalvirtual

Initialize serial communication.

Implements ComInterface.

References PacketSerial_< EncoderType, PacketMarker, BufferSize >::begin(), and PacketSerial_< EncoderType, PacketMarker, BufferSize >::setPacketHandler().

Here is the call graph for this function:

◆ onPacketReceived()

void Com::onPacketReceived ( const uint8_t *  buffer,
size_t  size 
)
finalvirtual

Callback for PacketSerial.

Parameters
bufferA pointer to a data buffer.
sizeThe number of bytes in the data buffer.

Implements ComInterface.

References h_cnfLine(), h_reqInfo(), h_reqInit(), h_reqStart(), h_reqTest(), and h_unrecognized().

Here is the call graph for this function:

◆ send()

void Com::send ( uint8_t *  payload,
size_t  length 
) const
finalvirtual

Send a packet of data.

Parameters
payloadA pointer to a data buffer.
lengthThe number of bytes in the data buffer.

Implements ComInterface.

References PacketSerial_< EncoderType, PacketMarker, BufferSize >::send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_cnfInit()

void Com::send_cnfInit ( Err_t  error) const
private

Send cnfInit message.

Parameters
errorError code (0 = success, other values = error).

References send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_cnfStart()

void Com::send_cnfStart ( Err_t  error) const
private

Send cnfStart message.

Parameters
errorError code (0 = success, other values = error).

References send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_cnfTest()

void Com::send_cnfTest ( Err_t  error) const
private

Send cnfTest message.

Parameters
errorError code (0 = success, other values = error).

References send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_indState()

void Com::send_indState ( Carriage_t  carriage,
uint8_t  position,
Err_t  error = ErrorCode::success 
) const
finalvirtual

Send indState message.

Parameters
carriageType of knitting carriage in use.
positionPosition of knitting carriage in needles from left hand side.
initStateState of readiness (0 = ready, other values = not ready).

Implements ComInterface.

References send().

Here is the call graph for this function:

◆ send_reqLine()

void Com::send_reqLine ( const uint8_t  lineNumber,
Err_t  error = ErrorCode::success 
) const
finalvirtual

Send reqLine message.

Parameters
lineNumberThe line number requested (0-indexed and modulo 256).
errorError code (0 = success).

Implements ComInterface.

References send().

Here is the call graph for this function:

◆ sendMsg()

void Com::sendMsg ( AYAB_API_t  id,
const char *  msg 
)
finalvirtual

send initial msgid followed by null-terminated string

Parameters
idThe msgid to be sent.
msgPointer to a data buffer containing a null-terminated string.

Implements ComInterface.

References send().

Here is the call graph for this function:

◆ update()

void Com::update ( )
finalvirtual

Service the serial connection.

Implements ComInterface.

References PacketSerial_< EncoderType, PacketMarker, BufferSize >::update().

Here is the call graph for this function:

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