Skip to content

Commit

Permalink
Merge pull request SoC-Arch-polito#16 from SoC-Arch-polito/wip_main
Browse files Browse the repository at this point in the history
WIP Main
  • Loading branch information
thegabriele97 authored Dec 21, 2021
2 parents 82c9e64 + 040d633 commit 6f5cce6
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion include/i2c_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ void lcd_send_two_string (char *str1, char * str2);

void lcd_set_text_downloading();

void lcd_set_number_people(int n_people);
void lcd_set_number_people(int n_people, int max_people);
31 changes: 20 additions & 11 deletions serialInterface.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
#!/usr/bin/python3.9

from os import times
import serial
from sys import argv
from datetime import datetime
import time
import socket


if __name__ == "__main__":
ser = serial.Serial(port= argv[1], baudrate=argv[2])
print(ser.name)

ser.write(bytearray("get\r".encode()))
entry = ser.read(5)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 1234))
s.settimeout(1)

s.send("\r".encode('utf-8'))
time.sleep(1)
s.recv(1024)

s.send("get\r".encode('utf-8'))
time.sleep(1)
s.recv(5)

totb = 0
time.sleep(1)
while ser.inWaiting() > 5:
entry = ser.read(6)
totb += 6
# print(entry.hex())
while True:
try:
entry = s.recv(6)
except:
exit(0)

timestamp = int.from_bytes(entry[0:4], "little")
cnt = int.from_bytes(entry[4:6], "little")

print(f"{datetime.utcfromtimestamp(timestamp).strftime('%d/%m/%Y %H/%M/%S')} -- {cnt} -- tot: {totb}")
print(f"{datetime.utcfromtimestamp(timestamp).strftime('%d/%m/%Y %H/%M/%S')} -- {cnt}")

18 changes: 10 additions & 8 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ static void txCpltCback(UART_HandleTypeDef *huart) {
send_etx--;
GAL_UART_Transmit_DMA(phcomm->SrcMemory.basePtr, send_etx == 1 ? phcomm->SrcMemory.size : 0xffff);
} else if (send_etx == 1) {
INVOKE_CB(phcomm->Callback.onUARTDownload, true);
buf[0] = '\n';
send_etx--;
GAL_UART_Transmit_DMA(&buf[0], 0x1);
INVOKE_CB(phcomm->Callback.onUARTDownload, true);
}

}
Expand All @@ -41,6 +39,7 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
bool cvrted;
uint8_t *pbuf;
uint16_t n;
uint32_t tmpNewValue;

GAL_UART_Transmit(buf + buf_cnt + len, 0x1); // echo back

Expand Down Expand Up @@ -90,8 +89,14 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
for (cvrted = false, i = 4; i < buf_cnt && (buf[i] >= '0' && buf[i] <= '9'); i++) {

if (!cvrted) {

tmpNewValue = atoi((char *)buf + 4);
if (tmpNewValue > 0xffff) {
break;
}

cvrted = true;
setValue = atol((char *)buf + 4);
setValue = tmpNewValue;
INVOKE_CB(phcomm->Callback.newValueSet, setValue);
}

Expand All @@ -112,7 +117,7 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {

send_etx = (phcomm->SrcMemory.size >> 16) + 1;
GAL_UART_Transmit_DMA(phcomm->SrcMemory.basePtr, send_etx == 1 ? phcomm->SrcMemory.size : 0xffff);
len = -4;
len = -1;

} else if (!strncmp((char *)buf, "help", 0x4)) {
strcpy((char *)buf, STR_HELP);
Expand All @@ -125,9 +130,6 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
}

strcpy((char *)(buf + buf_cnt + len + 1), STR_PROMPT);
// buf[buf_cnt + len + 1] = '\n';
// buf[buf_cnt + len + 2] = '>';
// buf[buf_cnt + len + 3] = ' ';
GAL_UART_Transmit_DMA(buf + buf_cnt, len + sizeof(STR_PROMPT));
buf_cnt = 0xff;
}
Expand Down
6 changes: 3 additions & 3 deletions src/i2c_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ void lcd_set_text_downloading(){
lcd_send_string(" ");
}

void lcd_set_number_people(int n_people){
char num_char[15];
sprintf(num_char, "%d", n_people);
void lcd_set_number_people(int n_people, int max_people){
char num_char[16];
sprintf(num_char, "%d/%d", n_people, max_people);

lcd_go_home();
lcd_send_string("Number of people");
Expand Down
4 changes: 2 additions & 2 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ void log_rtc_setup(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *gTime, RTC_DateType
// HAL_RTC_GetDate(hrtc, gDate, RTC_FORMAT_BIN);
// HAL_RTC_GetTime(hrtc, gTime, RTC_FORMAT_BIN);
sscanf((char *)start, "%d/%d/%d %d/%d/%d", &day, &month, &year, &hour, &min, &sec);
gTime->Hours = hour % 12;
gTime->Hours = hour > 12 ? hour % 12 : hour;
gTime->Minutes = min;
gTime->Seconds = sec;
gTime->TimeFormat = hour > 12 ? RTC_HOURFORMAT12_PM : RTC_HOURFORMAT12_AM;
gTime->TimeFormat = hour >= 12 ? RTC_HOURFORMAT12_PM : RTC_HOURFORMAT12_AM;
HAL_RTC_SetTime(hrtc, gTime, RTC_FORMAT_BIN);
gDate->Date = day;
gDate->Month = month;
Expand Down
6 changes: 3 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static void update_interface(){
turn_off_green_led();
}

lcd_set_number_people(number_people);
lcd_set_number_people(number_people, number_people_max);
}

/**
Expand All @@ -215,12 +215,12 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
case IR_1_PIN:
// Manage counter, increase
if(setup_phase > 1 && number_people < number_people_max)
log_update_number(&hrtc, &gTime, &gDate, number_people++, &hcomm);
log_update_number(&hrtc, &gTime, &gDate, ++number_people, &hcomm);
break;
case IR_2_PIN:
// Manage counter, decrease
if(setup_phase > 1 && number_people > 0)
log_update_number(&hrtc, &gTime, &gDate, number_people--, &hcomm);
log_update_number(&hrtc, &gTime, &gDate, --number_people, &hcomm);
break;
}

Expand Down
10 changes: 5 additions & 5 deletions stm32f4_discovery_modified.resc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ machine LoadPlatformDescription @./peripherals/ext_peripheral.repl

cpu PerformanceInMips 125

:emulation CreateServerSocketTerminal 1234 "externalUART" false
:connector Connect uart4 externalUART
:showAnalyzer uart4

emulation CreateUartPtyTerminal "externalUART" "/tmp/uart4" true
emulation CreateServerSocketTerminal 1234 "externalUART" False
connector Connect uart4 externalUART
showAnalyzer uart4

:emulation CreateUartPtyTerminal "externalUART" "/tmp/uart4" true
:connector Connect uart4 externalUART
:showAnalyzer uart4

macro reset
"""
sysbus LoadELF @.pio/build/disco_f407vg/firmware.elf
Expand Down

0 comments on commit 6f5cce6

Please sign in to comment.