Command all jmCLIG modules from serial port

Committer:
jm
Date:
Sat Feb 12 16:50:25 2011 +0000
Revision:
0:9112e09912db
jmAll Command Line Interface Module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jm 0:9112e09912db 1 /*************************************************************************
jm 0:9112e09912db 2 * @file jmStepperAxis.c
jm 0:9112e09912db 3 * @brief Command Line Interface StepperAxis Module
jm 0:9112e09912db 4 *
jm 0:9112e09912db 5 * @version 1.0
jm 0:9112e09912db 6 * @date Feb 12, 2011
jm 0:9112e09912db 7 */
jm 0:9112e09912db 8
jm 0:9112e09912db 9 #include "jmMessages.h"
jm 0:9112e09912db 10 #include "jmStepperAxis.h"
jm 0:9112e09912db 11 #include "LPC17xx.h"
jm 0:9112e09912db 12 #include "main.h"
jm 0:9112e09912db 13 #include "jmCommands.h"
jm 0:9112e09912db 14 #include "jmMessages.h"
jm 0:9112e09912db 15 #include "jmRingBuffer.h"
jm 0:9112e09912db 16 #include "stdio.h"
jm 0:9112e09912db 17 #include "jmSwitch.h"
jm 0:9112e09912db 18 #include "jmStepper.h"
jm 0:9112e09912db 19
jm 0:9112e09912db 20 #ifndef nonStop
jm 0:9112e09912db 21 #define nonStop 65535
jm 0:9112e09912db 22 #endif
jm 0:9112e09912db 23
jm 0:9112e09912db 24 #define NotInit 0
jm 0:9112e09912db 25 #define Initialized 1
jm 0:9112e09912db 26 #define CW 1
jm 0:9112e09912db 27 #define CCW 0
jm 0:9112e09912db 28 #define Open 1
jm 0:9112e09912db 29 #define Close 0
jm 0:9112e09912db 30 #define bothLimitSwitchActivated 4
jm 0:9112e09912db 31 #define LimitCWReached 3
jm 0:9112e09912db 32 #define LimitCCWReached 2
jm 0:9112e09912db 33 #define LogicOK 1
jm 0:9112e09912db 34 #define true 1
jm 0:9112e09912db 35 #define false 0
jm 0:9112e09912db 36
jm 0:9112e09912db 37 // static structures creation
jm 0:9112e09912db 38 struct StructStepperAxis sStepperAxis[stepperAxisQty];
jm 0:9112e09912db 39
jm 0:9112e09912db 40 /** Module Data Structure Initialization
jm 0:9112e09912db 41 * @brief All State Machines put to sleep.
jm 0:9112e09912db 42 * @param[in] none
jm 0:9112e09912db 43 * @returns none
jm 0:9112e09912db 44 */
jm 0:9112e09912db 45 void StepperAxisInit(void){
jm 0:9112e09912db 46 int i;
jm 0:9112e09912db 47 for(i=0;i<stepperAxisQty;i++){
jm 0:9112e09912db 48 sStepperAxis[i].active = false;
jm 0:9112e09912db 49 }
jm 0:9112e09912db 50 }
jm 0:9112e09912db 51
jm 0:9112e09912db 52 /** @brief stepperAxis Command Line Interface.
jm 0:9112e09912db 53 * Set up a stepper axis from one stepper and two limit switch modules
jm 0:9112e09912db 54 * Command Line Format: stepperAxis id stepperID limitCWid limitCCWid
jm 0:9112e09912db 55 * @param[in] Extracted from command line id stepperID limitCWid limitCCWid
jm 0:9112e09912db 56 * @returns Message: GPPSTA id stepperID limitCWid limitCCWid status
jm 0:9112e09912db 57 */
jm 0:9112e09912db 58 void cli_StepperAxis(void){
jm 0:9112e09912db 59 unsigned int id, stepperID, limitCWid, limitCCWid;
jm 0:9112e09912db 60
jm 0:9112e09912db 61 if(ExtractUInteger(pLine,&id,0,stepperAxisQty-1)){ // extract stepper axis id
jm 0:9112e09912db 62 if(ExtractUInteger(pLine,&stepperID,0,stepperQty-1)){ // extract stepper id
jm 0:9112e09912db 63 if(ExtractUInteger(pLine,&limitCWid,0,switchQty-1)){ // extract Limit Switch CW id
jm 0:9112e09912db 64 if(ExtractUInteger(pLine,&limitCCWid,0,switchQty-1)){ // extract Limit Switch CCW id
jm 0:9112e09912db 65
jm 0:9112e09912db 66 sStepperAxis[id].active=true;
jm 0:9112e09912db 67 sStepperAxis[id].stepperID=stepperID;
jm 0:9112e09912db 68 sStepperAxis[id].limitCW=limitCWid;
jm 0:9112e09912db 69 sStepperAxis[id].limitCCW=limitCCWid;
jm 0:9112e09912db 70
jm 0:9112e09912db 71 // chip report to GUI
jm 0:9112e09912db 72 rGPPSTA(id);
jm 0:9112e09912db 73 if(Feedback)printf("StepperAxis %d StepperID %d limitCCWid %d limitCWid %d\n",id,stepperID,limitCCWid,limitCWid);
jm 0:9112e09912db 74 return;
jm 0:9112e09912db 75 }// CCW
jm 0:9112e09912db 76 }// CW
jm 0:9112e09912db 77 }// stepper
jm 0:9112e09912db 78 }// axis
jm 0:9112e09912db 79 if(Help)printf("stepperAxis (Stepper id)0..3 (limit switch CCW id)0..7 (limit switch CW id)0..7\n");
jm 0:9112e09912db 80 // Ignore pending command line
jm 0:9112e09912db 81 NextCommand(nl,pLine);
jm 0:9112e09912db 82 }
jm 0:9112e09912db 83
jm 0:9112e09912db 84 /** @brief
jm 0:9112e09912db 85 * @param[in] none
jm 0:9112e09912db 86 * @returns
jm 0:9112e09912db 87 */
jm 0:9112e09912db 88 void StepperAxisSM(void)
jm 0:9112e09912db 89 {
jm 0:9112e09912db 90 int i;
jm 0:9112e09912db 91 for(i=0;i<stepperAxisQty;i++)
jm 0:9112e09912db 92 {
jm 0:9112e09912db 93 if(sStepperAxis[i].active==true)
jm 0:9112e09912db 94 {
jm 0:9112e09912db 95 uint8_t oldStatus = sStepperAxis[i].status;
jm 0:9112e09912db 96
jm 0:9112e09912db 97 // Limits Reached
jm 0:9112e09912db 98 // two limits switches activated ?
jm 0:9112e09912db 99 if(sSwitch[sStepperAxis[i].limitCW].state == Close && sSwitch[sStepperAxis[i].limitCCW].state==Close){
jm 0:9112e09912db 100 sStepper[sStepperAxis[i].stepperID].nSteps=0; // stop stepper
jm 0:9112e09912db 101 sStepperAxis[i].status = bothLimitSwitchActivated;
jm 0:9112e09912db 102 if(oldStatus != bothLimitSwitchActivated)rGPPSTA(i); // report change
jm 0:9112e09912db 103 continue;
jm 0:9112e09912db 104 }
jm 0:9112e09912db 105 // Limit Switch CW activated and step direction CW
jm 0:9112e09912db 106 if(sSwitch[sStepperAxis[i].limitCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CW){
jm 0:9112e09912db 107 sStepper[sStepperAxis[i].stepperID].nSteps=0; // stop stepper
jm 0:9112e09912db 108 sStepperAxis[i].status = LimitCWReached;
jm 0:9112e09912db 109 if(oldStatus != LimitCWReached)rGPPSTA(i); // report change
jm 0:9112e09912db 110 continue;
jm 0:9112e09912db 111 }
jm 0:9112e09912db 112
jm 0:9112e09912db 113 // Limit Switch CCW activated and step direction CCW
jm 0:9112e09912db 114 if(sSwitch[sStepperAxis[i].limitCCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CCW){
jm 0:9112e09912db 115 sStepper[sStepperAxis[i].stepperID].nSteps=0; // stop stepper
jm 0:9112e09912db 116 sStepperAxis[i].status = LimitCCWReached;
jm 0:9112e09912db 117 if(oldStatus != LimitCCWReached)rGPPSTA(i); // report change
jm 0:9112e09912db 118 continue;
jm 0:9112e09912db 119 }
jm 0:9112e09912db 120
jm 0:9112e09912db 121 // safe operating area
jm 0:9112e09912db 122 // no limit switch activated
jm 0:9112e09912db 123 if(sSwitch[sStepperAxis[i].limitCW].state == Open && sSwitch[sStepperAxis[i].limitCCW].state == Open){
jm 0:9112e09912db 124 sStepperAxis[i].status = LogicOK;
jm 0:9112e09912db 125 if(oldStatus != LogicOK)rGPPSTA(i); // report change
jm 0:9112e09912db 126 continue;
jm 0:9112e09912db 127 }
jm 0:9112e09912db 128
jm 0:9112e09912db 129 // Limit Switch CW activated and step direction CCW
jm 0:9112e09912db 130 if(sSwitch[sStepperAxis[i].limitCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CCW){
jm 0:9112e09912db 131 sStepperAxis[i].status = LogicOK;
jm 0:9112e09912db 132 if(oldStatus != LogicOK)rGPPSTA(i); // report change
jm 0:9112e09912db 133 continue;
jm 0:9112e09912db 134 }
jm 0:9112e09912db 135
jm 0:9112e09912db 136 // Limit Switch CCW activated and step direction CW
jm 0:9112e09912db 137 if(sSwitch[sStepperAxis[i].limitCCW].state == Close && sStepper[sStepperAxis[i].stepperID].cw ==CW){
jm 0:9112e09912db 138 sStepperAxis[i].status = LogicOK;
jm 0:9112e09912db 139 if(oldStatus != LogicOK)rGPPSTA(i); // report change
jm 0:9112e09912db 140 continue;
jm 0:9112e09912db 141 }
jm 0:9112e09912db 142 }
jm 0:9112e09912db 143 }
jm 0:9112e09912db 144 }
jm 0:9112e09912db 145
jm 0:9112e09912db 146 /** Module Get Module Process Properties Command Line Interface
jm 0:9112e09912db 147 * @brief Command Line Interface to Get Module Public Process Properties
jm 0:9112e09912db 148 * @param[in] id Extracted from command line id Process identification
jm 0:9112e09912db 149 * @returns none
jm 0:9112e09912db 150 */
jm 0:9112e09912db 151 void cli_GPPSTA(void)
jm 0:9112e09912db 152 { unsigned int id;
jm 0:9112e09912db 153 if(ExtractUInteger(pLine,&id,0,stepperAxisQty-1)){ // extract id
jm 0:9112e09912db 154 rGPPSTA(id);
jm 0:9112e09912db 155 return;
jm 0:9112e09912db 156 }
jm 0:9112e09912db 157
jm 0:9112e09912db 158 if(Help)printf("GPPSTA (StepperAxis id)0..%d\n",stepperAxisQty-1);
jm 0:9112e09912db 159 // Ignore pending command line
jm 0:9112e09912db 160 NextCommand(nl,pLine);
jm 0:9112e09912db 161 }
jm 0:9112e09912db 162
jm 0:9112e09912db 163 /** Public Properties Message
jm 0:9112e09912db 164 * @brief Send Process Properties to update GUI
jm 0:9112e09912db 165 * @param[in] id Process identification
jm 0:9112e09912db 166 * @returns Message: GPPSTA id stepperID limitCWid limitCCWid status
jm 0:9112e09912db 167 */
jm 0:9112e09912db 168 void rGPPSTA(unsigned int id ){
jm 0:9112e09912db 169 int status;
jm 0:9112e09912db 170 if(sStepperAxis[id].active==false)status=0;
jm 0:9112e09912db 171 else status = sStepperAxis[id].status;
jm 0:9112e09912db 172 printf("GPPSTA %d %d %d %d %d\n",id,sStepperAxis[id].stepperID,sStepperAxis[id].limitCCW,sStepperAxis[id].limitCW ,status);
jm 0:9112e09912db 173 }