]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/cmd_proc.c
Commit of version on DVD.
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / cmd_proc.c
index 66e9be804b321c4540db865cc353f8072d094e57..f1636025c26a2c910d3621a11a2e47eee23b8382 100644 (file)
@@ -5,11 +5,41 @@
 #include "cmd_proc.h"
 #include "logs.h"
 
+/*
+ * UDP_CAPABLE definuje, zda je pouzeitelna moznost cteni
+ * referencnich informaci z jineho zarizeni po protokolu
+ * UDP. Jde zatim jen o testovaci rezim
+ */
+#define UDP_CAPABLE_X
+
+#ifdef UDP_CAPABLE
+#include "udp_cli.h"
+#include "misc.h"
+#include <pthread.h>
+#endif
+
+
 #define PRUM_PROUD     2061
 #define PRUM_SOUC      6183
 
 static char doPrint = 1;
 
+#ifdef UDP_CAPABLE
+static struct remote_pos_st remote_pos={
+               .stop=1
+};
+#endif
+
+/*
+ * zastavi cteni po UDP
+ */
+static inline void stop_udp_SEM(){
+       #ifdef UDP_CAPABLE
+       remote_pos.stop=1;
+       #endif
+}
+
+
 
 /*
  * \brief
@@ -26,6 +56,11 @@ static void printHelp(){
        puts("log - Spusti nebo ulozi logovani.");
        puts("ao:[hodnota] - Prenastavi alpha offset.");
 
+       #ifdef UDP_CAPABLE
+       puts("udp_pos:[ip] - Bude ridit pozici na hodnotu vzdaleneho zarizeni");
+       puts("udp_spd:[ip] - Bude ridit rychlost na hodnotu vzdaleneho zarizeni");
+       #endif
+
        puts("print - Zapne nebo vypne pravidelne vypisovani hodnot.");
        puts("help - Vypne vypisovani hodnot a zobrazi tuto napovedu.");
        puts("exit - Bezpecne ukonci program.");
@@ -60,6 +95,7 @@ static void start(struct rpi_state* state){
  * Zastavi komutaci, vypne pwm
  */
 static void stop(struct rpi_state* state){
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        setCommutationOff(state);
        setRegulationOff(state);
@@ -75,6 +111,7 @@ static void stop(struct rpi_state* state){
  * Nastavi pevnou sirku plneni
  */
 static void dutySet(struct rpi_state* state, int duty){
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        if (duty>MAX_DUTY) duty=MAX_DUTY;
        if (duty<-MAX_DUTY) duty=-MAX_DUTY;/*paranoia*/
@@ -89,6 +126,7 @@ static void dutySet(struct rpi_state* state, int duty){
  * Zapne rizeni na zvolenou polohu vztazenou k pozici pri startu
  */
 static void goAbsolute(struct rpi_state* state, int pos){
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        setRegulationPos(state);
        setCommutationOn(state);
@@ -120,6 +158,7 @@ static void exitApp(struct rpi_state* state){
 static void setSpeed(struct rpi_state* state, int speed){
        if (speed>MAX_SPEED) speed=MAX_SPEED;
        if (speed<-MAX_SPEED) speed=-MAX_SPEED;/*paranoia*/
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        setRegulationSpeed(state);
        setCommutationOn(state);
@@ -159,6 +198,34 @@ static void setLogSEM(struct rpi_state* state){
        }
 }
 
+#ifdef UDP_CAPABLE
+static void  startUdpPos(struct rpi_state* state, char *ip){
+       pthread_t thread_id=pthread_self();
+       if (!remote_pos.stop) return; /*dont be reentrant*/
+       setCommutationOn(state);
+       setRegulationPos(state);
+       remote_pos.stop=0;
+       remote_pos.ip=ip;
+       remote_pos.factor=-5;
+       remote_pos.semaphore=&state->thd_par_sem;
+       remote_pos.rem_pos=&state->desired_pos;
+       create_rt_task(&thread_id,48,start_reading_remote_position,&remote_pos);
+}
+
+/*FIXME thers no max speed limit check!!! hard debug mode!! be careful*/
+static void  startUdpSpd(struct rpi_state* state, char *ip){
+       pthread_t thread_id=pthread_self();
+       if (!remote_pos.stop) return; /*dont be reentrant*/
+       setCommutationOn(state);
+       setRegulationSpeed(state);
+       remote_pos.stop=0;
+       remote_pos.ip=ip;
+       remote_pos.factor=-1;
+       remote_pos.semaphore=&state->thd_par_sem;
+       remote_pos.rem_pos=&state->desired_spd;
+       create_rt_task(&thread_id,48,start_reading_remote_position,&remote_pos);
+}
+#endif
 /**
  * \brief
  * Commands detection.
@@ -167,12 +234,14 @@ void poll_cmd(struct rpi_state* state){
        unsigned int tmp;
         char buff[50];
         char cmd[30];
+        char cmd2[30];
         int val;
 
         while(1){
                 scanf("%49s",buff);
                 delCol(buff);
                 sscanf(buff,"%s %d",cmd,&val);
+                sscanf(buff,"%s %s",cmd,cmd2);
 
 
                 if (!strcmp(cmd,"start")){
@@ -198,6 +267,15 @@ void poll_cmd(struct rpi_state* state){
                 }else if (!strcmp(cmd,"ao")){
                        setAlphaOff(state,val);
                 }
+               #ifdef UDP_CAPABLE
+                else if (!strcmp(cmd,"udp_pos")){
+                       startUdpPos(state,cmd2);
+                }else if (!strcmp(cmd,"udp_spd")){
+                       startUdpSpd(state,cmd2);
+
+                }
+               #endif
+
         }
 
 }