From cce75a678ae25fb09d723aed862ab2d12d4415e7 Mon Sep 17 00:00:00 2001 From: Ron Sluiter Date: Thu, 20 Oct 2005 20:06:47 +0000 Subject: [PATCH] Restore orginial format style. --- motorApp/ImsSrc/drvMDrive.cc | 533 +++++++++++++++++------------------ 1 file changed, 266 insertions(+), 267 deletions(-) diff --git a/motorApp/ImsSrc/drvMDrive.cc b/motorApp/ImsSrc/drvMDrive.cc index 2b57fa4f..ed5d0a6e 100644 --- a/motorApp/ImsSrc/drvMDrive.cc +++ b/motorApp/ImsSrc/drvMDrive.cc @@ -1,11 +1,11 @@ /* FILENAME... drvMDrive.cc USAGE... Motor record driver level support for Intelligent Motion - Systems, Inc. MDrive series; M17, M23, M34. + Systems, Inc. MDrive series; M17, M23, M34. -Version: $Revision: 1.18 $ +Version: $Revision: 1.19 $ Modified By: $Author: sluiter $ -Last Modified: $Date: 2005-05-10 16:34:13 $ +Last Modified: $Date: 2005-10-20 20:06:47 $ */ /* @@ -75,9 +75,9 @@ DESIGN LIMITATIONS... /*----------------debugging-----------------*/ #ifdef __GNUG__ #ifdef DEBUG - #define Debug(l, f, args...) {if (l <= drvMDrivedebug) printf(f, ## args);} + #define Debug(l, f, args...) {if (l <= drvMDrivedebug) printf(f, ## args);} #else - #define Debug(l, f, args...) + #define Debug(l, f, args...) #endif #else #define Debug() @@ -147,24 +147,24 @@ static long report(int level) int card; if (MDrive_num_cards <=0) - printf(" No MDrive controllers configured.\n"); + printf(" No MDrive controllers configured.\n"); else { - for (card = 0; card < MDrive_num_cards; card++) - { - struct controller *brdptr = motor_state[card]; + for (card = 0; card < MDrive_num_cards; card++) + { + struct controller *brdptr = motor_state[card]; - if (brdptr == NULL) - printf(" MDrive controller %d connection failed.\n", card); - else - { - struct IM483controller *cntrl; + if (brdptr == NULL) + printf(" MDrive controller %d connection failed.\n", card); + else + { + struct IM483controller *cntrl; - cntrl = (struct IM483controller *) brdptr->DevicePrivate; - printf(" IM483SM controller #%d, port=%s, id: %s \n", card, - cntrl->asyn_port, brdptr->ident); - } - } + cntrl = (struct IM483controller *) brdptr->DevicePrivate; + printf(" MDrive controller #%d, port=%s, id: %s \n", card, + cntrl->asyn_port, brdptr->ident); + } + } } return(OK); } @@ -172,16 +172,16 @@ static long report(int level) static long init() { - /* - * We cannot call motor_init() here, because that function can do GPIB I/O, - * and hence requires that the drvGPIB have already been initialized. - * That cannot be guaranteed, so we need to call motor_init from device - * support - */ + /* + * We cannot call motor_init() here, because that function can do GPIB I/O, + * and hence requires that the drvGPIB have already been initialized. + * That cannot be guaranteed, so we need to call motor_init from device + * support + */ /* Check for setup */ if (MDrive_num_cards <= 0) { - Debug(1, "init(): MDrive driver disabled. MDriveSetup() missing from startup script.\n"); + Debug(1, "init(): MDrive driver disabled. MDriveSetup() missing from startup script.\n"); } return((long) 0); } @@ -192,34 +192,33 @@ static void query_done(int card, int axis, struct mess_node *nodeptr) } -/******************************************************************************** -* * -* FUNCTION NAME: set_status * -* * -* LOGIC: * -* Initialize. * -* Send "Moving Status" query. * -* Read response. * -* IF normal response to query. * -* Set communication status to NORMAL. * -* ELSE * -* IF communication status is NORMAL. * -* Set communication status to RETRY. * -* NORMAL EXIT. * -* ELSE * -* Set communication status error. * -* ERROR EXIT. * -* ENDIF * -* ENDIF * -* * -* IF "Moving Status" indicates any motion (i.e. status != 0). * -* Clear "Done Moving" status bit. * -* ELSE * -* Set "Done Moving" status bit. * -* ENDIF * -* * -* * -********************************************************************************/ +/****************************************************************************** +* +* FUNCTION NAME: set_status +* +* LOGIC: +* Initialize. +* Send "Moving Status" query. +* Read response. +* IF normal response to query. +* Set communication status to NORMAL. +* ELSE +* IF communication status is NORMAL. +* Set communication status to RETRY. +* NORMAL EXIT. +* ELSE +* Set communication status error. +* ERROR EXIT. +* ENDIF +* ENDIF +* +* IF "Moving Status" indicates any motion (i.e. status != 0). +* Clear "Done Moving" status bit. +* ELSE +* Set "Done Moving" status bit. +* ENDIF +* +******************************************************************************/ static int set_status(int card, int signal) { @@ -244,25 +243,25 @@ static int set_status(int card, int signal) rtn_state = recv_mess(card, buff, 1); if (rtn_state > 0) { - cntrl->status = NORMAL; - status.Bits.CNTRL_COMM_ERR = 0; + cntrl->status = NORMAL; + status.Bits.CNTRL_COMM_ERR = 0; } else { - if (cntrl->status == NORMAL) - { - cntrl->status = RETRY; - rtn_state = OK; - goto exit; - } - else - { - cntrl->status = COMM_ERR; - status.Bits.CNTRL_COMM_ERR = 1; - status.Bits.RA_PROBLEM = 1; - rtn_state = 1; - goto exit; - } + if (cntrl->status == NORMAL) + { + cntrl->status = RETRY; + rtn_state = OK; + goto exit; + } + else + { + cntrl->status = COMM_ERR; + status.Bits.CNTRL_COMM_ERR = 1; + status.Bits.RA_PROBLEM = 1; + rtn_state = 1; + goto exit; + } } rtnval = atoi(buff); @@ -282,67 +281,67 @@ static int set_status(int card, int signal) if (motorData == motor_info->position) { - if (nodeptr != 0) /* Increment counter only if motor is moving. */ - motor_info->no_motion_count++; + if (nodeptr != 0) /* Increment counter only if motor is moving. */ + motor_info->no_motion_count++; } else { - epicsInt32 newposition; + epicsInt32 newposition; - newposition = NINT(motorData); - status.Bits.RA_DIRECTION = (newposition >= motor_info->position) ? 1 : 0; - motor_info->position = newposition; - motor_info->no_motion_count = 0; + newposition = NINT(motorData); + status.Bits.RA_DIRECTION = (newposition >= motor_info->position) ? 1 : 0; + motor_info->position = newposition; + motor_info->no_motion_count = 0; } plusdir = (status.Bits.RA_DIRECTION) ? true : false; if (confptr->plusLS == 0 || confptr->minusLS == 0) { - status.Bits.RA_PLUS_LS = 0; - status.Bits.RA_MINUS_LS = 0; + status.Bits.RA_PLUS_LS = 0; + status.Bits.RA_MINUS_LS = 0; } else { - sprintf(buff, "PR I%d", confptr->plusLS); - send_mess(card, buff, MDrive_axis[signal]); - recv_mess(card, buff, 1); - Lswitch = atoi(buff); + sprintf(buff, "PR I%d", confptr->plusLS); + send_mess(card, buff, MDrive_axis[signal]); + recv_mess(card, buff, 1); + Lswitch = atoi(buff); - /* Set limit Lswitch error indicators. */ - if (Lswitch != 0) - { - status.Bits.RA_PLUS_LS = 1; - if (plusdir == true) - ls_active = true; - } - else - status.Bits.RA_PLUS_LS = 0; + /* Set limit Lswitch error indicators. */ + if (Lswitch != 0) + { + status.Bits.RA_PLUS_LS = 1; + if (plusdir == true) + ls_active = true; + } + else + status.Bits.RA_PLUS_LS = 0; - sprintf(buff, "PR I%d", confptr->minusLS); - send_mess(card, buff, MDrive_axis[signal]); - recv_mess(card, buff, 1); - Lswitch = atoi(buff); + sprintf(buff, "PR I%d", confptr->minusLS); + send_mess(card, buff, MDrive_axis[signal]); + recv_mess(card, buff, 1); + Lswitch = atoi(buff); - if (Lswitch != 0) - { - status.Bits.RA_MINUS_LS = 1; - if (plusdir == false) - ls_active = true; - } - else - status.Bits.RA_MINUS_LS = 0; + if (Lswitch != 0) + { + status.Bits.RA_MINUS_LS = 1; + if (plusdir == false) + ls_active = true; + } + else + status.Bits.RA_MINUS_LS = 0; } if (confptr->homeLS == 0) - status.Bits.RA_HOME = 0; + status.Bits.RA_HOME = 0; else { - sprintf(buff, "PR I%d", confptr->homeLS); - send_mess(card, buff, MDrive_axis[signal]); - recv_mess(card, buff, 1); - Lswitch = atoi(buff); - status.Bits.RA_HOME = (Lswitch) ? 1 : 0; + sprintf(buff, "PR I%d", confptr->homeLS); + send_mess(card, buff, MDrive_axis[signal]); + recv_mess(card, buff, 1); + Lswitch = atoi(buff); + status.Bits.RA_HOME = (Lswitch) ? 1 : 0; } /* !!! Assume no closed-looped control!!!*/ @@ -354,13 +353,13 @@ static int set_status(int card, int signal) status.Bits.EA_HOME = 0; if (motor_state[card]->motor_info[signal].encoder_present == NO) - motor_info->encoder_position = 0; + motor_info->encoder_position = 0; else { - send_mess(card, "PR C2", MDrive_axis[signal]); - recv_mess(card, buff, 1); - motorData = atof(buff); - motor_info->encoder_position = (int32_t) motorData; + send_mess(card, "PR C2", MDrive_axis[signal]); + recv_mess(card, buff, 1); + motorData = atof(buff); + motor_info->encoder_position = (int32_t) motorData; } status.Bits.RA_PROBLEM = 0; @@ -371,18 +370,18 @@ static int set_status(int card, int signal) motor_info->velocity = 0; if (!status.Bits.RA_DIRECTION) - motor_info->velocity *= -1; + motor_info->velocity *= -1; rtn_state = (!motor_info->no_motion_count || ls_active == true || - status.Bits.RA_DONE | status.Bits.RA_PROBLEM) ? 1 : 0; + status.Bits.RA_DONE | status.Bits.RA_PROBLEM) ? 1 : 0; /* Test for post-move string. */ if ((status.Bits.RA_DONE || ls_active == true) && nodeptr != 0 && - nodeptr->postmsgptr != 0) + nodeptr->postmsgptr != 0) { - strcpy(buff, nodeptr->postmsgptr); - send_mess(card, buff, MDrive_axis[signal]); - nodeptr->postmsgptr = NULL; + strcpy(buff, nodeptr->postmsgptr); + send_mess(card, buff, MDrive_axis[signal]); + nodeptr->postmsgptr = NULL; } exit: @@ -392,8 +391,8 @@ exit: /*****************************************************/ -/* send a message to the MDrive board */ -/* send_mess() */ +/* send a message to the MDrive board */ +/* send_mess() */ /*****************************************************/ static RTN_STATUS send_mess(int card, char const *com, char *name) { @@ -407,32 +406,32 @@ static RTN_STATUS send_mess(int card, char const *com, char *name) if ((comsize + namesize) > MAX_MSG_SIZE) { - errlogMessage("drvMDrive.c:send_mess(); message size violation.\n"); - return(ERROR); + errlogMessage("drvMDrive.c:send_mess(); message size violation.\n"); + return(ERROR); } else if (comsize == 0) /* Normal exit on empty input message. */ - return(OK); + return(OK); if (!motor_state[card]) { - errlogPrintf("drvMDrive.c:send_mess() - invalid card #%d\n", card); - return(ERROR); + errlogPrintf("drvMDrive.c:send_mess() - invalid card #%d\n", card); + return(ERROR); } /* Make a local copy of the string and add the command line terminator. */ if (namesize != 0) { - strcpy(local_buff, name); /* put in axis */ - strcat(local_buff, com); + strcpy(local_buff, name); /* put in axis */ + strcat(local_buff, com); } else - strcpy(local_buff, com); + strcpy(local_buff, com); Debug(2, "send_mess(): message = %s\n", local_buff); cntrl = (struct IM483controller *) motor_state[card]->DevicePrivate; pasynOctetSyncIO->write(cntrl->pasynUser, local_buff, strlen(local_buff), - COMM_TIMEOUT, &nwrite); + COMM_TIMEOUT, &nwrite); return(OK); } @@ -440,7 +439,7 @@ static RTN_STATUS send_mess(int card, char const *com, char *name) /*****************************************************/ /* receive a message from the MDrive board */ -/* recv_mess() */ +/* recv_mess() */ /*****************************************************/ static int recv_mess(int card, char *com, int flag) { @@ -452,20 +451,20 @@ static int recv_mess(int card, char *com, int flag) /* Check that card exists */ if (!motor_state[card]) - return(ERROR); + return(ERROR); cntrl = (struct IM483controller *) motor_state[card]->DevicePrivate; if (flag == FLUSH) - pasynOctetSyncIO->flush(cntrl->pasynUser); + pasynOctetSyncIO->flush(cntrl->pasynUser); else - status = pasynOctetSyncIO->read(cntrl->pasynUser, com, BUFF_SIZE, - timeout, &nread, &eomReason); + status = pasynOctetSyncIO->read(cntrl->pasynUser, com, BUFF_SIZE, + timeout, &nread, &eomReason); if ((status != asynSuccess) || (nread <= 0)) { - com[0] = '\0'; - nread = 0; + com[0] = '\0'; + nread = 0; } Debug(2, "recv_mess(): message = \"%s\"\n", com); @@ -479,32 +478,32 @@ static int recv_mess(int card, char *com, int flag) /*****************************************************/ RTN_STATUS MDriveSetup(int num_cards, /* maximum number of chains in system. */ - int scan_rate) /* polling rate - 1/60 sec units. */ + int scan_rate) /* polling rate - 1/60 sec units. */ { int itera; if (num_cards < 1 || num_cards > MDrive_NUM_CARDS) - MDrive_num_cards = MDrive_NUM_CARDS; + MDrive_num_cards = MDrive_NUM_CARDS; else - MDrive_num_cards = num_cards; + MDrive_num_cards = num_cards; /* Set motor polling task rate */ if (scan_rate >= 1 && scan_rate <= 60) - targs.motor_scan_rate = scan_rate; + targs.motor_scan_rate = scan_rate; else - targs.motor_scan_rate = SCAN_RATE; + targs.motor_scan_rate = SCAN_RATE; - /* - * Allocate space for motor_state structures. Note this must be done - * before IM483Config is called, so it cannot be done in motor_init() - * This means that we must allocate space for a card without knowing - * if it really exists, which is not a serious problem - */ + /* + * Allocate space for motor_state structures. Note this must be done + * before IM483Config is called, so it cannot be done in motor_init() + * This means that we must allocate space for a card without knowing + * if it really exists, which is not a serious problem + */ motor_state = (struct controller **) malloc(MDrive_num_cards * - sizeof(struct controller *)); + sizeof(struct controller *)); for (itera = 0; itera < MDrive_num_cards; itera++) - motor_state[itera] = (struct controller *) NULL; + motor_state[itera] = (struct controller *) NULL; return(OK); } @@ -515,13 +514,13 @@ MDriveSetup(int num_cards, /* maximum number of chains in system. */ /* MDriveConfig() */ /*****************************************************/ RTN_STATUS -MDriveConfig(int card, /* chain being configured */ - const char *name) /* ASYN port name */ +MDriveConfig(int card, /* chain being configured */ + const char *name) /* ASYN port name */ { struct IM483controller *cntrl; if (card < 0 || card >= MDrive_num_cards) - return(ERROR); + return(ERROR); motor_state[card] = (struct controller *) malloc(sizeof(struct controller)); motor_state[card]->DevicePrivate = malloc(sizeof(struct IM483controller)); @@ -533,10 +532,10 @@ MDriveConfig(int card, /* chain being configured */ /*****************************************************/ -/* initialize all software and hardware */ +/* initialize all software and hardware */ /* This is called from the initialization routine in */ /* device support. */ -/* motor_init() */ +/* motor_init() */ /*****************************************************/ static int motor_init() { @@ -550,137 +549,137 @@ static int motor_init() static const char output_terminator[] = "\n"; static const char input_terminator[] = "\r\n"; - initialized = true; /* Indicate that driver is initialized. */ + initialized = true; /* Indicate that driver is initialized. */ /* Check for setup */ if (MDrive_num_cards <= 0) - return(ERROR); + return(ERROR); for (card_index = 0; card_index < MDrive_num_cards; card_index++) { - if (!motor_state[card_index]) - continue; + if (!motor_state[card_index]) + continue; - brdptr = motor_state[card_index]; - brdptr->ident[0] = (char) NULL; /* No controller identification message. */ - brdptr->cmnd_response = false; - total_cards = card_index + 1; - cntrl = (struct IM483controller *) brdptr->DevicePrivate; + brdptr = motor_state[card_index]; + brdptr->ident[0] = (char) NULL; /* No controller identification message. */ + brdptr->cmnd_response = false; + total_cards = card_index + 1; + cntrl = (struct IM483controller *) brdptr->DevicePrivate; - /* Initialize communications channel */ - success_rtn = pasynOctetSyncIO->connect(cntrl->asyn_port, 0, - &cntrl->pasynUser, NULL); + /* Initialize communications channel */ + success_rtn = pasynOctetSyncIO->connect(cntrl->asyn_port, 0, + &cntrl->pasynUser, NULL); - if (success_rtn == asynSuccess) - { - pasynOctetSyncIO->setOutputEos(cntrl->pasynUser, output_terminator, - strlen(output_terminator)); - pasynOctetSyncIO->setInputEos(cntrl->pasynUser, input_terminator, - strlen(input_terminator)); - /* Send a message to the board, see if it exists */ - /* flush any junk at input port - should not be any data available */ - pasynOctetSyncIO->flush(cntrl->pasynUser); + if (success_rtn == asynSuccess) + { + pasynOctetSyncIO->setOutputEos(cntrl->pasynUser, output_terminator, + strlen(output_terminator)); + pasynOctetSyncIO->setInputEos(cntrl->pasynUser, input_terminator, + strlen(input_terminator)); + /* Send a message to the board, see if it exists */ + /* flush any junk at input port - should not be any data available */ + pasynOctetSyncIO->flush(cntrl->pasynUser); - for (total_axis = 0; total_axis < MAX_AXES; total_axis++) - { - int retry = 0; + for (total_axis = 0; total_axis < MAX_AXES; total_axis++) + { + int retry = 0; - /* Try 3 times to connect to controller. */ - do - { - send_mess(card_index, "PR VR", MDrive_axis[total_axis]); - status = recv_mess(card_index, buff, 1); - retry++; - } while (status == 0 && retry < 3); + /* Try 3 times to connect to controller. */ + do + { + send_mess(card_index, "PR VR", MDrive_axis[total_axis]); + status = recv_mess(card_index, buff, 1); + retry++; + } while (status == 0 && retry < 3); - if (status <= 0) - break; - else if (total_axis == 0) - strcpy(brdptr->ident, buff); - } - brdptr->total_axis = total_axis; - cntrl->inconfig = (input_config *) malloc( - sizeof(struct IM483controller) * total_axis); - } + if (status <= 0) + break; + else if (total_axis == 0) + strcpy(brdptr->ident, buff); + } + brdptr->total_axis = total_axis; + cntrl->inconfig = (input_config *) malloc( + sizeof(struct IM483controller) * total_axis); + } - if (success_rtn == asynSuccess && total_axis > 0) - { - input_config *confptr = cntrl->inconfig; + if (success_rtn == asynSuccess && total_axis > 0) + { + input_config *confptr = cntrl->inconfig; - brdptr->localaddr = (char *) NULL; - brdptr->motor_in_motion = 0; + brdptr->localaddr = (char *) NULL; + brdptr->motor_in_motion = 0; - for (motor_index = 0; motor_index < total_axis; motor_index++) - { - int itera; - struct mess_info *motor_info = &brdptr->motor_info[motor_index]; + for (motor_index = 0; motor_index < total_axis; motor_index++) + { + int itera; + struct mess_info *motor_info = &brdptr->motor_info[motor_index]; - motor_info->status.All = 0; - motor_info->no_motion_count = 0; - motor_info->encoder_position = 0; - motor_info->position = 0; - brdptr->motor_info[motor_index].motor_motion = NULL; - /* Assume no encoder support. */ - motor_info->encoder_present = NO; + motor_info->status.All = 0; + motor_info->no_motion_count = 0; + motor_info->encoder_position = 0; + motor_info->position = 0; + brdptr->motor_info[motor_index].motor_motion = NULL; + /* Assume no encoder support. */ + motor_info->encoder_present = NO; - /* Determine if encoder present based last character of "ident". */ - if (brdptr->ident[strlen(brdptr->ident) - 1] == 'E') - { - motor_info->pid_present = YES; - motor_info->status.Bits.GAIN_SUPPORT = 1; - motor_info->encoder_present = YES; - motor_info->status.Bits.EA_PRESENT = 1; - } + /* Determine if encoder present based last character of "ident". */ + if (brdptr->ident[strlen(brdptr->ident) - 1] == 'E') + { + motor_info->pid_present = YES; + motor_info->status.Bits.GAIN_SUPPORT = 1; + motor_info->encoder_present = YES; + motor_info->status.Bits.EA_PRESENT = 1; + } - /* Determine input configuration. */ - confptr->homeLS = confptr->minusLS = confptr->plusLS = 0; + /* Determine input configuration. */ + confptr->homeLS = confptr->minusLS = confptr->plusLS = 0; - for (itera = 1; itera <= 4; itera++) - { - int type, active; + for (itera = 1; itera <= 4; itera++) + { + int type, active; - sprintf(buff, "PR S%d", itera); - send_mess(card_index, buff, MDrive_axis[motor_index]); - status = recv_mess(card_index, buff, 1); - if (status == 0) - { - errlogPrintf("Error reading I/O configuration.\n"); - break; - } + sprintf(buff, "PR S%d", itera); + send_mess(card_index, buff, MDrive_axis[motor_index]); + status = recv_mess(card_index, buff, 1); + if (status == 0) + { + errlogPrintf("Error reading I/O configuration.\n"); + break; + } - status = sscanf(buff, "%d,%d", &type, &active); - switch (type) - { - case 0: - break; - case 1: // Home switch. - confptr->homeLS = itera; - break; - case 2: // Plus limit switch. - confptr->plusLS = itera; - break; - case 3: // Minus limit switch. - confptr->minusLS = itera; - break; - default: - errlogPrintf("Invalid I/O type: %d.\n", type); + status = sscanf(buff, "%d,%d", &type, &active); + switch (type) + { + case 0: + break; + case 1: // Home switch. + confptr->homeLS = itera; + break; + case 2: // Plus limit switch. + confptr->plusLS = itera; + break; + case 3: // Minus limit switch. + confptr->minusLS = itera; + break; + default: + errlogPrintf("Invalid I/O type: %d.\n", type); - } - } - // Test for missing configuration. - if (confptr->minusLS == 0 || confptr->plusLS == 0) - { - const char p_label[6] = "Plus", m_label[6] = "Minus"; - errlogPrintf("MDrive chain #%d, motor #%d %s LS not configured.\n", - card_index, motor_index, - (confptr->minusLS == 0) ? m_label : p_label); - } + } + } + // Test for missing configuration. + if (confptr->minusLS == 0 || confptr->plusLS == 0) + { + const char p_label[6] = "Plus", m_label[6] = "Minus"; + errlogPrintf("MDrive chain #%d, motor #%d %s LS not configured.\n", + card_index, motor_index, + (confptr->minusLS == 0) ? m_label : p_label); + } - set_status(card_index, motor_index); /* Read status of each motor */ - } - } - else - motor_state[card_index] = (struct controller *) NULL; + set_status(card_index, motor_index); /* Read status of each motor */ + } + } + else + motor_state[card_index] = (struct controller *) NULL; } any_motor_in_motion = 0; @@ -692,8 +691,8 @@ static int motor_init() free_list.tail = (struct mess_node *) NULL; epicsThreadCreate((char *) "MDrive_motor", epicsThreadPriorityMedium, - epicsThreadGetStackSize(epicsThreadStackMedium), - (EPICSTHREADFUNC) motor_task, (void *) &targs); + epicsThreadGetStackSize(epicsThreadStackMedium), + (EPICSTHREADFUNC) motor_task, (void *) &targs); return(OK); }