Skip to content

Commit

Permalink
receiver side implemented, ready for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
zLukas committed Jan 14, 2025
1 parent ea1eaff commit c61d9e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/tools/TestApp/Inc/mcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ int mcm_init_client(mcm_ts* mcm, const char* cfg);
int mcm_create_tx_connection(mcm_ts* mcm, const char* cfg);
int mcm_create_rx_connection(mcm_ts* mcm, const char* cfg);
int mcm_send_video_frame(mcm_ts* mcm, FILE* frame);
int mcm_receive_video_frames(mcm_ts* mcm);
int mcm_receive_video_frames(mcm_ts* mcm, FILE* frame);

#endif /* _MCM_H_*/
17 changes: 12 additions & 5 deletions tests/tools/TestApp/rx_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@
#include "Inc/input.h"
#include "Inc/mcm.h"
#include <unistd.h>
#include <stdlib.h>

const char* client_cfg;
const char* conn_cfg;

int main(int argc, char* argv[]){
if (argc != 4) {
fprintf(stderr, "Usage: %s <client_cfg.json> <connection_cfg.json> <abs path>/file|frame>\n", argv[0]);
exit(EXIT_FAILURE);
}

char* client_cfg_file = argv[1];
char* conn_cfg_file = argv[2];
char* frame_file = argv[3];
printf("launching RX App \n");
printf("RX App PID: %d\n", getpid());
printf("reading client configuration... \n");
client_cfg = parse_json_to_string("client.json");
client_cfg = parse_json_to_string(client_cfg_file);
printf("reading connection configuration... \n");
conn_cfg = parse_json_to_string("connection.json");
conn_cfg = parse_json_to_string(conn_cfg_file);
mcm_ts mcm;
mcm_init_client(&mcm, client_cfg);
mcm_create_rx_connection(&mcm, conn_cfg);
printf("waiting for frames... \n");
FILE *frame = fopen(frame_file, "rb");
while(1){
// mcm_create_rx_connection(&mcm, conn_cfg);
// mcm_receive_video_frames(&mcm);
mcm_receive_video_frames(&mcm, frame);
}
return 0;
}
22 changes: 18 additions & 4 deletions tests/tools/TestApp/src/mcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/* PRIVATE */
void file_to_buffer(FILE *file, MeshBuffer* buf);
void buffer_to_file(FILE *file, MeshBuffer* buf);

int mcm_init_client(mcm_ts* mcm, const char* cfg){
int err = mesh_create_client_json(&(mcm->client), cfg);
Expand Down Expand Up @@ -64,7 +65,7 @@ int mcm_send_video_frame(mcm_ts* mcm, FILE* frame){
}


int mcm_receive_video_frames(mcm_ts* mcm){
int mcm_receive_video_frames(mcm_ts* mcm, FILE* frame){
int err = 0;
MeshBuffer *buf;

Expand All @@ -78,7 +79,7 @@ int mcm_receive_video_frames(mcm_ts* mcm){
}

/* Process the received user data */
//get_user_video_frames(buf->payload_ptr, buf->payload_len);
buffer_to_file(frame,buf);


/* Release and put the buffer back to the mesh */
Expand Down Expand Up @@ -132,6 +133,19 @@ void file_to_buffer(FILE *file, MeshBuffer* buf){
free(frame_buf);
}

void get_user_video_frames(){
//get buffer and save it to the file
void buffer_to_file(FILE *file, MeshBuffer* buf){
if (file == NULL) {
perror("Failed to open file for writing");
return;
}

// Write the buffer to the file
size_t written_size = fwrite(buf->payload_ptr, BYTE_SIZE, buf->payload_len, file);
if (written_size != buf->payload_len) {
perror("Failed to write buffer to file");
fclose(file);
return;
}

fclose(file);
}

0 comments on commit c61d9e5

Please sign in to comment.