Example #1
0
static int8_t _gsmRead(char *resp, uint8_t size)
{
	int8_t len = 0;

	ASSERT(resp);

	// Init response vector
	resp[0]='\0';

	// NOTE: kfile_gets returns also "empty" lines.
	// Loop to get a (not null) text lines (or EOF, e.g. timeout)
	WATCHDOG_RESET();
	do {
		len = kfile_gets(&(gsm->fd), (void*)resp , size);
		if (len==-1) {
			gsmDebug("RX FAILED\n");
			return len;
		}
		WATCHDOG_RESET();
	} while (!len);

	gsmDebug("RX [%s]\n", resp);

	// Wait a while before allowing for a new GSM command
	timer_delay(200);

	return len;
}
Example #2
0
static void NORETURN hadarp_process(void)
{
	char buf[16];

	while (1)
	{
		if (sig_check(SIG_POLIFEMO))
			kfile_putc('@', &ser.fd);

		if (kfile_gets(&ser.fd, buf, sizeof(buf)) == EOF)
		{
			hadarp_cnt = -1;
			kfile_clearerr(&ser.fd);
			continue;
		}

		if (buf[0] == '\0')
		{
			/* Discard empty strings */
			continue;
		}


		char *endptr = buf;
		int hadarp_raw = strtol(buf, &endptr, 10);

		if (*endptr != '\0' || hadarp_raw > 10000 || hadarp_raw < 0)
			hadarp_cnt = -1;
		else
		{
			/* Compensate for geiger tube dead time */
			float cps = hadarp_raw / 60.0;
			hadarp_cnt = ABS(cps / (1.0 - (cps * 1.9e-4)) * 60.0 + 0.5);
		}
		LOG_INFO("HADARP cnt:%d\n", hadarp_cnt);
	}
}
Example #3
0
void protocol_run(KFile *fd)
{
	/**
	 * \todo to be removed, we could probably access the serial FIFO
	 * directly
	 */
	static char linebuf[80];

	if (!interactive)
	{
		kfile_gets(fd, linebuf, sizeof(linebuf));

		// reset serial port error anyway
		kfile_clearerr(fd);

		// check message minimum length
		if (linebuf[0])
		{
			/* If we enter lines beginning with sharp(#)
			they are stripped out from commands */
			if(linebuf[0] != '#')
			{
				if (linebuf[0] == 0x1B && linebuf[1] == 0x1B)  // ESC
				{
					interactive = true;
					kfile_printf(fd, "Entering interactive mode\r\n");
				}
				else
				{
					protocol_parse(fd, linebuf);
				}
			}
		}
	}
	else
	{
		const char *buf;

		/*
		 * Read a line from serial. We use a temporary buffer
		 * because otherwise we would have to extract a message
		 * from the port immediately: there might not be any
		 * available, and one might get free while we read
		 * the line. We also add a fake ID at the start to
		 * fool the parser.
		 */
		buf = rl_readline(&rl_ctx);

		/* If we enter lines beginning with sharp(#)
		they are stripped out from commands */
		if(buf && buf[0] != '#')
		{
			if (buf[0] != '\0')
			{
				// exit special case to immediately change serial input
				if (!strcmp(buf, "exit") || !strcmp(buf, "quit"))
				{
					rl_clear_history(&rl_ctx);
					kfile_printf(fd, "Leaving interactive mode...\r\n");
					interactive = FORCE_INTERACTIVE;
				}
				else
				{
					//TODO: remove sequence numbers
					linebuf[0] = '0';
					linebuf[1] = ' ';

					strncpy(linebuf + 2, buf, sizeof(linebuf) - 3);
					linebuf[sizeof(linebuf) - 1] = '\0';
					protocol_parse(fd, linebuf);
				}
			}
		}
	}
}