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,26 +126,33 @@ 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
shared_ptr<vector<uint32_t>> newBuffer(new vector<uint32_t>()); const size_t bytesPerValue = sizeof(uint32_t);
uint32_t input; const size_t bufferSize = blockSize * bytesPerValue; // Total bytes per block
// Assuming the input stream provides data in a format that can be directly read into uint32_t char buffer[bufferSize]; // Temporary buffer to store bytes
while (cin.read(reinterpret_cast<char*>(&input), sizeof(uint32_t))) { while (!cin.eof() && !doExit) {
newBuffer->push_back(input); cin.read(buffer, bufferSize);
if (newBuffer->size() == 2048) { // Arbitrary buffer size, adjust based on your needs 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>());
for (size_t i = 0; i < bytesRead; i += bytesPerValue) {
if (i + bytesPerValue <= bytesRead) {
// Ensure we have a full 4 bytes to read
uint32_t value = 0;
memcpy(&value, buffer + i, bytesPerValue);
newBuffer->push_back(value);
}
}
if (!newBuffer->empty()) {
#pragma omp critical #pragma omp critical
dataQueue.push(newBuffer); dataQueue.push(newBuffer);
newBuffer = shared_ptr<vector<uint32_t>>(new vector<uint32_t>());
} }
} }
if (!newBuffer->empty()) { doExit = true; // Exit if stdin closes or reaches EOF
#pragma omp critical
dataQueue.push(newBuffer);
}
doExit = true; // Stop if stdin closes or reaches EOF
} }
}
#pragma omp section #pragma omp section
@ -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