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)
115 cmd_des_t const cmd_des_regcurdp={0, CDESM_OPCHR|CDESM_RW,
116 "REGCURDP?","current controller d component p parameter", cmd_do_reg_short_val,
117 {(char*)pxmc_spimc_state_offs(cur_d_p),
120 cmd_des_t const cmd_des_regcurdi={0, CDESM_OPCHR|CDESM_RW,
121 "REGCURDI?","current controller d component i parameter", cmd_do_reg_short_val,
122 {(char*)pxmc_spimc_state_offs(cur_d_i),
125 cmd_des_t const cmd_des_regcurqp={0, CDESM_OPCHR|CDESM_RW,
126 "REGCURQP?","current controller q component p parameter", cmd_do_reg_short_val,
127 {(char*)pxmc_spimc_state_offs(cur_q_p),
130 cmd_des_t const cmd_des_regcurqi={0, CDESM_OPCHR|CDESM_RW,
131 "REGCURQI?","current controller q component i parameter", cmd_do_reg_short_val,
132 {(char*)pxmc_spimc_state_offs(cur_q_i),
135 cmd_des_t const cmd_des_regcurhold={0, CDESM_OPCHR|CDESM_RW,
136 "REGCURHOLD?","current steady hold value for stepper", cmd_do_reg_short_val,
137 {(char*)pxmc_spimc_state_offs(cur_hold),
140 cmd_des_t const cmd_des_logcurrent={0, 0,
141 "logcurrent","log current history", cmd_do_logcurrent,
146 cmd_des_t const *cmd_appl_pxmc[] =