bool System::setParameter( u16 paramID, s32 value, SMCommandQueue &queue )
{
	bool fail;
	SMPayloadCommandForQueue tx;

	queue.lockMutex();

	//set param address to write
	tx.ID = SMPCMD_SET_PARAM_ADDR;
	tx.discardRetData = true;
	tx.param = paramID;
	if (queue.sendCommand( tx ) == false)
	{
		fail = true;
		setFault( FLT_GC_COMM, 150201 );
		queue.unlockMutex();
		return false;
	}
	tx.ID = SMPCMD_32B;
	tx.param = value;
	tx.discardRetData = true;
	if (queue.sendCommand( tx ) == false)
	{
		fail = true;
		setFault( FLT_GC_COMM, 150202 );
		queue.unlockMutex();
		return false;
	}

	queue.unlockMutex();
	return true;
}
s32 System::getParameter( u16 paramID, bool &fail )
{
	SMPayloadCommandForQueue tx;

	xSemaphoreTake( SysCmdMutex, portMAX_DELAY );

	//set return data len to 32b
	tx.ID = SMPCMD_SET_PARAM_ADDR;
	tx.discardRetData = true;
	tx.param = SMP_RETURN_PARAM_LEN;
	if (GCCmdStream2_MediumPriority.sendCommand( tx ) == false)
	{
		fail = true;
		setFault( FLT_GC_COMM, 150101 );
		xSemaphoreGive( SysCmdMutex );
		return -1;
	}
	tx.ID = SMPCMD_24B;
	tx.param = SMPRET_32B;
	if (GCCmdStream2_MediumPriority.sendCommand( tx ) == false)
	{
		fail = true;
		setFault( FLT_GC_COMM, 150102 );
		xSemaphoreGive( SysCmdMutex );
		return -1;
	}

	//set param address to read
	tx.ID = SMPCMD_SET_PARAM_ADDR;
	tx.discardRetData = true;
	tx.param = SMP_RETURN_PARAM_ADDR;
	if (GCCmdStream2_MediumPriority.sendCommand( tx ) == false)
	{
		fail = true;
		setFault( FLT_GC_COMM, 150103 );
		xSemaphoreGive( SysCmdMutex );
		return -1;
	}
	tx.ID = SMPCMD_24B;
	tx.param = paramID;
	tx.discardRetData = false;
	if (GCCmdStream2_MediumPriority.sendCommand( tx ) == false)
	{
		fail = true;
		setFault( FLT_GC_COMM, 150104 );
		xSemaphoreGive( SysCmdMutex );
		return -1;
	}

	s32 ret = GCCmdStream2_MediumPriority.getReturnValue( fail );
	if (fail)
		setFault( FLT_GC_COMM, 150105 );

	xSemaphoreGive( SysCmdMutex );
	return ret;
}
Exemplo n.º 3
0
void MonitoringDevice::commandGetEvent(unsigned char* _pArea){
	const unsigned int EVENT_ID_OFFSET = 5;
	const unsigned int EVENT_FAULT_OFFSET = 7;
	const unsigned int EVENT_COUNT_OFFSET = 8;

	setFault(_pArea[EVENT_FAULT_OFFSET]);

	unsigned short _eventId = _pArea[EVENT_ID_OFFSET] + _pArea[EVENT_ID_OFFSET + 1] * 256;
	if (_eventId != eventId){
		if (_pArea[EVENT_COUNT_OFFSET] != 0){
			if (!SerialDebug::getSingleton().isOn())
				redirectToPc(_pArea);

			unsigned int messageCount = firstMessage(&_pArea);
			for (unsigned int i = 0; i < messageCount; ++i){
				if (isEventMessage(_pArea)){
					toLog(_pArea);
					setOutputs(_pArea);
				}

				nextMessage(&_pArea);
			}
		}
	}

	eventId = _eventId;
}
System::System() :
		//SMComm( &serialPortRS485, this, 5 ),
		BootloaderInfo((BLHeader*)BLHEADER_ADDRESS),
		physIO(this),
		SMComm( &serialPortRS485, this, physIO.getDIPSwitchAddress() ),
		serialPortRS485( Serial::RS485,
				this ), serialPortGC( Serial::DSC, this ), GCCmdStream1_HighPriority(
				this, COMMAND_QUEUE1_SIZE, "cmdQ1Hi" ), GCCmdStream2_LowPriority(
				this, COMMAND_QUEUE2_SIZE, "cmdQ2Med" ), GCCmdStream2_HighPriority(
				this, COMMAND_QUEUE2_SIZE, "cmdQS2High" ), GCCmdStream2_MediumPriority(
				this, SYS_COMMAND_QUEUE_SIZE, "cmdQ2Low" ),
				resolver(this)

{
	lastPositionFBValue=0;
	FaultBitsReg = 0;
	FirstFaultBitsReg = 0;
	FirstFaultLocation = 0;
	LastFaultLocation = 0;
	StatusBitsReg = 0;
	GCStatusBits=STAT_BRAKING;//set braking on initially to prevent brake clitch at boot
	GCFaultBits=0;
	GCFirstFault=0;
	SignalReg=0;
	DriveFlagBits=0;
	setpointOffset=0;
	serialSetpoint=0;
	//deviceResetRequested=false;



	//encoder is the default setting, changed later if configured so
	positionFeedbackDevice=None;
	velocityFeedbackDevice=None;

	//positionFeedbackDevice=Resolver;
	//velocityFeedbackDevice=Resolver; //set also  resolver.enableResolverRead(true); later

	//digitalCounterInput.setCountMode( DigitalCounterInput::PWM );

	setDebugParam(4,-1);
	setDebugParam(5,-1);
	setDebugParam(6,-1);

	updateSpreadSpectrumClockMode();
	initGeneralTimer();
	enableHighFrequencyTask( true );

	//s32 testPulseAmpl=0;
	//s32 testPulsePause=0;
	vSemaphoreCreateBinary( SysCmdMutex );
    if(SysCmdMutex==NULL)
    {
    	setFault( FLT_FIRMWARE|FLT_ALLOC,FAULTLOCATION_BASE+01);
    }

    INPUT_REFERENCE_QUEUE.setIgnoreSetpointCommands(true);
}