move completely to spdlog, refactor channel class
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ r
|
|||||||
build
|
build
|
||||||
old
|
old
|
||||||
dump
|
dump
|
||||||
|
spdlog
|
||||||
|
|||||||
6
Makefile
6
Makefile
@@ -1,10 +1,10 @@
|
|||||||
target = r
|
target = r
|
||||||
CXX = g++
|
CXX = g++
|
||||||
CXX_FLAGS := -std=c++14 -Ispdlog/include -Wall
|
CXX_FLAGS := -std=c++14 -I/home/daq/sw/include -Wall -DSPDLOG_COMPILED_LIB
|
||||||
LD_FLAGS := -lpthread -ldl
|
LD_FLAGS := -lpthread -ldl -L/home/daq/sw/lib64 -lspdlog
|
||||||
|
|
||||||
BUILD := ./build
|
BUILD := ./build
|
||||||
OBJS := $(BUILD)/client.o
|
OBJS = $(BUILD)/client.o $(BUILD)/channel.o
|
||||||
|
|
||||||
all: $(target)
|
all: $(target)
|
||||||
|
|
||||||
|
|||||||
34
channel.cc
Normal file
34
channel.cc
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "channel.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Channel::Print(){
|
||||||
|
if (valid) {
|
||||||
|
spdlog::info("channel {}, spill {}, size {}, blocks {}, crossing {}, integrals {}, {}, {}",
|
||||||
|
id, spill, size, block_count, crossing, integral[0], integral[1], integral[2]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spdlog::info("Invalid channel");
|
||||||
|
}
|
||||||
|
}
|
||||||
32
channel.h
32
channel.h
@@ -19,36 +19,4 @@ class Channel {
|
|||||||
void Print();
|
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 */
|
#endif /* end of include guard */
|
||||||
|
|||||||
26
client.cc
26
client.cc
@@ -39,7 +39,7 @@ size_t process_block(char const * ptr, size_t len){
|
|||||||
}
|
}
|
||||||
size_t process_channel(char const * ptr, size_t len){
|
size_t process_channel(char const * ptr, size_t len){
|
||||||
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
|
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
|
||||||
spdlog::info("channel length must be between %lu and %lu.",
|
spdlog::debug("channel length must be between {} and {}.",
|
||||||
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
|
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ size_t process_channel(char const * ptr, size_t len){
|
|||||||
|
|
||||||
while ((bytes_left > 0) && !valid_channel) {
|
while ((bytes_left > 0) && !valid_channel) {
|
||||||
if ((ptr[0] & 0xFF) != CHANNEL_MARKER){
|
if ((ptr[0] & 0xFF) != CHANNEL_MARKER){
|
||||||
spdlog::info("bad_data, expecting %02X, received %02X",
|
spdlog::debug("bad_data, expecting {0:x}, received {0:x}",
|
||||||
static_cast<uint32_t>(CHANNEL_MARKER), static_cast<uint32_t>(ptr[0]));
|
static_cast<uint32_t>(CHANNEL_MARKER), static_cast<uint32_t>(ptr[0]));
|
||||||
bytes_left -= 4;
|
bytes_left -= 4;
|
||||||
} else {
|
} else {
|
||||||
@@ -58,21 +58,21 @@ size_t process_channel(char const * ptr, size_t len){
|
|||||||
|
|
||||||
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
|
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
|
||||||
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
|
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
|
||||||
spdlog::info("Invalid channel size: %lu", channel_size);
|
spdlog::debug("Invalid channel size: {}", channel_size);
|
||||||
}
|
}
|
||||||
uint32_t version = wordData[0] && 0xFF;
|
uint32_t version = wordData[0] && 0xFF;
|
||||||
spdlog::info("channel size %lu, version %u", channel_size, version);
|
spdlog::debug("channel size {}, version {}", channel_size, version);
|
||||||
|
|
||||||
int32_t integral[3];
|
int32_t integral[3];
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
|
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
|
||||||
spdlog::info("integrals: %d, %d, %d", integral[0], integral[1], integral[2]);
|
spdlog::debug("integrals: {}, {}, {}", integral[0], integral[1], integral[2]);
|
||||||
|
|
||||||
uint32_t crossing_count = wordData[4] & 0x00FFFFFF;
|
uint32_t crossing_count = wordData[4] & 0x00FFFFFF;
|
||||||
uint32_t block_count = (wordData[5] &0xFF000000) >> 24;
|
uint32_t block_count = (wordData[5] &0xFF000000) >> 24;
|
||||||
uint32_t channel = (wordData[5] & 0x00FF0000) >> 16;
|
uint32_t channel = (wordData[5] & 0x00FF0000) >> 16;
|
||||||
uint32_t spill_id = (wordData[5] & 0x0000FFFF);
|
uint32_t spill_id = (wordData[5] & 0x0000FFFF);
|
||||||
spdlog::info("crossing_count %u, block_count %u, channel %u, spill_id %u",
|
spdlog::debug("crossing_count {}, block_count {}, channel {}, spill_id {}",
|
||||||
crossing_count, block_count, channel, spill_id);
|
crossing_count, block_count, channel, spill_id);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < block_count; i++) {
|
for (uint32_t i = 0; i < block_count; i++) {
|
||||||
@@ -89,7 +89,7 @@ size_t process_channel(char const * ptr, size_t len){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return number of bytes cosumed of the channel
|
// return number of bytes cosumed of the channel
|
||||||
spdlog::info("processed %lu bytes out of %lu", (len - bytes_left), len);
|
spdlog::debug("processed {} bytes out of {}", (len - bytes_left), len);
|
||||||
return len - bytes_left;
|
return len - bytes_left;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ int main(int argc, char * argv[])
|
|||||||
else{
|
else{
|
||||||
// read in first 4 bytes
|
// read in first 4 bytes
|
||||||
nread = recv(sock, char_buffer, 4, 0);
|
nread = recv(sock, char_buffer, 4, 0);
|
||||||
spdlog::info("read in %ld bytes: 0x%08X", nread, wordData[0]);
|
spdlog::info("read in {:d} bytes: 0x{:X}", nread, wordData[0]);
|
||||||
// if not A5 marker, go to next iteration (read in 4 more bytes)
|
// if not A5 marker, go to next iteration (read in 4 more bytes)
|
||||||
if ((char_buffer[0] & 0xFF) != 0xA5){
|
if ((char_buffer[0] & 0xFF) != 0xA5){
|
||||||
bad_data = true;
|
bad_data = true;
|
||||||
@@ -140,14 +140,14 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// ok, this seems to be good data
|
// ok, this seems to be good data
|
||||||
spdlog::info("next %ld bytes (expecting %lu): %08X %08X %08X %08X",
|
spdlog::info("next {:d} bytes (expecting {:d}): {:X} {:X} {:X} {:X}",
|
||||||
nread, frameSize - 4, wordData[0], wordData[1], wordData[2], wordData[3]);
|
nread, frameSize - 4, wordData[0], wordData[1], wordData[2], wordData[3]);
|
||||||
spdlog::info("%08X %08X %08X %08X", wordData[4], wordData[5], wordData[6], wordData[7]);
|
spdlog::info("{:X} {:X} {:X} {:X}", wordData[4], wordData[5], wordData[6], wordData[7]);
|
||||||
uint8_t board_id = (wordData[0] >> 24) & 0xFF;
|
uint8_t board_id = (wordData[0] >> 24) & 0xFF;
|
||||||
uint8_t version = wordData[0] & 0xFF;
|
uint8_t version = wordData[0] & 0xFF;
|
||||||
uint16_t spill_id = (wordData[1] & 0x00FFFF00) >> 8;
|
uint16_t spill_id = (wordData[1] & 0x00FFFF00) >> 8;
|
||||||
uint8_t channel_count = (wordData[1]) & 0x000000FF;
|
uint8_t channel_count = (wordData[1]) & 0x000000FF;
|
||||||
spdlog::info("board %u, version %u, spill %u, channel_count %u",
|
spdlog::info("board {}, version {}, spill {}, channel_count {}",
|
||||||
static_cast<uint32_t>(board_id),
|
static_cast<uint32_t>(board_id),
|
||||||
static_cast<uint32_t>(version),
|
static_cast<uint32_t>(version),
|
||||||
static_cast<uint32_t>(spill_id),
|
static_cast<uint32_t>(spill_id),
|
||||||
@@ -164,7 +164,7 @@ int main(int argc, char * argv[])
|
|||||||
bytes_processed += process_channel(char_buffer + 2 * sizeof(uint32_t) + bytes_processed,
|
bytes_processed += process_channel(char_buffer + 2 * sizeof(uint32_t) + bytes_processed,
|
||||||
bytes_left - bytes_processed);
|
bytes_left - bytes_processed);
|
||||||
}
|
}
|
||||||
spdlog::info("Done, %lu bytes processed.", bytes_processed);
|
spdlog::info("Done, {} bytes processed.", bytes_processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
void signalHandler( int signum ) {
|
void signalHandler( int signum ) {
|
||||||
spdlog::info("Interrupt signal (%d) received, exiting...", signum);
|
spdlog::info("Interrupt signal ({}) received, exiting...", signum);
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user