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 makeLog(struct rpi_state* this){
30 if (this->log_col==MAX_LOGS-1){
34 this->logs[0][this->log_col]=(int)this->tf_count;
35 this->logs[1][this->log_col]=(int)this->spi_dat->pozice;
37 this->logs[2][this->log_col]=(int)this->pwm1;
38 this->logs[3][this->log_col]=(int)this->pwm2;
39 this->logs[4][this->log_col]=(int)this->pwm3;
40 this->logs[5][this->log_col]=this->duty;
42 this->logs[6][this->log_col]=this->desired_spd;
43 this->logs[7][this->log_col]=this->speed;
45 this->logs[8][this->log_col]=(int)(this->spi_dat->ch1/this->spi_dat->adc_m_count);
46 this->logs[9][this->log_col]=(int)(this->spi_dat->ch2/this->spi_dat->adc_m_count);
47 this->logs[10][this->log_col]=(int)(this->spi_dat->ch0/this->spi_dat->adc_m_count);
51 if (rps.log_col==rps.log_col_count-1){
53 rps.log_col_count%=MAX_LOGS;
54 for (r=0;r<LOG_ROWS;r++){
55 rps.logs[r]=realloc(rps.logs[r],rps.log_col_count*sizeof(int));
56 if (rps.logs[r]==NULL){
69 void saveLogs(struct rpi_state* this){
73 f = fopen("logs.log", "w");
75 printf("Error opening file!\n");
79 for (r=0;r<LOG_ROWS;r++){
80 for(s=0;s<this->log_col-1;s++){ /*posledni sloupec je vevyplneny*/
81 if (s==this->log_col-2){
82 fprintf(f,"%d ",this->logs[r][s]);
84 fprintf(f,"%d, ",this->logs[r][s]);