Skip to content

Commit

Permalink
ts-streamer: Stop faster
Browse files Browse the repository at this point in the history
Signed-off-by: João Silva <jgc3silva@gmail.com>
  • Loading branch information
vankxr committed Jun 5, 2024
1 parent 8ee4a4a commit a7d6a55
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ts-streamer/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ uint8_t packet_received_cb(void *ptr, const framesync_stats_t *stats, const uint
if(!header_valid)
return 1;

if(g_iStop)
return 0;

// DBGPRINTLN_CTX("Packet received (H %s, P: (%lu bytes, %s], RSSI: %.2f dB, EVM: %.2f dB, CFO %.2f %%Fs)", header_valid ? "OK" : "FAIL", payload_len, payload_valid ? "OK" : "FAIL", stats->rssi, stats->evm, stats->cfo * 100);

static uint64_t ullTotalPackets = 0;
Expand Down Expand Up @@ -81,7 +84,8 @@ uint8_t packet_received_cb(void *ptr, const framesync_stats_t *stats, const uint
}
void signal_handler(int iSignal)
{
DBGPRINTLN_CTX("Got signal %d, stop sampling...", iSignal);
if(iSignal == SIGINT)
DBGPRINTLN_CTX("Kayboard interrupt, stopping...");

g_iStop = 1;
}
Expand All @@ -93,7 +97,6 @@ int main(int argc, char *argv[])
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);

DBGPRINTLN_CTX("Set SIGINT handler...");
signal(SIGINT, signal_handler);

// Parse arguments
Expand Down Expand Up @@ -352,10 +355,16 @@ int main(int argc, char *argv[])
pubPayload[i] = rand() % 256;
}

if(g_iStop)
break;

clock_t begin = clock();
framegen_assemble(xFrameGen, pubHeader, pubPayload, TS_PACKET_LEN * ulNumTSFramesPerPacket);
clock_t end = clock();

if(g_iStop)
break;

size_t ulSamplesLeft = framegen_get_symbol_count(xFrameGen);

ullNumSamples += ulSamplesLeft;
Expand Down Expand Up @@ -482,6 +491,9 @@ int main(int argc, char *argv[])
ulRead = fread(pfBuffer, sizeof(float complex), ulMTU, stdin);
}

if(g_iStop)
break;

clock_t begin = clock();
framesync_process_samples(xFrameSync, pfBuffer, ulRead);
clock_t end = clock();
Expand Down

0 comments on commit a7d6a55

Please sign in to comment.