Exemplo n.º 1
0
bool FUNCREFPCTARGET::execute(void)
{
	bool result= false;
	static VPVIEWMASTER viewmaster= 0;
	VPREFERENCE target= 0;

	result= ((viewmaster || getMachine().ReadMem((VPVOID)reltolinear(MASTER2_IMAGE),&viewmaster,sizeof(viewmaster)))
		&& getMachine().ReadMem((VPVOID)&viewmaster->target,&target,sizeof(target))
		&& setref(target));


	return result;
}
Exemplo n.º 2
0
bool FUNCFIRSTITEM::execute(void)
{
	bool result= false;
	static VPCELLMASTER cellmaster= 0;
	VPCELLPTR pcellptr;
	TES3CELLPTR cellptr;
	VPCELL intcell= 0;
	VPREFERENCE ref= 0;

// 2005-07-02  CDC
	int i;	
	exteriors[0] = 0;
	if((cellmaster || getMachine().ReadMem((VPVOID)reltolinear(MASTERCELL_IMAGE),&cellmaster,sizeof(cellmaster)))
		&& getMachine().ReadMem((VPVOID)&cellmaster->interiorcell,&intcell,sizeof(intcell)))
	{
		if(intcell)
			result= getMachine().ReadMem((VPVOID)&intcell->otheritems.first,&ref,sizeof(ref));
		else
		{
			if(getMachine().ReadMem((VPVOID)&cellmaster->exteriorcells[CENTRE],&pcellptr,sizeof(pcellptr))
				&& getMachine().ReadMem((VPVOID)pcellptr,&cellptr,sizeof(cellptr)))
			{
				if(cellptr.size==1)
				{
					result= getMachine().ReadMem((VPVOID)&cellptr.first->otheritems.first,&ref,sizeof(ref));
					for ( i=0; i<8; i++ )  // Read the other 8 exteriors too
					{
						if(getMachine().ReadMem((VPVOID)&cellmaster->exteriorcells[(i<4?i:i+1)],&pcellptr,sizeof(pcellptr))
							&& getMachine().ReadMem((VPVOID)pcellptr,&cellptr,sizeof(cellptr)))
						{
							if(cellptr.size==1)
								getMachine().ReadMem((VPVOID)&cellptr.first->otheritems.first,&exteriors[i],sizeof(VPREFERENCE));
							else
							{
								exteriors[i] = 0;
								i = 9;
							}
						}
					}
				}
				else
					result= true;
			}
		}
	}
	result= getMachine().push((VMREGTYPE)ref) && result;


	return result;
}
Exemplo n.º 3
0
void IState::TransitToState( IState* nextState,const ElapsedTime& t )
{
	if(IStateMachine* pMachine = getMachine() )
	{
		pMachine->ChangeState(nextState,t);
	}
}
Exemplo n.º 4
0
void IState::TransitToState( IState* nextState,CARCportEngine* pEngine )
{
	if(IStateMachine* pMachine = getMachine() )
	{
		pMachine->ChangeState(nextState,pEngine);
	}
}
Exemplo n.º 5
0
bool FUNCFIRSTSTATIC::execute(void)
{
	bool result = false;
	static VPCELLMASTER cellmaster= 0;
	VPCELLPTR pcellptr;
	TES3CELLPTR cellptr;
	VPCELL intcell= 0;
	VPREFERENCE ref= 0;
	exteriors[0] = 0;

	if((cellmaster || getMachine().ReadMem((VPVOID)reltolinear(MASTERCELL_IMAGE),&cellmaster,sizeof(cellmaster)))
		&& getMachine().ReadMem((VPVOID)&cellmaster->interiorcell,&intcell,sizeof(intcell)))
	{
		if(intcell)
			result = getMachine().ReadMem((VPVOID)&intcell->statics.first,&ref,sizeof(ref));
		else
		{
			if(getMachine().ReadMem((VPVOID)&cellmaster->exteriorcells[CENTRE],&pcellptr,sizeof(pcellptr))
				&& getMachine().ReadMem((VPVOID)pcellptr,&cellptr,sizeof(cellptr)))
			{
				if(cellptr.size==1)
					result= getMachine().ReadMem((VPVOID)&cellptr.first->statics.first,&ref,sizeof(ref));
				else
					result= true;
			}
		}
	}
	result= getMachine().push((VMREGTYPE)ref) && result;


	return result;
}
Exemplo n.º 6
0
bool FUNCREF::execute(void)
{
	VMREGTYPE pref= 0;
	bool result= (getMachine().pop(pref)
		&& setref((VPREFERENCE)pref));


	return result;
}
Exemplo n.º 7
0
bool FUNCNEXTREF::execute(void)
{
	bool result= false;

	VMREGTYPE pref;
	VPREFERENCE next= 0;
	if(getMachine().pop(pref))
	{
		VPREFERENCE ref= (VPREFERENCE)pref;
		int i;
		getMachine().ReadMem((VPVOID)&ref->next,&next,sizeof(next));
		while ( !next && exteriors[0] ) 
		{
			ref = exteriors[0];
			for ( i=0; i<8; i++ )
				exteriors[i] = exteriors[i+1];
			getMachine().ReadMem((VPVOID)&ref->next,&next,sizeof(next));
		}
		result= getMachine().push((VMREGTYPE)next);
	}


	return result;
}
Exemplo n.º 8
0
//Read the string and execute instructions
 void GcodeProcessor::process_string(char instruction[])
{ 
  //the character / means delete block... used for comments and stuff.
  if (instruction[0] == '/' 
	|| instruction[0] == ';'
	|| instruction[0] == '#'){
    return; 
  }

//  float  currentPosition[] ={getUnitsX(), getUnitsY(), getUnitsZ() };
Point currentPosition = getMachine().getCurrentPosition();
  Point target ;


int code = 0;

   //Get Target
    
		target.x = currentPosition.x ;
		target.y = currentPosition.y ;
		target.z = currentPosition.z ;
        if (has_command('X', instruction)) target.x = search_string('X', instruction);
        if (has_command('Y', instruction)) target.y = search_string('Y', instruction);
        if (has_command('Z', instruction)) target.z = search_string('Z', instruction);
     
	 if(!abs_mode){
		target.x = currentPosition.x + search_string('X', instruction);
        target.y =  currentPosition.y + search_string('Y', instruction);;
        target.z =  currentPosition.z + search_string('X', instruction);;
      }
	//set our target.
//	 getMachine().set_target(target);
  
	double feedrate = search_string('F', instruction);
    if (feedrate > 0)  nominalFeedRate = feedrate;
  
  
  
  // handle no G code but has Coordinates remember the last feed rate
  if( ( has_command('X', instruction) ||
		has_command('Y', instruction) ||
		has_command('Z', instruction))&&
		! has_command('G', instruction)){
		//	setFeedRate(nominalFeedRate);
	  getMachine().goTo(target);

	}		
  
  
  if (    has_command('G', instruction)     )
  {
    //which one?
    code = (int)search_string('G', instruction);
    switch (code)
    {
      //Rapid Positioning
    case 0:
    	getMachine().setMaxFeedRate();
    	getMachine().goTo(target);
	break;
	
	//Linear Interpolation
    case 1:
    	getMachine().setFeedRate(nominalFeedRate);
    	getMachine().goTo(target);
      break;


      //Clockwise arc
    case 2:
      //Counterclockwise arc
    case 3:


      // Centre coordinates are always relative
      centr.x = search_string('I', instruction) + currentPosition.x;
      centr.y = search_string('J', instruction) + currentPosition.y;
      centr.z = target.z;
      bool clockwise;
	 clockwise	  = (code==2);

	 getMachine().moveAlongCurve( centr,  target, clockwise);
      break;

    case 4:
//      delay(1000*(int)search_string('P', instruction, size));
      break;

      //Inches for Units
    case 20:
    	getMachine().setInches();
      break;

      //mm for Units
    case 21:
    	getMachine().setMillimeters();
      break;

      //go home.
    case 28:
    	getMachine().goToOrigin();
      break;

      //go home via an intermediate point.
    case 30:
    	getMachine().setMaxFeedRate();
    	getMachine().goTo(target);
      //go home.
		getMachine().goToOrigin();
      break;

      //Absolute Positioning
    case 90:
      abs_mode = true; 
      break;

      //Incremental Positioning
    case 91:
	
      abs_mode = false;
      break;

      //Set as home
    case 92:
    	getMachine().setPosition(Point());
      break;

      /*
			//Inverse Time Feed Mode
       			case 93:
       
       			break;  //TODO: add this
       
       			//Feed per Minute Mode
       			case 94:
       
       			break;  //TODO: add this
       */

    default:
    	break;
//      Serial.print("huh? G");
//      Serial.println(code,DEC);
    }
  }

  if (has_command('F', instruction))
  {
		double rate = search_string('F', instruction);
		getMachine().setFeedRate(rate);
		 nominalFeedRate = rate;
		
  }
  //find us an m code.
  if (has_command('M', instruction))
  {
    code = search_string('M', instruction);
    switch (code)
    {
      //TODO: this is a bug because search_string returns 0.  gotta fix that.
    case 0:
      true;
      break;
      /*
			case 0:
       				//todo: stop program
       			break;
       
       			case 1:
       				//todo: optional stop
       			break;
       
       			case 2:
       				//todo: program end
       			break;
       	*/
      //set max extruder speed, 0-255 PWM
//    case 100:
//      extruder_speed = (int)(search_string('P', instruction, size));
//      break;
//
//      //turn extruder on, forward
//    case 101:
//      extruder_set_direction(1);
//      extruder_set_speed(extruder_speed);
//      break;
//
//      //turn extruder on, reverse
//    case 102:
//      extruder_set_direction(0);
//      extruder_set_speed(extruder_speed);
//      break;
//
//      //turn extruder off
//    case 103:
//      extruder_set_speed(0);
//      break;
//
//      //custom code for temperature control
//    case 104:
//      extruder_set_temperature((int)search_string('P', instruction, size));
//
//      //warmup if we're too cold.
//      while (extruder_get_temperature() < extruder_target_celsius)
//      {
//        extruder_manage_temperature();
//        Serial.print("T:");
//        Serial.println(extruder_get_temperature());
//        delay(1000);
//      }
//
//      break;
//
//      //custom code for temperature reading
//    case 105:
//      Serial.print("T:");
//      Serial.println(extruder_get_temperature());
//      break;
//
//      //turn fan on
//    case 106:
//      extruder_set_cooler(255);
//      break;
//
//      //turn fan off
//    case 107:
//      extruder_set_cooler(0);
//      break;

    default:
    	break;
//      Serial.print("Huh? M");
//      Serial.println(code);
    }		
  }

  //tell our host we're done.
//  Serial.println("ok");
  //	Serial.println(line, DEC);
}
void paraNode()
/* paraNode - a net server. */
{
char *line;
char *command;
struct sockaddr_in sai;

/* We have to know who we are... */
hostName = getMachine();
initRandom();
getTicksToHundreths();

/* log init */
if (optionExists("log"))
    logOpenFile("paraNode", optionVal("log", NULL));
else    
    logOpenSyslog("paraNode", optionVal("logFacility", NULL));
logSetMinPriority(optionVal("logMinPriority", "info"));
logInfo("starting paraNode on %s", hostName);

/* Make job lists. */
jobsRunning = newDlList();
jobsFinished = newDlList();

/* Set up socket and self to listen to it. */
ZeroVar(&sai);
sai.sin_family = AF_INET;
sai.sin_port = htons(paraNodePort);
sai.sin_addr.s_addr = INADDR_ANY;
mainRudp = rudpMustOpenBound(&sai);
mainRudp->maxRetries = 12;

/* Event loop. */
findNow();
for (;;)
    {
    /* Get next incoming message and optionally check to make
     * sure that it's from a host we trust, and check signature
     * on first bit of incoming data. */
    if (pmReceive(&pmIn, mainRudp))
	{
	findNow();
	if (hubName == NULL || ntohl(pmIn.ipAddress.sin_addr.s_addr) == hubIp 
		|| ntohl(pmIn.ipAddress.sin_addr.s_addr) == localIp)
	    {
	    /* Host and signature look ok,  read a string and
	     * parse out first word as command. */
	    line = pmIn.data;
	    logDebug("message from %s: \"%s\"",
                     paraFormatIp(ntohl(pmIn.ipAddress.sin_addr.s_addr)),
                     line);
	    command = nextWord(&line);
	    if (command != NULL)
		{
		if (sameString("quit", command))
		    break;
		else if (sameString("run", command))
		    doRun(line, &pmIn.ipAddress);
		else if (sameString("jobDone", command))
		    jobDone(line);
		else if (sameString("status", command))
		    doStatus();
		else if (sameString("kill", command))
		    doKill(line);
		else if (sameString("check", command))
		    doCheck(line, &pmIn.ipAddress);
		else if (sameString("resurrect", command))
		    doResurrect(line, &pmIn.ipAddress);
		else if (sameString("listJobs", command))
		    listJobs();
		else if (sameString("fetch", command))
		    doFetch(line);
                else
                    logWarn("invalid command: \"%s\"", command);
		}
	    logDebug("done command");
	    }
	else
	    {
	    logWarn("command from unauthorized host %s",
                    paraFormatIp(ntohl(pmIn.ipAddress.sin_addr.s_addr)));
	    }
	}
    }
rudpClose(&mainRudp);
}