Completed network communication and updated header format. TODO multiple clients
parent
09a7b2528b
commit
23b42c58fa
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": ".."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
Binary file not shown.
|
@ -1,4 +1,5 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <csignal>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
@ -49,7 +50,14 @@ int acceptConnection(int server_fd) {
|
|||
return client_fd;
|
||||
}
|
||||
|
||||
void term_handler(int signal) {
|
||||
printf("Terminated, received SIGNAL %d", signal);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
signal(SIGTERM, term_handler);
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s portNumber \n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -69,7 +77,7 @@ int main(int argc, char const *argv[]) {
|
|||
perror("Receive failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printf("[RICEVUTO]\t0x%x", word);
|
||||
printf("[RICEVUTO]\t0x%x\n", word);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ typedef struct Header {
|
|||
uint32_t startOfHeaderMarker = START_OF_HEADER_MARKER;
|
||||
uint32_t headerSize;
|
||||
uint32_t fragmentSize;
|
||||
uint32_t sourceIdentifier;
|
||||
uint32_t runNumber;
|
||||
uint32_t detectorEventNumber;
|
||||
uint32_t numberOfStatusElements;
|
||||
|
@ -39,11 +40,12 @@ void encode_header(uint32_t *buffer, const Header &header) {
|
|||
buffer[0] = header.startOfHeaderMarker;
|
||||
buffer[1] = header.headerSize;
|
||||
buffer[2] = header.fragmentSize;
|
||||
buffer[3] = header.runNumber;
|
||||
buffer[4] = header.detectorEventNumber;
|
||||
buffer[5] = header.numberOfStatusElements;
|
||||
buffer[3] = header.sourceIdentifier;
|
||||
buffer[4] = header.runNumber;
|
||||
buffer[5] = header.detectorEventNumber;
|
||||
buffer[6] = header.numberOfStatusElements;
|
||||
|
||||
std::memcpy(&buffer[6], header.statusElementsArray, header.numberOfStatusElements * sizeof(uint32_t));
|
||||
std::memcpy(&buffer[7], header.statusElementsArray, header.numberOfStatusElements * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void encode_fragment(uint32_t *buffer, const Fragment &fragment){
|
||||
|
|
54
provider.cxx
54
provider.cxx
|
@ -12,6 +12,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <csignal>
|
||||
|
||||
|
||||
#include "fragment_dataformat.h"
|
||||
|
@ -51,7 +52,16 @@ void connectTo(int sock, const char* host, int port) {
|
|||
}
|
||||
|
||||
|
||||
void term_handler(int signal) {
|
||||
printf("Terminated, received SIGNAL %d", signal);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
signal(SIGTERM, term_handler);
|
||||
signal(SIGINT, term_handler);
|
||||
|
||||
//will use it later to obtain random number from hardware
|
||||
std::random_device rd;
|
||||
std::mt19937 generator(42);
|
||||
|
@ -67,21 +77,24 @@ int main(int argc, char* argv[]) {
|
|||
uint32_t event_number = 0;
|
||||
|
||||
uint32_t run_number = 0;
|
||||
uint32_t source_id = 0;
|
||||
|
||||
if (argc != 4) {
|
||||
printf("Usage %s host portNumber runNumber\n", argv[0]);
|
||||
if (argc != 5) {
|
||||
printf("Usage %s host portNumber sourceId runNumber\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char* host = argv[1];
|
||||
int port = atoi(argv[2]);
|
||||
run_number = atoi(argv[3]);
|
||||
source_id = atoi(argv[3]);
|
||||
run_number = atoi(argv[4]);
|
||||
|
||||
int socket = makeSocket();
|
||||
connectTo(socket, host, port);
|
||||
|
||||
while (true) {
|
||||
Header header;
|
||||
header.sourceIdentifier = source_id;
|
||||
header.runNumber = run_number;
|
||||
header.detectorEventNumber = event_number;
|
||||
event_number++;
|
||||
|
@ -106,7 +119,7 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
|
||||
uint32_t payload_size = std::max(std::min(static_cast<int>(std::round(normal_distr(generator))), MAX_FRAGMENTS), MIN_FRAGMENTS);
|
||||
header.headerSize = 6 + header.numberOfStatusElements;
|
||||
header.headerSize = 7 + header.numberOfStatusElements;
|
||||
header.fragmentSize = header.headerSize + payload_size;
|
||||
|
||||
Fragment fragment;
|
||||
|
@ -116,25 +129,24 @@ int main(int argc, char* argv[]) {
|
|||
fragment.payloadElements[i] = unif_int_distib(generator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < header.fragmentSize; i++) {
|
||||
|
||||
uint32_t buffer[header.fragmentSize];
|
||||
encode_fragment(buffer, fragment);
|
||||
ssize_t bytes = send(socket, reinterpret_cast<char*>(buffer), sizeof(buffer), 0);
|
||||
if (bytes != header.fragmentSize * sizeof(uint32_t)) {
|
||||
perror("Send failed: nub bytes not matching");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::cout << std::hex << std::setw(8) << std::setfill('0');
|
||||
//std::cout << fragment.header;
|
||||
for (uint8_t i = 0; i < fragment.header.numberOfStatusElements; i++) {
|
||||
std::cout << "status element " << std::setw(8) << std::setfill('0') << fragment.header.statusElementsArray[i] << std::endl;
|
||||
}
|
||||
for (uint32_t i = 0; i < payload_size; i++) {
|
||||
std::cout << "payload element " << std::setw(8) << std::setfill('0') << fragment.payloadElements[i] << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
//std::cout << std::hex << std::setw(8) << std::setfill('0');
|
||||
////std::cout << fragment.header;
|
||||
//for (uint8_t i = 0; i < fragment.header.numberOfStatusElements; i++) {
|
||||
// std::cout << "status element " << std::setw(8) << std::setfill('0') << fragment.header.statusElementsArray[i] << std::endl;
|
||||
//}
|
||||
//for (uint32_t i = 0; i < payload_size; i++) {
|
||||
// std::cout << "payload element " << std::setw(8) << std::setfill('0') << fragment.payloadElements[i] << std::endl;
|
||||
//}
|
||||
//std::cout << std::endl;
|
||||
|
||||
if (header.numberOfStatusElements > 0){
|
||||
delete [] fragment.header.statusElementsArray;
|
||||
|
|
Loading…
Reference in New Issue