serial/main.c
Nicholas Stănescu 0b3608c6ba initial commit
2025-05-02 02:02:08 +02:00

42 lines
816 B
C

//
// Created by nano on 4/26/25.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "communication.h"
extern struct sp_port *port;
int main(int argc, char *argv[]) {
comm_init_communication();
u_int8_t data = 205;
int size = strlen(&data);
printf("size: %d\n", size);
unsigned int timeout = 50 * size; //50 ms timeout per byte
check(sp_nonblocking_write(port, &data, size));
char *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);
u_int8_t bits[8];
uint8_to_bit_array(bits, buf[0]);
free(buf);
for (int i = 0; i < 8; i++) {
printf("%d ", bits[i]);
}
printf("\n");
comm_end_communication(port);
return 0;
}