Class BabelMatrixDemo2

java.lang.Object
pt.unl.fct.di.novasys.babel.core.GenericProtocol
pt.unl.fct.di.tardis.babel.iot.demos.BabelMatrixDemo2
All Implemented Interfaces:
BabelDemo

public class BabelMatrixDemo2 extends pt.unl.fct.di.novasys.babel.core.GenericProtocol implements BabelDemo
Extended LED-matrix demo: a companion to BabelMatrixDemo that steps through a longer, fixed catalogue of frames added by ParadigmShift — coloured letters, the full set of arrow glyphs (plain, inverted, mosaic), and the standard symbols (forbidden / OK / wrong / mandatory direction signs), several of them painted with explicit or randomised colours.

Like BabelMatrixDemo it drives the single I²C LED matrix through I2COutputControlProtocol (id 2000), registering it with a RegisterIoTDeviceRequest (no GPIO line — it is an I²C device) and painting each frame as a raw 8×8 bitmap via ShowDisplayRequest, with SetDisplayColorRequest used to clear the panel between cycles.

The Babel concept this variant illustrates is the fixed-rate periodic timer: instead of re-arming a one-shot timer per frame, it advances one sequencePosition step on every DemoTimer tick from a single setupPeriodicTimer. (Compare BabelMatrixDemo's self-rescheduling one-shot approach.)

The application never touches Pi4J or the I²C bus directly — it only sends Babel requests; I2COutputControlProtocol does the hardware work.

Run with the LedMatrix2 command-line name (see Main).

  • Nested Class Summary

    Nested classes/interfaces inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    pt.unl.fct.di.novasys.babel.core.GenericProtocol.ProtocolMetricsBabelMetrics
  • Field Summary

    Fields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    babel, babelSecurity

    Fields inherited from interface pt.unl.fct.di.tardis.babel.iot.demos.BabelDemo

    PROTO_ID, PROTO_NAME
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sets the protocol identity Babel uses to route events here.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Application bootstrap (the entry point Main calls for the LedMatrix2 demo).
    void
    handleDemoTimer(DemoTimer t, long time)
    Periodic timer handler that paints one catalogue frame per tick.
    void
    handleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId)
    Reply handler for the device registration: keeps the matrix DeviceHandle and starts the slideshow.
    void
    Babel lifecycle hook: register the timer and reply handlers, then request the matrix.

    Methods inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    addSecret, addSecret, addSecret, addSecret, cancelTimer, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, createChannel, createSecureChannel, createSecureChannel, createSecureChannel, createSecureChannelWithAliases, createSecureChannelWithAliases, createSecureChannelWithIdentities, createSecureChannelWithIdentities, createSecureChannelWithProtoIdentities, enableGenericMetrics, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateSecret, generateSecret, generateSecret, generateSecret, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, getChannelOrThrow, getDefaultChannel, getDefaultProtoIdentity, getDefaultProtoIdentityCrypt, getDefaultProtoSecret, getMillisSinceBabelStart, getOrGenerateDefaultProtoIdentity, getProtoId, getProtoName, hasProtocolThreadStarted, openConnection, openConnection, openConnection, openConnection, registerChannelEventHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageSerializer, registerMetric, registerReplyHandler, registerRequestHandler, registerSharedChannel, registerTimerHandler, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendReply, sendRequest, setDefaultChannel, setDefaultProtoIdentity, setDefaultProtoIdentity, setDefaultProtoSecret, setupPeriodicTimer, setupTimer, startEventThread, subscribeNotification, triggerNotification, unsubscribeNotification

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BabelMatrixDemo2

      public BabelMatrixDemo2()
      Sets the protocol identity Babel uses to route events here. No hardware is touched yet — registration happens in init(java.util.Properties).
  • Method Details

    • init

      public void init(Properties props) throws pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException, IOException
      Babel lifecycle hook: register the timer and reply handlers, then request the matrix. The RegisterIoTDeviceReply handler is registered before the RegisterIoTDeviceRequest is sent so the reply always lands on a handler.
      Specified by:
      init in class pt.unl.fct.di.novasys.babel.core.GenericProtocol
      Throws:
      pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException
      IOException
    • handleDemoTimer

      public void handleDemoTimer(DemoTimer t, long time)
      Periodic timer handler that paints one catalogue frame per tick. It selects the frame by sequencePosition, encodes it into an 8×8 bitmap with LedMatrixUtils, and sends it as a ShowDisplayRequest; when the sequence runs out it clears the panel and wraps back to the start. The tick cadence is owned by the setupPeriodicTimer armed in the reply handler, so this method just advances state and emits one display request.
    • handleRegisterIoTDeviceReply

      public void handleRegisterIoTDeviceReply(pt.unl.fct.di.tardis.babel.iot.api.replies.RegisterIoTDeviceReply rep, short protocolId)
      Reply handler for the device registration: keeps the matrix DeviceHandle and starts the slideshow. Checks RegisterIoTDeviceReply.isSuccessful() and the alias before using the handle, paints an initial green fill, then arms a fixed-rate periodic timer that drives handleDemoTimer(pt.unl.fct.di.tardis.babel.iot.demos.events.DemoTimer, long) every 2s.
    • execute

      public void execute() throws Exception
      Application bootstrap (the entry point Main calls for the LedMatrix2 demo). Standard Babel start-up: get the Babel singleton, load config, instantiate the one control protocol it needs (I2COutputControlProtocol), register both protocols, init them in dependency order (controller before demo), then b.start() to enter the event loop.
      Specified by:
      execute in interface BabelDemo
      Throws:
      Exception