Send cmd struct to device

This commit is contained in:
2026-06-20 16:26:40 +02:00
parent 8bd82613e9
commit 7bf46a4c27
5 changed files with 410 additions and 404 deletions
+1
View File
@@ -1 +1,2 @@
__pycache__/ __pycache__/
**.swp
+1 -1
View File
@@ -10,7 +10,7 @@ struct prng{
#define CSPRNG_VERS 0x1 #define CSPRNG_VERS 0x1
/* Define all commandes */ /* Define all commands */
#define CSPRNG_CMD_GET_RNG 0x10 #define CSPRNG_CMD_GET_RNG 0x10
struct cmd{ struct cmd{
BIN
View File
Binary file not shown.
+400 -400
View File
File diff suppressed because it is too large Load Diff
+8 -3
View File
@@ -60,7 +60,7 @@ static unsigned short csum(unsigned short *buf, int nwords) {
int send_uart(struct prng **s_prng){ int send_uart(struct prng **s_prng){
int fd; int fd;
if ((fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY)) < 0){ if ((fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY)) < 0){
printf("Failed to read the device\n"); printf("Failed to read the device\n");
exit(-1); exit(-1);
} }
@@ -68,10 +68,15 @@ int send_uart(struct prng **s_prng){
set_serial_device(fd); set_serial_device(fd);
char buffer[sizeof(struct prng)]; char buffer[sizeof(struct prng)];
u_int8_t cmd = 1; char buf_cmd[sizeof(struct cmd)];
struct cmd s_cmd = {0};
s_cmd.version = CSPRNG_VERS;
s_cmd.cmd = CSPRNG_CMD_GET_RNG;
memcpy(buf_cmd, &s_cmd, sizeof(struct cmd));
//printf("Sending command...\n"); //printf("Sending command...\n");
size_t len = write(fd, &cmd, 1); size_t len = write(fd, &buf_cmd, sizeof(struct cmd));
//printf("Data sent: %ld\n\n", len); //printf("Data sent: %ld\n\n", len);
// Read data // Read data