001/* 002 * geordi 003 * 004 * Copyright (C) 2018 Richard "Shred" Körber 005 * https://github.com/shred/geordi 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as 009 * published by the Free Software Foundation, either version 3 of the 010 * License, or (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 015 */ 016package org.shredzone.geordi.device; 017 018import java.util.List; 019 020import org.json.JSONObject; 021import org.quartz.CronExpression; 022import org.shredzone.geordi.data.Sample; 023 024/** 025 * A {@link Device} is some kind of hardware that is to be frequently polled for new 026 * sensor data. A device can have one or more sensors. 027 * <p> 028 * Even though all Geordi devices use the network to access sensor data, this is not a 029 * requirement. A {@link Device} implementation could also read hardware sensors directly. 030 */ 031public abstract class Device { 032 033 private int id; 034 private String name; 035 private CronExpression cron; 036 private JSONObject config; 037 038 /** 039 * Reads the device ID. 040 */ 041 public int getId() { 042 return id; 043 } 044 045 /** 046 * Sets the device ID. It must be unique. 047 */ 048 public void setId(int id) { 049 this.id = id; 050 } 051 052 /** 053 * Reads a human-readable device name. 054 */ 055 public String getName() { 056 return name; 057 } 058 059 /** 060 * Sets the device name. 061 */ 062 public void setName(String name) { 063 this.name = name; 064 } 065 066 /** 067 * Reads the {@link CronExpression} that is used for polling the device sensors. 068 */ 069 public CronExpression getCron() { 070 return cron; 071 } 072 073 /** 074 * Sets the {@link CronExpression} that is used for polling the device sensors. 075 */ 076 public void setCron(CronExpression cron) { 077 this.cron = cron; 078 } 079 080 /** 081 * Reads the JSON configuration of the device. 082 */ 083 public JSONObject getConfig() { 084 return config; 085 } 086 087 /** 088 * Sets the JSON configuration of the device. 089 */ 090 public void setConfig(JSONObject config) { 091 this.config = config; 092 } 093 094 /** 095 * Reads all sensors of this device. 096 * 097 * @return List of {@link Sample} objects containing all current sensor values that 098 * have been read. 099 */ 100 public abstract List<Sample> readSensors(); 101 102}