Created
February 13, 2023 12:11
-
-
Save JoshuaJakowlew/baad9163e031ed7c3667e2d43d974308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
void read_command(std::ifstream & file) | |
{ | |
char first_byte; | |
file.get(first_byte); | |
if (first_byte == '$') | |
{ | |
std::cout << "Text command:\n"; | |
while (true) | |
{ | |
char sym; | |
file.get(sym); | |
std::cout << sym; | |
if (sym == '*') | |
{ | |
for (int i = 0; i < 4; ++i) | |
{ | |
file.get(); | |
} | |
std::cout << "\n"; | |
break; | |
} | |
} | |
// std::cout << "Read text command\n"; | |
} | |
else | |
{ | |
file.get(); | |
file.get(); | |
char header_length; | |
file.get(header_length); | |
uint16_t msg_id; | |
file.read((char*)&msg_id, sizeof(msg_id)); | |
file.get(); | |
file.get(); | |
uint16_t msg_len; | |
file.read((char*)&msg_len, sizeof(msg_len)); | |
for (int i = 0; i < 18; ++i) | |
{ | |
file.get(); | |
} | |
std::cout << "Command ID: " << msg_id << " length: " << msg_len << "\n"; | |
for (int i = 0; i < msg_len; ++i) | |
{ | |
char byte = file.get(); | |
std::cout << (int)byte << " "; | |
} | |
file.get(); | |
file.get(); | |
file.get(); | |
file.get(); | |
} | |
} | |
int main() | |
{ | |
std::ifstream file("C:/Users/jakow/Desktop/Programming/pasha/1.cnb", std::ios_base::binary); | |
while (!file.eof()) | |
{ | |
read_command(file); | |
// break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment