TwiceAsNice
2019-02-18
|
A class to communicate with the AAG Cloud Watcher. More...
#include <CloudWatcherController.h>
Public Member Functions | |
CloudWatcherController (char *serialP) | |
A constructor. More... | |
CloudWatcherController (char *serialP, bool verbose) | |
A constructor. More... | |
virtual | ~CloudWatcherController () |
A destructor More... | |
bool | checkCloudWatcher () |
Checks if the AAG Cloud Watcher is connected and accesible by requesting its device name. More... | |
bool | getSwitchStatus (int *switchStatus) |
Obtains the status of the internal Switch of the AAG CLoud Watcher. More... | |
bool | getAllData (CloudWatcherData *cwd) |
Gets all raw dynamic data from the AAG Cloud Watcher. More... | |
bool | getConstants (CloudWatcherConstants *cwc) |
Gets all constants from the AAG Cloud Watcher. More... | |
bool | closeSwitch () |
Closes the internal switch of the AAG Cloud Watcher More... | |
bool | openSwitch () |
Opens the internal switch of the AAG Cloud Watcher More... | |
bool | setPWMDutyCycle (int pwmDutyCycle) |
Sets the PWM Duty Cycle (heater control) of the AAG Cloud Watcher More... | |
Private Member Functions | |
void | printBuffer (char *buffer, int num) |
Print a buffer of chars. More... | |
void | printMessage (const char *fmt,...) |
Prints a printf like expression if verbose mode is enabled. More... | |
bool | connectSerial () |
Connects to the serial port and set the appropriate flags for communication. More... | |
bool | disconnectSerial () |
Disconnects from the serial port and restores its previous configuration. More... | |
int | writeSerial (const char *buffer, int numberOfBytes) |
Writes a number of chars buffer into the serial port. More... | |
int | readSerial (char *buffer, int numberOfBytes) |
Reads a number of chars from the serial port. More... | |
bool | checkValidMessage (char *buffer, int nBlocks) |
Checks if the received message is a AAG CLoud Wathcer valid message. More... | |
bool | sendCloudwatcherCommand (const char *command) |
Sends a command to the AAG Cloud Watcher. More... | |
bool | sendCloudwatcherCommand (const char *command, int size) |
Sends a command to the AAG Cloud Watcher. More... | |
bool | getCloudWatcherAnswer (char *buffer, int nBlocks) |
Reads a AAG Cloud Watcher answer More... | |
bool | getFirmwareVersion () |
Reads the firmware version of the AAG Cloud Watcher and stores it in firmwareVersion attribute. More... | |
bool | getFirmwareVersion (char *version) |
Reads the firmware version of the AAG Cloud Watcher (if not previously read). More... | |
bool | getSerialNumber (int *serialNumber) |
Reads the serial number of the AAG Cloud Watcher More... | |
float | aggregateFloats (float values[], int numberOfValues) |
Performs an aggregation of the values stored in a float array. More... | |
int | aggregateInts (int values[], int numberOfValues) |
Performs an aggregation of the values stored in a int array. More... | |
bool | getIRSkyTemperature (int *temp) |
Reads the current IR Sky Temperature value of the AAG Cloud Watcher More... | |
bool | getIRSensorTemperature (int *temp) |
Reads the current IR Sensor Temperature value of the AAG Cloud Watcher More... | |
bool | getRainFrequency (int *rainFreq) |
Reads the current Rain Frequency value of the AAG Cloud Watcher More... | |
bool | getValues (int *internalSupplyVoltage, int *ambientTemperature, int *ldrValue, int *rainSensorTemperature) |
Reads the current Internal Supply Voltage, Ambient Temperature, LDR Value and Rain Sensor Temperature values of the AAG Cloud Watcher More... | |
bool | getPWMDutyCycle (int *pwmDutyCycle) |
Reads the current PWM Duty Cycle value of the AAG Cloud Watcher More... | |
bool | getIRErrors (int *firstAddressByteErrors, int *commandByteErrors, int *secondAddressByteErrors, int *pecByteErrors) |
Reads the current Error values of the AAG Cloud Watcher More... | |
bool | getElectricalConstants () |
Reads the electrical constants from the AAG Cloud Watcher and stores them into the internal attributes More... | |
bool | getAnemometerStatus (int *anemomterStatus) |
Reads the anemometer status of the AAG Cloud Watcher More... | |
bool | getWindSpeed (int *windSpeed) |
Reads the wind speed from the anemomter More... | |
Private Attributes | |
int | verbose |
true if info verbose output should be shown. More... | |
int | serialportFD |
File descriptor for the serial port. More... | |
struct termios | previousOptions |
Used to return the serial port to its original state More... | |
float | zenerConstant |
Hard coded constant. More... | |
float | ambPullUpResistance |
Hard coded constant. More... | |
float | ambResAt25 |
Hard coded constant. More... | |
float | ambBeta |
Hard coded constant. More... | |
float | LDRMaxResistance |
Hard coded constant. More... | |
float | LDRPullUpResistance |
Hard coded constant. More... | |
float | rainPullUpResistance |
Hard coded constant. More... | |
float | rainResAt25 |
Hard coded constant. More... | |
float | rainBeta |
Hard coded constant. More... | |
char * | firmwareVersion |
Firmware version. More... | |
char * | serialPort |
The serial port where the AAG Cloud Watcher is connected. More... | |
int | totalReadings |
The total number of readings performed by the controller More... | |
Static Private Attributes | |
static const int | BLOCK_SIZE = 15 |
AAG CloudWatcher send information in 15 bytes blocks More... | |
static const int | NUMBER_OF_READS = 5 |
Number of reads to aggregate for the cloudwatcher data More... | |
A class to communicate with the AAG Cloud Watcher.
It is responsible to send and recieve all the commands specified in the AAG Cloud Watcher documentation through the serial port.
CloudWatcherController::CloudWatcherController | ( | char * | serialP | ) |
A constructor.
serialP | the serial port to which the AAG Cloud Watcher is connected. For example: /dev/ttyUSB0 |
CloudWatcherController::CloudWatcherController | ( | char * | serialP, |
bool | verbose | ||
) |
A constructor.
serialP | the serial port to which the AAG Cloud Watcher is connected. For example: /dev/ttyUSB0 |
verbose | to specify if communication details have to be printed in the standar output. Do not use, just for testign pourposes. |
|
virtual |
A destructor
|
private |
Performs an aggregation of the values stored in a float array.
It computes average and standard deviation of the array and averages only the values within [average - deviation, average + deviation]
values | the values to be aggregated |
numberOfValues | the size of values |
|
private |
Performs an aggregation of the values stored in a int array.
It computes average and standard deviation of the array and averages only the values within [average - deviation, average + deviation]
values | the values to be aggregated |
numberOfValues | the size of values |
bool CloudWatcherController::checkCloudWatcher | ( | ) |
Checks if the AAG Cloud Watcher is connected and accesible by requesting its device name.
|
private |
Checks if the received message is a AAG CLoud Wathcer valid message.
buffer | the readed message |
nBlocks | the number of expected blocks in the message |
bool CloudWatcherController::closeSwitch | ( | ) |
Closes the internal switch of the AAG Cloud Watcher
|
private |
Connects to the serial port and set the appropriate flags for communication.
Also stores the previous configuration data of the port to be able to restore it when disconnecting.
|
private |
Disconnects from the serial port and restores its previous configuration.
bool CloudWatcherController::getAllData | ( | CloudWatcherData * | cwd | ) |
Gets all raw dynamic data from the AAG Cloud Watcher.
It follows the procedure described in the AAG Documents (5 readings for some values). This function takes more than 2 seconds and less than 3 to complete.
cwd | where the dynamic data of the AAG Cloud Watcher will be stored. |
|
private |
Reads the anemometer status of the AAG Cloud Watcher
anemometerStatus | where the anemometer status will be stored |
|
private |
Reads a AAG Cloud Watcher answer
buffer | where the answer will be stored. Should be big enough |
nBlocks | number of blocks to be readed |
bool CloudWatcherController::getConstants | ( | CloudWatcherConstants * | cwc | ) |
Gets all constants from the AAG Cloud Watcher.
Some of the constants are retrieved from the device (from firmware version >3.0)
cwc | where the constants of the AAG Cloud Watcher will be stored. |
|
private |
Reads the electrical constants from the AAG Cloud Watcher and stores them into the internal attributes
|
private |
Reads the firmware version of the AAG Cloud Watcher and stores it in firmwareVersion attribute.
|
private |
Reads the firmware version of the AAG Cloud Watcher (if not previously read).
version | a buffer where the version will be stored (at least 5 chars) |
|
private |
Reads the current Error values of the AAG Cloud Watcher
firstAddressByteErrors | where the first byte error count will be stored |
commandByteErrors | where the command byte error count will be stored |
secondAddressByteErrors | where the second byte error count will be stored |
pecByteErrors | where the PEC byte error count will be stored |
|
private |
Reads the current IR Sensor Temperature value of the AAG Cloud Watcher
temp | where the sensor value will be stored |
|
private |
Reads the current IR Sky Temperature value of the AAG Cloud Watcher
temp | where the sensor value will be stored |
|
private |
Reads the current PWM Duty Cycle value of the AAG Cloud Watcher
pwmDutyCycle | where the sensor value will be stored |
|
private |
Reads the current Rain Frequency value of the AAG Cloud Watcher
rainFreq | where the sensor value will be stored |
|
private |
Reads the serial number of the AAG Cloud Watcher
serialNumber | where the serial number will be stored |
bool CloudWatcherController::getSwitchStatus | ( | int * | switchStatus | ) |
Obtains the status of the internal Switch of the AAG CLoud Watcher.
switchStatus | where the switch status will be stored. 1 if open, 0 if closed. |
|
private |
Reads the current Internal Supply Voltage, Ambient Temperature, LDR Value and Rain Sensor Temperature values of the AAG Cloud Watcher
internalSupplyVoltage | where the sensor value will be stored |
ambientTemperature | where the sensor value will be stored |
ldrValue | where the sensor value will be stored |
rainSensorTemperature | where the sensor value will be stored |
|
private |
Reads the wind speed from the anemomter
windSpeed | where the wind speed will be stored |
bool CloudWatcherController::openSwitch | ( | ) |
Opens the internal switch of the AAG Cloud Watcher
|
private |
Print a buffer of chars.
Just for debugging
buffer | the buffer to be printed |
num | the number of chars to be printed |
|
private |
Prints a printf like expression if verbose mode is enabled.
Just for debugging
fmt | the pritnfexpression to be printed |
|
private |
Reads a number of chars from the serial port.
buffer | the buffer where the readed chars will be stored. Should be big enough por all chars |
numberOfBytes | the number of bytes to be read. |
Sends a command to the AAG Cloud Watcher.
command | a two byte array with the command to be sent |
Sends a command to the AAG Cloud Watcher.
command | a byte array with the command to be sent |
size | the number of bytes of the command |
bool CloudWatcherController::setPWMDutyCycle | ( | int | pwmDutyCycle | ) |
Sets the PWM Duty Cycle (heater control) of the AAG Cloud Watcher
pwmDutyCycle | The value of the PWM Duty Cycle (min - 0 to max - 1023) |
|
private |
Writes a number of chars buffer into the serial port.
It opens the serial port if not already opened.
buffer | the buffer of chars to be written in the serial port |
numberOfBytes | the number of chars to be written |
|
private |
Hard coded constant.
|
private |
Hard coded constant.
|
private |
Hard coded constant.
|
staticprivate |
AAG CloudWatcher send information in 15 bytes blocks
|
private |
|
private |
Hard coded constant.
May be changed with internal device constants.
|
private |
Hard coded constant.
May be changed with internal device constants.
|
staticprivate |
Number of reads to aggregate for the cloudwatcher data
|
private |
Used to return the serial port to its original state
|
private |
Hard coded constant.
May be changed with internal device constants.
|
private |
Hard coded constant.
May be changed with internal device constants.
|
private |
Hard coded constant.
May be changed with internal device constants.
|
private |
The serial port where the AAG Cloud Watcher is connected.
Set up at constructor.
|
private |
File descriptor for the serial port.
|
private |
The total number of readings performed by the controller
|
private |
true if info verbose output should be shown.
Just for debugging pourposes.
|
private |
Hard coded constant.
May be changed with internal device constants.