i wrote a small c program to extract object detection data from /run/mpa/tflite_data
when I list the contents of tflite_data i get two files: info & request.
when i "cat /run/mpa/tflite_data/info" i get the the correct data type of ai_detection_t
when i "cat /run/mpa/tflite_data/request" the system just hangs as if waiting for data
I know data is being sent as the tflite camera is showing object detections in the web interface
here is my simple c program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#define BUF_LEN 32
#define MAX_DETECTIONS 100
#define PIPE_PATH "/run/mpa/tflite_data/request"
typedef struct ai_detection_t {
uint32_t magic_number;
int64_t timestamp_ns;
uint32_t class_id;
int32_t frame_id;
char class_name[BUF_LEN];
char cam[BUF_LEN];
float class_confidence;
float detection_confidence;
float x_min;
float y_min;
float x_max;
float y_max;
} attribute((packed)) ai_detection_t;
int open_pipe(const char* path) {
int fd = open(path, O_RDONLY);
if (fd < 0) {
perror("Failed to open pipe");
exit(EXIT_FAILURE);
}
return fd;
}
ssize_t read_pipe(int fd, void* buffer, size_t size) {
return read(fd, buffer, size);
}
int main() {
int pipe_fd = open_pipe(PIPE_PATH);
ai_detection_t detections[MAX_DETECTIONS];
ssize_t bytes_read;
while (1) {
bytes_read = read_pipe(pipe_fd, detections, sizeof(detections));
if (bytes_read <= 0) {
usleep(10000);
continue;
}
int num_detections = bytes_read / sizeof(ai_detection_t);
printf("\nReceived %d detections:\n", num_detections);
for (int i = 0; i < num_detections; ++i) {
ai_detection_t *det = &detections[i];
printf("Detection %d:\n", i + 1);
printf(" Magic Number: 0x%X\n", det->magic_number);
printf(" Timestamp (ns): %ld\n", det->timestamp_ns);
printf(" Frame ID: %d\n", det->frame_id);
printf(" Class ID: %u\n", det->class_id);
printf(" Class Name: %s\n", det->class_name);
printf(" Camera Name: %s\n", det->cam);
printf(" Class Confidence: %.2f\n", det->class_confidence);
printf(" Detection Confidence: %.2f\n", det->detection_confidence);
printf(" Bounding Box (x_min,y_min,x_max,y_max): (%.2f, %.2f, %.2f, %.2f)\n",
det->x_min, det->y_min, det->x_max, det->y_max);
}
usleep(10000);
}
close(pipe_fd);
return 0;
}
The code just hangs waiting for data to come in from the pipe /run/mpa/tflite_data/request
what am i doing wrong?