add test setup
This commit is contained in:
parent
89fcef5619
commit
ddf35406c3
|
@ -32,6 +32,14 @@ int main(int argc, char** argv) {
|
||||||
Network network("Testnet");
|
Network network("Testnet");
|
||||||
NetworkRenderer networkRenderer(network);
|
NetworkRenderer networkRenderer(network);
|
||||||
|
|
||||||
|
auto dev1 = Device::Create();
|
||||||
|
auto dev2 = Device::Create();
|
||||||
|
|
||||||
|
dev1->Connect(dev2);
|
||||||
|
|
||||||
|
networkRenderer.AddDevice(dev1, 300, 400);
|
||||||
|
networkRenderer.AddDevice(dev2, 500, 400);
|
||||||
|
|
||||||
bool shouldClose = false;
|
bool shouldClose = false;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
||||||
|
@ -66,7 +74,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
if (ImGui::BeginMenu("New...")) {
|
if (ImGui::BeginMenu("New...")) {
|
||||||
if (ImGui::MenuItem("Host")) {
|
if (ImGui::MenuItem("Host")) {
|
||||||
auto device = Device::create();
|
auto device = Device::Create();
|
||||||
|
|
||||||
network.addDevice(device);
|
network.addDevice(device);
|
||||||
networkRenderer.AddDevice(device, 400, 400);
|
networkRenderer.AddDevice(device, 400, 400);
|
||||||
|
|
|
@ -15,14 +15,16 @@ public:
|
||||||
Device(const std::string& macAddress);
|
Device(const std::string& macAddress);
|
||||||
Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f);
|
Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f);
|
||||||
|
|
||||||
inline static std::shared_ptr<Device> create(const std::string& macAddress) {
|
inline static std::shared_ptr<Device> Create(const std::string& macAddress) {
|
||||||
return std::make_shared<Device>(macAddress);
|
return std::make_shared<Device>(macAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static std::shared_ptr<Device> create() {
|
inline static std::shared_ptr<Device> Create() {
|
||||||
return std::make_shared<Device>(rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256);
|
return std::make_shared<Device>(rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Connect(std::shared_ptr<Device> other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseAndSetMac(const std::string& macAddress);
|
void parseAndSetMac(const std::string& macAddress);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ Device::Device(const std::string& macAddress) {
|
||||||
Device::Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f) :
|
Device::Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f) :
|
||||||
macAddress{a, b, c, d, e, f}
|
macAddress{a, b, c, d, e, f}
|
||||||
{
|
{
|
||||||
|
port = std::make_shared<Port>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::parseAndSetMac(const std::string& mac) {
|
void Device::parseAndSetMac(const std::string& mac) {
|
||||||
|
@ -28,6 +29,11 @@ void Device::parseAndSetMac(const std::string& mac) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Device::Connect(std::shared_ptr<Device> other) {
|
||||||
|
port->Connect(other->port);
|
||||||
|
other->port->Connect(port);
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Device& device) {
|
std::ostream& operator<<(std::ostream& os, const Device& device) {
|
||||||
printf(
|
printf(
|
||||||
"%02X:%02X:%02X:%02X:%02X:%02X",
|
"%02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
|
|
Loading…
Reference in a new issue