aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen/simpleserial
diff options
context:
space:
mode:
Diffstat (limited to 'pyecsca/codegen/simpleserial')
-rw-r--r--pyecsca/codegen/simpleserial/simpleserial.c18
-rw-r--r--pyecsca/codegen/simpleserial/simpleserial.h5
2 files changed, 13 insertions, 10 deletions
diff --git a/pyecsca/codegen/simpleserial/simpleserial.c b/pyecsca/codegen/simpleserial/simpleserial.c
index ca7c54d..d15b309 100644
--- a/pyecsca/codegen/simpleserial/simpleserial.c
+++ b/pyecsca/codegen/simpleserial/simpleserial.c
@@ -3,7 +3,6 @@
#include "simpleserial.h"
#include <stdint.h>
#include "hal.h"
-#include <stdio.h>
typedef struct ss_cmd
{
@@ -12,12 +11,9 @@ typedef struct ss_cmd
uint8_t (*fp)(uint8_t*, uint16_t);
} ss_cmd;
-#define MAX_SS_CMDS 26
static ss_cmd commands[MAX_SS_CMDS];
static int num_commands = 0;
-#define MAX_SS_LEN 256
-
#define SS_VER_1_0 0
#define SS_VER_1_1 1
@@ -89,14 +85,17 @@ int simpleserial_addcmd(char c, unsigned int len, uint8_t (*fp)(uint8_t*, uint16
return 0;
}
-void simpleserial_get(void)
+int simpleserial_get(void)
{
char ascii_buf[2*MAX_SS_LEN];
uint8_t data_buf[MAX_SS_LEN];
- char c;
+ int ci;
// Find which command we're receiving
- c = getch();
+ ci = getch();
+ if (ci == -1)
+ return 0;
+ char c = (char) ci;
int cmd;
for(cmd = 0; cmd < num_commands; cmd++)
@@ -107,7 +106,7 @@ void simpleserial_get(void)
// If we didn't find a match, give up right away
if(cmd == num_commands)
- return;
+ return 1;
// Receive characters until we fill the ASCII buffer
int i = 0;
@@ -125,7 +124,7 @@ void simpleserial_get(void)
// ASCII buffer is full: convert to bytes
// Check for illegal characters here
if(hex_decode(i, ascii_buf, data_buf))
- return;
+ return 1;
// Callback
uint8_t ret[1];
@@ -135,6 +134,7 @@ void simpleserial_get(void)
#if SS_VER == SS_VER_1_1
simpleserial_put('z', 1, ret);
#endif
+ return 1;
}
void simpleserial_put(char c, int size, uint8_t* output)
diff --git a/pyecsca/codegen/simpleserial/simpleserial.h b/pyecsca/codegen/simpleserial/simpleserial.h
index fa64865..a5dff81 100644
--- a/pyecsca/codegen/simpleserial/simpleserial.h
+++ b/pyecsca/codegen/simpleserial/simpleserial.h
@@ -6,6 +6,9 @@
#include <stdint.h>
+#define MAX_SS_CMDS 26
+#define MAX_SS_LEN 512
+
// Set up the SimpleSerial module
// This prepares any internal commands
void simpleserial_init(void);
@@ -32,7 +35,7 @@ int simpleserial_addcmd(char c, unsigned int len, uint8_t (*fp)(uint8_t*, uint16
// - First character didn't match any known commands
// - One of the characters wasn't in [0-9|A-F|a-f]
// - Data was too short or too long
-void simpleserial_get(void);
+int simpleserial_get(void);
// Write some data to the serial port
// Prepends the character c to the start of the line