Crea sito


org.zu.ardulink.protocol
Class SimpleBinaryProtocol

java.lang.Object
  extended by org.zu.ardulink.protocol.SimpleBinaryProtocol
All Implemented Interfaces:
IProtocol

public class SimpleBinaryProtocol
extends Object
implements IProtocol

Ardulink - return to homepage

v0.6.1 Magnum PI

This is a binary protocol to minimize messages payload. With this protocol tiny devices as Digispark work better than with text protocols as ALProtocol (that is the default). Hovewer this protocol is actually very limited and are implemented only sendPowerPinIntensity and sendPowerPinSwitch methods (without callback feature).

Author:
Luciano Zu project Ardulink http://www.ardulink.org/
See Also:



Nested Class Summary
 
Nested classes/interfaces inherited from interface org.zu.ardulink.protocol.IProtocol
IProtocol.ProtocolType
 
Field Summary
static String NAME
           
 
Fields inherited from interface org.zu.ardulink.protocol.IProtocol
DEFAULT_INCOMING_MESSAGE_DIVIDER, DEFAULT_OUTGOING_MESSAGE_DIVIDER, HIGH, LOW, POWER_HIGH, POWER_LOW, REPLY_KO, REPLY_OK, UNDEFINED_ID, UNDEFINED_REPLY
 
