TwiceAsNice  2019-02-18
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CloudWatcherController Class Reference

A class to communicate with the AAG Cloud Watcher. More...

#include <CloudWatcherController.h>

Collaboration diagram for CloudWatcherController:
Collaboration graph

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CloudWatcherController() [1/2]

CloudWatcherController::CloudWatcherController ( char *  serialP)


A constructor.

Parameters
serialPthe serial port to which the AAG Cloud Watcher is connected. For example: /dev/ttyUSB0

◆ CloudWatcherController() [2/2]

CloudWatcherController::CloudWatcherController ( char *  serialP,
bool  verbose 
)


A constructor.

Parameters
serialPthe serial port to which the AAG Cloud Watcher is connected. For example: /dev/ttyUSB0
verboseto specify if communication details have to be printed in the standar output. Do not use, just for testign pourposes.

◆ ~CloudWatcherController()

CloudWatcherController::~CloudWatcherController ( )
virtual


A destructor

Member Function Documentation

◆ aggregateFloats()

float CloudWatcherController::aggregateFloats ( float  values[],
int  numberOfValues 
)
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]

Parameters
valuesthe values to be aggregated
numberOfValuesthe size of values
Returns
the aggregated value

◆ aggregateInts()

int CloudWatcherController::aggregateInts ( int  values[],
int  numberOfValues 
)
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]

Parameters
valuesthe values to be aggregated
numberOfValuesthe size of values
Returns
the aggregated value

◆ checkCloudWatcher()

bool CloudWatcherController::checkCloudWatcher ( )


Checks if the AAG Cloud Watcher is connected and accesible by requesting its device name.

Returns
true if the AAG CLoud Watcher is connected and accesible. false otherwise.

◆ checkValidMessage()

bool CloudWatcherController::checkValidMessage ( char *  buffer,
int  nBlocks 
)
private


Checks if the received message is a AAG CLoud Wathcer valid message.

Parameters
bufferthe readed message
nBlocksthe number of expected blocks in the message
Returns
true if it is a valid message. false otherwise

◆ closeSwitch()

bool CloudWatcherController::closeSwitch ( )


Closes the internal switch of the AAG Cloud Watcher

Returns
true if the internal switch is closed. false otherwise.

◆ connectSerial()

bool CloudWatcherController::connectSerial ( )
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.

Returns
true if successfully connected to the port. false otherwise.
See also
disconnectSerial()

◆ disconnectSerial()

bool CloudWatcherController::disconnectSerial ( )
private


Disconnects from the serial port and restores its previous configuration.

Returns
true if successfully disconnected. false otherwise.
See also
connectSerial()

◆ getAllData()

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.

Parameters
cwdwhere the dynamic data of the AAG Cloud Watcher will be stored.
Returns
true if the data has been correctly gathered. false otherwise.

◆ getAnemometerStatus()

bool CloudWatcherController::getAnemometerStatus ( int *  anemomterStatus)
private


Reads the anemometer status of the AAG Cloud Watcher

Parameters
anemometerStatuswhere the anemometer status will be stored
Returns
true if succesfully read. false otherwise.

◆ getCloudWatcherAnswer()

bool CloudWatcherController::getCloudWatcherAnswer ( char *  buffer,
int  nBlocks 
)
private


Reads a AAG Cloud Watcher answer

Parameters
bufferwhere the answer will be stored. Should be big enough
nBlocksnumber of blocks to be readed

◆ getConstants()

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)

Parameters
cwcwhere the constants of the AAG Cloud Watcher will be stored.
Returns
true if the constants has been correctly gathered. false otherwise.

◆ getElectricalConstants()

bool CloudWatcherController::getElectricalConstants ( )
private


Reads the electrical constants from the AAG Cloud Watcher and stores them into the internal attributes

Returns
true if succesfully read. false otherwise.
See also
zenerConstant
LDRMaxResistance
LDRPullUpResistance
rainPullUpResistance
rainResAt25
rainBeta

◆ getFirmwareVersion() [1/2]

bool CloudWatcherController::getFirmwareVersion ( )
private


Reads the firmware version of the AAG Cloud Watcher and stores it in firmwareVersion attribute.

Returns
true if successfully read. false otherwise
See also
getFirmwareVersion(char *version)
firmwareVersion

◆ getFirmwareVersion() [2/2]

bool CloudWatcherController::getFirmwareVersion ( char *  version)
private


Reads the firmware version of the AAG Cloud Watcher (if not previously read).

Parameters
versiona buffer where the version will be stored (at least 5 chars)
Returns
true if succesfully read. false otherwise.
See also
getFirmwareVersion()

◆ getIRErrors()

bool CloudWatcherController::getIRErrors ( int *  firstAddressByteErrors,
int *  commandByteErrors,
int *  secondAddressByteErrors,
int *  pecByteErrors 
)
private


Reads the current Error values of the AAG Cloud Watcher

Parameters
firstAddressByteErrorswhere the first byte error count will be stored
commandByteErrorswhere the command byte error count will be stored
secondAddressByteErrorswhere the second byte error count will be stored
pecByteErrorswhere the PEC byte error count will be stored
Returns
true if succesfully read. false otherwise.

◆ getIRSensorTemperature()

bool CloudWatcherController::getIRSensorTemperature ( int *  temp)
private


Reads the current IR Sensor Temperature value of the AAG Cloud Watcher

Parameters
tempwhere the sensor value will be stored
Returns
true if succesfully read. false otherwise.

◆ getIRSkyTemperature()

bool CloudWatcherController::getIRSkyTemperature ( int *  temp)
private


Reads the current IR Sky Temperature value of the AAG Cloud Watcher

Parameters
tempwhere the sensor value will be stored
Returns
true if succesfully read. false otherwise.

◆ getPWMDutyCycle()

bool CloudWatcherController::getPWMDutyCycle ( int *  pwmDutyCycle)
private


Reads the current PWM Duty Cycle value of the AAG Cloud Watcher

Parameters
pwmDutyCyclewhere the sensor value will be stored
Returns
true if succesfully read. false otherwise.

◆ getRainFrequency()

bool CloudWatcherController::getRainFrequency ( int *  rainFreq)
private


Reads the current Rain Frequency value of the AAG Cloud Watcher

Parameters
rainFreqwhere the sensor value will be stored
Returns
true if succesfully read. false otherwise.

◆ getSerialNumber()

bool CloudWatcherController::getSerialNumber ( int *  serialNumber)
private


Reads the serial number of the AAG Cloud Watcher

Parameters
serialNumberwhere the serial number will be stored
Returns
true if succesfully read. false otherwise.

◆ getSwitchStatus()

bool CloudWatcherController::getSwitchStatus ( int *  switchStatus)


Obtains the status of the internal Switch of the AAG CLoud Watcher.

Parameters
switchStatuswhere the switch status will be stored. 1 if open, 0 if closed.
Returns
true if the status of the switch has been correctly determined. false otherwise.

◆ getValues()

bool CloudWatcherController::getValues ( int *  internalSupplyVoltage,
int *  ambientTemperature,
int *  ldrValue,
int *  rainSensorTemperature 
)
private


Reads the current Internal Supply Voltage, Ambient Temperature, LDR Value and Rain Sensor Temperature values of the AAG Cloud Watcher

Parameters
internalSupplyVoltagewhere the sensor value will be stored
ambientTemperaturewhere the sensor value will be stored
ldrValuewhere the sensor value will be stored
rainSensorTemperaturewhere the sensor value will be stored
Returns
true if succesfully read. false otherwise.

◆ getWindSpeed()

bool CloudWatcherController::getWindSpeed ( int *  windSpeed)
private


Reads the wind speed from the anemomter

Parameters
windSpeedwhere the wind speed will be stored
Returns
true if succesfully read. false otherwise.

◆ openSwitch()

bool CloudWatcherController::openSwitch ( )


Opens the internal switch of the AAG Cloud Watcher

Returns
true if the internal switch is opened. false otherwise.

◆ printBuffer()

void CloudWatcherController::printBuffer ( char *  buffer,
int  num 
)
private


Print a buffer of chars.

Just for debugging

Parameters
bufferthe buffer to be printed
numthe number of chars to be printed

◆ printMessage()

void CloudWatcherController::printMessage ( const char *  fmt,
  ... 
)
private


Prints a printf like expression if verbose mode is enabled.

Just for debugging

Parameters
fmtthe pritnfexpression to be printed
See also
CloudWatcherController(char *serialP, bool verbose)

◆ readSerial()

