コード例 #1
0
ファイル: geiger.c プロジェクト: JChristensen/geiger
// log data over the serial port
void sendreport(void)
{
    uint32_t cpm;   // This is the CPM value we will report
    if(tick) {  // 1 second has passed, time to report data via UART
        tick = 0;   // reset flag for the next interval

        if (overflow) {
            cpm = cps*60UL;
            mode = 2;
            overflow = 0;
        }
        else if (fastcpm > THRESHOLD) { // if cpm is too high, use the short term average instead
            mode = 1;
            cpm = fastcpm;  // report cpm based on last 5 samples
        } else {
            mode = 0;
            cpm = slowcpm;  // report cpm based on last 60 samples
        }

        // Send CPM value to the serial port
        uart_putstring_P(PSTR("CPS, "));
        utoa(cps, serbuf, 10);      // radix 10
        uart_putstring(serbuf);

        uart_putstring_P(PSTR(", CPM, "));
        ultoa(cpm, serbuf, 10);     // radix 10
        uart_putstring(serbuf);

        uart_putstring_P(PSTR(", uSv/hr, "));

        // calculate uSv/hr based on scaling factor, and multiply result by 100
        // so we can easily separate the integer and fractional components (2 decimal places)
        uint32_t usv_scaled = (uint32_t)(cpm*SCALE_FACTOR); // scale and truncate the integer part

        // this reports the integer part
        utoa((uint16_t)(usv_scaled/10000), serbuf, 10);
        uart_putstring(serbuf);

        uart_putchar('.');

        // this reports the fractional part (2 decimal places)
        uint8_t fraction = (usv_scaled/100)%100;
        if (fraction < 10)
            uart_putchar('0');  // zero padding for <0.10
        utoa(fraction, serbuf, 10);
        uart_putstring(serbuf);

        // Tell us what averaging method is being used
        if (mode == 2) {
            uart_putstring_P(PSTR(", INST"));
        } else if (mode == 1) {
            uart_putstring_P(PSTR(", FAST"));
        } else {
            uart_putstring_P(PSTR(", SLOW"));
        }

        // We're done reporting data, output a newline.
        uart_putchar('\n');
    }
}
コード例 #2
0
ファイル: pc_link.c プロジェクト: anrieff/geiger-counter
static void interpret_command(const char* cmd)
{
	if (!strcmp(cmd, "HELO")) {
		uart_putstring_P(PSTR("O HAI," FIRMWARE_REVISION_STR ",42\n"));
	} else if (!strcmp(cmd, "STATUS")) {
		uart_print_number(battery_get_voltage()); uart_putchar(',');
		uart_print_number(get_uptime_seconds()); uart_putchar(',');
		
		struct LogInfo info;
		logging_get_info(LOG_EEPROM, &info);
		uart_print_number(info.id); uart_putchar(',');
		uart_print_number(info.length); uart_putchar(',');
		uart_print_number(info.res); uart_putchar(',');

		logging_get_info(LOG_SRAM, &info);
		uart_print_number(info.id); uart_putchar(',');
		uart_print_number(info.length); print_newline();
	} else if (!strcmp(cmd, "CLOG")) {
		logging_reset_all();
		uart_putstring_P(PSTR("OK\n"));
	} else if (!strcmp(cmd, "SILENT")) {
		silent = 1;
		uart_putstring_P(PSTR("OK\n"));
	} else if (!strcmp(cmd, "NOISY")) {
		silent = 0;
		uart_putstring_P(PSTR("OK\n"));
	} else if (!strcmp(cmd, "RSLOG") || !strcmp(cmd, "REELOG")) {
		LogEntry e = (cmd[1] == 'E') ? LOG_EEPROM : LOG_SRAM;
		logging_fetch_log(e, print_number_uint16, print_newline);
	} else if (!strcmp(cmd, "GETID")) {
		uart_print_number(nv_read_word(ADDR_device_id));
		print_newline();
	} else if (!strncmp(cmd, "SID ", 4)) {
		uint16_t value = 0;
		for (uint8_t i = 4; cmd[i]; i++)
			value = value * 10 + (cmd[i] - '0');
		nv_update_word(ADDR_device_id, value);
		uart_putstring_P(PSTR("OK\n"));
	} else {
		uart_putstring_P(PSTR("Unknown command!\n"));
	}
}