Compare commits
10 Commits
57443a5c26
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a2e8997090 | |||
| e07831fcad | |||
| ec73a87d31 | |||
| e3fb134dbb | |||
| 6c3b0ceed4 | |||
| e5218cd885 | |||
| afc9b1d6fb | |||
|
|
f24628443f | ||
|
|
b8550dee70 | ||
|
|
78fc7cb184 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,4 +2,3 @@ r
|
||||
build
|
||||
old
|
||||
dump
|
||||
spdlog
|
||||
|
||||
15
CMakeLists.txt
Normal file
15
CMakeLists.txt
Normal 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})
|
||||
4
Makefile
4
Makefile
@@ -1,7 +1,7 @@
|
||||
target = r
|
||||
CXX = g++
|
||||
CXX_FLAGS := -std=c++14 -I/home/daq/sw/include -Wall -DSPDLOG_COMPILED_LIB
|
||||
LD_FLAGS := -lpthread -ldl -L/home/daq/sw/lib64 -lspdlog
|
||||
CXX_FLAGS := -std=c++14 -I./include -Wall
|
||||
LD_FLAGS := -lpthread -ldl
|
||||
|
||||
BUILD := ./build
|
||||
OBJS = $(BUILD)/client.o $(BUILD)/channel.o
|
||||
|
||||
38
channel.cc
38
channel.cc
@@ -1,32 +1,11 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -34,10 +13,10 @@ Channel::Channel(char const * ptr, size_t len, uint32_t board) {
|
||||
if (version != 0x1) valid = false;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
integral[i] = (wordData[i + 1] & 0xFFFFFF00)>>8;
|
||||
integral[i] = ((int32_t)(wordData[i+1])) >> 8;
|
||||
|
||||
crossing = wordData[4] & 0x00FFFFFF;
|
||||
block_count = (wordData[5] &0xFF000000) >> 24;
|
||||
block_count = wordData[5] >> 24;
|
||||
id = (wordData[5] & 0x00FF0000) >> 16;
|
||||
spill = (wordData[5] & 0x0000FFFF);
|
||||
if ((id > 8) || (id < 1)) {
|
||||
@@ -45,9 +24,16 @@ Channel::Channel(char const * ptr, size_t len, uint32_t board) {
|
||||
}
|
||||
|
||||
}
|
||||
void Channel::Print(){
|
||||
void Channel::Print(bool raw){
|
||||
if (valid) {
|
||||
spdlog::get("zynqDump")->info("board {}, channel {}, spill {}, size {}, blocks {}, crossing {}, integrals {}, {}, {}",
|
||||
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 {
|
||||
|
||||
@@ -16,9 +16,8 @@ class Channel {
|
||||
char * block_data;
|
||||
bool valid;
|
||||
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);
|
||||
|
||||
};
|
||||
#endif /* end of include guard */
|
||||
|
||||
136
client.cc
136
client.cc
@@ -17,7 +17,7 @@
|
||||
#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 size_t MAX_EVENT_SIZE = 33484; // in bytes
|
||||
const size_t MIN_EVENT_SIZE = 204; // in bytes
|
||||
@@ -33,66 +33,11 @@ bool bad_data = true;
|
||||
int open_socket();
|
||||
void signalHandler( int signum );
|
||||
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){
|
||||
return len;
|
||||
}
|
||||
size_t process_channel(char const * ptr, size_t len){
|
||||
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);
|
||||
c.Print();
|
||||
}
|
||||
}
|
||||
|
||||
// return number of bytes cosumed of the channel
|
||||
spdlog::debug("processed {} bytes out of {}", (len - bytes_left), len);
|
||||
return len - bytes_left;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
@@ -106,6 +51,9 @@ int main(int argc, char * argv[])
|
||||
char char_buffer[MAX_EVENT_SIZE];
|
||||
uint32_t * wordData = (uint32_t*) char_buffer;
|
||||
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
|
||||
struct timeval timeout; // Time value for time out
|
||||
@@ -125,6 +73,9 @@ int main(int argc, char * argv[])
|
||||
// read in first 4 bytes
|
||||
nread = recv(sock, char_buffer, 4, 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 ((char_buffer[0] & 0xFF) != 0xA5){
|
||||
bad_data = true;
|
||||
@@ -144,6 +95,9 @@ int main(int argc, char * argv[])
|
||||
spdlog::get("zynqDump")->debug("next {:d} bytes (expecting {:d}): {:X} {:X} {:X} {:X}",
|
||||
nread, frameSize - 4, wordData[0], wordData[1], wordData[2], wordData[3]);
|
||||
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 version = wordData[0] & 0xFF;
|
||||
uint16_t spill_id = (wordData[1] & 0x00FFFF00) >> 8;
|
||||
@@ -162,8 +116,10 @@ int main(int argc, char * argv[])
|
||||
size_t bytes_left = (frameSize - 3 * sizeof(uint32_t));
|
||||
size_t bytes_processed = 0;
|
||||
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_left - bytes_processed);
|
||||
bytes_processed += process_channel(
|
||||
char_buffer + 2 * sizeof(uint32_t) + bytes_processed,
|
||||
bytes_left - bytes_processed,
|
||||
static_cast<uint32_t>(board_id));
|
||||
}
|
||||
spdlog::get("zynqDump")->debug("Done, {} bytes processed.", bytes_processed);
|
||||
}
|
||||
@@ -209,11 +165,69 @@ int open_socket(){
|
||||
void setup_logger(){
|
||||
try {
|
||||
auto max_size = 1048576 * 5;
|
||||
auto max_files = 3;
|
||||
auto logger = spdlog::rotating_logger_mt("zynqDump", "logs/dump.txt", max_size, max_files);
|
||||
auto max_files = 20;
|
||||
auto logger = spdlog::rotating_logger_mt("zynqDump", "output/run.txt", max_size, max_files);
|
||||
auto channel_logger = spdlog::rotating_logger_mt("channel_logger", "output/chn.txt", max_size * 10, max_files);
|
||||
}
|
||||
catch (const spdlog::spdlog_ex &ex) {
|
||||
std::cerr << "Log init failed: " << ex.what() << std::endl;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user