states Module

This module contains the state machine for the communication class.

Click on this image to go to the states from the diagram:

State Disgram for the Communication class.
class AYABInterface.communication.states.State(communication)[source]

Bases: object

The base class for states.

__init__(communication)[source]

Create a new state.

Please use the subclasses of this.

Parameters:communication (AYABInterface.communication.Communication) – the communication object which is in this state
__repr__()[source]

This object as string.

Return type:str
__weakref__

list of weak references to the object (if defined)

communication_started()[source]

Call when the communication starts.

enter()[source]

Called when the state is entered.

The AYABInterface.communication.Communication.state is set to this state.

exit()[source]

Called when this state is left.

The AYABInterface.communication.Communication.state is set to this state.

is_before_knitting()[source]

Whether the knitting should start soon.

Return type:bool
Returns:False
is_connection_closed()[source]

Whether the connection is closed.

Return type:bool
Returns:False
is_final()[source]

Whether the communication is over.

Return type:bool
Returns:False
is_initial_handshake()[source]

Whether the communication object is in the intial handshake.

Return type:bool
Returns:False
is_initializing_machine()[source]

Whether the machine is currently being initialized.

Return type:bool
Returns:False
is_knitting()[source]

Whether the machine ready to knit or knitting.

Return type:bool
Returns:False
is_knitting_line()[source]

Whether the machine knits a line.

Return type:bool
Returns:False
is_knitting_started()[source]

Whether the machine ready to knit the first line.

Return type:bool
Returns:false
is_starting_to_knit()[source]

Whether the machine initialized and knitting starts.

Return type:bool
Returns:False
is_unsupported_api_version()[source]

Whether the API version of communcation and controller do not match.

Return type:bool
Returns:False
is_waiting_for_start()[source]

Whether this state is waiting for the start.

Return type:bool
Returns:False
is_waiting_for_the_communication_to_start()[source]

Whether the communication can be started.

When this is True, you call call AYABInterface.communication.Communication.start() to leave the state.

Return type:bool
Returns:False
receive_connection_closed(message)[source]

Receive a ConnectionClosed message.

Parameters:message – a ConnectionClosed message

If the is called, the communication object transits into the ConnectionClosed.

receive_debug(message)[source]

Receive a Debug message.

Parameters:message – a Debug message

This logs the debug message.

receive_information_confirmation(message)[source]

Receive a InformationConfirmation message.

Parameters:message – a InformationConfirmation message
receive_line_request(message)[source]

Receive a LineRequest message.

Parameters:message – a LineRequest message
receive_message(message)[source]

Receive a message from the controller.

Parameters:message (AYABInterface.communication.hardware_messages.Message) – the message to receive

This method calls message.received_by which dispatches the call to the receive_* methods.

receive_start_confirmation(message)[source]

Receive a StartConfirmation message.

Parameters:message – a StartConfirmation message
receive_state_indication(message)[source]

Receive a StateIndication message.

Parameters:message – a StateIndication message
receive_test_confirmation(message)[source]

Receive a TestConfirmation message.

Parameters:message – a TestConfirmation message
receive_unknown(message)[source]

Receive a UnknownMessage message.

Parameters:message – a UnknownMessage message
class AYABInterface.communication.states.ConnectionClosed(communication)[source]

Bases: AYABInterface.communication.states.FinalState

The connection is closed.

is_connection_closed()[source]

The connection is closed.

Return type:bool
Returns:True
class AYABInterface.communication.states.WaitingForStart(communication)[source]

Bases: AYABInterface.communication.states.State

Waiting for the start() method to be called.

This is the initial state of a AYABInterface.communication.Communication.

communication_started()[source]

Call when the communication starts.

The communication object transits into InitialHandshake.

is_before_knitting()[source]

Whether the knitting should start soon.

Return type:bool
Returns:True
is_waiting_for_start()[source]

Whether this state is waiting for the start.

Call AYABInterface.communication.Comunication.start() to leave this state.

Return type:bool
Returns:True
class AYABInterface.communication.states.InitialHandshake(communication)[source]

