Commit 1a96b767 by Sebastian Renner

Log to file for debugging

parent 726359a5
Read following action from stdin: c
Data sent to serial: b'c \x00\x00\x00'
Data sent to serial: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Read following action from stdin: s
Data sent to serial: b's\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: m
Data sent to serial: b'm\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: a
Data sent to serial: b'a\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: k
Data sent to serial: b'k\x10\x00\x00\x00'
Data sent to serial: b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
Read following action from stdin: p
Data sent to serial: b'p\x0f\x00\x00\x00'
Data sent to serial: b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e'
Read following action from stdin: e
Data sent to serial: b'e'
Read following action from stdin: C
Data sent to serial: b'C'
......@@ -52,6 +52,7 @@ unsigned char m[MAX_LEN];
unsigned long long mlen = 0;
unsigned char ad[MAX_LEN];
unsigned long long adlen = 0;
unsigned char text[6] = "HELLO";
unsigned char nsec[CRYPTO_NSECBYTES];
const unsigned long long nslen = CRYPTO_NSECBYTES;
......@@ -80,17 +81,12 @@ static void write_serial(const void *src, unsigned int len) {
for (int i = 0; i < len; i++) {
while (!LL_USART_IsActiveFlag_TXE(USART1));
LL_USART_TransmitData8(USART1, buf[i]);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
}
}
static void read_variable_serial(unsigned char action) {
uint32_t len;
read_serial(&len, sizeof(len));
switch(action) {
case 'k':
while (len != CRYPTO_KEYBYTES);
......@@ -187,7 +183,16 @@ int main(void)
read_variable_serial(rcv);
break;
case 'C': write_variable_serial(c, clen); break;
case 'C':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
write_variable_serial(c, clen);
break;
case 'M': write_variable_serial(m, mlen); break;
case 'A': write_variable_serial(ad, adlen); break;
case 'K': write_variable_serial(k, klen); break;
......@@ -195,15 +200,30 @@ int main(void)
case 'P': write_variable_serial(npub, nplen); break;
case 'd':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
break;
case 'e':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
break;
default:
return 2;
LL_mDelay(1);
}
/* USER CODE END WHILE */
}
......
#!/usr/bin/env python3
#!/usr/bin/python3 -u
import os
import sys
......@@ -6,6 +6,8 @@ import struct
import serial
from subprocess import Popen, PIPE, run
f = open("subprocess.log", "w+")
ser = serial.Serial('/dev/ttyUSB0', 115200)
def flash():
......@@ -25,6 +27,7 @@ def read(channel, l):
def write(channel, data):
if channel == 'ser':
l = ser.write(data)
f.write("Data sent to serial: " + str(data) + "\n")
elif channel == 'std':
l = sys.stdout.write(data)
else:
......@@ -47,7 +50,7 @@ def main():
#flash()
while(1):
action = read('std', 1)
if (action):
f.write("Read following action from stdin: " + action + "\n")
if action == 'c' or action == 'm' or action == 'a' or action == 'k' or action == 's' or action == 'p':
data = obtain('std')
submit('ser', action, data)
......@@ -58,7 +61,9 @@ def main():
elif action == 'C' or action == 'M' or action == 'A' or action == 'K' or action == 'S' or action == 'P':
write('ser', str.encode(action))
data = obtain('ser')
f.write("Obtained following data from serial: " + data + "\n")
submit('std', action, data)
f.write("Submitted following data to stdout: " + data + "\n")
else:
raise Exception("no capiche aczione %s" % (action))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment