void BMDSmartViewClient::runLoop(uint16_t delayTime) {

	unsigned long enterTime = millis();

	do {
	 	// if there are incoming bytes available 
		// from the server, read them and process them:
		if (_client.connected()) {
			while (_client.available()) {
				char c = _client.read();

				if (c==10)	{	// Line break:
					_parseline();
					_resetLineBuffer();
				} else if (_linebufferPointer<BMDSmartViewClient_BUFFERSIZE-1)	{	// one byte for null termination
					_linebuffer[_linebufferPointer] = c;
					_linebufferPointer++;
				} else {
					if (_serialOutput)	Serial.println(F("ERROR: Buffer overflow."));
				}
			}
/*		
				// Request an acknowledge message:
			if (hasTimedOut(_lastIncomingMsg,_ackMsgInterval) && _isReady)	{
				setBorder(0, getBorder(0));	// Unfortunately there is no "PING" command on this protocol, so we just set a random of the parameters to its current value to provoke an "ACK" in return.
			}
				// Disconnect if no answer 2000 ms later:
			if (hasTimedOut(_lastIncomingMsg,_ackMsgInterval+2000))	{	// Has 2 seconds to respond, otherwise we disconnect to initiate a reconnect...
				disconnect();
			}
*/		}

	
		// if the server's disconnected, stop the client:
		// ACTUALLY: _client.connected() returns true EVEN if I remove the cable! So what use is it??? None... (aug. 2013)
		if (!_client.connected()) {
			if (_devicePresent)	{
				disconnect();
			} else {
				if (hasTimedOut(_lastReconnectAttempt,_reconnectInterval))	{
					connect();
				}
			}
		}
	} while (delayTime>0 && !hasTimedOut(enterTime,delayTime));
}
/**
 * Reads information from the videohub as it arrives, does the parsing, stores in memory
 */
void BMDVideohubClient::runLoop() {
  	// if there are incoming bytes available 
	// from the server, read them and print them:
	while (_client.available()) {
		char c = _client.read();

		if (c==10)	{	// Line break:
			if (serialOutput) {
				for (uint8_t i = 0; i < _linebufferPointer+1; i++) {
					Serial.print(_linebuffer[i]);
				}
				Serial.println("");
			}
			_parseline();
			memset(_linebuffer,0,40-1);
			_linebufferPointer=0;
		} else if (_linebufferPointer<40-1)	{	// one byte for null termination
			_linebuffer[_linebufferPointer] = c;
			_linebufferPointer++;
		} else {
			if (serialOutput) {
				Serial.println(PSTR("ERROR: Buffer overflow."));
			}
		}
	}
	
	// if the server's disconnected, stop the client:
	if (!_client.connected()) {
		if (serialOutput) {
			Serial.println();
			Serial.println(PSTR("disconnecting."));
		}
		_client.stop(); // stop the client
		_isConnected = false; // update status
	}
}
Beispiel #3
0
int
conffile_parse(conffile_t cf,
               const char *filename,
               struct conffile_option *options,
               int options_len,
               void *app_ptr,
               int app_data,
               int flags)
{
    int i, temp, len = 0, retval = -1;
    char linebuf[CONFFILE_MAX_LINELEN];

    if (cf == NULL || cf->magic != CONFFILE_MAGIC)
        return -1;

    if (options == NULL || options_len <= 0) {
        cf->errnum = CONFFILE_ERR_PARAMETERS;
        return -1;
    }

    /* Ensure option array is legitimate */ 
    for (i = 0; i < options_len; i++) {
        if (options[i].optionname == NULL
            || strlen(options[i].optionname) >= CONFFILE_MAX_OPTIONNAMELEN
            || options[i].option_type < CONFFILE_OPTION_IGNORE
            || options[i].option_type > CONFFILE_OPTION_LIST_STRING
            || ((options[i].option_type != CONFFILE_OPTION_IGNORE
                 && options[i].option_type != CONFFILE_OPTION_FLAG)
                && options[i].callback_func == NULL)
            || ((options[i].option_type == CONFFILE_OPTION_LIST_INT
                 || options[i].option_type == CONFFILE_OPTION_LIST_DOUBLE
                 || options[i].option_type == CONFFILE_OPTION_LIST_STRING)
                && ((int)options[i].option_type_arg) == 0)
            || options[i].required_count < 0
            || (options[i].option_type != CONFFILE_OPTION_IGNORE
                && options[i].count_ptr == NULL)) {
            cf->errnum = CONFFILE_ERR_PARAMETERS;
            return -1;
        }
    }

    /* Ensure flags are appropriate */
    temp = flags;
    temp &= ~CONFFILE_FLAG_OPTION_CASESENSITIVE;
    temp &= ~CONFFILE_FLAG_OPTION_IGNORE_UNKNOWN;
    if (temp) {
        cf->errnum = CONFFILE_ERR_PARAMETERS;
        return -1;
    }

    if (_setup(cf, filename, options, options_len, app_ptr, app_data, flags) < 0)
        goto cleanup;

    while (cf->end_of_file == 0 && 
           (len = _readline(cf, linebuf, CONFFILE_MAX_LINELEN)) > 0) {

        if (_parseline(cf, linebuf, len) < 0)
            goto cleanup;
    }
  
    if (len < 0)
        goto cleanup;

    cf->line_num = 0;
    /* Check required counts */
    for (i = 0; i < cf->options_len; i++) {
        if (cf->options[i].count_ptr == NULL)
            continue;
        if ((*cf->options[i].count_ptr) < cf->options[i].required_count) {
            strcpy(cf->optionname, cf->options[i].optionname);
            cf->errnum = CONFFILE_ERR_PARSE_OPTION_TOOFEW;
            goto cleanup;
        }
    }

    cf->errnum = CONFFILE_ERR_SUCCESS;
    retval = 0;

 cleanup:
    /* ignore potential error, just return result to user */
    close(cf->fd);
    return retval;
}