add channel header
This commit is contained in:
54
channel.h
Normal file
54
channel.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef CHANNEL_HEADER_HH
|
||||
#define CHANNEL_HEADER_HH
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
class Channel {
|
||||
uint32_t id;
|
||||
uint32_t size;
|
||||
uint32_t version;
|
||||
int32_t integral[3];
|
||||
uint32_t crossing;
|
||||
uint32_t block_count;
|
||||
uint32_t spill;
|
||||
char * block_data;
|
||||
bool valid;
|
||||
public:
|
||||
Channel(char const * ptr, size_t len);
|
||||
void Print();
|
||||
|
||||
};
|
||||
Channel::Channel(char const * ptr, size_t len) {
|
||||
valid = true;
|
||||
uint32_t * wordData = (uint32_t *)ptr;
|
||||
size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
|
||||
if (size != len) valid = false;
|
||||
|
||||
version = wordData[0] && 0xFF;
|
||||
if (version != 0x1) valid = false;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
|
||||
|
||||
crossing = wordData[4] & 0x00FFFFFF;
|
||||
block_count = (wordData[5] &0xFF000000) >> 24;
|
||||
id = (wordData[5] & 0x00FF0000) >> 16;
|
||||
spill = (wordData[5] & 0x0000FFFF);
|
||||
if ((id > 8) || (id < 1)) {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
void Channel::Print(){
|
||||
if (valid) {
|
||||
printf("channel %u, spill %u, size %u, blocks %u, crossing %u, integrals %d, %d, %d\n",
|
||||
id, spill, size, block_count, crossing, integral[0], integral[1], integral[2]);
|
||||
}
|
||||
else {
|
||||
printf("Invalid channel\n");
|
||||
}
|
||||
}
|
||||
#endif /* end of include guard */
|
||||
15
client.cc
15
client.cc
@@ -13,7 +13,8 @@
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <csignal>
|
||||
#include <loguru.hpp>
|
||||
#include "loguru.hpp"
|
||||
#include "channel.h"
|
||||
|
||||
const char * HOST = "192.168.30.89";
|
||||
const uint32_t PORT = 9999;
|
||||
@@ -65,7 +66,7 @@ size_t process_channel(char const * ptr, size_t len){
|
||||
int32_t integral[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
|
||||
LOG_SCOPE_F(INFO, "integrals: %u, %u, %u", integral[0], integral[1], integral[2]);
|
||||
LOG_SCOPE_F(INFO, "integrals: %d, %d, %d", integral[0], integral[1], integral[2]);
|
||||
|
||||
uint32_t crossing_count = wordData[4] & 0x00FFFFFF;
|
||||
uint32_t block_count = (wordData[5] &0xFF000000) >> 24;
|
||||
@@ -78,8 +79,12 @@ size_t process_channel(char const * ptr, size_t len){
|
||||
process_block(ptr, channel_size); // not correct yet!
|
||||
}
|
||||
|
||||
// the number of bytes processed should be equal to the channel size
|
||||
// the number of bytes cosumed by this function, regardless of block
|
||||
// processing
|
||||
bytes_left -= channel_size;
|
||||
|
||||
Channel c(ptr, channel_size);
|
||||
c.Print();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +207,8 @@ int open_socket(){
|
||||
}
|
||||
|
||||
void setup_logger(){
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
// loguru::g_stderr_verbosity = loguru::Verbosity_WARNING;
|
||||
// loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_WARNING;
|
||||
loguru::g_preamble_date = true; // The date field
|
||||
loguru::g_preamble_time = true; // The time of the current day
|
||||
loguru::g_preamble_uptime = true; // The time since init call
|
||||
|
||||
Reference in New Issue
Block a user