Skip to content

Commit

Permalink
More whitespace and other style changes to most files.
Browse files Browse the repository at this point in the history
Use explicit scope for case statements.
Tidy up look up tables.
  • Loading branch information
ZXGuesser committed Nov 13, 2021
1 parent 8f3c223 commit 2290410
Show file tree
Hide file tree
Showing 28 changed files with 1,784 additions and 1,976 deletions.
781 changes: 402 additions & 379 deletions TCPClient.cpp

Large diffs are not rendered by default.

129 changes: 62 additions & 67 deletions TCPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,76 +52,71 @@

#include "pagelist.h"
#include "newfor.h"
#include "hamm-tables.h"

#include "packetsubtitle.h"

namespace vbit
{

class TCPClient
{
public:
TCPClient(PacketSubtitle* subtitle, ttx::PageList* pageList);
~TCPClient();
void Handler(int clntSocket);

private:
// Constants
static const uint8_t MAXCMD=128;
static const uint8_t RCVBUFSIZE=132; /* Size of receive buffer */

// Normal command mode
static const uint8_t MODENORMAL=0;
static const uint8_t MODESOFTELPAGEINIT=1;
// Get row count
static const uint8_t MODEGETROWCOUNT=3;
// Get a row of data
static const uint8_t MODEGETROW=4;
// Display the row
static const uint8_t MODESUBTITLEONAIR=5;
// Clear down
static const uint8_t MODESUBTITLEOFFAIR=6;
static const uint8_t MODESUBTITLEDATAHIGHNYBBLE=7;
static const uint8_t MODESUBTITLEDATALOWNYBBLE=8;

// Variables
char _cmd[MAXCMD]; /// command buffer
char* _pCmd; /// Pointer into the command buffer
Newfor _newfor;
int _row; // Row counter
char* _pkt; // A teletext packet (one row of VBI)
int _rowAddress; // The address of this row

/// The page address in MPPSS (hex. 10000..8FF99. Omitting trailing characters defaults to 0
/// * wildcard
char _pageNumber[6];

ttx::PageList* _pageList; /// List of pages for XTP620 commands to access


// Functions
void clearCmd(void);
void addChar(char ch, char* response);
void command(char* cmd, char* response); /// Handles XPT620 commands
void DieWithError(std::string errorMessage);

/** Validate a page identity of the form mppss
* Where:
* m=1..8
* p=0..f
* s=0,,9
* and any digit can be wildcarded with *
* and trailing digits can be omitted where they will be defaulted to 0
* \param src - the page identity parameter of a P command. (only one allowed in this implementation)
* \param dest - the validated page number
* \return true if the page identity is valid
*/
bool Validate(char* dest, char* src);

}; // TCPClient

} // End of namespace vbit


class TCPClient
{
public:
TCPClient(PacketSubtitle* subtitle, ttx::PageList* pageList);
~TCPClient();
void Handler(int clntSocket);

private:
// Constants
static const uint8_t MAXCMD=128;
static const uint8_t RCVBUFSIZE=132; /* Size of receive buffer */

// Normal command mode
static const uint8_t MODENORMAL=0;
static const uint8_t MODESOFTELPAGEINIT=1;
// Get row count
static const uint8_t MODEGETROWCOUNT=3;
// Get a row of data
static const uint8_t MODEGETROW=4;
// Display the row
static const uint8_t MODESUBTITLEONAIR=5;
// Clear down
static const uint8_t MODESUBTITLEOFFAIR=6;
static const uint8_t MODESUBTITLEDATAHIGHNYBBLE=7;
static const uint8_t MODESUBTITLEDATALOWNYBBLE=8;

// Variables
char _cmd[MAXCMD]; // command buffer
char* _pCmd; // Pointer into the command buffer
Newfor _newfor;
int _row; // Row counter
char* _pkt; // A teletext packet (one row of VBI)
int _rowAddress; // The address of this row

/** The page address in MPPSS (hex. 10000..8FF99. Omitting trailing characters defaults to 0
* wildcard
*/
char _pageNumber[6];

ttx::PageList* _pageList; // List of pages for XTP620 commands to access


// Functions
void clearCmd(void);
void addChar(char ch, char* response);
void command(char* cmd, char* response); // Handles XPT620 commands
void DieWithError(std::string errorMessage);

/** Validate a page identity of the form mppss
* Where:
* m=1..8
* p=0..f
* s=0,,9
* and any digit can be wildcarded with *
* and trailing digits can be omitted where they will be defaulted to 0
* \param src - the page identity parameter of a P command. (only one allowed in this implementation)
* \param dest - the validated page number
* \return true if the page identity is valid
*/
bool Validate(char* dest, char* src);
};
}
#endif
13 changes: 7 additions & 6 deletions command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ using namespace vbit;
using namespace ttx;

