Options
All
  • Public
  • Public/Protected
  • All
Menu

Manages a set of registered Sensors and provides a source for both Sensors and Sensor-related objects.

This controller is designed to be used by a server as a counterpart of a SensorObserverController.

You can either register the Sensors manually by calling registerSensor method or do it automatically from the controller options by defining your Sensors in a SensorDefinition array given in the sensors option of the controller.

SensorSourceController also takes some other options (they all default to false):

  • ignoreSensorDiscoverEvents: Ignores received discover events for registered sensors.
  • ignoreSensorQueryEvents: Ignores received query events for registered sensors.
  • skipSensorAdvertise: Does not advertise a sensor when registered.
  • skipSensorDeadvertise: Does not deadvertise a sensor when unregistered.

Hierarchy

Index

Constructors

constructor

Accessors

communicationManager

container

options

registeredName

  • get registeredName(): string
  • Gets the registered name of this controller.

    The registered name is either defined by the corresponding key in the Components.controllers object in the container configuration, or by invoking Container.registerController method with this name.

    Returns string

registeredSensorContainers

registeredSensors

  • get registeredSensors(): Sensor[]

runtime

Methods

Protected createObservation

  • Creates an Observation object for a Sensor.

    Subclasses can override this method to provide their own logic.

    Parameters

    • container: SensorContainer

      Sensor container creating the observation.

    • value: any

      Value of the observation.

    • Optional resultQuality: string[]

      The quality of the result. (optional)

    • Optional validTime: TimeInterval

      The validity time of the observation. (optional)

    • Optional parameters: {}

      Extra parameters for the observation. (optional)

      • [key: string]: any
    • Optional featureOfInterestId: string

      UUID of associated feature of interest. (optional)

    Returns Observation

Protected extendLogObject

  • extendLogObject(log: Log): void
  • Whenever one of the controller's log methods (e.g. logDebug, logInfo, logWarning, logError, logFatal) is called by application code, the controller creates a Log object with appropriate property values and passes it to this method before advertising it.

    You can override this method to additionally set certain properties (such as LogHost.hostname or Log.logLabels). Ensure that super.extendLogObject is called in your override. The base method does nothing.

    Parameters

    • log: Log

      log object to be extended before being advertised

    Returns void

findSensor

  • Returns the first registered sensor where the given predicate is true, undefined otherwise.

    Parameters

    • predicate: (sensor: Sensor) => boolean

      findSensor calls predicate once in arbitrary order for each registered sensor, until it finds one where predicate returns true. If such a sensor is found, that sensor is returned immediately. Otherwise, undefined is returned

        • Parameters

          Returns boolean

    Returns Sensor

    the first sensor matching the predicate; otherwise undefined

Protected getChannelId

getSensor

  • getSensor(sensorId: string): Sensor

getSensorContainer

getSensorIo

getSensorValueObservable

  • getSensorValueObservable(sensorId: string): Observable<any>
  • Returns an observable that emits values read from the sensor.

    Only the values read with publishChanneledObservation or publishAdvertisedObservation will emit new values. Reading the sensor value manually with SensorIo.read will not emit any new value.

    The observable is created lazily and cached. Once the Sensor associated with the observable is unregistered, all subscriptions to the observable are also unsubscribed.

    If the Sensor is not registered, this method will throw an error.

    Parameters

    • sensorId: string

    Returns Observable<any>

isRegistered

  • isRegistered(sensorId: string): boolean

logDebug

  • logDebug(message: string, ...tags: string[]): void

