Compare commits

...

15 Commits

Author SHA1 Message Date
a2e8997090 change spdlog library name 2021-06-09 15:33:06 -04:00
e07831fcad cmake use precompiled spdlog 2021-06-05 08:36:31 -04:00
ec73a87d31 remove spdlog submodule 2021-06-05 00:11:06 -04:00
e3fb134dbb add spdlog to CMakeLists 2021-06-04 22:59:02 -04:00
6c3b0ceed4 submodule added 2021-06-04 22:55:49 -04:00
e5218cd885 add submodule 2021-06-04 20:39:27 -04:00
afc9b1d6fb switch to cmake 2021-06-04 20:38:33 -04:00
Nam Tran
f24628443f correct interpretation of integrals 2020-11-25 18:48:43 -06:00
Nam Tran
b8550dee70 ready to check missing trigger 2020-11-24 22:22:46 -06:00
Nam Tran
78fc7cb184 move function around 2020-11-24 18:43:59 -06:00
Nam Tran
57443a5c26 channel carries board info 2020-11-24 18:42:01 -06:00
Nam Tran
a561e6b428 set up log files 2020-11-24 18:36:58 -06:00
Nam Tran
14070f8017 move completely to spdlog, refactor channel class 2020-11-24 17:53:31 -06:00
Nam Tran
4a692fc42f remove loguru artifact from Makefile 2020-11-24 15:20:20 -06:00
Nam Tran
7501c9ff77 remove loguru 2020-11-24 15:05:42 -06:00
7 changed files with 154 additions and 122 deletions

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "loguru"]
path = loguru
url = https://github.com/emilk/loguru

15
CMakeLists.txt Normal file
View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.0.0)
project(zynqDump VERSION 0.1.0)
set(TARGET zynqDump)
add_compile_options("-std=c++14")
include_directories("/home/nam/sw/include")
add_library(channel STATIC channel.cc)
find_library(SPDLOG
NAMES spdlog
HINTS "/home/nam/sw/lib"
)
add_executable(${TARGET} client.cc)
target_link_libraries(${TARGET} channel ${SPDLOG})

View File

@@ -1,10 +1,10 @@
target = r target = r
CXX = g++ CXX = g++
CXX_FLAGS := -std=c++14 -Iloguru -Wall CXX_FLAGS := -std=c++14 -I./include -Wall
LD_FLAGS := -lpthread -ldl LD_FLAGS := -lpthread -ldl
# LOGURU_FLAG := -DLOGURU_SCOPE_TIME_PRECISION=9
BUILD := ./build BUILD := ./build
OBJS := $(BUILD)/client.o $(BUILD)/loguru.o OBJS = $(BUILD)/client.o $(BUILD)/channel.o
all: $(target) all: $(target)
@@ -12,10 +12,6 @@ $(BUILD)/%.o: %.cc
@mkdir -p $(BUILD) @mkdir -p $(BUILD)
g++ -c $< -o $@ $(CXX_FLAGS) g++ -c $< -o $@ $(CXX_FLAGS)
$(BUILD)/loguru.o:
@mkdir -p $(BUILD)
g++ -c loguru/loguru.cpp -Iloguru -o $@ $(CXX_FLAGS) $(LOGURU_FLAG)
r: $(OBJS) r: $(OBJS)
g++ -o $@ $^ $(LD_FLAGS) g++ -o $@ $^ $(LD_FLAGS)

42
channel.cc Normal file
View File

@@ -0,0 +1,42 @@
#include "channel.h"
#include "spdlog/spdlog.h"
Channel::Channel(char const * ptr, size_t len, uint32_t board) {
board_id = board;
valid = true;
uint32_t * wordData = (uint32_t *)ptr;
block_data = (char *)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] = ((int32_t)(wordData[i+1])) >> 8;
crossing = wordData[4] & 0x00FFFFFF;
block_count = wordData[5] >> 24;
id = (wordData[5] & 0x00FF0000) >> 16;
spill = (wordData[5] & 0x0000FFFF);
if ((id > 8) || (id < 1)) {
valid = false;
}
}
void Channel::Print(bool raw){
if (valid) {
if (raw) {
uint32_t * wordData = (uint32_t *)block_data;
spdlog::info("{:08X} {:08X} {:08X}", wordData[0], wordData[1], wordData[2]);
spdlog::info("{:08X} {:08X} {:08X}", wordData[3], wordData[4], wordData[5]);
}
// spdlog::get("channel_logger")->info("board {}, channel {}, spill {}, size {}, blocks {}, crossing {}, integrals {}, {}, {}",
// board_id, id, spill, size, block_count, crossing, integral[0], integral[1], integral[2]);
spdlog::info("board {}, channel {}, spill {}, size {}, blocks {}, crossing {}, integrals {}, {}, {}",
board_id, id, spill, size, block_count, crossing, integral[0], integral[1], integral[2]);
}
else {
spdlog::get("zynqDump")->info("Invalid channel");
}
}

View File

