예제 #1
0
static void
vFileTask (void *parameter)
{
    uint32_t pos;
    UINT written;
    uint8_t data;
    static FIL fil;
    portTickType time, time_old;

    /* delay SD card init by 5 seconds */
    vTaskDelay (5000 / portTICK_RATE_MS);

    /* never fails - data init */
    memset (&fatfs, 0, sizeof (fatfs));
    f_mount (0, &fatfs);

    /* opening new file for write access */
    debug_printf ("\nCreating logfile (%s).\n", logfile);
    if (f_open (&fil, logfile, FA_WRITE | FA_CREATE_ALWAYS))
        debug_printf ("\nfailed to create file\n");
    else
    {
        /* Enable Debug output as we were able to open the log file */
        debug_printf ("OpenBeacon firmware version %s\nreader_id=%i.\n", VERSION, env.e.reader_id);
        PtSetDebugLevel (1);

        /* Storing clock ticks for flushing cache action */
        time_old = xTaskGetTickCount ();
        pos = 0;

        for (;;)
            if (xQueueReceive (xLogfile, &data, 100))
            {
                sector_buffer[pos++] = data;
                if (pos == SECTOR_BUFFER_SIZE)
                {
                    pos = 0;
                    if (f_write
                            (&fil, &sector_buffer, sizeof (sector_buffer), &written)
                            || written != sizeof (sector_buffer))
                        debug_printf ("\nfailed to write to logfile\n");
                }

                /* flush file every 5 seconds */
                time = xTaskGetTickCount ();
                if ((time - time_old) > (5000 / portTICK_RATE_MS))
                {
                    time_old = time;
                    if (f_sync (&fil))
                        debug_printf ("\nfailed to flush to logfile\n");
                }
            }
    }
}
예제 #2
0
static inline void
vCmdProcess (const char *cmdline)
{
	unsigned char cmd, assign;
	unsigned int t;

	cmd = (unsigned char) (*cmdline++);
	if ((cmd >= 'a') && (cmd <= 'z'))
		cmd -= ('a' - 'A');

	switch (*cmdline)
	{
		case '=':
		case ' ':
			assign = 1;
			cmdline++;
			break;
		case 0:
			assign = 0;
			break;
		default:
			assign = 1;
	}

	switch (cmd)
	{
		case 'A':
			vNetworkSetIP (&env.e.ip_host, assign ? cmdline : NULL, "reader");
			break;

		case 'B':
			debug_printf ("rebooting...\n");
			vTaskDelay (1000 / portTICK_RATE_MS);
			/*force watchdog reset */
			while (1);
			break;

		case 'C':
			vNetworkDumpConfig ();
			debug_printf ("System configuration:\n"
						  "\tFirmware Version: v" PROGRAM_VERSION "\n"
						  "\tReader ID: %i\n"
						  "\tRF packet duplicate filter: %s\n\n",
						  env.e.reader_id,
						  env.e.filter_duplicates ? "ON" : "OFF");
			break;

		case 'D':
			if (assign)
			{
				t = atoiEx (cmdline);
				debug_printf ("setting debug level to %u\n", t);
				PtSetDebugLevel (t);
			}
			else
				debug_printf
					("usage: 'd' - set debug level ('d[disable=0, lowest=1]')\n");
			break;

		case 'F':
			if (assign)
			{
				t = atoiEx (cmdline) ? 1 : 0;
				debug_printf ("%s duplicate filtering\n",
							  t ? "enabled" : "disabled");
				env.e.filter_duplicates = t;
			}
			else
				debug_printf
					("usage: 'f' - set RF packet duplicate filtering\n"
					 "             ('f[disable=0, enable=1]')\n");
			break;

		case 'G':
			vNetworkSetIP (&env.e.ip_gateway, assign ? cmdline : NULL,
						   "gateway");
			break;

		case 'I':
			if (assign)
			{
#ifndef ALLOW_READER_ID_CHANGE
				if (env.e.reader_id)
					debug_printf ("ERROR: reader id already set!\n");
				else
				{
#endif /*ALLOW_READER_ID_CHANGE */
					t = atoiEx (cmdline);
					if (t > 0 && t < MAC_IAB_MASK)
						env.e.reader_id = t;
					else
						debug_printf
							("error: reader_id needs to be between 1 and %u (used '%s')\n",
							 MAC_IAB_MASK, cmdline);
#ifndef ALLOW_READER_ID_CHANGE
				}
#endif /*ALLOW_READER_ID_CHANGE */
			}
			debug_printf ("reader_id=%i\n", env.e.reader_id);
			break;

		case 'L':
			if (assign)
			{
				t = atoiEx (cmdline) > 0;
				debug_printf ("red_led=%i\n", t);
				led_set_red (t);
			}
			else
				debug_printf
					("usage: 'l' - red LED ('l[enable=0, disable=1]')\n");
			break;

		case 'M':
			vNetworkSetIP (&env.e.ip_netmask, assign ? cmdline : NULL,
						   "netmask");
			break;

		case 'N':
			if (assign)
				env.e.ip_autoconfig = atoiEx (cmdline);
			debug_printf ("ip_autoconfig=%i\n", env.e.ip_autoconfig);
			break;

		case 'P':
			if (assign)
				env.e.ip_server_port = atoiEx (cmdline);
			debug_printf ("server UDP port=%i\n", env.e.ip_server_port);
			break;

		case 'R':
			/* backup reader id */
			t = env.e.reader_id;
			vNetworkResetDefaultSettings ();
			/* restore reader id */
			env.e.reader_id = t;
			debug_printf ("restoring original settings & reboot...\n");
			vNetworkDumpConfig ();
			vTaskDelay (1000 / portTICK_RATE_MS);
			env_store ();
			/*force watchdog reset */
			while (1);
			break;

		case 'S':
			debug_printf ("storing configuration & reboot...\n");
			vTaskDelay (1000 / portTICK_RATE_MS);
			env_store ();
			/*force watchdog reset */
			while (1);
			break;

		case 'T':
			vNetworkSetIP (&env.e.ip_server, assign ? cmdline : NULL,
						   "server");
			break;

		case 'U':
			debug_printf ("resetting reader to firmware update mode...\n");
			vTaskDelay (1000 / portTICK_RATE_MS);
			env_reboot_to_update ();
			break;

		case 'H':
		case '?':
			vCmdHelp ();
			break;

		case 'X':
			vCmdDumpStatistics ();
			PtStatusRxTx ();
			break;

		default:
			debug_printf ("Unkown CMD:'%c'\n", cmd);
	}
}