Ejemplo n.º 1
0
/******************************************************************************
 * This funtion is the main entry point to the queryValue type of action.  It
 * receives the currently read line and dispatch the work depending on the
 * context.
 */
void doQueryValue(LPTSTR stdInput) {
  /*
   * We encoutered the end of the file, make sure we
   * close the opened key and exit
   */
  if (stdInput == NULL) {
    if (bTheKeyIsOpen != FALSE)
      closeKey();
    return;
  }

  if (stdInput[0] == _T('[')) {     /* We are reading a new key */
    if (bTheKeyIsOpen != FALSE)
      closeKey();                    /* Close the previous key before */
    if (openKey(stdInput) != ERROR_SUCCESS ) {
      _tprintf(_T("doQueryValue failed to open key %s\n"), stdInput);
    }
  }
  else if( (bTheKeyIsOpen) &&
           ((stdInput[0] == _T('@')) || /* reading a default @=data pair */
           (stdInput[0] == _T('\"')))) { /* reading a new value=data pair */
    processQueryValue(stdInput);
  } else {                /* since we are assuming that the file format is */
    if (bTheKeyIsOpen)    /* valid we must be reading a blank line which  */
      closeKey();         /* indicate end of this key processing */
  }
}
Ejemplo n.º 2
0
bool XMLParser::parseActiveKey(bool closed) {
	bool ignore = false;
	assert(_activeKey.empty() == false);

	ParserNode *key = _activeKey.top();

	if (key->name == "xml" && key->header == true) {
		assert(closed);
		return parseXMLHeader(key) && closeKey();
	}

	XMLKeyLayout *layout = (_activeKey.size() == 1) ? _XMLkeys : getParentNode(key)->layout;

	if (layout->children.contains(key->name)) {
		key->layout = layout->children[key->name];

		Common::StringMap localMap = key->values;
		int keyCount = localMap.size();

		for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) {
			if (i->required && !localMap.contains(i->name))
				return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str());
			else if (localMap.contains(i->name))
				keyCount--;
		}

		if (keyCount > 0)
			return parserError("Unhandled property inside key '%s'.", key->name.c_str());

	} else {
		return parserError("Unexpected key in the active scope ('%s').", key->name.c_str());
	}

	// check if any of the parents must be ignored.
	// if a parent is ignored, all children are too.
	for (int i = _activeKey.size() - 1; i >= 0; --i) {
		if (_activeKey[i]->ignore)
			ignore = true;
	}

	if (ignore == false && keyCallback(key) == false) {
		// HACK:  People may be stupid and overlook the fact that
		// when keyCallback() fails, a parserError() must be set.
		// We set it manually in that case.
		if (_state != kParserError)
			parserError("Unhandled exception when parsing '%s' key.", key->name.c_str());

		return false;
	}

	if (closed)
		return closeKey();

	return true;
}
Ejemplo n.º 3
0
/******************************************************************************
 * This function receives the currently read entry and performs the
 * corresponding action.
 * isUnicode affects parsing of REG_MULTI_SZ values
 */
static void processRegEntry(WCHAR* stdInput, BOOL isUnicode)
{
    /*
     * We encountered the end of the file, make sure we
     * close the opened key and exit
     */
    if (stdInput == NULL) {
        closeKey();
        return;
    }

    if      ( stdInput[0] == '[')      /* We are reading a new key */
    {
        WCHAR* keyEnd;
        closeKey();                    /* Close the previous key */

        /* Get rid of the square brackets */
        stdInput++;
        keyEnd = strrchrW(stdInput, ']');
        if (keyEnd)
            *keyEnd='\0';

        /* delete the key if we encounter '-' at the start of reg key */
        if ( stdInput[0] == '-')
        {
            delete_registry_key(stdInput + 1);
        } else if ( openKeyW(stdInput) != ERROR_SUCCESS )
        {
            char* stdInputA = GetMultiByteString(stdInput);
            fprintf(stderr,"%s: setValue failed to open key %s\n",
                    getAppName(), stdInputA);
            HeapFree(GetProcessHeap(), 0, stdInputA);
        }
    } else if( currentKeyHandle &&
               (( stdInput[0] == '@') || /* reading a default @=data pair */
                ( stdInput[0] == '\"'))) /* reading a new value=data pair */
    {
        processSetValue(stdInput, isUnicode);
    } else
    {
        /* Since we are assuming that the file format is valid we must be
         * reading a blank line which indicates the end of this key processing
         */
        closeKey();
    }
}
Ejemplo n.º 4
0
/******************************************************************************
 * This function receives the currently read entry and performs the
 * corresponding action.
 * isUnicode affects parsing of REG_MULTI_SZ values
 */
