myWRIO
C++ framework for NationalInstruments myRIO
myRIO::Wifi Class Reference

Use this class to exchange data via wifi. More...

#include <Wifi.h>

Public Member Functions

 Wifi (std::function< void(long)> func)
 Create a Wifi handler. More...
 
 ~Wifi ()
 Close the socket if we are still connected. More...
 
void openServer ()
 Create a wifi server. More...
 
bool isConnected ()
 Returns the state of the socket. More...
 
void updateAngle (short angle)
 Send data to the client. More...
 

Private Member Functions

void writeChar (char c)
 Write a char to the socket. More...
 
void writeShort (short s)
 Write a short to the socket. More...
 
void writeLong (long l)
 Write a long to the socket. More...
 

Private Attributes

bool connected
 
int _socket
 
std::thread _socketThread
 
std::function< void(long)> _func
 Function to call when receiving data. More...
 

Detailed Description

Use this class to exchange data via wifi.

Examples
project_angle.cpp, project_car.cpp, and project_pendulum.cpp.

Definition at line 18 of file Wifi.h.

Constructor & Destructor Documentation

◆ Wifi()

Wifi::Wifi ( std::function< void(long)>  func)

Create a Wifi handler.

This detach a thread so it can read and write synchronously without blocking other tasks.

Parameters
funcfunction to call when receiving data

Definition at line 12 of file Wifi.cpp.

◆ ~Wifi()

Wifi::~Wifi ( )

Close the socket if we are still connected.

Definition at line 132 of file Wifi.cpp.

Member Function Documentation

◆ isConnected()

bool Wifi::isConnected ( )

Returns the state of the socket.

Returns
true if wifi is connected

Definition at line 101 of file Wifi.cpp.

◆ openServer()

void Wifi::openServer ( )

Create a wifi server.

Ressources used to understand C socket programming : https://www.geeksforgeeks.org/socket-programming-cc/ http://manpages.ubuntu.com/manpages/cosmic/en/man2/accept.2.html

Definition at line 26 of file Wifi.cpp.

◆ updateAngle()

void Wifi::updateAngle ( short  angle)

Send data to the client.

Parameters
anglethe angle to send

Definition at line 92 of file Wifi.cpp.

◆ writeChar()

void Wifi::writeChar ( char  c)
private

Write a char to the socket.

Parameters
ca char to write

Definition at line 109 of file Wifi.cpp.

◆ writeLong()

void Wifi::writeLong ( long  l)
private

Write a long to the socket.

Parameters
la long to write

Definition at line 125 of file Wifi.cpp.

◆ writeShort()

void Wifi::writeShort ( short  s)
private

Write a short to the socket.

Parameters
sa short to write

Definition at line 117 of file Wifi.cpp.

Member Data Documentation

◆ _func

std::function<void(long)> myRIO::Wifi::_func
private

Function to call when receiving data.

Definition at line 31 of file Wifi.h.

◆ _socket

int myRIO::Wifi::_socket
private

Definition at line 29 of file Wifi.h.

◆ _socketThread

std::thread myRIO::Wifi::_socketThread
private

Definition at line 30 of file Wifi.h.

◆ connected

bool myRIO::Wifi::connected
private

Definition at line 28 of file Wifi.h.


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