Esempio n. 1
0
bool MapHelperUniversal::start()
{
    Q_D(MapHelperUniversal);
    if (d->recv && d->recv != d->_recv)
        if (!isStill())
            return false;

    if (d->recv)
        finish();

    d->started = false;
    D_MAP;
    if (!d->_recv || !d->_abortSignal)
        return false;
    d->recv = d->_recv;
    bool connFlag = true;

    if (d->_abortSignal)
        connFlag = connFlag && connect(d->recv, d->_abortSignal, this, SLOT(finish()));
    if (d->_handlerSlot)
        connFlag = connFlag && connect(d, SIGNAL(handler(minigis::MHEvent*)), d->recv, d->_handlerSlot);

    if (connFlag) {
        connect(d->recv, SIGNAL(destroyed()), SLOT(finish()));

        d->started = true;
    }
    else
        finish();

    return connFlag;
}
Esempio n. 2
0
bool MapHelper::clear()
{
    if (isStill()) {
        if (isStarted())
            finish();
        return true;
    }
    else
        return !isStarted();
    return false;
}
/**
 * Parses data from client. (Overloading from superclass)
 */
void ClientSonyDeckControlUDP::_parselineDispatch() {

  if (_serialOutput > 2) {
    Serial.print(F("INCOMING DATA: \n"));
    for (uint8_t i = 0; i < _bufferWriteIndex; i++) {
      if (_binarybuffer[i] < 16) {
        Serial.print(0);
      }
      Serial.print(_binarybuffer[i], HEX);
      Serial.print(':');
      if (i == 20) {
        Serial.print(' ');
      }
    }
    Serial.print(F(" Length="));
    Serial.println(_bufferWriteIndex);
  }

  unsigned int cmd = ((unsigned int)_binarybuffer[0] << 8) + (unsigned int)_binarybuffer[1];

  switch (cmd) {
  case 0x7920:
    // Both flags are set in one go:
    _hasInitialized = true;
    _initialize();

    if (_binarybufferCheckSum != _lastStatusCheckSum) { // Only update if new information (we use the checksum to determine that, since it depends entirely on the data transmitted)
      _lastStatusCheckSum = _binarybufferCheckSum;
      if (_serialOutput > 1)
        Serial.println(F("*** Updating states:"));

      // Playing:
      if (_isPlaying != ((_binarybuffer[3] & B00000001) > 0)) {
        _isPlaying = ((_binarybuffer[3] & B00000001) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isPlaying: "));
        if (_serialOutput > 1)
          Serial.println(isPlaying());
      }

      // Recording
      if (_isRecording != ((_binarybuffer[3] & B00000010) > 0)) {
        _isRecording = ((_binarybuffer[3] & B00000010) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isRecording: "));
        if (_serialOutput > 1)
          Serial.println(isRecording());
      }

      // Forwarding x2 or more:
      if (_isForwarding != ((_binarybuffer[3] & B00000100) > 0)) {
        _isForwarding = ((_binarybuffer[3] & B00000100) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isForwarding: "));
        if (_serialOutput > 1)
          Serial.println(isForwarding());
      }

      // Rewinding x1 or more:
      if (_isRewinding != ((_binarybuffer[3] & B00001000) > 0)) {
        _isRewinding = ((_binarybuffer[3] & B00001000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isRewinding: "));
        if (_serialOutput > 1)
          Serial.println(isRewinding());
      }

      // Stopped:
      if (_isStopped != ((_binarybuffer[3] & B00100000) > 0)) {
        _isStopped = ((_binarybuffer[3] & B00100000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isStopped: "));
        if (_serialOutput > 1)
          Serial.println(isStopped());
      }

      // Cassette Out:
      if (_isCassetteOut != ((_binarybuffer[2] & B00100000) > 0)) {
        _isCassetteOut = ((_binarybuffer[2] & B00100000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isCassetteOut: "));
        if (_serialOutput > 1)
          Serial.println(isCassetteOut());
      }

      // Local mode (If REM is not enabled):
      if (_isInLocalModeOnly != ((_binarybuffer[2] & B00000001) > 0)) {
        _isInLocalModeOnly = ((_binarybuffer[2] & B00000001) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isInLocalModeOnly: "));
        if (_serialOutput > 1)
          Serial.println(isInLocalModeOnly());
      }

      // Stand By:
      if (_isStandby != ((_binarybuffer[3] & B10000000) > 0)) {
        _isStandby = ((_binarybuffer[3] & B10000000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isStandby: "));
        if (_serialOutput > 1)
          Serial.println(isStandby());
      }

      // Jog Mode:
      if (_isInJogMode != ((_binarybuffer[4] & B00010000) > 0)) {
        _isInJogMode = ((_binarybuffer[4] & B00010000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isInJogMode: "));
        if (_serialOutput > 1)
          Serial.println(isInJogMode());
      }

      // Direction Backwards:
      if (_isDirectionBackwards != ((_binarybuffer[4] & B00000100) > 0)) {
        _isDirectionBackwards = ((_binarybuffer[4] & B00000100) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isDirectionBackwards: "));
        if (_serialOutput > 1)
          Serial.println(isDirectionBackwards());
      }

      // Still:
      if (_isStill != ((_binarybuffer[4] & B00000010) > 0)) {
        _isStill = ((_binarybuffer[4] & B00000010) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isStill: "));
        if (_serialOutput > 1)
          Serial.println(isStill());
      }

      // Near EOT:
      if (_isNearEOT != ((_binarybuffer[10] & B00100000) > 0)) {
        _isNearEOT = ((_binarybuffer[10] & B00100000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isNearEOT: "));
        if (_serialOutput > 1)
          Serial.println(isNearEOT());
      }

      // EOT:
      if (_isEOT != ((_binarybuffer[10] & B00010000) > 0)) {
        _isEOT = ((_binarybuffer[10] & B00010000) > 0);
        if (_serialOutput > 1)
          Serial.print(F("isEOT: "));
        if (_serialOutput > 1)
          Serial.println(isEOT());
      }
    }
    break;
  case 0x1001:
    if (_serialOutput > 1)
      Serial.println(F("ACK"));
    break;
  case 0x1112:
    if (_serialOutput > 1)
      Serial.println(F("NACK"));
    if (_serialOutput > 1)
      Serial.println(_binarybuffer[2]);
    break;
  default:
    if (_serialOutput) {
      if (_serialOutput > 1)
        Serial.println(F("Unsupported Data Packet:"));
      for (uint8_t i = 0; i < _binarybufferExpectedLength; i++) {
        Serial.println(_binarybuffer[i], HEX);
      }
      if (_serialOutput > 1)
        Serial.println(F("==="));
    }
    break;
  }
}
Esempio n. 4
0
/*********主函数**********/
void main (void)
{
	delay(100);						//上电延时
	Init_ADXL345();                 //初始化ADXL345
	Init_UART();					//初始化串口通信
   	SpaceCreate(A);					//坐标系建立
	delay(200);
	OPTION=9;
	while( 1 )            			//循环
	{ 
		
		switch(OPTION)
		{
		case 1:
			STATUS_PRE=-1;
			STATUS_NOW=-1;
			STATUS_HISTORY[0]=0;
			STATUS_HISTORY[1]=0;
			STATUS_HISTORY[2]=0;
			OPTION=2;
		case 2:					  
			UpdateDatabase( DATABASE, A );
			AnalyzeDatabase( DATABASE, SET, ZArray);
			STATUS_HISTORY[0]=STATUS_HISTORY[1];
			STATUS_HISTORY[1]=STATUS_HISTORY[2];
			if ( isStill(SET) )
			{	
				STATUS_HISTORY[2]=StillStatus(SET);	
			}
			else
			{
				STATUS_HISTORY[2]=MovingStatus(ZArray);
			}
			if(STATUS_HISTORY[0]==STATUS_HISTORY[1]&&STATUS_HISTORY[2]==STATUS_HISTORY[1])
				STATUS_NOW=STATUS_HISTORY[2];
			else
				STATUS_NOW=STATUS_PRE;
			Send2PhoneMotion(STATUS_NOW, STATUS_PRE);
			STATUS_PRE=STATUS_NOW;
			break;
		case 3:
			temp=0;
			result=0;
			prestatus=0;
			OPTION=4;
		case 4:
			UpdateDatabase( DATABASE, A );
			AnalyzeDatabase( DATABASE, SET, ZArray);
			if ( isStill(SET) )
			{
				break;
			}
			result=Count( ZArray );
			if( prestatus==0 )
				prestatus=result/10;
			else if( prestatus!=result/10 )
			{
				temp=prestatus;
				prestatus=result/10;
				result=temp*10+result%10;
			}
			Send2PhoneSteps(result);
			break;
		case 9:
			break;
		}		
	}


}