6 #include "pmsm_state.h"
13 void freeLogs(struct rpi_state* this){
15 if (this->log_col_count){
16 for (r=0;r<LOG_ROWS;r++){
20 this->log_col_count=0;
28 void logInit(struct rpi_state* state){
31 state->log_col_count=LOG_DEF_COL;
32 for (r=0;r<LOG_ROWS;r++){
33 state->logs[r]=malloc(state->log_col_count*sizeof(int));
34 if (state->logs[r]==NULL){
36 state->log_col_count=-1;
47 void makeLog(struct rpi_state* this){
49 if (this->log_col==MAX_LOGS-1){
53 this->logs[0][this->log_col]=(int)this->tf_count;
54 this->logs[1][this->log_col]=(int)this->spi_dat->pozice;
56 this->logs[2][this->log_col]=(int)this->pwm1;
57 this->logs[3][this->log_col]=(int)this->pwm2;
58 this->logs[4][this->log_col]=(int)this->pwm3;
59 this->logs[5][this->log_col]=this->duty;
61 this->logs[6][this->log_col]=this->desired_spd;
62 this->logs[7][this->log_col]=this->speed;
64 this->logs[8][this->log_col]=(int)(this->spi_dat->ch1/this->spi_dat->adc_m_count);
65 this->logs[9][this->log_col]=(int)(this->spi_dat->ch2/this->spi_dat->adc_m_count);
66 this->logs[10][this->log_col]=(int)(this->spi_dat->ch0/this->spi_dat->adc_m_count);
70 if (rps.log_col==rps.log_col_count-1){
72 rps.log_col_count%=MAX_LOGS;
73 for (r=0;r<LOG_ROWS;r++){
74 rps.logs[r]=realloc(rps.logs[r],rps.log_col_count*sizeof(int));
75 if (rps.logs[r]==NULL){
88 void saveLogs(struct rpi_state* this){
92 f = fopen("logs.log", "w");
94 printf("Error opening file!\n");
98 for (r=0;r<LOG_ROWS;r++){
99 for(s=0;s<this->log_col-1;s++){ /*posledni sloupec je vevyplneny*/
100 if (s==this->log_col-2){
101 fprintf(f,"%d ",this->logs[r][s]);
103 fprintf(f,"%d, ",this->logs[r][s]);