Пример #1
0
static msg_t GpsThreadEntryPoint(void *arg) {
    (void) arg;
    chRegSetThreadName("GPS thread");

    int count = 0;

    while (true) {
        msg_t charbuf = chSequentialStreamGet(GPS_SERIAL_DEVICE);
        if (charbuf == 10 || count == GPS_MAX_STRING) {					// if 0xD,0xA or limit
            if (count >= 1)
                gps_str[--count] = '\0';					// delete 0xD

//			scheduleMsg(&logger, "got GPS [%s]", gps_str);

            // 'gps_str' string completed
            onGpsMessage(gps_str);
            memset(&gps_str, '\0', GPS_MAX_STRING);			// clear buffer
            count = 0;
        } else {
            gps_str[count++] = charbuf;
        }
    }
#if defined __GNUC__
    return 0;
#endif
}
Пример #2
0
/**
 * @brief   Reads a whole line from the input channel.
 *
 * @param[in] chp       pointer to a @p BaseChannel object
 * @param[in] line      pointer to the line buffer
 * @param[in] size      buffer maximum length
 * @return              The operation status.
 * @retval TRUE         the channel was reset or CTRL-D pressed.
 * @retval FALSE        operation successful.
 */
static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size) {
	char *p = line;

	while (true) {
		if (!isConsoleReady()) {
			// we better do not read from USB serial before it is ready
			chThdSleepMilliseconds(10);
			continue;
		}

		short c = (short) chSequentialStreamGet(chp);

		if (isSerialOverUart()) {
			uint32_t flags;
			chSysLock()
			;

			flags = chEvtGetAndClearFlagsI(&consoleEventListener);
			chSysUnlock()
			;

			if (flags & SD_OVERRUN_ERROR) {
//				firmwareError("serial overrun");
			}

		}

#if EFI_UART_ECHO_TEST_MODE
		/**
		 * That's test code - let's test connectivity
		 */
		consolePutChar((uint8_t) c);
		continue;
#endif

		if (c < 0 || c == 4) {
			return true;
		}
		if (c == 8) {
			if (p != line) {
				// backspace
				consolePutChar((uint8_t) c);
				consolePutChar(0x20);
				consolePutChar((uint8_t) c);
				p--;
			}
			continue;
		}
		if (c == '\r') {
			consolePutChar('\r');
			consolePutChar('\n');
			*p = 0;
			return false;
		}
		if (c == '\n') {
			consolePutChar('\n');
			*p = 0;
			return false;
		}
		if (c < 0x20) {
			continue;
		}
		if (p < line + size - 1) {
			consolePutChar((uint8_t) c);
			*p++ = (char) c;
		}
	}
}