fixed pipe, removed console control

This commit is contained in:
randogoth 2024-03-02 18:18:25 +02:00
parent 0fe369bc5a
commit 5389cf9df1
2 changed files with 31 additions and 17 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
CMakeFiles/
*.cmake
CMakeCache.txt
Makefile
*.bin
qngmeter

View file

@ -59,7 +59,7 @@ int main()
system("cls"); system("cls");
#elif __linux #elif __linux
// clear screen // clear screen
cout << "\E[?25l\E[H\E[2J"; // cout << "\E[?25l\E[H\E[2J";
// Signal handler to catch CTRL-C in terminal // Signal handler to catch CTRL-C in terminal
signal(SIGINT, (__sighandler_t)&sigintevent); signal(SIGINT, (__sighandler_t)&sigintevent);
#elif MACOSX #elif MACOSX
@ -126,25 +126,32 @@ int main()
#pragma omp section #pragma omp section
{ {
// This section reads from stdin and enqueues data for testing // This section reads from stdin as binary data and enqueues it for testing
while (!doExit) { const size_t blockSize = 2048; // Number of uint32_t values in a block
const size_t bytesPerValue = sizeof(uint32_t);
const size_t bufferSize = blockSize * bytesPerValue; // Total bytes per block
char buffer[bufferSize]; // Temporary buffer to store bytes
while (!cin.eof() && !doExit) {
cin.read(buffer, bufferSize);
size_t bytesRead = cin.gcount();
// Convert read bytes to uint32_t and store in a vector
shared_ptr<vector<uint32_t>> newBuffer(new vector<uint32_t>()); shared_ptr<vector<uint32_t>> newBuffer(new vector<uint32_t>());
uint32_t input; for (size_t i = 0; i < bytesRead; i += bytesPerValue) {
// Assuming the input stream provides data in a format that can be directly read into uint32_t if (i + bytesPerValue <= bytesRead) {
while (cin.read(reinterpret_cast<char*>(&input), sizeof(uint32_t))) { // Ensure we have a full 4 bytes to read
newBuffer->push_back(input); uint32_t value = 0;
if (newBuffer->size() == 2048) { // Arbitrary buffer size, adjust based on your needs memcpy(&value, buffer + i, bytesPerValue);
#pragma omp critical newBuffer->push_back(value);
dataQueue.push(newBuffer);
newBuffer = shared_ptr<vector<uint32_t>>(new vector<uint32_t>());
} }
} }
if (!newBuffer->empty()) { if (!newBuffer->empty()) {
#pragma omp critical #pragma omp critical
dataQueue.push(newBuffer); dataQueue.push(newBuffer);
} }
doExit = true; // Stop if stdin closes or reaches EOF
} }
doExit = true; // Exit if stdin closes or reaches EOF
} }
@ -352,11 +359,12 @@ int main()
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
#elif __linux #elif __linux
// clear screen // clear screen
printf("\E[H"); // printf("\E[H");
#elif MACOSX #elif MACOSX
#endif #endif
timePrev = timeNow; timePrev = timeNow;
cout.flush();
} }
// End on an 'x' keypress // End on an 'x' keypress