diff --git a/cmds/cmd_system.c b/cmds/cmd_system.c index b23a090..18775b8 100644 --- a/cmds/cmd_system.c +++ b/cmds/cmd_system.c @@ -424,6 +424,7 @@ static int cat_file(int argc, char **argv) { char path[64], outputm[300]; struct stat st; + int i; int nerrors = arg_parse(argc, argv, (void **)&cat_args); if (nerrors != 0) { @@ -444,15 +445,17 @@ static int cat_file(int argc, char **argv) FILE *f = fopen(path, "r"); if (f != NULL) { + i = 0; while(!feof(f)) { fgets(outputm, 298, f); if(feof(f)) break; my_printf("%s", outputm); + i++; } fclose(f); - my_printf("\nEOF\n"); + my_printf("\nEOF %d lines\n", i); } } return 0; diff --git a/utils/utils.c b/utils/utils.c index 8b5565e..f1b4913 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -299,7 +299,7 @@ int rw_params(int rw, int param_type, void * param_val) } else { - sprintf(buf, "%.3lf %.3lf\n", ((pnorm_param_t *)param_val)->hmp, ((pnorm_param_t *)param_val)->psl); + sprintf(buf, "%.3lf %.3lf\n", ((pnorm_param_t *)param_val)->psl, ((pnorm_param_t *)param_val)->hmp); if(fputs(buf, f) >= 0) ret = ESP_OK; fclose(f); @@ -376,30 +376,38 @@ int rw_params(int rw, int param_type, void * param_val) //esp_vfs_spiffs_unregister(conf.partition_label); return ret; } -int rw_tpdata(int rw, char *bufdata) +int write_tpdata(int rw, char *bufdata) { FILE *f = NULL; time_t now = 0; struct tm timeinfo = { 0 }; char strtime[100], file_name[64], fbuf[400]; - int ret; + int ret = ESP_FAIL; time(&now); localtime_r(&now, &timeinfo); strftime(strtime, sizeof(strtime), "%Y-%m-%d/%H:%M:%S", &timeinfo); sprintf(file_name, "%s/%d.tph", BASE_PATH, timeinfo.tm_year + 1900); if(rw == PARAM_WRITE) - f = fopen(file_name, "a"); - if(f) { - sprintf(fbuf, "%s %s\n", strtime, bufdata); - fputs(fbuf, f); - fclose(f); - ret = ESP_OK; - } - else - { - ESP_LOGI(TAG, "Cannot open %s for writing. errnp = %d", file_name, errno); - ret = ESP_FAIL; + if(xSemaphoreTake(pthfile_mutex, ( TickType_t ) 50 )) // 2 sec wait + { + f = fopen(file_name, "a"); + if(f) + { + sprintf(fbuf, "%s %s\n", strtime, bufdata); + fputs(fbuf, f); + fclose(f); + ret = ESP_OK; + } + else + { + ESP_LOGI(TAG, "Cannot open %s for writing. errno = %d", file_name, errno); + ret = ESP_FAIL; + } + xSemaphoreGive(pthfile_mutex); + } + else + ret = ESP_FAIL; } return ret; } diff --git a/utils/utils.h b/utils/utils.h index fb4de10..a08ed93 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -11,6 +11,6 @@ void my_printf(char *format, ...); int my_log_vprintf(const char *fmt, va_list arguments); int rw_params(int rw, int param_type, void * param_val); -int rw_tpdata(int rw, char * bufdata); +int write_tpdata(int rw, char *bufdata); #endif /* MAIN_UTILS_H_ */