Crea sito


org.zu.ardulink.protocol
Class ALProtocol

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

public class ALProtocol
extends Object
implements IProtocol

Ardulink - return to homepage

v0.6.1 Magnum PI

This class implements the native Arduino Link protocol.
With this class you are able to send messages to Arduino.

Messages are in the format:

alp://<request or response>/<variable data>?id=<numeric message id>

where
requests from ardulink to arduino are:
kprs - Key Pressed
ppin - Power Pin Intensity
ppsw - Power Pin Switch
tone - Tone square wave start
notn - Tone square wave stop
srld - Start Listening Digital Pin
spld - Stop Listening Digital Pin
srla - Start Listening Analog Pin
spla - Stop Listening Analog Pin
cust - Custom message
requests from arduino to ardulink are:
ared - Analog Pin Read
dred - Digital Pin Read

responses (only from arduino) are:
rply - reply message

?id=<numeric message id> is not mandatory (for requests). If is supplied then a asynchronous
rply response will send from arduino. Otherwise arduino will not send a response.

Each message from ardulink to arduino terminate with a \n

See methods about variable data.

Variable data:
alp://kprs/chr<char pressed>cod<key code>loc<key location>mod<key modifiers>mex<key modifiers>?id=<message id>
alp://ppin/<pin>/<intensity>?id=<message id> intensity:0-255
alp://ppsw/<pin>/<power>?id=<message id> power:0-1
alp://srld/<pin>?id=<message id>
alp://spld/<pin>?id=<message id>
alp://srla/<pin>?id=<message id>
alp://spla/<pin>?id=<message id>
alp://tone/<pin>/<frequency>?id=<message id>
alp://tone/<pin>/<frequency>/<duration>?id=<message id>
alp://notn/<pin>?id=<message id>
alp://cust/<a custom message>?id=<message id>
alp://ared/<pin>/<intensity> intensity:0-1023
alp://dred/<pin>/<power> power:0-1
alp://rply/ok|ko?id=<message id>

Author:
Luciano Zu


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.zu.ardulink.protocol.IProtocol
IProtocol.ProtocolType
 
Field Summary
static String NAME
           
static int NO_DURATION
           
 
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
ALProtocol()
           
 
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[] message)
          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

NO_DURATION

public static final int NO_DURATION
See Also:
Constant Field Values
Constructor Detail

ALProtocol

public ALProtocol()
Method Detail

getProtocolName

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

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)

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)

parseMessage

public IncomingMessageEvent parseMessage(int[] message)
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.

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.