giuliomoro
Thank you Giulio, so essentially the example code is basically aligning the logged data with the audio samples. In order to make it easier to distinguish in this case the telemetry (position) information with for example a certain event in the audio sample (i.e. someone speaking)?
Apologies I have a link to the main telemetry code: https://we.tl/t-D5GmTzTHmN which includes includes the file telemetry_sample_amended.cpp
which is within the Telemetry folder. That is where the getBroadcastData()
function resides. I have also included the code that relates to threads and linux serial device for additional reference.
I currently have two different threads in my Bela code, one that is the writebuffer for the audio that I record and the other one is for the serial thread (UART4 connection). I've copied just the relevant parts of the code related to the serial thread and logging the incoming data below:
WriteFile file1;
uint64_t gSamplesElapsed;
//Serial connection (UART4 Connection)
Serial gSerial;
AuxiliaryTask serialCommsTask;
....
void startSerial(void* arg)
{
unsigned int maxLen = 256;
char serialBuffer[maxLen];
// read from the serial port with a timeout of 100ms
int ret2 = gSerial.read(serialBuffer, maxLen, 100);
if (ret2 > 0) {
printf("Received: %.*s\n", ret2, serialBuffer);
} else {
printf("UART4 not available\n");
}
}
....
bool setup(BelaContext* context, void* arg)
{
gSerial.setup("/dev/ttyS4", 230400);
serialCommsTask = Bela_createAuxiliaryTask(startSerial, 0, "serial-thread", NULL);
file1.setup("droneData.txt"); //set the file name to write to
file1.setFileType(kText);
//file1.setFileType(kBinary); //this file type reduces the size of the file
file1.setFormat("%f %f %f %f %f %f %f %f\n");
}
...
void render(BelaContext* context, void* arg)
{
...
gSamplesElapsed = context->audioFramesElapsed;
Bela_scheduleAuxiliaryTask(serialCommsTask);
...
}
void loggingTask(){
file1.log(gSamplesElapsed, getBroadcastData());
}
Currently I have the use of undeclared identifier
for the call to getBroadcastData()
within file1.log()
. However I'm unsure what identifier it requires. Would this need to match how it is setup in the telemetry_sample_amended.cpp
file?
I've also noticed that I'm technically not writing any of the data coming in from the serial to file1
within my current code. Would I be right in saying that calling serialCommsTask
within file1.log()
; is the correct way to do that? As that essentially points to what is being read from the serial connection (UART4).
As an additional note, I just realised that potentially I might not have to call getBroadcastData()
directly, as the telemetry program is run within the OSDK on Bela. So I think as long as I am reading the incoming data from the serial (UART4), its a case of just logging that incoming data with a timestamp for reference. Then logging it to the .txt file. Although I'm not 100% certain about this and I could be wrong so it probably is still worth directly accessing getBroadcastData()
to avoid potential error.