@@ -5,6 +5,7 @@
#include <cstdlib> #include <cstdlib>
class Channel { class Channel {
uint32_t board_id;
uint32_t id; uint32_t id;
uint32_t size; uint32_t size;
uint32_t version; uint32_t version;
@@ -15,40 +16,8 @@ class Channel {
char * block_data; char * block_data;
bool valid; bool valid;
public: public:
Channel(char const * ptr, size_t len); Channel(char const * ptr, size_t len, uint32_t board);
void Print(); void Print(bool raw = false);
}; };
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 */

166
client.cc
View File

@@ -13,10 +13,11 @@
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <csignal> #include <csignal>
#include "loguru.hpp"
#include "channel.h" #include "channel.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"
const char * HOST = "192.168.30.89"; const char * HOST = "192.168.19.1";
const uint32_t PORT = 9999; const uint32_t PORT = 9999;
const size_t MAX_EVENT_SIZE = 33484; // in bytes const size_t MAX_EVENT_SIZE = 33484; // in bytes
const size_t MIN_EVENT_SIZE = 204; // in bytes const size_t MIN_EVENT_SIZE = 204; // in bytes
@@ -32,72 +33,16 @@ bool bad_data = true;
int open_socket(); int open_socket();
void signalHandler( int signum ); void signalHandler( int signum );
void setup_logger(); void setup_logger();
size_t process_channel(char const * ptr, size_t len); size_t process_channel(char const * ptr, size_t len, uint32_t board_id);
size_t process_block(char const * ptr, size_t len); size_t process_block(char const * ptr, size_t len);
size_t process_block(char const * ptr, size_t len){ size_t process_block(char const * ptr, size_t len){
return len; return len;
} }
size_t process_channel(char const * ptr, size_t len){
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
LOG_SCOPE_F(WARNING, "channel length must be between %lu and %lu.",
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
return len;
}
size_t bytes_left = len;
bool valid_channel = false;
uint32_t * wordData = (uint32_t *)ptr;
while ((bytes_left > 0) && !valid_channel) {
if ((ptr[0] & 0xFF) != CHANNEL_MARKER){
LOG_SCOPE_F(WARNING, "bad_data, expecting %02X, received %02X",
static_cast<uint32_t>(CHANNEL_MARKER), static_cast<uint32_t>(ptr[0]));
bytes_left -= 4;
} else {
valid_channel = true;
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
LOG_SCOPE_F(WARNING, "Invalid channel size: %lu", channel_size);
}
uint32_t version = wordData[0] && 0xFF;
LOG_SCOPE_F(INFO, "channel size %lu, version %u", channel_size, version);
int32_t integral[3];
for (int i = 0; i < 3; i++)
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
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;
uint32_t channel = (wordData[5] & 0x00FF0000) >> 16;
uint32_t spill_id = (wordData[5] & 0x0000FFFF);
LOG_SCOPE_F(INFO, "crossing_count %u, block_count %u, channel %u, spill_id %u",
crossing_count, block_count, channel, spill_id);
for (uint32_t i = 0; i < block_count; i++) {
process_block(ptr, channel_size); // not correct yet!
}
// the number of bytes cosumed by this function, regardless of block
// processing
bytes_left -= channel_size;
Channel c(ptr, channel_size);
c.Print();
}
}
// return number of bytes cosumed of the channel
LOG_SCOPE_F(INFO, "processed %lu bytes out of %lu", (len - bytes_left), len);
return len - bytes_left;
}
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
setup_logger(); setup_logger();
loguru::init(argc, argv);
signal(SIGINT, signalHandler); signal(SIGINT, signalHandler);
int ret = open_socket(); int ret = open_socket();
if (ret != 0) if (ret != 0)
@@ -106,6 +51,9 @@ int main(int argc, char * argv[])
char char_buffer[MAX_EVENT_SIZE]; char char_buffer[MAX_EVENT_SIZE];
uint32_t * wordData = (uint32_t*) char_buffer; uint32_t * wordData = (uint32_t*) char_buffer;
ssize_t nread; ssize_t nread;
std::ofstream output;
std::string outputName = "dump.bin";
output.open (outputName, std::ios::out );
fd_set select_fds; // fd's used by select fd_set select_fds; // fd's used by select
struct timeval timeout; // Time value for time out struct timeval timeout; // Time value for time out
@@ -124,7 +72,10 @@ 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);
LOG_F(INFO, "read in %ld bytes: 0x%08X", nread, wordData[0]); spdlog::get("zynqDump")->debug("read in {:d} bytes: 0x{:X}", nread, wordData[0]);
for (uint32_t j = 0; j < nread; ++j) {
output << char_buffer[j];
}
// 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;
@@ -141,14 +92,17 @@ int main(int argc, char * argv[])
} }
else { else {
// ok, this seems to be good data // ok, this seems to be good data
LOG_F(INFO, "next %ld bytes (expecting %lu): %08X %08X %08X %08X", spdlog::get("zynqDump")->debug("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]);
LOG_F(INFO, "%08X %08X %08X %08X", wordData[4], wordData[5], wordData[6], wordData[7]); spdlog::get("zynqDump")->debug("{:X} {:X} {:X} {:X}", wordData[4], wordData[5], wordData[6], wordData[7]);
for (uint32_t j = 0; j < nread; ++j) {
output << char_buffer[j];
}
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;
LOG_F(INFO, "board %u, version %u, spill %u, channel_count %u", spdlog::get("zynqDump")->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),
@@ -162,10 +116,12 @@ int main(int argc, char * argv[])
size_t bytes_left = (frameSize - 3 * sizeof(uint32_t)); size_t bytes_left = (frameSize - 3 * sizeof(uint32_t));
size_t bytes_processed = 0; size_t bytes_processed = 0;
while ((bytes_left - bytes_processed >= MIN_CHANNEL_SIZE) && (bytes_processed < bytes_left)) { while ((bytes_left - bytes_processed >= MIN_CHANNEL_SIZE) && (bytes_processed < bytes_left)) {
bytes_processed += process_channel(char_buffer + 2 * sizeof(uint32_t) + bytes_processed, bytes_processed += process_channel(
bytes_left - bytes_processed); char_buffer + 2 * sizeof(uint32_t) + bytes_processed,
bytes_left - bytes_processed,
static_cast<uint32_t>(board_id));
} }
LOG_F(INFO, "Done, %lu bytes processed.", bytes_processed); spdlog::get("zynqDump")->debug("Done, {} bytes processed.", bytes_processed);
} }
} }
@@ -178,7 +134,7 @@ int main(int argc, char * argv[])
} }
void signalHandler( int signum ) { void signalHandler( int signum ) {
RAW_LOG_F(WARNING, "Interrupt signal (%d) received, exiting...", signum); spdlog::get("zynqDump")->info("Interrupt signal ({}) received, exiting...", signum);
running = false; running = false;
} }
@@ -207,13 +163,71 @@ int open_socket(){
} }
void setup_logger(){ void setup_logger(){
// loguru::g_stderr_verbosity = loguru::Verbosity_INFO; try {
loguru::g_stderr_verbosity = loguru::Verbosity_WARNING; auto max_size = 1048576 * 5;
loguru::g_preamble_date = true; // The date field auto max_files = 20;
loguru::g_preamble_time = true; // The time of the current day auto logger = spdlog::rotating_logger_mt("zynqDump", "output/run.txt", max_size, max_files);
loguru::g_preamble_uptime = true; // The time since init call auto channel_logger = spdlog::rotating_logger_mt("channel_logger", "output/chn.txt", max_size * 10, max_files);
loguru::g_preamble_thread = false; // The logging thread }
loguru::g_preamble_file = false; // The file from which the log originates from catch (const spdlog::spdlog_ex &ex) {
loguru::g_preamble_verbose = false; // The verbosity field std::cerr << "Log init failed: " << ex.what() << std::endl;
loguru::g_preamble_pipe = false; // The pipe symbol right before the message exit(-1);
}
} }
size_t process_channel(char const * ptr, size_t len, uint32_t board_id){
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
spdlog::debug("channel length must be between {} and {}.",
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
return len;
}
size_t bytes_left = len;
bool valid_channel = false;
uint32_t * wordData = (uint32_t *)ptr;
while ((bytes_left > 0) && !valid_channel) {
if ((ptr[0] & 0xFF) != CHANNEL_MARKER){
spdlog::debug("bad_data, expecting {0:x}, received {0:x}",
static_cast<uint32_t>(CHANNEL_MARKER), static_cast<uint32_t>(ptr[0]));
bytes_left -= 4;
} else {
valid_channel = true;
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
spdlog::debug("Invalid channel size: {}", channel_size);
}
uint32_t version = wordData[0] && 0xFF;
spdlog::debug("channel size {}, version {}", channel_size, version);
int32_t integral[3];
for (int i = 0; i < 3; i++)
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
spdlog::debug("integrals: {}, {}, {}", integral[0], integral[1], integral[2]);
uint32_t crossing_count = wordData[4] & 0x00FFFFFF;
uint32_t block_count = (wordData[5] &0xFF000000) >> 24;
uint32_t channel = (wordData[5] & 0x00FF0000) >> 16;
uint32_t spill_id = (wordData[5] & 0x0000FFFF);
spdlog::debug("crossing_count {}, block_count {}, channel {}, spill_id {}",
crossing_count, block_count, channel, spill_id);
for (uint32_t i = 0; i < block_count; i++) {
process_block(ptr, channel_size); // not correct yet!
}
// the number of bytes consumed by this function, regardless of block
// processing
bytes_left -= channel_size;
Channel c(ptr, channel_size, board_id);
c.Print(true);
}
}
// return number of bytes cosumed of the channel
spdlog::debug("processed {} bytes out of {}", (len - bytes_left), len);
return len - bytes_left;
}

1
loguru

Submodule loguru deleted from f64f3fc088