Command::Command(Configure *configure, PacketSubtitle* subtitle=nullptr, PageList *pageList=nullptr) :
_portNumber(configure->GetCommandPort()),
_client(subtitle, pageList)
_portNumber(configure->GetCommandPort()),
_client(subtitle, pageList)
{
// Constructor
// Start a listener thread
// Start a listener thread
}

Command::~Command()
Expand Down Expand Up @@ -69,7 +69,8 @@ void Command::run()

// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
if (iResult != 0)
{
DieWithError("WSAStartup failed");
}
#else
Expand All @@ -87,11 +88,11 @@ void Command::run()

/* Create socket for incoming connections */
if ((serverSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
DieWithError("socket() failed\n");
DieWithError("socket() failed\n");

/* Bind to the local address */
if (bind(serverSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
DieWithError("bind() failed");
DieWithError("bind() failed");

/* Mark the socket so it will listen for incoming connections */
if (listen(serverSock, MAXPENDING) < 0)
Expand Down
76 changes: 33 additions & 43 deletions command.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,38 @@

namespace vbit
{

class Command
{
public:

/**
* @brief Constructor
* @description Listens on port 5570 and accepts connections.
* When connected it can be sent Newfor commands.
*/
Command(ttx::Configure *configure, vbit::PacketSubtitle* subtitle, ttx::PageList* pageList);

/**
* @brief Constructor
* @param port - TCP port number to use
*/
// Command(int port);

/**
* @brief Destructor
*/
~Command();

/**
* @brief Run the listener thread.
*/
void run();

private:
int _portNumber; /// The port number is configurable. Default is 5570 for no oarticular reason.
TCPClient _client; /// Did I call this a client? It is where clients connect and get their commands executed.

/* Page init and subtitle data can respond with these standard codes */
static const uint8_t ASCII_ACK=0x06;
static const uint8_t ASCII_NACK=0x15;

static const uint8_t MAXPENDING=5; /* Maximum outstanding connection requests */

void DieWithError(std::string errorMessage); /* Error handling function */


}; // Command
} // namespace vbit
class Command
{
public:
/**
* @brief Constructor
* @description Listens on port 5570 and accepts connections.
* When connected it can be sent Newfor commands.
*/
Command(ttx::Configure *configure, vbit::PacketSubtitle* subtitle, ttx::PageList* pageList);

/**
* @brief Destructor
*/
~Command();

/**
* @brief Run the listener thread.
*/
void run();

private:
int _portNumber; /// The port number is configurable. Default is 5570 for no oarticular reason.
TCPClient _client; /// Did I call this a client? It is where clients connect and get their commands executed.

/* Page init and subtitle data can respond with these standard codes */
static const uint8_t ASCII_ACK=0x06;
static const uint8_t ASCII_NACK=0x15;

static const uint8_t MAXPENDING=5; /* Maximum outstanding connection requests */

void DieWithError(std::string errorMessage); /* Error handling function */
};
}

#endif
Loading

0 comments on commit 2290410

Please sign in to comment.