int32 ClientSession::GetCurrentInt( const char* name ) const
{
    PyRep* v = _GetCurrent( name );
    if( v == NULL )
        return 0;

    if( !v->IsInt() )
        return 0;

    return v->AsInt()->value();
}
int64 ClientSession::GetCurrentLong( const char* name ) const
{
    PyRep* v = _GetCurrent( name );
    if( v == NULL )
        return 0;

    if( !v->IsLong() )
        return 0;

    return v->AsLong()->value();
}
std::string ClientSession::GetCurrentString( const char* name ) const
{
    PyRep* v = _GetCurrent( name );
    if( v == NULL )
        return std::string();

    if( !v->IsString() )
        return std::string();

    return v->AsString()->content();
}
/**
 * Call this function periodically outside the interrupt context to process commands
 */
void Command_Task()
{
	if(CommandStatus != CommandStateFinishedReceiving)
		return;

	LED_GREEN_ClrVal();

	CommandStatus = CommandStateExecuting;

	uint32 intendedAddress = 0; // this is the address the packet is intended for
//	uint32 intendedAddress = ( (uint32)ReceiveBuffer[1] << 24 ) | ( (uint32)ReceiveBuffer[2] << 16 ) | ( (uint32)ReceiveBuffer[3] << 8 ) | (uint32)ReceiveBuffer[4];
//	intendedAddress = (intendedAddress << 8) + ReceiveBuffer[4];
//	intendedAddress = (intendedAddress << 8) + ReceiveBuffer[3];
//	intendedAddress = (intendedAddress << 8) + ReceiveBuffer[2];
//	intendedAddress = (intendedAddress << 8) + ReceiveBuffer[1];
	intendedAddress |= ReceiveBuffer[4] & 0xFF;
	intendedAddress <<= 8;
	intendedAddress |= ReceiveBuffer[3] & 0xFF;
	intendedAddress <<= 8;
	intendedAddress |= ReceiveBuffer[2] & 0xFF;
	intendedAddress <<= 8;
	intendedAddress |= ReceiveBuffer[1] & 0xFF;

	if(intendedAddress == MyAddress || intendedAddress == 0) // 0 = broadcast
	{
		switch(ReceiveBuffer[5])
		{
		case CommandPing:
			_Ping();
			break;
		case CommandConfigure:
			_Configure(&ReceiveBuffer[6]);
			break;
		case CommandHomeUp:
			//_HomeUp();
			break;
		case CommandHomeDown:
			//_HomeDown();
			break;
		case CommandMoveTo:
			_MoveTo(&ReceiveBuffer[6]);
			break;
		case CommandGetStatus:
			_GetStatus();
			break;
		case CommandAssociate:
			_Associate();
			break;
		case CommandIdentifyLed:
			_IdentifyLed(ReceiveBuffer[6]);
			break;
		case CommandJog:
			_Jog(&ReceiveBuffer[6]);
			break;
		case CommandResetCounters:
			_ResetCounter(ReceiveBuffer[6], ReceiveBuffer[7]);
			break;
		case CommandDoubleMoveTo:
			_DoubleMoveTo(&ReceiveBuffer[6]);
			break;
		case CommandSetPosGetData:
			_SetPosGetData(&ReceiveBuffer[6]);
			break;
		case CommandGetHallPos:
			_GetHallPos();
			break;
		case CommandGetPots:
			_GetPots();
			break;
		case CommandGetCurremt:
			_GetCurrent();
			break;
		}
	}
	CommandStatus = CommandStateWaiting;
	LED_GREEN_SetVal();
}