Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ves011 committed Apr 10, 2023
1 parent 5cc16bf commit b9228d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
5 changes: 4 additions & 1 deletion cmds/cmd_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
36 changes: 22 additions & 14 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit b9228d2

Please sign in to comment.