logError

  • logError(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for an error.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logErrorWithStacktrace

  • logErrorWithStacktrace(error: any, message: string, ...tags: string[]): void

logFatal

  • logFatal(error: any, message: string, ...tags: string[]): void
  • Advertise a Log object for a fatal error.

    Parameters

    • error: any

      an error (object)

    • message: string

      additional error message

    • Rest ...tags: string[]

      any number of log tags

    Returns void

logInfo

  • logInfo(message: string, ...tags: string[]): void

logWarning

  • logWarning(message: string, ...tags: string[]): void

onCommunicationManagerStarting

  • onCommunicationManagerStarting(): void

onCommunicationManagerStopping

  • onCommunicationManagerStopping(): void

onDispose

  • onDispose(): void
  • Called by the container when this instance should be disposed.

    Implement cleanup side effects here. Ensure that super.onDispose is called in your override. The base implementation does nothing.

    Returns void

onInit

  • onInit(): void
  • Called when the container has completely set up and injected all dependency components, including all its controllers.

    Override this method to perform initializations in your custom controller class instead of defining a constructor. Although the base implementation does nothing it is good practice to call super.onInit() in your override method; especially if your custom controller class does not extend from the base Controller class directly.

    Returns void

Protected onObservationDidPublish

Protected onObservationWillPublish

publishAdvertisedObservation

  • publishAdvertisedObservation(sensorId: string, resultQuality?: string[], validTime?: TimeInterval, parameters?: {}, featureOfInterestId?: string): void
  • Publishes an observation for a registered Sensor.

    If no such registered Sensor exists then an error is thrown. The publication is performed in the form of an advertise event.

    The observation value is read directly from the IO handler of the Sensor. The observation time is recorded as this method is called. Subclasses can change the final value of the observation object by overriding the createObservation method.

    Parameters

    • sensorId: string

      ObjectId of the Sensor to publish the observation.

    • Optional resultQuality: string[]

      The quality of the result. (optional)

    • Optional validTime: TimeInterval

      The validity time of the observation. (optional)

    • Optional parameters: {}

      Extra parameters for the observation. (optional)

      • [key: string]: any
    • Optional featureOfInterestId: string

      UUID of associated feature of interest. (optional)

    Returns void

publishChanneledObservation

  • publishChanneledObservation(sensorId: string, resultQuality?: string[], validTime?: TimeInterval, parameters?: {}, featureOfInterestId?: string): void
  • Publishes an observation for a registered Sensor.

    If no such registered Sensor exists then an error is thrown. The publication is performed in the form of a channel event. By default the channelId is the sensorId. However, subclasses can change it by overriding getChannelId method.

    The observation value is read directly from the IO handler of the Sensor. The observation time is recorded as this method is called. Subclasses can change the final value of the observation object by overriding the createObservation method.

    Parameters

    • sensorId: string

      ObjectId of the Sensor to publish the observation.

    • Optional resultQuality: string[]

      The quality of the result. (optional)

    • Optional validTime: TimeInterval

      The validity time of the observation. (optional)

    • Optional parameters: {}

      Extra parameters for the observation. (optional)

      • [key: string]: any
    • Optional featureOfInterestId: string

      UUID of associated feature of interest. (optional)

    Returns void

registerSensor

  • Registers a Sensor to this controller along with its IO handler interface.

    You can call this function at runtime or register sensors automatically at the beginning by passing them in the controller options under sensors as a SensorDefinition array.

    If a Sensor with the given objectId already exists, this method is simply ignored.

    When a sensor is registered, it is advertised to notify other listeners (unless ignoreSensorAdvertise option is set). The controller class also starts to listen on query and discover events for Sensors (unless skipSensorQueryEvents or skipSensorDiscoverEvents options are set).

    If the observationPublicationType is not set to none, then the value of the sensor is read every samplingInterval milliseconds and published as an observation automatically.

    Parameters

    • sensor: Sensor

      Sensor to register to the controller.

    • io: SensorIo

      IO handler interface for the sensor. This could be an Aio, InputGpio, OutputGpio, MockSensorIo or a custom handler.

    • observationPublicationType: ObservationPublicationType = "none"

      Whether and how the observations of the sensor should be published.

    • Optional samplingInterval: number

      If the observations are published automatically, defines how often the publications should be sent.

    Returns void

unregisterSensor

  • unregisterSensor(sensorId: string): Error
  • Unregisters a previously registered Sensor.

    If no such Sensor is registered, then an error is thrown.

    This also sends a disadvertise event to notify the listeners (unless ignoreSensorDeadvertise option is set). The query and discover events for this Sensor are ignored from this point on.

    If a value observable for the Sensor exists, then all subscriptions to that observable are unsubscribed.

    Parameters

    • sensorId: string

    Returns Error

Generated using TypeDoc