All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.geotab.model.entity.ioxaddon.IoxAddOn Maven / Gradle / Ivy

/*
 *
 * 2020 Copyright (C) Geotab Inc. All rights reserved.
 */

package com.geotab.model.entity.ioxaddon;

import com.geotab.model.entity.Entity;
import com.geotab.model.entity.device.Device;
import java.time.LocalDateTime;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * Represents an Iox Add-On (like modem or navigation device) that is attached to a GO unit. Each
 * Iox Add-On is assigned a channel - which is the serial port number that it typically communicates
 * with.
 */
@NoArgsConstructor
@Getter
@Setter
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class IoxAddOn extends Entity {

  /**
   * The channel on which the Add-On is attached to the GO unit. This is typically just a serial
   * port. 0 means the Add-On is not attached.
   */
  private Integer channel;

  /**
   * The unique identifier for this Iox Add-On type. Iox Add-On types are assigned by Geotab. See
   * {@link KnownIoxAddOnType}.
   */
  private Integer type;

  /**
   * The {@link Device} this IoxAddOn is connected to.
   */
  private Device device;

  /**
   * The DateTime this IoxAddOn was assigned it's channel.
   */
  private LocalDateTime dateTime;

  @Builder
  public IoxAddOn(String id, Integer channel, Integer type,
      Device device, LocalDateTime dateTime) {
    super(id);

    if (!isIoxAddOn(type)) {
      throw new IllegalArgumentException("Invalid identifier " + type);
    }

    this.channel = channel;
    this.type = type;
    this.device = device;
    this.dateTime = dateTime;
  }

  public void setType(Integer type) {
    if (!isIoxAddOn(type)) {
      throw new IllegalArgumentException("Invalid identifier " + type);
    }
    this.type = type;
  }

  /**
   * Determines whether the provided identifier is for an Iox Add-On. See {@link
   * KnownIoxAddOnType}.
   *
   * @param identifier The identifier.
   * @return true if the identifier is for a Iox Add-On; otherwise, false.
   */
  public static boolean isIoxAddOn(Integer identifier) {
    return identifier != null && identifier >= 4096 && identifier < 8192;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy