示例#1
0
文件: lsstools.c 项目: jalilag/apspir
void lsstools_config(UNS8 nodeID, UNS8 command,void* dat2send1, void* dat2send2,int checkactive) {
    configNetworkNode(&SpirallingMaster_Data,command,dat2send1,dat2send2,NULL);
    if (checkactive) {
        UNS32 dat1;
        UNS8 dat2;
        UNS8 res = getConfigResultNetworkNode (&SpirallingMaster_Data, command, &dat1, &dat2);
        while (res == LSS_TRANS_IN_PROGRESS || res == LSS_RESET) {
            usleep(100000);
            res = getConfigResultNetworkNode (&SpirallingMaster_Data, command, &dat1, &dat2);
        }
        if (res == LSS_ABORTED_INTERNAL) {
			printf("Master : Failed in LSS comand %d.  Trying again\n", command);
            LSS_step_error++;
            if (LSS_step_error < LSS_step_error_max) {
                lsstools_loop(nodeID, 0);
            } else {
                lsstools_loop(nodeID, 1);
            }
        } else if (res == LSS_FINISHED) {
            LSS_step++;
            switch(command){
            case LSS_CONF_NODE_ID:
                switch(dat1){
                    case 0: printf("Node ID change succesful\n");break;
                    case 1: printf("Node ID change error:out of range\n");break;
                    case 0xFF:printf("Node ID change error:specific error\n");break;
                    default:break;
                }
                break;
            case LSS_CONF_BIT_TIMING:
                switch(dat1){
                    case 0: printf("Baud rate change succesful\n");break;
                    case 1: printf("Baud rate change error: change baud rate not supported\n");break;
                    case 0xFF:printf("Baud rate change error:specific error\n");break;
                    default:break;
                }
                break;
            case LSS_CONF_STORE:
                switch(dat1){
                    case 0: printf("Store configuration succesful\n");break;
                    case 1: printf("Store configuration error:not supported\n");break;
                    case 0xFF:printf("Store configuration error:specific error\n");break;
                    default:break;
                }
                break;
            case LSS_SM_SELECTIVE_SERIAL:
                printf("Slave in LSS CONFIGURATION state\n");
                break;
            case LSS_INQ_NODE_ID:
                printf("Slave nodeid %x\n", dat1);
                if (dat1 == nodeID) {
                    LSS_step = 5;
                }
                break;
            }
            printf("\n");
            lsstools_loop(nodeID, 0);
        }
    }
}
示例#2
0
static void CheckLSSAndContinue(CO_Data* d, UNS8 command)
{
	UNS32 dat1;
	UNS8 dat2;
	
	printf("CheckLSS->");
	if(getConfigResultNetworkNode (d, command, &dat1, &dat2) != LSS_FINISHED){
			eprintf("Master : Failed in LSS comand %d.  Trying again\n", command);
	}
	else
	{
		init_step_LSS++;
	
		switch(command){
		case LSS_CONF_NODE_ID:
   			switch(dat1){
   				case 0: printf("Node ID change succesful\n");break;
   				case 1: printf("Node ID change error:out of range\n");break;
   				case 0xFF:printf("Node ID change error:specific error\n");break;
   				default:break;
   			}
   			break;
   		case LSS_CONF_BIT_TIMING:
   			switch(dat1){
   				case 0: printf("Baud rate change succesful\n");break;
   				case 1: printf("Baud rate change error: change baud rate not supported\n");break;
   				case 0xFF:printf("Baud rate change error:specific error\n");break;
   				default:break;
   			}
   			break;
   		case LSS_CONF_STORE:
   			switch(dat1){
   				case 0: printf("Store configuration succesful\n");break;
   				case 1: printf("Store configuration error:not supported\n");break;
   				case 0xFF:printf("Store configuration error:specific error\n");break;
   				default:break;
   			}
   			break;
   		case LSS_CONF_ACT_BIT_TIMING:
   			if(dat1==0){
   				UNS8 LSS_mode=LSS_WAITING_MODE;
				UNS32 SINC_cicle=50000;// us
				UNS32 size = sizeof(UNS32); 
	
				/* The slaves are now configured (nodeId and Baudrate) via the LSS services.
   			 	* Switch the LSS state to WAITING and restart the slaves. */
				
				/*TODO: change the baud rate of the master!!*/
   			 	MasterBoard.baudrate="250K";
   			 	
   			 	
	   			printf("Master : Switch Delay period finished. Switching to LSS WAITING state\n");
   				configNetworkNode(d,LSS_SM_GLOBAL,&LSS_mode,0,NULL);
	   			
   				printf("Master : Restarting all the slaves\n");
   				masterSendNMTstateChange (d, 0x00, NMT_Reset_Comunication);
	   			
   				printf("Master : Starting the SYNC producer\n");
   				writeLocalDict( d, /*CO_Data* d*/
					0x1006, /*UNS16 index*/
					0x00, /*UNS8 subind*/ 
					&SINC_cicle, /*void * pSourceData,*/ 
					&size, /* UNS8 * pExpectedSize*/
					RW);  /* UNS8 checkAccess */
					
				return;
			}
   			else{
   				UNS16 Switch_delay=1;
				UNS8 LSS_mode=LSS_CONFIGURATION_MODE;
				
	   			eprintf("Master : unable to activate bit timing. trying again\n");
				configNetworkNode(d,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0,CheckLSSAndContinue);
				return;
   			}
   			break;	
		case LSS_SM_SELECTIVE_SERIAL:
   			printf("Slave in LSS CONFIGURATION state\n");
   			break;
   		case LSS_IDENT_REMOTE_SERIAL_HIGH:
   			printf("node identified\n");
   			break;
   		case LSS_IDENT_REMOTE_NON_CONF:
   			if(dat1==0)
   				eprintf("There are no-configured remote slave(s) in the net\n");
   			else
   			{
   				UNS16 Switch_delay=1;
				UNS8 LSS_mode=LSS_CONFIGURATION_MODE;
			
				/*The configuration of the slaves' nodeId ended.
				 * Start the configuration of the baud rate. */
				eprintf("Master : There are not no-configured slaves in the net\n");
				eprintf("Switching all the nodes to LSS CONFIGURATION state\n");
				configNetworkNode(d,LSS_SM_GLOBAL,&LSS_mode,0,NULL);
				eprintf("LSS=>Activate Bit Timing\n");
				configNetworkNode(d,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0,CheckLSSAndContinue);
				return;
   			}
   			break;
   		case LSS_INQ_VENDOR_ID:
   			printf("Slave VendorID %x\n", dat1);
   			break;
   		case LSS_INQ_PRODUCT_CODE:
   			printf("Slave Product Code %x\n", dat1);
   			break;
   		case LSS_INQ_REV_NUMBER:
   			printf("Slave Revision Number %x\n", dat1);
   			break;
   		case LSS_INQ_SERIAL_NUMBER:
   			printf("Slave Serial Number %x\n", dat1);
   			break;
   		case LSS_INQ_NODE_ID:
   			printf("Slave nodeid %x\n", dat1);
   			break;
#ifdef CO_ENABLE_LSS_FS
   		case LSS_IDENT_FASTSCAN:
   			if(dat1==0)
   				printf("Slave node identified with FastScan\n");
   			else
   			{
   				printf("There is not unconfigured node in the net\n");
   				return;
   			}	
   			init_step_LSS++;
   			break;
#endif	
	
		}
	}

	printf("\n");
	ConfigureLSSNode(d);
}