/
gerrero
/
RequestsAnalyzator
Обзор
Документация
Войти
/
gerrero
/
RequestsAnalyzator
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
include/common/protocol.h
46 строк
1 KB
Кирилл Матвеев
create: config.yaml, protocol.h, stend.h, tcp_client.cpp, analyzer.cpp, tcp_client.h, ssr_service.h, stend.cpp, analyzer.h, main.cpp, ssr_service.cpp, test_simulators.cpp, CMakeLists.txt, README.md
28 май 2026, 11:41
Верифицирован
28 май 2026, 11:41
9b02f48
Код
Авторство
О чём код?
#ifndef PROTOCOL_H #define PROTOCOL_H #include <cstdint> #include <cstring> #include <string> #include <sstream> #include <iomanip> #include <vector> const int PACKET_SIZE = 32; inline uint32_t getBits(const uint8_t* data, size_t start, size_t n) { uint32_t r = 0; for (size_t i = 0; i < n; i++) { size_t bi = (start + i) / 8; size_t bit = 7 - ((start + i) % 8); if (data[bi] & (1 << bit)) r |= (1 << (n - 1 - i)); } return r; } struct Packet { uint8_t raw[PACKET_SIZE]; Packet() { memset(raw, 0, PACKET_SIZE); } uint32_t getId() const { return (raw[28]<<24)|(raw[29]<<16)|(raw[30]<<8)|raw[31]; } uint8_t getType() const { return getBits(raw, 22*8, 6); } uint8_t getAttenuationCode() const { return getBits(raw, 3*8 + 6, 2); } uint16_t getAmplitude() const { return (raw[4]<<8)|raw[5]; } bool hasNext() const { return getBits(raw, 23*8 + 7, 1); } // Признак начала нового круга: id == 0 bool isNewRound() const { return getId() == 0; } }; inline std::string packetToHex(const Packet& p) { std::ostringstream ss; for (int i = 0; i < PACKET_SIZE; i++) { ss << std::hex << std::setw(2) << std::setfill('0') << (int)p.raw[i]; if ((i+1) % 8 == 0) ss << " "; } return ss.str(); } #endif