source docs - SoftwareCornwall/HouseSensors GitHub Wiki

Source Code Documentation


The Curl Class

The Curl classes uses the libcurl C library to interact with the server when sending the data recorded by an attached sensor.

Constructor

The constructor defines doDisplayMessages to true.

Destructor

The destructor calls notes to the standard output stream that a Curl object is being destroyed and then calls curl_global_cleanup(), if initialised.

bool doDisplayMessages

A public field that determines whether messages are displayed from within functions, describing execution details and success.

bool initialise()

Initialises the Curl object. This calls curl_global_init() and sets a private bool (isInitialised_) to true. Returns whether initialisation succeeded or not.

bool postStringTo(const std::string& data, const std::string& destination)

Sends a string (data) to a server (destination) using POST over HTTP. Requires this.initialise() to be called. Returns whether the post operation succeeded or not.


The IMUReading Structure

The IMUReading struct is used by the IMUController class to return information retrieved by the IMU sensor,

struct IMUReading

  • float temperature
  • float humidity

The IMUController Class

The IMUController class uses the RTIMULib library to interact with a sensor and return the humidity and temperature recorded by it.

Constructor

The IMUController class has an empty constructor.

Destructor

The destructor calls notes to the standard output stream that an IMUController object is being destroyed.

bool initialise()

Initialises the IMUController instance. This defines RTIMUSettings, RTIMU and RTHumidiy typed private fields and checks that a valid sensor is connected.

Returns whether initialisation succeeded or not.

IMUReading read()

Gets the current humidity and temperature recorded by the sensor. Requires this.initialise() to be called. Returns an IMUReading struct that contains the recorded information. If either value cannot be retrieved, they will be returned as -1.


The WaterController Class

Uses the wiringPi library to read information from a connected water sensor. (Reads using pin 25 on a raspberry-pi.)

Constructor

The constructor defines all private fields (timeAtLastRead_ = 0, isInitialised = false).

Destructor

The destructor notes to the standard output stream that a WaterController object is being destroyed.

bool initialise()

Initialises the WaterController object. This sets an interrupt counter to 0 and sets up the wiringPi library to use pin 25 as an ISR to measure water flow. It also sets timeAtLastRead_ to be the current unix time.

float read()

Checks how many times the wiringPi library has called an interrupt to determine how much water has flowed through the sensor. This resets the interrupt counter and the recorded time at last read is set to now. Requires this.initialise() to be called. Returns the calculated water flow in litres per seconds.

float quietRead()

Does the same thing as read(), except it does not change the interrupt counter or time since last read. Requires this.initialise() to be called. Returns the calculated water flow in litres per seconds.


The Utility Namespace

SensorType Enum

Used by getSensorTypefromUser(bool) to return the chosen sensor type.

  • NONE
  • WATER
  • IMU

StringStyle Enum

Used by styleString(const std::string&, StringStyle) and printStyled(const std::string&, StringStyle) to determine how to style the string.

  • DEFUALT
  • GREEN
  • RED
  • BOLD
  • BOLD_GREEN
  • BOLD_RED

std::string styleString(const std::string& message, StringStyle style)

Returns a string the is the same as message, except it is styled in a certain was (as determined by style).

void printStyled(const std::string& message, StringStyle style)

The same as styleString(const std::string&, StringStyle) except is stream it to the standard output stream instead of returning.

SensorType getSensorTypeFromUser(bool loopOnInvalidInput)

Asks the user for which sensor type to use. If loopOnInvalidInput is true, the use will be repeatedly asked for input until their answer is either 'imu' or 'water'. If it is false, the function will return SensorType::NONE if the input is invalid. Returns the sensor type entered by the user.

std::string getMACAddress()

Gets the MAC Address from /sys/class/net/wlan0/address.

Returns the MAC Address.

long long getUnixTime()

Returns a long long that is equal to the current Unix Time.

void Sleep(int seconds)

Sleeps the current thread for a defined number of seconds.

std::string serialiseIMUReading(const IMUReading& reading)

Formats a string to work in an HTTP POST operation.

Returns the new string.