diff --git a/README.md b/README.md index 874015b..3c8283a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/include/comm.h b/include/comm.h index 9f1651a..e75967c 100644 --- a/include/comm.h +++ b/include/comm.h @@ -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 { @@ -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; }; diff --git a/src/comm.c b/src/comm.c index 12eab06..2ee9c5f 100644 --- a/src/comm.c +++ b/src/comm.c @@ -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 \r\n\ get : Retrieves the log of the system. Usage: \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; @@ -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; diff --git a/src/log.c b/src/log.c index 0306ad4..7933c39 100644 --- a/src/log.c +++ b/src/log.c @@ -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 diff --git a/src/main.c b/src/main.c index ffe5cd3..f047f47 100644 --- a/src/main.c +++ b/src/main.c @@ -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; @@ -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(); @@ -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; @@ -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: