1 /*******************************************************************
2 Motion and Robotic System (MARS) aplication components.
4 appl_pxmccmds.c - position controller RoCoN specific commands
6 Copyright (C) 2001-2013 by Pavel Pisa - originator
8 (C) 2001-2013 by PiKRON Ltd. - originator
11 This file can be used and copied according to next
13 - GPL - GNU Public License
14 - other license provided by project originators
16 *******************************************************************/
18 #include <system_def.h>
23 #include <sys/types.h>
28 #include "pxmc_cmds.h"
30 #include "appl_defs.h"
31 #include "appl_pxmc.h"
32 #include "pxmc_spimc.h"
34 #define SPIMC_LOG_CURRENT_SIZE 1024*1024
36 int32_t *spimc_logcurrent_buff;
37 int32_t *spimc_logcurrent_pos;
39 extern spimc_state_t spimc_state0;
41 int spimc_logcurrent(struct pxmc_state *mcs)
43 /*pxmc_spimc_state_t *mcsrc = pxmc_state2spimc_state(mcs); */
44 /*mcsrc->spimc_state*/
45 spimc_state_t *spimc = &spimc_state0;
47 if ((spimc_logcurrent_buff == NULL) ||
48 (spimc_logcurrent_pos == NULL) ||
49 ((char*)spimc_logcurrent_pos -
50 (char*)spimc_logcurrent_buff + 64 >= SPIMC_LOG_CURRENT_SIZE))
54 spimc_logcurrent_pos[0] = mcs->pxms_ptindx;
56 spimc_logcurrent_pos[1] = spimc->pwm[0];
57 spimc_logcurrent_pos[2] = spimc->pwm[1];
58 spimc_logcurrent_pos[3] = spimc->pwm[2];
60 spimc_logcurrent_pos[4] = spimc->curadc_sqn;
62 spimc_logcurrent_pos[5] = spimc->curadc_cumsum[0];
63 spimc_logcurrent_pos[6] = spimc->curadc_cumsum[1];
64 spimc_logcurrent_pos[7] = spimc->curadc_cumsum[2];
66 spimc_logcurrent_pos += 8;
71 int cmd_do_logcurrent(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
76 if (pxmc_main_list.pxml_cnt < 1)
79 if (pxmc_dbgset(pxmc_main_list.pxml_arr[0], NULL, 0) < 0)
82 if (spimc_logcurrent_buff == NULL) {
83 spimc_logcurrent_buff = malloc(SPIMC_LOG_CURRENT_SIZE);
84 if (spimc_logcurrent_buff == NULL)
88 if (spimc_logcurrent_pos != NULL) {
89 log_size = (char*)spimc_logcurrent_pos - (char*)spimc_logcurrent_buff;
90 printf("Log size %ld\n", (long)log_size);
92 if ((spimc_logcurrent_pos > spimc_logcurrent_buff) &&
93 (log_size < SPIMC_LOG_CURRENT_SIZE)) {
95 fd = open("currents.bin", O_WRONLY | O_CREAT | O_TRUNC,
96 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
101 write(fd, spimc_logcurrent_buff, log_size);
107 spimc_logcurrent_pos = spimc_logcurrent_buff;
109 if (pxmc_dbgset(pxmc_main_list.pxml_arr[0], spimc_logcurrent, 1) < 0)
116 * cmd_do_axis_mode - checks the command format and busy flag validity, calls pxmc_axis_mode
118 * if pxmc_axis_mode returns -1, cmd_do_axis_mode returns -1.
120 int cmd_do_axis_mode(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
125 if((mcs=cmd_opchar_getreg(cmd_io,des,param))==NULL) return -CMDERR_BADREG;
128 return cmd_opchar_replong(cmd_io, param, pxmc_axis_rdmode(mcs), 0, 0);
131 if(*param[2]!=':') return -CMDERR_OPCHAR;
133 if(mcs->pxms_flg&PXMS_BSY_m) return -CMDERR_BSYREG;
136 val=pxmc_axis_mode(mcs,val);
143 cmd_des_t const cmd_des_regcurdp={0, CDESM_OPCHR|CDESM_RW,
144 "REGCURDP?","current controller d component p parameter", cmd_do_reg_short_val,
145 {(char*)pxmc_spimc_state_offs(cur_d_p),
148 cmd_des_t const cmd_des_regcurdi={0, CDESM_OPCHR|CDESM_RW,
149 "REGCURDI?","current controller d component i parameter", cmd_do_reg_short_val,
150 {(char*)pxmc_spimc_state_offs(cur_d_i),
153 cmd_des_t const cmd_des_regcurqp={0, CDESM_OPCHR|CDESM_RW,
154 "REGCURQP?","current controller q component p parameter", cmd_do_reg_short_val,
155 {(char*)pxmc_spimc_state_offs(cur_q_p),
158 cmd_des_t const cmd_des_regcurqi={0, CDESM_OPCHR|CDESM_RW,
159 "REGCURQI?","current controller q component i parameter", cmd_do_reg_short_val,
160 {(char*)pxmc_spimc_state_offs(cur_q_i),
163 cmd_des_t const cmd_des_regcurhold={0, CDESM_OPCHR|CDESM_RW,
164 "REGCURHOLD?","current steady hold value for stepper", cmd_do_reg_short_val,
165 {(char*)pxmc_spimc_state_offs(cur_hold),
168 cmd_des_t const cmd_des_axis_mode={0, CDESM_OPCHR|CDESM_WR,
169 "REGMODE?","axis working mode",cmd_do_axis_mode,
172 cmd_des_t const cmd_des_logcurrent={0, 0,
173 "logcurrent","log current history", cmd_do_logcurrent,
178 cmd_des_t const *cmd_appl_pxmc[] =