channel processing works correctly (without adc block)
This commit is contained in:
64
client.cc
64
client.cc
@@ -32,21 +32,24 @@ int open_socket();
|
||||
void signalHandler( int signum );
|
||||
void setup_logger();
|
||||
size_t process_channel(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;
|
||||
}
|
||||
size_t process_channel(char const * ptr, size_t len){
|
||||
if ((len < MIN_CHANNEL_SIZE) || (len > MAX_CHANNEL_SIZE)) {
|
||||
LOG_F(WARNING, "channel length must be between %u and %u.",
|
||||
LOG_SCOPE_F(WARNING, "channel length must be between %lu and %lu.",
|
||||
MIN_CHANNEL_SIZE, MAX_CHANNEL_SIZE);
|
||||
return 0;
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t bytes_processed = 0;
|
||||
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_F(WARNING, "bad_data, expecting %02X, received %02X",
|
||||
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 {
|
||||
@@ -54,16 +57,34 @@ size_t process_channel(char const * ptr, size_t len){
|
||||
|
||||
size_t channel_size = ((wordData[0] & 0xFFFFFF00) >> 8) * sizeof(uint32_t);
|
||||
if ((channel_size > MAX_CHANNEL_SIZE) || (channel_size < MIN_CHANNEL_SIZE)) {
|
||||
bad_data = true;
|
||||
LOG_F(WARNING, "Invalid channel size: %u", 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: %u, %u, %u", 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!
|
||||
}
|
||||
|
||||
LOG_F(INFO, "channel size %u", channel_size);
|
||||
bytes_left -= (channel_size - 4);
|
||||
// the number of bytes processed should be equal to the channel size
|
||||
bytes_left -= channel_size;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -98,7 +119,7 @@ int main(int argc, char * argv[])
|
||||
else{
|
||||
// read in first 4 bytes
|
||||
nread = recv(sock, char_buffer, 4, 0);
|
||||
LOG_F(INFO, "read in %u bytes: 0x%08X", nread, wordData[0]);
|
||||
LOG_F(INFO, "read in %ld bytes: 0x%08X", nread, wordData[0]);
|
||||
// if not A5 marker, go to next iteration (read in 4 more bytes)
|
||||
if ((char_buffer[0] & 0xFF) != 0xA5){
|
||||
bad_data = true;
|
||||
@@ -109,13 +130,13 @@ int main(int argc, char * argv[])
|
||||
size_t frameSize = 4 * (wordData[0] >> 8);
|
||||
nread = recv(sock, char_buffer, frameSize - 4, 0);
|
||||
// nread + 4 must be between MIN_EVENT_SIZE and MAX_EVENT_SIZE, and equal to frameSize.
|
||||
if ((nread != frameSize - 4) || (frameSize < MIN_EVENT_SIZE)|| (frameSize > MAX_EVENT_SIZE)){
|
||||
if (((size_t)nread != frameSize - 4) || (frameSize < MIN_EVENT_SIZE)|| (frameSize > MAX_EVENT_SIZE)){
|
||||
bad_data = true;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// ok, this seems to be good data
|
||||
LOG_F(INFO, "next %u bytes (expecting %u): %08X %08X %08X %08X",
|
||||
LOG_F(INFO, "next %ld bytes (expecting %lu): %08X %08X %08X %08X",
|
||||
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]);
|
||||
uint8_t board_id = (wordData[0] >> 24) & 0xFF;
|
||||
@@ -133,12 +154,13 @@ int main(int argc, char * argv[])
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
size_t bytes_left = frameSize - 3;
|
||||
size_t bytes_left = (frameSize - 3 * sizeof(uint32_t));
|
||||
size_t bytes_processed = 0;
|
||||
while (bytes_left >= MIN_CHANNEL_SIZE) {
|
||||
bytes_processed = process_channel(char_buffer + 2 * 4, bytes_left);
|
||||
bytes_left -= bytes_processed;
|
||||
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);
|
||||
}
|
||||
LOG_F(INFO, "Done, %lu bytes processed.", bytes_processed);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -183,10 +205,10 @@ void setup_logger(){
|
||||
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
|
||||
loguru::g_preamble_thread = false; // The logging thread
|
||||
loguru::g_preamble_file = false; // The file from which the log originates from
|
||||
loguru::g_preamble_verbose = false; // The verbosity field
|
||||
loguru::g_preamble_pipe = false; // The pipe symbol right before the message
|
||||
loguru::g_preamble_time = true; // The time of the current day
|
||||
loguru::g_preamble_uptime = true; // The time since init call
|
||||
loguru::g_preamble_thread = false; // The logging thread
|
||||
loguru::g_preamble_file = false; // The file from which the log originates from
|
||||
loguru::g_preamble_verbose = false; // The verbosity field
|
||||
loguru::g_preamble_pipe = false; // The pipe symbol right before the message
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user