static void processRegEntry(WCHAR* stdInput, BOOL isUnicode)
{
    /*
     * We encountered the end of the file, make sure we
     * close the opened key and exit
     */
    if (stdInput == NULL) {
        closeKey();
        return;
    }

    if      ( stdInput[0] == '[')      /* We are reading a new key */
    {
        WCHAR* keyEnd;
        closeKey();                    /* Close the previous key */

        /* Get rid of the square brackets */
        stdInput++;
        keyEnd = strrchrW(stdInput, ']');
        if (keyEnd)
            *keyEnd='\0';

        /* delete the key if we encounter '-' at the start of reg key */
        if (stdInput[0] == '-')
            delete_registry_key(stdInput + 1);
        else if (openKeyW(stdInput) != ERROR_SUCCESS)
            output_message(STRING_OPEN_KEY_FAILED, stdInput);
    } else if( currentKeyHandle &&
               (( stdInput[0] == '@') || /* reading a default @=data pair */
                ( stdInput[0] == '\"'))) /* reading a new value=data pair */
    {
        processSetValue(stdInput, isUnicode);
    } else
    {
        /* Since we are assuming that the file format is valid we must be
         * reading a blank line which indicates the end of this key processing
         */
        closeKey();
    }
}
Ejemplo n.º 5
0
/*!
 This is the main routine of measurement.
 @param[in,out] prms A pointer to a #AK8975PRMS structure.
 */
