serial/main.c

36 lines
671 B
C

//
// Created by nano on 4/26/25.
//
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
#include "communication.h"
extern struct sp_port *port;
int main(int argc, char *argv[]) {
comm_init_communication();
while (1) {
if (comm_await()) {
byte *buffer = malloc(sizeof(byte));
if (sp_nonblocking_read(port, buffer, 1) == 1) {
byte *bits = malloc(sizeof(byte) * 8);
byte_to_bit_array(bits, *buffer);
printf("Data received: ");
for (int i = 7; i; i--) {
printf("%d", bits[i]);
}
printf("\n");
free(buffer);
if (bits[7] == 1) {
free(bits);
break;
}
}
}
}
comm_end_communication(port);
return 0;
}