| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <map> |
| 24 |
#include <mutex> |
| 25 |
#include <sstream> |
| 26 |
#include <vector> |
| 27 |
|
| 28 |
#include "ControlInterface.h" |
| 29 |
#include "Logger/Logger.h" |
| 30 |
#include "Manager.h" |
| 31 |
#include "Network/UdpServer.h" |
| 32 |
|
| 33 |
namespace Server { namespace Z21 |
| 34 |
{ |
| 35 |
class Z21Client; |
| 36 |
|
| 37 |
class Z21Server : public ControlInterface, private Network::UdpServer |
| 38 |
{ |
| 39 |
public: |
| 40 |
static const unsigned short Z21Port = 21105; |
| 41 |
|
| 42 |
Z21Server() = delete; |
| 43 |
Z21Server(const Z21Server&) = delete; |
| 44 |
Z21Server& operator=(const Z21Server&) = delete; |
| 45 |
|
| 46 |
Z21Server(Manager& manager, const unsigned short port); |
| 47 |
~Z21Server(); |
| 48 |
|
| 49 |
void Start() override; |
| 50 |
|
| 51 |
void Stop() override; |
| 52 |
|
| 53 |
bool NextUpdate(unsigned int& updateIDClient, std::string& s); |
| 54 |
|
| 55 |
inline const std::string& GetName() const override |
| 56 |
{ |
| 57 |
static const std::string Z21Name("Z21Server"); |
| 58 |
return Z21Name; |
| 59 |
} |
| 60 |
|
| 61 |
void Booster(const ControlType controlType, const BoosterState status) override; |
| 62 |
|
| 63 |
void LocoBaseOrientation(const ControlType controlType, |
| 64 |
const DataModel::LocoBase* loco, |
| 65 |
const Orientation direction) override; |
| 66 |
|
| 67 |
void LocoBaseFunction(const ControlType controlType, |
| 68 |
const DataModel::LocoBase* loco, |
| 69 |
const DataModel::LocoFunctionNr function, |
| 70 |
const DataModel::LocoFunctionState on) override; |
| 71 |
|
| 72 |
void LocoBaseSpeed(const ControlType controlType, |
| 73 |
const DataModel::LocoBase* loco, |
| 74 |
const Speed speed) override; |
| 75 |
|
| 76 |
void AccessoryState(const ControlType controlType, const DataModel::Accessory* accessory) override; |
| 77 |
|
| 78 |
void SwitchState(const ControlType controlType, const DataModel::Switch* mySwitch) override; |
| 79 |
|
| 80 |
void SignalState(const ControlType controlType, const DataModel::Signal* signal) override; |
| 81 |
|
| 82 |
protected: |
| 83 |
Network::UdpClient* UdpClientFactory(const int serverSocket, |
| 84 |
const struct sockaddr_storage* clientAddress) override; |
| 85 |
|
| 86 |
private: |
| 87 |
Logger::Logger* logger; |
| 88 |
Manager& manager; |
| 89 |
unsigned int lastClientID; |
| 90 |
|
| 91 |
ssize_t ParseData(const unsigned char* buffer, |
| 92 |
const ssize_t bufferLength, |
| 93 |
const struct sockaddr_storage* clientAddress); |
| 94 |
|
| 95 |
void ParseXHeader(const unsigned char* buffer); |
| 96 |
|
| 97 |
void ParseDB0(const unsigned char* buffer); |
| 98 |
|
| 99 |
void AccessoryBaseState(const DataModel::AccessoryBase* accessoryBase); |
| 100 |
}; |
| 101 |
}} |