Constructor Summary
SimpleBinaryProtocol()
           
 
Method Summary
 int getIncomingMessageDivider()
          the incoming message divider used from Connection to divide incoming message (if ProtocolType is binary then incoming must be equal to outgoing
 int getOutgoingMessageDivider()
          the outgoing message divider used from Protocol to divide outgoing message (if ProtocolType is binary then incoming must be equal to outgoing
 String getProtocolName()
           
 IProtocol.ProtocolType getProtocolType()
           
 IncomingMessageEvent parseMessage(int[] realMsg)
          When a message arrives from Arduino, ConnectionContactImpl and Link classes call this method that parses message and returns a specific event.
 MessageInfo sendCustomMessage(Link link, String message)
          Sends a custom message used for specific actions in Arduino sketches
 MessageInfo sendCustomMessage(Link link, String message, ReplyMessageCallback callback)
          Sends a custom message used for specific actions in Arduino sketches
 MessageInfo sendKeyPressEvent(Link link, char keychar, int keycode, int keylocation, int keymodifiers, int keymodifiersex)
          Sends information about which key was pressed.
 MessageInfo sendKeyPressEvent(Link link, char keychar, int keycode, int keylocation, int keymodifiers, int keymodifiersex, ReplyMessageCallback callback)
          Sends information about which key was pressed.
 MessageInfo sendNoToneMessage(Link link, int pin)
          Sends the request to stop the generation of a tone (square wave)
 MessageInfo sendNoToneMessage(Link link, int pin, ReplyMessageCallback callback)
          Sends the request to stop the generation of a tone (square wave)
 MessageInfo sendPowerPinIntensity(Link link, int pin, int intensity)
          Sends the request to set a PWM type pin to a certain intensity.
 MessageInfo sendPowerPinIntensity(Link link, int pin, int intensity, ReplyMessageCallback callback)
          Sends the request to set a PWM type pin to a certain intensity.
 MessageInfo sendPowerPinSwitch(Link link, int pin, int power)
          Sends the request to set a pin to HIGH or LOW power.
 MessageInfo sendPowerPinSwitch(Link link, int pin, int power, ReplyMessageCallback callback)
          Sends the request to set a pin to HIGH or LOW power.
 MessageInfo sendToneMessage(Link link, int pin, int frequency)
          Sends the request to generate a tone (square wave)
 MessageInfo sendToneMessage(Link link, int pin, int frequency, int duration)
          Sends the request to generate a tone (square wave)
 MessageInfo sendToneMessage(Link link, int pin, int frequency, int duration, ReplyMessageCallback callback)
          Sends the request to generate a tone (square wave)
 MessageInfo sendToneMessage(Link link, int pin, int frequency, ReplyMessageCallback callback)
          Sends the request to generate a tone (square wave)
 MessageInfo startListenAnalogPin(Link link, int pin)
          Sends the request to listen on a specific analog pin.
 MessageInfo startListenAnalogPin(Link link, int pin, ReplyMessageCallback callback)
          Sends the request to listen on a specific analog pin.
 MessageInfo startListenDigitalPin(Link link, int pin)
          Sends the request to listen on a specific pin.
 MessageInfo startListenDigitalPin(Link link, int pin, ReplyMessageCallback callback)
          Sends the request to listen on a specific pin.
 MessageInfo stopListenAnalogPin(Link link, int pin)
          Sends the request to not listen on a specific analog pin.
 MessageInfo stopListenAnalogPin(Link link, int pin, ReplyMessageCallback callback)
          Sends the request to not listen on a specific analog pin.
 MessageInfo stopListenDigitalPin(Link link, int pin)
          Sends the request to not listen on a specific pin.
 MessageInfo stopListenDigitalPin(Link link, int pin, ReplyMessageCallback callback)
          Sends the request to not listen on a specific pin.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME

public static final String NAME
See Also:
Constant Field Values
Constructor Detail

SimpleBinaryProtocol

public SimpleBinaryProtocol()
Method Detail

sendKeyPressEvent

public MessageInfo sendKeyPressEvent(Link link,
                                     char keychar,
                                     int keycode,
                                     int keylocation,
                                     int keymodifiers,
                                     int keymodifiersex)
Description copied from interface: IProtocol
Sends information about which key was pressed.

Specified by:
sendKeyPressEvent in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendPowerPinIntensity

public MessageInfo sendPowerPinIntensity(Link link,
                                         int pin,
                                         int intensity)
Description copied from interface: IProtocol
Sends the request to set a PWM type pin to a certain intensity. Values must be between 0 and 255. Arduino should perform an analogWrite(pin, intensity)

Specified by:
sendPowerPinIntensity in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendPowerPinSwitch

public MessageInfo sendPowerPinSwitch(Link link,
                                      int pin,
                                      int power)
Description copied from interface: IProtocol
Sends the request to set a pin to HIGH or LOW power. Arduino should perform a digitalWrite(pin, power)

Specified by:
sendPowerPinSwitch in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendToneMessage

public MessageInfo sendToneMessage(Link link,
                                   int pin,
                                   int frequency)
Description copied from interface: IProtocol
Sends the request to generate a tone (square wave)

Specified by:
sendToneMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendToneMessage

public MessageInfo sendToneMessage(Link link,
                                   int pin,
                                   int frequency,
                                   int duration)
Description copied from interface: IProtocol
Sends the request to generate a tone (square wave)

Specified by:
sendToneMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendNoToneMessage

public MessageInfo sendNoToneMessage(Link link,
                                     int pin)
Description copied from interface: IProtocol
Sends the request to stop the generation of a tone (square wave)

Specified by:
sendNoToneMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendCustomMessage

public MessageInfo sendCustomMessage(Link link,
                                     String message)
Description copied from interface: IProtocol
Sends a custom message used for specific actions in Arduino sketches

Specified by:
sendCustomMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendKeyPressEvent

public MessageInfo sendKeyPressEvent(Link link,
                                     char keychar,
                                     int keycode,
                                     int keylocation,
                                     int keymodifiers,
                                     int keymodifiersex,
                                     ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends information about which key was pressed.

Specified by:
sendKeyPressEvent in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendPowerPinIntensity

public MessageInfo sendPowerPinIntensity(Link link,
                                         int pin,
                                         int intensity,
                                         ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to set a PWM type pin to a certain intensity. Values must be between 0 and 255. Arduino should perform an analogWrite(pin, intensity)

Specified by:
sendPowerPinIntensity in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendPowerPinSwitch

public MessageInfo sendPowerPinSwitch(Link link,
                                      int pin,
                                      int power,
                                      ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to set a pin to HIGH or LOW power. Arduino should perform a digitalWrite(pin, power)

Specified by:
sendPowerPinSwitch in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendToneMessage

public MessageInfo sendToneMessage(Link link,
                                   int pin,
                                   int frequency,
                                   ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to generate a tone (square wave)

Specified by:
sendToneMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendToneMessage

public MessageInfo sendToneMessage(Link link,
                                   int pin,
                                   int frequency,
                                   int duration,
                                   ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to generate a tone (square wave)

Specified by:
sendToneMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendNoToneMessage

public MessageInfo sendNoToneMessage(Link link,
                                     int pin,
                                     ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to stop the generation of a tone (square wave)

Specified by:
sendNoToneMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

sendCustomMessage

public MessageInfo sendCustomMessage(Link link,
                                     String message,
                                     ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends a custom message used for specific actions in Arduino sketches

Specified by:
sendCustomMessage in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

parseMessage

public IncomingMessageEvent parseMessage(int[] realMsg)
Description copied from interface: IProtocol
When a message arrives from Arduino, ConnectionContactImpl and Link classes call this method that parses message and returns a specific event. If message arrived is a reply message then null is returned and a callback action is taken. Otherwise the caller take specific action based on specific IncomingMessage. i.e. if a AnalogReadChangeEvent is raised then the caller fire the event to all the listeners.

Specified by:
parseMessage in interface IProtocol
Returns:
IncomingMessageEvent dependent from message parsed, null if message is a reply message.

startListenDigitalPin

public MessageInfo startListenDigitalPin(Link link,
                                         int pin)
Description copied from interface: IProtocol
Sends the request to listen on a specific pin. After calling this method, Arduino should start sending messages about the value read from the specified pin (digitalRead).

Specified by:
startListenDigitalPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

stopListenDigitalPin

public MessageInfo stopListenDigitalPin(Link link,
                                        int pin)
Description copied from interface: IProtocol
Sends the request to not listen on a specific pin. After calling this method, Arduino should stop sending messages about the value read from the specified pin (digitalRead).

Specified by:
stopListenDigitalPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

startListenAnalogPin

public MessageInfo startListenAnalogPin(Link link,
                                        int pin)
Description copied from interface: IProtocol
Sends the request to listen on a specific analog pin. After calling this method, Arduino should start sending messages about the value read from the specified pin (analogRead).

Specified by:
startListenAnalogPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

stopListenAnalogPin

public MessageInfo stopListenAnalogPin(Link link,
                                       int pin)
Description copied from interface: IProtocol
Sends the request to not listen on a specific analog pin. After calling this method, Arduino should stop sending messages about the value read from the specified pin (analogRead).

Specified by:
stopListenAnalogPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

startListenDigitalPin

public MessageInfo startListenDigitalPin(Link link,
                                         int pin,
                                         ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to listen on a specific pin. After calling this method, Arduino should start sending messages about the value read from the specified pin (digitalRead).

Specified by:
startListenDigitalPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

stopListenDigitalPin

public MessageInfo stopListenDigitalPin(Link link,
                                        int pin,
                                        ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to not listen on a specific pin. After calling this method, Arduino should stop sending messages about the value read from the specified pin (digitalRead).

Specified by:
stopListenDigitalPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

startListenAnalogPin

public MessageInfo startListenAnalogPin(Link link,
                                        int pin,
                                        ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to listen on a specific analog pin. After calling this method, Arduino should start sending messages about the value read from the specified pin (analogRead).

Specified by:
startListenAnalogPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

stopListenAnalogPin

public MessageInfo stopListenAnalogPin(Link link,
                                       int pin,
                                       ReplyMessageCallback callback)
Description copied from interface: IProtocol
Sends the request to not listen on a specific analog pin. After calling this method, Arduino should stop sending messages about the value read from the specified pin (analogRead).

Specified by:
stopListenAnalogPin in interface IProtocol
Returns:
a MessageInfo containing the success or failure (for comunication)

getProtocolName

public String getProtocolName()
Specified by:
getProtocolName in interface IProtocol
Returns:
the protocol name

getProtocolType

public IProtocol.ProtocolType getProtocolType()
Specified by:
getProtocolType in interface IProtocol
Returns:
the protocol type

getIncomingMessageDivider

public int getIncomingMessageDivider()
Description copied from interface: IProtocol
the incoming message divider used from Connection to divide incoming message (if ProtocolType is binary then incoming must be equal to outgoing

Specified by:
getIncomingMessageDivider in interface IProtocol

getOutgoingMessageDivider

public int getOutgoingMessageDivider()
Description copied from interface: IProtocol
the outgoing message divider used from Protocol to divide outgoing message (if ProtocolType is binary then incoming must be equal to outgoing

Specified by:
getOutgoingMessageDivider in interface IProtocol


Copyright © 2015. All rights reserved.