Send cmd struct to device
This commit is contained in:
@@ -1 +1,2 @@
|
||||
__pycache__/
|
||||
**.swp
|
||||
|
||||
@@ -10,7 +10,7 @@ struct prng{
|
||||
|
||||
#define CSPRNG_VERS 0x1
|
||||
|
||||
/* Define all commandes */
|
||||
/* Define all commands */
|
||||
#define CSPRNG_CMD_GET_RNG 0x10
|
||||
|
||||
struct cmd{
|
||||
|
||||
@@ -60,7 +60,7 @@ static unsigned short csum(unsigned short *buf, int nwords) {
|
||||
int send_uart(struct prng **s_prng){
|
||||
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");
|
||||
exit(-1);
|
||||
}
|
||||
@@ -68,10 +68,15 @@ int send_uart(struct prng **s_prng){
|
||||
set_serial_device(fd);
|
||||
|
||||
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");
|
||||
size_t len = write(fd, &cmd, 1);
|
||||
size_t len = write(fd, &buf_cmd, sizeof(struct cmd));
|
||||
//printf("Data sent: %ld\n\n", len);
|
||||
|
||||
// Read data
|
||||
|
||||
Reference in New Issue
Block a user