Bases: AYABInterface.communication.states.State

The communication has started.

enter()[source]

This starts the handshake.

A AYABInterface.communication.host_messages.InformationRequest is sent to the controller.

is_before_knitting()[source]

Whether the knitting should start soon.

Return type:bool
Returns:True
is_initial_handshake()[source]

Whether the communication object is in the intial handshake.

Return type:bool
Returns:True
receive_information_confirmation(message)[source]

A InformationConfirmation is received.

If the api version is supported, the communication object transitions into a InitializingMachine, if unsupported, into a UnsupportedApiVersion

class AYABInterface.communication.states.UnsupportedApiVersion(communication)[source]

Bases: AYABInterface.communication.states.FinalState

The api version of the controller is not supported.

is_unsupported_api_version()[source]

Whether the API version of communcation and controller do not match.

Return type:bool
Returns:True
class AYABInterface.communication.states.InitializingMachine(communication)[source]

Bases: AYABInterface.communication.states.State

The machine is currently being intialized.

is_before_knitting()[source]

Whether the knitting should start soon.

Return type:bool
Returns:True
is_initializing_machine()[source]

Whether the machine is currently being initialized.

Return type:bool
Returns:True
is_waiting_for_carriage_to_pass_the_left_turn_mark()[source]

The carriage should be moved over the left turn mark.

Return type:bool
Returns:True
receive_state_indication(message)[source]

Receive a StateIndication message.

Parameters:message – a StateIndication message

If the message says that the controller is is ready to knit, there is a transition to StartingToKnit or else the messages are ignored because they come from The reqTest Message.

class AYABInterface.communication.states.StartingToKnit(communication)[source]

Bases: AYABInterface.communication.states.State

The cnfStart Message is sent and we wait for an answer.

enter()[source]

Send a StartRequest.

is_before_knitting()[source]

The knitting should start soon.

Return type:bool
Returns:True
is_starting_to_knit()[source]

The machine initialized and knitting starts.

Return type:bool
Returns:True
receive_start_confirmation(message)[source]

Receive a StartConfirmation message.

Parameters:message – a StartConfirmation message

If the message indicates success, the communication object transitions into KnittingStarted or else, into StartingFailed.

class AYABInterface.communication.states.StartingFailed(communication)[source]

Bases: AYABInterface.communication.states.FinalState

The starting process has failed.

is_starting_failed()[source]

The machine machine could not be configured to start.

Return type:bool
Returns:True
class AYABInterface.communication.states.KnittingStarted(communication)[source]

Bases: AYABInterface.communication.states.State

The knitting started and we are ready to receive The reqLine Message.

is_knitting()[source]

The machine ready to knit or knitting.

Return type:bool
Returns:True
is_knitting_started()[source]

The machine ready to knit the first line.

Return type:bool
Returns:True
receive_line_request(message)[source]

Receive a LineRequest message.

Parameters:message – a LineRequest message

The communicaion transisitions into a KnittingLine.

class AYABInterface.communication.states.KnittingLine(communication, line_number)[source]

Bases: AYABInterface.communication.states.State

The machine is currently knitting a line.

__init__(communication, line_number)[source]

The machine is knitting a line.

enter()[source]

Send a LineConfirmation to the controller.

When this state is entered, a AYABInterface.communication.host_messages.LineConfirmation is sent to the controller. Also, the last line requested is set.

is_knitting()[source]

The machine ready to knit or knitting.

Return type:bool
Returns:True
is_knitting_last_line()[source]

Whether the line currently knit is the last line.

Return type:bool
is_knitting_line()[source]

The machine knits a line.

Return type:bool
Returns:True
line_number

The number if the line which is currently knit.

Return type:int
receive_line_request(message)[source]

Receive a LineRequest message.

Parameters:message – a LineRequest message

The communicaion transisitions into a KnittingLine.

class AYABInterface.communication.states.FinalState(communication)[source]

Bases: AYABInterface.communication.states.State

Base class for states that can not reach knitting.

is_final()[source]

From the current state, the knitting can not be reached.

Return type:bool
Returns:True