--- /dev/null
+/*******************************************************************
+ Motion and Robotic System (MARS) aplication components.
+
+ appl_pxmccmds.c - position controller RoCoN specific commands
+
+ Copyright (C) 2001-2013 by Pavel Pisa - originator
+ pisa@cmp.felk.cvut.cz
+ (C) 2001-2013 by PiKRON Ltd. - originator
+ http://www.pikron.com
+
+ This file can be used and copied according to next
+ license alternatives
+ - GPL - GNU Public License
+ - other license provided by project originators
+
+ *******************************************************************/
+
+#include <system_def.h>
+#include <pxmc.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "pxmc_cmds.h"
+
+#include "appl_defs.h"
+#include "appl_pxmc.h"
+#include "pxmc_spimc.h"
+
+#define SPIMC_LOG_CURRENT_SIZE 1024*1024
+
+int32_t *spimc_logcurrent_buff;
+int32_t *spimc_logcurrent_pos;
+
+extern spimc_state_t spimc_state0;
+
+int spimc_logcurrent(struct pxmc_state *mcs)
+{
+ /*pxmc_spimc_state_t *mcsrc = pxmc_state2spimc_state(mcs); */
+ /*mcsrc->spimc_state*/
+ spimc_state_t *spimc = &spimc_state0;
+
+ if ((spimc_logcurrent_buff == NULL) ||
+ (spimc_logcurrent_pos == NULL) ||
+ ((char*)spimc_logcurrent_pos -
+ (char*)spimc_logcurrent_buff + 64 >= SPIMC_LOG_CURRENT_SIZE))
+ return 0;
+
+
+ spimc_logcurrent_pos[0] = mcs->pxms_ptindx;
+
+ spimc_logcurrent_pos[1] = spimc->pwm[0];
+ spimc_logcurrent_pos[2] = spimc->pwm[1];
+ spimc_logcurrent_pos[3] = spimc->pwm[2];
+
+ spimc_logcurrent_pos[4] = spimc->curadc_sqn;
+
+ spimc_logcurrent_pos[5] = spimc->curadc_cumsum[0];
+ spimc_logcurrent_pos[6] = spimc->curadc_cumsum[1];
+ spimc_logcurrent_pos[7] = spimc->curadc_cumsum[2];
+
+ spimc_logcurrent_pos += 8;
+
+ return 0;
+}
+
+int cmd_do_logcurrent(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ int fd;
+ size_t log_size;
+
+ if (pxmc_main_list.pxml_cnt < 1)
+ return -1;
+
+ if (pxmc_dbgset(pxmc_main_list.pxml_arr[0], NULL, 0) < 0)
+ return -1;
+
+ if (spimc_logcurrent_buff == NULL) {
+ spimc_logcurrent_buff = malloc(SPIMC_LOG_CURRENT_SIZE);
+ if (spimc_logcurrent_buff == NULL)
+ return -1;
+ }
+
+ if (spimc_logcurrent_pos != NULL) {
+ log_size = (char*)spimc_logcurrent_pos - (char*)spimc_logcurrent_buff;
+ printf("Log size %ld\n", (long)log_size);
+
+ if ((spimc_logcurrent_pos > spimc_logcurrent_buff) &&
+ (log_size < SPIMC_LOG_CURRENT_SIZE)) {
+
+ fd = open("currents.bin", O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+
+ if (fd == -1)
+ return -1;
+
+ write(fd, spimc_logcurrent_buff, log_size);
+
+ close(fd);
+ }
+ }
+
+ spimc_logcurrent_pos = spimc_logcurrent_buff;
+
+ if (pxmc_dbgset(pxmc_main_list.pxml_arr[0], spimc_logcurrent, 1) < 0)
+ return -1;
+
+ return 0;
+}
+
+cmd_des_t const cmd_des_regcurdp={0, CDESM_OPCHR|CDESM_RW,
+ "REGCURDP?","current controller d component p parameter", cmd_do_reg_short_val,
+ {(char*)pxmc_spimc_state_offs(cur_d_p),
+ 0}};
+
+cmd_des_t const cmd_des_regcurdi={0, CDESM_OPCHR|CDESM_RW,
+ "REGCURDI?","current controller d component i parameter", cmd_do_reg_short_val,
+ {(char*)pxmc_spimc_state_offs(cur_d_i),
+ 0}};
+
+cmd_des_t const cmd_des_regcurqp={0, CDESM_OPCHR|CDESM_RW,
+ "REGCURQP?","current controller q component p parameter", cmd_do_reg_short_val,
+ {(char*)pxmc_spimc_state_offs(cur_q_p),
+ 0}};
+
+cmd_des_t const cmd_des_regcurqi={0, CDESM_OPCHR|CDESM_RW,
+ "REGCURQI?","current controller q component i parameter", cmd_do_reg_short_val,
+ {(char*)pxmc_spimc_state_offs(cur_q_i),
+ 0}};
+
+cmd_des_t const cmd_des_regcurhold={0, CDESM_OPCHR|CDESM_RW,
+ "REGCURHOLD?","current steady hold value for stepper", cmd_do_reg_short_val,
+ {(char*)pxmc_spimc_state_offs(cur_hold),
+ 0}};
+
+cmd_des_t const cmd_des_logcurrent={0, 0,
+ "logcurrent","log current history", cmd_do_logcurrent,
+ {(char*)0,
+ 0}};
+
+
+cmd_des_t const *cmd_appl_pxmc[] =
+{
+ &cmd_des_regcurdp,
+ &cmd_des_regcurdi,
+ &cmd_des_regcurqp,
+ &cmd_des_regcurqi,
+ &cmd_des_regcurhold,
+ &cmd_des_logcurrent,
+ NULL
+};