-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.cpp
More file actions
44 lines (34 loc) · 1.13 KB
/
App.cpp
File metadata and controls
44 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "App.hpp"
#include "EnlaceLayer.hpp"
void App::appReceiver(vector<bool>& bits) {
string msg{};
bitset<8> bytes{};
unsigned long character;
int i = 0;
Logger::logBeginOfLayer("Camada de Aplicaçao");
Logger::logInfo("Convertendo para ASCII.");
for (auto b : bits) {
bytes[7 - i++ % 8] = b;
if (i % 8 == 0) {
character = bytes.to_ulong();
msg += static_cast<char>(character);
}
}
Logger::logInfo(msg, "Mensagem Recebida");
}
void App::appSender(const std::string& msg) {
Logger::logBeginOfLayer("Camada de Aplicaçao Transmissora");
Logger::logInfo("Convertendo os Bits.");
Logger::logInfo(("Mensagem original: " + msg));
// convertendo para bits
vector<bool> frame;
for (auto character : msg) {
bitset<8> bits(character);
string bitsAsString = bits.to_string();
for (int i = 0; i < bitsAsString.size(); i++) {
frame.push_back(bitsAsString[i] == '1');
}
}
Logger::logInfo("Mensagem Convertida: " + Logger::bitsAsString(frame));
EnlaceLayer::enlaceLayerSender(frame);
}