Add read/write cycles

This commit is contained in:
Robert 2023-07-02 18:32:14 +02:00
parent e227933b53
commit 90fbb5109c
5 changed files with 46 additions and 0 deletions

View file

@ -34,6 +34,26 @@ void Device::Connect(std::shared_ptr<Device> other) {
other->port->Connect(port);
}
void Device::Send() {
port->Send({40});
}
void Device::Receive() {
std::vector<uint8_t> data = port->Receive();
if (data.size() != 0) {
std::cout << "Device " << *this << " received data: " << std::endl;
std::cout << "{";
for (uint8_t byte : data) {
std::cout << (int)byte << ", ";
}
std::cout << "}" << std::endl;
}
}
std::ostream& operator<<(std::ostream& os, const Device& device) {
printf(
"%02X:%02X:%02X:%02X:%02X:%02X",

View file

@ -11,6 +11,23 @@ void Network::AddDevice(std::shared_ptr<Device> device) {
devices.push_back(device);
}
void Network::SendCycle() {
for (auto device : devices) {
device->Send();
}
}
void Network::ReceiveCycle() {
for (auto device : devices) {
device->Receive();
}
}
void Network::Cycle() {
SendCycle();
ReceiveCycle();
}
std::ostream& operator<<(std::ostream& os, const Network& network) {
os << "Network '" << network.name << "'" << std::endl << std::endl;