int CloudWatcherController::readSerial ( char *  buffer,
int  numberOfBytes 
)
private


Reads a number of chars from the serial port.

Parameters
bufferthe buffer where the readed chars will be stored. Should be big enough por all chars
numberOfBytesthe number of bytes to be read.
Returns
the number of bytes that have been read

◆ sendCloudwatcherCommand() [1/2]

bool CloudWatcherController::sendCloudwatcherCommand ( const char *  command)
private


Sends a command to the AAG Cloud Watcher.

Parameters
commanda two byte array with the command to be sent
Returns
true if successfully sent. false otherwise

◆ sendCloudwatcherCommand() [2/2]

bool CloudWatcherController::sendCloudwatcherCommand ( const char *  command,
int  size 
)
private


Sends a command to the AAG Cloud Watcher.

Parameters
commanda byte array with the command to be sent
sizethe number of bytes of the command
Returns
true if successfully sent. false otherwise

◆ setPWMDutyCycle()

bool CloudWatcherController::setPWMDutyCycle ( int  pwmDutyCycle)


Sets the PWM Duty Cycle (heater control) of the AAG Cloud Watcher

Parameters
pwmDutyCycleThe value of the PWM Duty Cycle (min - 0 to max - 1023)
Returns
true if the PWM Duty Cycle has been successfully setted. false otherwise.

◆ writeSerial()

int CloudWatcherController::writeSerial ( const char *  buffer,
int  numberOfBytes 
)
private


Writes a number of chars buffer into the serial port.

It opens the serial port if not already opened.

Parameters
bufferthe buffer of chars to be written in the serial port
numberOfBytesthe number of chars to be written
Returns
the number of written bytes or -1 if error.

Member Data Documentation

◆ ambBeta

float CloudWatcherController::ambBeta
private


Hard coded constant.

◆ ambPullUpResistance

float CloudWatcherController::ambPullUpResistance
private


Hard coded constant.

◆ ambResAt25

float CloudWatcherController::ambResAt25
private


Hard coded constant.

◆ BLOCK_SIZE

const int CloudWatcherController::BLOCK_SIZE = 15
staticprivate


AAG CloudWatcher send information in 15 bytes blocks

◆ firmwareVersion

char* CloudWatcherController::firmwareVersion
private


Firmware version.

Just read once.

See also
getFirmwareVersion()
getFirmwareVersion(char *version)

◆ LDRMaxResistance

float CloudWatcherController::LDRMaxResistance
private


Hard coded constant.

May be changed with internal device constants.

See also
getElectricalConstants()

◆ LDRPullUpResistance

float CloudWatcherController::LDRPullUpResistance
private


Hard coded constant.

May be changed with internal device constants.

See also
getElectricalConstants()

◆ NUMBER_OF_READS

const int CloudWatcherController::NUMBER_OF_READS = 5
staticprivate


Number of reads to aggregate for the cloudwatcher data

◆ previousOptions

struct termios CloudWatcherController::previousOptions
private


Used to return the serial port to its original state

◆ rainBeta

float CloudWatcherController::rainBeta
private


Hard coded constant.

May be changed with internal device constants.

See also
getElectricalConstants()

◆ rainPullUpResistance

float CloudWatcherController::rainPullUpResistance
private


Hard coded constant.

May be changed with internal device constants.

See also
getElectricalConstants()

◆ rainResAt25

float CloudWatcherController::rainResAt25
private


Hard coded constant.

May be changed with internal device constants.

See also
getElectricalConstants()

◆ serialPort

char* CloudWatcherController::serialPort
private


The serial port where the AAG Cloud Watcher is connected.

Set up at constructor.

See also
CloudWatcherController(char *serialP)
CloudWatcherController(char *serialP, bool verbose)

◆ serialportFD

int CloudWatcherController::serialportFD
private

File descriptor for the serial port.

◆ totalReadings

int CloudWatcherController::totalReadings
private


The total number of readings performed by the controller

◆ verbose

int CloudWatcherController::verbose
private


true if info verbose output should be shown.

Just for debugging pourposes.

See also
CloudWatcherController(char *serialP, bool verbose)

◆ zenerConstant

float CloudWatcherController::zenerConstant
private


Hard coded constant.

May be changed with internal device constants.

See also
getElectricalConstants()

The documentation for this class was generated from the following files: