Skip to content

Commit

Permalink
Merge branch 'main' of github.com:SoC-Arch-polito/cnt21 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBattilana committed Feb 10, 2022
2 parents 104ae11 + 1cf6599 commit d7f8df7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ main module, finally, puts together them and creates the real interaction betwee

- `newValueSet`: launched when the operator set a new value, only if it's a valid value (<= 65535). The new value is passed as function argument to the callback.
- `onUARTDownload`: it's executed both when a download operation begins and ends (it can be distinguished thanks to the function's boolean argument). In the final implementation, it's used to set the LCD screen with the sentence "Downloading..".
- `texttt{onNewSysDateTime`: launched when the operator set a new date and time for the system, only if it has a valid format dd/mm/yyyy hh/mm/ss. In the final implementation, it's used to set up the RTC peripheral's time.
- `onNewSysDateTime`: launched when the operator set a new date and time for the system, only if it has a valid format dd/mm/yyyy hh/mm/ss. In the final implementation, it's used to set up the RTC peripheral's time.
- `onReset`: launched when the operator wants to reset both the log file, the current counter and the max number of allowed people. This command has no parameters and it does not reset the RTC.

Finally, the important thing to underline is that the log are stored in the flash memory in a raw format (4 bytes timestamp + 2 bytes count) so a simple get command gives as output an unreadable string. In order to read and understand it, an external python script has been developed that sends via UART the command get and decodes the output given by the system.

Expand Down
4 changes: 4 additions & 0 deletions include/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define ONNEW_VALUE_SET_CB(__fnc__name__, __arg__name__) void (__fnc__name__)(uint32_t __arg__name__)
#define ONUART_DOWNLOAD_CB(__fnc__name__, __arg__name__) void (__fnc__name__)(bool __arg__name__)
#define ONNEW_SYSDTTIME_CB(__fnc__name__, __arg__name__) void (__fnc__name__)(const char *__arg__name__)
#define ONNEW_RESET_CB(__fnc__name__, __arg__name__) void (__fnc__name__)(bool __arg__name__)

struct COMM_Handle {

Expand All @@ -34,6 +35,9 @@ struct COMM_Handle {
@param newDateTime: string with the new date time to be set.
Format: dd/mm/yyyy hh/mm/ss */
ONNEW_SYSDTTIME_CB(*onNewSysDateTime, newDateTime);

/* Callback invoked when a RESET command is requested via UART. */
ONNEW_RESET_CB(*onReset, flash);
} Callback;

};
Expand Down
10 changes: 8 additions & 2 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
set_time : Set the system date and time. Usage: set_time dd/mm/yyyy hh/mm/ss\r\n\
set : Set the threshold for people count. Usage: set <N>\r\n\
get : Retrieves the log of the system. Usage: <use external script to decode>\r\n\
help : Shows this help. Usage: help\r\n"
help : Shows this help. Usage: help\r\n\
reset : Reset the counter and the log. Usage: reset\r\n"


static struct COMM_Handle *phcomm;
Expand Down Expand Up @@ -123,7 +124,12 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
strcpy((char *)buf, STR_HELP);
len = sizeof(STR_HELP) - 3;
buf_cnt = 0;
} else if (buf_cnt) {
} else if (!strncmp((char *)buf, "reset", 0x5)) {
INVOKE_CB(phcomm->Callback.onReset, true);
strcpy((char *)buf, "\r\nRESET DONE!\r\n");
len = 12;
buf_cnt = 0;
} else if (buf_cnt) {
strcpy((char *)buf, STR_NOTFOUND);
len = sizeof(STR_NOTFOUND) - 3;
buf_cnt = 0;
Expand Down
1 change: 1 addition & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void flashEraseSector(uint8_t sector_num) {
// Erase the required Flash sector
FLASH_Erase_Sector(sector_num, FLASH_VOLTAGE_RANGE_3);
HAL_FLASH_Lock();
i = 0;
}

// 2. Set Sector Adress
Expand Down
17 changes: 16 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static void enable_IRQ();
ONNEW_SYSDTTIME_CB(onNewSysDateTime, newTime);
ONNEW_VALUE_SET_CB(onNewValueSet, newMax);
ONUART_DOWNLOAD_CB(onUartDownload, xferDone);
ONNEW_RESET_CB(onReset, flash);


static int number_people;
Expand Down Expand Up @@ -59,6 +60,7 @@ int main(void) {
hcomm.Callback.newValueSet = onNewValueSet;
hcomm.Callback.onNewSysDateTime = onNewSysDateTime;
hcomm.Callback.onUARTDownload = onUartDownload;
hcomm.Callback.onReset = onReset;

COMM_Init(&hcomm);
COMM_StartListen();
Expand Down Expand Up @@ -133,6 +135,19 @@ ONUART_DOWNLOAD_CB(onUartDownload, xferDone) {
}
}

ONNEW_RESET_CB(onReset, flash) {
// Reset flash memory
if(flash){
flashEraseSector(11);
hcomm.SrcMemory.size = 0x0;
}

// Reset counter and update interterface
number_people = 0;
number_people_max = 0;
update_interface();
}

static void MX_I2C1_Init(void) {
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000;
Expand Down Expand Up @@ -214,7 +229,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
switch (GPIO_Pin) {
case IR_1_PIN:
// Manage counter, increase
if(setup_phase > 1 && number_people < number_people_max)
if(setup_phase > 1)
log_update_number(&hrtc, &gTime, &gDate, ++number_people, &hcomm);
break;
case IR_2_PIN:
Expand Down

0 comments on commit d7f8df7

Please sign in to comment.