void MeasureSNGLoop(AK8975PRMS* prms)
{
	BYTE    i2cData[AKSC_BDATA_SIZE];
	int16   i;
	int16   bData[AKSC_BDATA_SIZE];  // Measuring block data
	int16   ret;
	int32   ch;
	int32   doze;
	int32_t delay;
	AKMD_INTERVAL interval;
	struct timespec tsstart, tsend;
	

	if (openKey() < 0) {
		DBGPRINT(DBG_LEVEL1, 
				 "%s:%d Error.\n", __FUNCTION__, __LINE__);
		return;
	}
	
	if (openFormation() < 0) {
		DBGPRINT(DBG_LEVEL1, 
				 "%s:%d Error.\n", __FUNCTION__, __LINE__);
		return;
	}

	// Get initial interval
	GetValidInterval(CSPEC_INTERVAL_SNG, &interval);

	// Initialize
	if(InitAK8975_Measure(prms) != AKD_SUCCESS){
		return;
	}
	
	while(TRUE){
		// Get start time
		if (clock_gettime(CLOCK_REALTIME, &tsstart) < 0) {
			DBGPRINT(DBG_LEVEL1, 
					 "%s:%d Error.\n", __FUNCTION__, __LINE__);
			return;
		}
		// Set to SNG measurement pattern (Set CNTL register) 
		if (AKD_SetMode(AK8975_MODE_SNG_MEASURE) != AKD_SUCCESS) {
			DBGPRINT(DBG_LEVEL1, 
					 "%s:%d Error.\n", __FUNCTION__, __LINE__);
			return;
		}
		
        // .! : 获取 M snesor 的原始数据. 这里可能阻塞.  
		// Get measurement data from AK8975
		// ST1 + (HXL + HXH) + (HYL + HYH) + (HZL + HZH) + ST2
		// = 1 + (1 + 1) + (1 + 1) + (1 + 1) + 1 = 8 bytes
		if (AKD_GetMagneticData(i2cData) != AKD_SUCCESS) {
			DBGPRINT(DBG_LEVEL1, 
					 "%s:%d Error.\n", __FUNCTION__, __LINE__);
			return;
		}

		// Copy to local variable
		// DBGPRINT(DBG_LEVEL3, "%s: bData(Hex)=", __FUNCTION__);
		for(i=0; i<AKSC_BDATA_SIZE; i++){
			bData[i] = i2cData[i];
			// DBGPRINT(DBG_LEVEL3, "%02x,", bData[i]);
		}
		// DBGPRINT(DBG_LEVEL3, "\n");
        D_WHEN_REPEAT(100, 
                      "raw mag x : %d, raw mag y : %d, raw mag z : %d.", 
                      (signed short)(bData[1] + (bData[2] << 8) ), 
                      (signed short)(bData[3] + (bData[4] << 8) ), 
                      (signed short)(bData[5] + (bData[6] << 8) ) );
		
        // .! : 
		//  Get acceelration sensor's measurement data.
		if (GetAccVec(prms) != AKRET_PROC_SUCCEED) {
			return;
		}
        /*
		DBGPRINT(DBG_LEVEL3, 
				 "%s: acc(Hex)=%02x,%02x,%02x\n", __FUNCTION__,
				 prms->m_avec.u.x, prms->m_avec.u.y, prms->m_avec.u.z);
        */
		
		ret = MeasuringEventProcess(
									bData,
									prms,
									getFormation(),
									interval.decimator,
									CSPEC_CNTSUSPEND_SNG
									);
		// Check the return value
		if(ret == AKRET_PROC_SUCCEED){
			if(prms->m_cntSuspend > 0){
				// Show message
				DBGPRINT(DBG_LEVEL2, 
						 "Suspend cycle count = %d\n", prms->m_cntSuspend);
			} 
			else if (prms->m_callcnt <= 1){
				// Check interval
				if (AKD_GetDelay(&delay) != AKD_SUCCESS) {
					DBGPRINT(DBG_LEVEL1, 
							 "%s:%d Error.\n", __FUNCTION__, __LINE__);
				} else {
					GetValidInterval(delay, &interval);
				}
			}
			
			// Display(or dispatch) the result.
			Disp_MeasurementResultHook(prms);
		}
		else if(ret == AKRET_FORMATION_CHANGED){
			// Switch formation.
			SwitchFormation(prms);
		}
		else if(ret == AKRET_DATA_READERROR){
			DBGPRINT(DBG_LEVEL2, 
					 "Data read error occurred.\n\n");
		}
		else if(ret == AKRET_DATA_OVERFLOW){
			DBGPRINT(DBG_LEVEL2, 
					 "Data overflow occurred.\n\n");
		}
		else if(ret == AKRET_HFLUC_OCCURRED){
			DBGPRINT(DBG_LEVEL2, 
					 "AKSC_HFlucCheck did not return 1.\n\n");
		}
		else{
			// Does not reach here
			LOGE("MeasuringEventProcess has failed.\n");
			break;
		}
		
		// Check user order
		ch = checkKey();
		
		if (ch == AKKEY_STOP_MEASURE) {
			break;
		}
		else if(ch < 0){
			LOGD("Bad key code.\n");
			break;
		}

		// Get end time
		if (clock_gettime(CLOCK_REALTIME, &tsend) < 0) {
			DBGPRINT(DBG_LEVEL1, 
					 "%s:%d Error.\n", __FUNCTION__, __LINE__);
			return;
		}
		// calculate wait time
		doze = interval.interval - ((tsend.tv_sec - tsstart.tv_sec)*1000000 +
									(tsend.tv_nsec - tsstart.tv_nsec)/1000);
		if (doze < 0) {
			doze = 0;
		}

		// Adjust sampling frequency
		// DBGPRINT(DBG_LEVEL3, "Sleep %d usec.\n", doze);
		usleep(doze);
	}
	// Set to PowerDown mode 
	if (AKD_SetMode(AK8975_MODE_POWERDOWN) != AKD_SUCCESS) {
		DBGPRINT(DBG_LEVEL1, 
				 "%s:%d Error.\n", __FUNCTION__, __LINE__);
	}

	closeFormation();
	closeKey();
}
Ejemplo n.º 6
0
bool XMLParser::parse() {

	if (_stream == 0)
		return parserError("XML stream not ready for reading.");

	if (_XMLkeys == 0)
		buildLayout();

	while (!_activeKey.empty())
		freeNode(_activeKey.pop());

	cleanup();

	bool activeClosure = false;
	bool activeHeader = false;
	bool selfClosure;

	_state = kParserNeedHeader;
	_activeKey.clear();

	_char = _stream->readByte();

	while (_char && _state != kParserError) {
		if (skipSpaces())
			continue;

		if (skipComments())
			continue;

		switch (_state) {
		case kParserNeedHeader:
		case kParserNeedKey:
			if (_char != '<') {
				parserError("Parser expecting key start.");
				break;
			}

			if ((_char = _stream->readByte()) == 0) {
				parserError("Unexpected end of file.");
				break;
			}

			if (_state == kParserNeedHeader) {
				if (_char != '?') {
					parserError("Expecting XML header.");
					break;
				}

				_char = _stream->readByte();
				activeHeader = true;
			} else if (_char == '/') {
				_char = _stream->readByte();
				activeClosure = true;
			} else if (_char == '?') {
				parserError("Unexpected header. There may only be one XML header per file.");
				break;
			}

			_state = kParserNeedKeyName;
			break;

		case kParserNeedKeyName:
			if (!parseToken()) {
				parserError("Invalid key name.");
				break;
			}

			if (activeClosure) {
				if (_activeKey.empty() || _token != _activeKey.top()->name) {
					parserError("Unexpected closure.");
					break;
				}
			} else {
				ParserNode *node = allocNode(); //new ParserNode;
				node->name = _token;
				node->ignore = false;
				node->header = activeHeader;
				node->depth = _activeKey.size();
				node->layout = 0;
				_activeKey.push(node);
			}

			_state = kParserNeedPropertyName;
			break;

		case kParserNeedPropertyName:
			if (activeClosure) {
				if (!closeKey()) {
					parserError("Missing data when closing key '%s'.", _activeKey.top()->name.c_str());
					break;
				}

				activeClosure = false;

				if (_char != '>')
					parserError("Invalid syntax in key closure.");
				else
					_state = kParserNeedKey;

				_char = _stream->readByte();
				break;
			}

			selfClosure = false;

			if (_char == '/' || (_char == '?' && activeHeader)) {
				selfClosure = true;
				_char = _stream->readByte();
			}

			if (_char == '>') {
				if (activeHeader && !selfClosure) {
					parserError("XML Header must be self-closed.");
				} else if (parseActiveKey(selfClosure)) {
					_char = _stream->readByte();
					_state = kParserNeedKey;
				}

				activeHeader = false;
				break;
			}

			if (selfClosure)
				parserError("Expecting key closure after '/' symbol.");
			else if (!parseToken())
				parserError("Error when parsing key value.");
			else
				_state = kParserNeedPropertyOperator;

			break;

		case kParserNeedPropertyOperator:
			if (_char != '=')
				parserError("Syntax error after key name.");
			else
				_state = kParserNeedPropertyValue;

			_char = _stream->readByte();
			break;

		case kParserNeedPropertyValue:
			if (!parseKeyValue(_token))
				parserError("Invalid key value.");
			else
				_state = kParserNeedPropertyName;

			break;

		default:
			break;
		}
	}

	if (_state == kParserError)
		return false;

	if (_state != kParserNeedKey || !_activeKey.empty())
		return parserError("Unexpected end of file.");

	return true;
}