serial/main.c
2025-05-02 02:02:08 +02:00

43 lines
844 B
C

//
// Created by nano on 4/26/25.
//
#include <stdio.h>
#include <stdlib.h>
#include "communication.h"
extern struct sp_port *port;
int main(int argc, char *argv[]) {
comm_init_communication();
byte data = 205;
int size = 1;
printf("size: %d\n", size);
unsigned int timeout = 50 * size; //50 ms timeout per byte
check(sp_nonblocking_write(port, &data, size));
byte *buf = malloc(size + 1);
int result = check(sp_blocking_read(port, buf, size, timeout));
if (result == size) {
printf("Received the same amount of bytes back \n");
}
buf[result] = '\0';
printf("%s\n", buf);
byte bits[8];
uint8_to_bit_array(bits, buf);
for (int i = 0; i < 8; i++) {
printf("%d ", bits[i]);
}
byte reconv_data = bit_array_to_uint8(bits);
printf("data: %d\n", reconv_data);
printf("\n");
comm_end_communication(port);
return 0;
}