Browse Source

Initial network files

merge-requests/29/head
Adam Honse 2 years ago
parent
commit
594f66ab23
  1. 26
      NetworkClient.cpp
  2. 20
      NetworkClient.h
  3. 20
      NetworkProtocol.cpp
  4. 35
      NetworkProtocol.h
  5. 27
      NetworkServer.cpp
  6. 20
      NetworkServer.h
  7. 49
      RGBController/RGBController_Network.cpp
  8. 28
      RGBController/RGBController_Network.h

26
NetworkClient.cpp

@ -0,0 +1,26 @@
#include "NetworkClient.h"
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
{
//Start the connection thread
}
void NetworkClient::ConnectionThread()
{
//This thread manages the connection to the server
while(1)
{
//Connect to server and reconnect if the connection is lost
}
}
void NetworkClient::ListenThread()
{
//This thread handles messages received from the server
while(1)
{
//Listen for request
//Request received, select functionality based on request ID
}
}

20
NetworkClient.h

@ -0,0 +1,20 @@
#include "RGBController.h"
#include "NetworkProtocol.h"
#include "net_port.h"
#pragma once
class NetworkClient
{
public:
NetworkClient(std::vector<RGBController *>& control);
void ConnectionThread();
void ListenThread();
protected:
std::vector<RGBController *>& controllers;
private:
net_port port;
};

20
NetworkProtocol.cpp

@ -0,0 +1,20 @@
#include "NetworkProtocol.h"
NetPacketHeader * InitNetPacketHeader
(
unsigned int pkt_dev_idx,
unsigned int pkt_id,
unsigned int pkt_size
)
{
NetPacketHeader * new_header = new NetPacketHeader;
new_header->pkt_magic[0] = 'O';
new_header->pkt_magic[1] = 'R';
new_header->pkt_magic[2] = 'G';
new_header->pkt_magic[3] = 'B';
new_header->pkt_dev_idx = pkt_dev_idx;
new_header->pkt_id = pkt_id;
new_header->pkt_size = pkt_size;
}

35
NetworkProtocol.h

@ -0,0 +1,35 @@
typedef struct NetPacketHeader
{
unsigned char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */
unsigned int pkt_dev_idx; /* Device index */
unsigned int pkt_id; /* Packet ID */
unsigned int pkt_size; /* Packet size */
};
enum
{
/*----------------------------------------------------------------------------------------------------------*\
| Network requests |
\*----------------------------------------------------------------------------------------------------------*/
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
/*----------------------------------------------------------------------------------------------------------*\
| RGBController class functions |
\*----------------------------------------------------------------------------------------------------------*/
NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */
NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */
NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */
NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */
NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */
NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */
};
NetPacketHeader * InitNetPacketHeader
(
unsigned int pkt_dev_idx,
unsigned int pkt_id,
unsigned int pkt_size
);

27
NetworkServer.cpp

@ -0,0 +1,27 @@
#include "NetworkServer.h"
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
{
//Start a TCP server and launch threads
port.tcp_server("1337");
}
void NetworkServer::ConnectionThread()
{
//This thread handles client connections
while(1)
{
port.tcp_server_listen();
}
}
void NetworkServer::ListenThread()
{
//This thread handles messages received from clients
while(1)
{
//Listen for request
//Request received, select functionality based on request ID
}
}

20
NetworkServer.h

@ -0,0 +1,20 @@
#include "RGBController.h"
#include "NetworkProtocol.h"
#include "net_port.h"
#pragma once
class NetworkServer
{
public:
NetworkServer(std::vector<RGBController *>& control);
void ConnectionThread();
void ListenThread();
protected:
std::vector<RGBController *>& controllers;
private:
net_port port;
};

49
RGBController/RGBController_Network.cpp

@ -0,0 +1,49 @@
/*-----------------------------------------*\
| RGBController_Network.cpp |
| |
| Generic RGB Interface Network Class |
| |
| Adam Honse (CalcProgrammer1) 4/11/2020 |
\*-----------------------------------------*/
#include "RGBController_Network.h"
RGBController_Network::RGBController_Network()
{
//Don't need to set up anything, this class should be initialized by network manager
}
void RGBController_Network::SetupZones()
{
//Don't send anything, this function should only process on host
}
void RGBController_Network::ResizeZone(int /*zone*/, int /*new_size*/)
{
//Send NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE
}
void RGBController_Network::UpdateLEDs()
{
//Send NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS
}
void RGBController_Network::UpdateZoneLEDs(int /*zone*/)
{
//Send NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS
}
void RGBController_Network::UpdateSingleLED(int /*led*/)
{
//Send NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED
}
void RGBController_Network::SetCustomMode()
{
//Send NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE
}
void RGBController_Network::UpdateMode()
{
//Send NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE
}

28
RGBController/RGBController_Network.h

@ -0,0 +1,28 @@
/*-----------------------------------------*\
| RGBController_Network.h |
| |
| Generic RGB Interface Network Class |
| |
| Adam Honse (CalcProgrammer1) 4/11/2020 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
class RGBController_Network : public RGBController
{
public:
RGBController_Network();
void SetupZones();
void ResizeZone(int zone, int new_size);
void UpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void UpdateMode();
};
Loading…
Cancel
Save