예제 #1
0
void handle_command() {
  serial_in[serial_in_ctr] = '\0';
  p = serial_out;

  if (!strncmp_P((char*)serial_in, PSTR("TIME"), 4)) {
    handle_time();
  } else if (!strncmp_P((char*)serial_in, PSTR("ACCELVERB"), 9)) {
    handle_accelverb();
  } else if (!strncmp_P((char*)serial_in, PSTR("ACCEL"), 5)) {
    handle_accel();
    p += strlcpy_P(p, off, 64);
  } else if (!strncmp_P((char*)serial_in, PSTR("SCAN"), 4)) {
    flash_scan();
    p += strlcpy_P(p, cmdresult, 64);
    p += sprintf(p, " %03d %03d", flash_addr >> 8, flash_addr & 0xFF);
  } else if (!strncmp_P((char*)serial_in, PSTR("ADDR"), 4)) {
예제 #2
0
/**
 * Send a POST request to the API with four arguments.
 *
 * \param[in] method The method to call.
 * \param[in] key1 Name of the first parameter.
 * \param[in] value1 String value of the first parameter.
 * \param[in] key2 Name of the second parameter.
 * \param[in] value2 String value of the second parameter.
 * \param[in] key3 Name of the third parameter.
 * \param[in] value3 String value of the third parameter.
 * \param[in] key4 Name of the fourth parameter.
 * \param[in] value4 String value of the fourth parameter.
 *
 * \return The number of bytes actually received, -1 in case of failure.
 */
int Api::post(PGM_P method, PGM_P key1, const char* value1, PGM_P key2,
    const char* value2, PGM_P key3, const char* value3, PGM_P key4,
    const char* value4) {
    if (!connected())
        return -1;
    char path[API_PATH_BUFFER_SIZE] = {0};
    snprintf_P(
        path,
        API_PATH_BUFFER_SIZE,
        API_CALL_NO_PARAMS,
        baseUrl_,
        method,
        fixedArgs_
    );
    char host[API_HOST_BUFFER_SIZE] = {0};
    strlcpy_P(host, host_, API_HOST_BUFFER_SIZE);
    char content[API_POST_DATA_BUFFER_SIZE] = {0};
    snprintf_P(
        content,
        API_POST_DATA_BUFFER_SIZE,
        POST_DATA_FOUR_PARAMS,
        key1,
        value1,
        key2,
        value2,
        key3,
        value3,
        key4,
        value4
    );
    return HttpClient::post(buffer_, bufferSize_, host, path, content);
}
//----------------------------------------------------------------------------------------------------------
void setTestName(const __FlashStringHelper* name) 
{
	currentTestName[0]= 0;
	if(name != NULL)
	{
		strlcpy_P(currentTestName, (const char PROGMEM *)name, TEST_NAME_BUFFER_LEN);
	}
	
	countAtLastNameChange = passCount+failCount;
}
예제 #4
0
파일: ntpd.c 프로젝트: anhquang/app-sync
/*---------------------------------------------------------------------------*/
static void
timeout_handler(void)
{
#if CONTIKI_TARGET_AVR_RAVEN
  char buf[48];
  strlcpy_P(buf, ntpmsg, 48);
  uip_udp_packet_send(ntp_conn, buf, 48);
#else
  uip_udp_packet_send(ntp_conn, ntpmsg, 48);
#endif
printf("send ntp packet \n");
}
uint8_t application_function_light_read(uint8_t nargs, uint8_t args[application_num_args][application_length_args], uint16_t size, uint8_t *dst)
{
	static const __flash char ok[]				= "> light sensor %d ok light [%.3f] Lux\n";
	static const __flash char error_bounds[]	= "> invalid sensor\n";
	static const __flash char twi_error[]		= "> twi error\n";
	static const __flash char overflow[]		= "> sensor overflow\n";

	uint8_t	sensor;
	float	light = 0;

	sensor = atoi((const char *)args[1]);

	switch(sensor)
	{
		case(0):	// tsl2550 standard range
		case(1):	// tsl2550 extended range
		{
			switch(read_sensor(&light, (sensor == 1)))
			{
				case(read_io_error):
				{
					strcpy_P((char *)dst, twi_error);
					return(1);
				}

				case(read_overflow):
				{
					strcpy_P((char *)dst, overflow);
					return(1);
				}
			}

			break;
		}

		default:
		{
			strlcpy_P((char *)dst, error_bounds, (size_t)size);
			return(1);
		}
	}

	light *= eeprom_read_light_cal_factor(sensor);
	light += eeprom_read_light_cal_offset(sensor);

	snprintf_P((char *)dst, size, ok, sensor, light);

	return(1);
}
예제 #6
0
/**
 * Send a call to the API with one argument.
 *
 * \param[in] method The method to call.
 * \param[in] key1 Name of the first parameter.
 * \param[in] value1 String value of the first parameter.
 *
 * \return The number of bytes actually received, -1 in case of failure.
 */
int Api::call(PGM_P method, PGM_P key1, const char* value1) {
    if (!connected())
        return -1;
    char path[API_PATH_BUFFER_SIZE] = {0};
    snprintf_P(
        path,
        API_PATH_BUFFER_SIZE,
        API_CALL_ONE_PARAM,
        baseUrl_,
        method,
        fixedArgs_,
        key1, value1
    );
    char host[API_PATH_BUFFER_SIZE] = {0};
    strlcpy_P(host, host_, API_PATH_BUFFER_SIZE);
    return get(buffer_, bufferSize_, host, path);
}
예제 #7
0
/**
 * Save the file located at the given path to the SD card with the provided
 * local name.
 *
 * \param[in] path The path to the file on the host.
 * \param[in] localName The desired name for the local copy of the file.
 *
 * \return true if the download is successfull, false in case of failure.
 */
bool Download::save(const char* path, const char* localName) {
    // check socket
    if (!wifly_->connectedTo_P(host_))
        return false;

    // load host name to SRAM
    char host[DOWNLOAD_HOST_BUFFER_SIZE];
    strlcpy_P(host, host_, DOWNLOAD_HOST_BUFFER_SIZE);

    // fetch content length and compute the number of pieces
    uint32_t fileSize = getContentLength(buffer_, bufferSize_, host, path);
    if (fileSize == 0)
        return false;
    uint16_t nbPieces = (fileSize - 1)/bufferSize_ + 1;

    // create the local file
    if (!sd_->init(SPI_EIGHTH_SPEED, sdChipSelectPin_)) {
        sd_->initErrorHalt();
        return false;
    }
    if (sd_->exists(localName))
        sd_->remove(localName);

    if (!open(localName, O_CREAT | O_WRITE)) {
        return false;
    }

    // download the file piece by piece
    uint32_t firstByte, lastByte;
    for (uint32_t i = 0; i < nbPieces; i++) {
        firstByte = i * bufferSize_;
        if (i < nbPieces - 1)
            lastByte = firstByte + bufferSize_ - 1;
        else if (i == nbPieces - 1)
            lastByte = fileSize - 1;
        while (!getRange(buffer_, bufferSize_, host, path, firstByte, lastByte));
        write(buffer_, lastByte - firstByte + 1);
        sync();
    }

    // close the file
    close();

    return true;
}
예제 #8
0
/**
 * Send a call to the API without any arguments.
 *
 * \param[in] method The method to call.
 *
 * \return The number of bytes actually received, -1 in case of failure.
 */
int Api::post(PGM_P method) {
    if (!connected()) {
        return -1;
    }
    char path[API_PATH_BUFFER_SIZE] = {0};
    snprintf_P(
        path,
        API_PATH_BUFFER_SIZE,
        API_CALL_NO_PARAMS,
        baseUrl_,
        method,
        fixedArgs_
    );
    char host[API_HOST_BUFFER_SIZE] = {0};
    strlcpy_P(host, host_, API_HOST_BUFFER_SIZE);
    int nBytes = HttpClient::post(buffer_, bufferSize_, host, path, "");
    return nBytes;
}
예제 #9
0
/// \brief      Handler for the `help` command
static inline bool exec_help(void)
{
    usb_puts(PSTR(""));
    usb_puts(PSTR("Welcome to the uMIDI serial interface!"));
    usb_printf(PSTR("Software ID: %s" USB_NEWLINE), UMIDI_SOFTWARE_ID);
    usb_puts(PSTR("Built-in commands:"));
    usb_puts(PSTR("    clear             :  Clears the console by printing CR/LFs."));
    usb_puts(PSTR("    fwupdate <s>      :  Initiates a firmware update:"));
    usb_puts(PSTR("                         <s> : firmware update packet size"));
    usb_puts(PSTR("    help              :  Prints this help message."));
    usb_puts(PSTR("    reset             :  Resets the device."));

    if (user_commands_size) {
        usb_puts(PSTR("Special commands:"));
    }

    for (uint8_t i=0; i<user_commands_size; ++i) {
        // Copy strings to RAM for processing
        uint16_t cmd_string_size = strlen_P(user_commands[i].cmd_string)+1;
        char* cmd_string = malloc(cmd_string_size);
        strlcpy_P(cmd_string, user_commands[i].cmd_string, cmd_string_size);

        uint16_t help_string_size = strlen_P(user_commands[i].help_string)+1;
        char* help_string = malloc(help_string_size);
        strlcpy_P(help_string, user_commands[i].help_string, help_string_size);

        // Check if the help string contains newline characters
        const char* first_nl = strchr(help_string, '\n');
        if (first_nl) {
            // Parse specified options / parameters to the command string
            char* params = strtok(help_string, "\n");

            if (help_string == first_nl) {
                // If the first character of the help string is a newline character, the parsed
                // params are actually the first line of the description text.
                usb_printf(PSTR("    %-16s  :  %s" USB_NEWLINE), cmd_string, params);
            }
            else {
                // Append options / parameters to command string and print the whole thing
                char first_column[17] = "";
                snprintf(first_column, sizeof(first_column),
                         "%s %s", cmd_string, params);
                usb_printf(PSTR("    %-16s  :  "), first_column);

                // Complete the first line of the help string
                usb_printf(PSTR("%s" USB_NEWLINE), strtok(NULL, "\n"));
            }

            // Split remaining command description at '\n' chars, pad with spaces and print
            char* tail = strtok(NULL, "\n");
            while (tail) {
                usb_printf(PSTR("                         %s" USB_NEWLINE), tail);
                tail = strtok(NULL, "\n");
            }
        }
        else {
            // Print simple command description
            usb_printf(PSTR("    %-16s  :  %s" USB_NEWLINE), cmd_string, help_string);
        }

        free(help_string);
    }

    usb_puts(PSTR("Please enter a command:"));

    // Success
    return true;
}
예제 #10
0
/**
 * Open a connection to the host.
 *
 * \return true is returned if a connection is successfully opened to the host.
 * Otherwise, false is returned.
 */
bool Api::connect() {
    char host[WIFLY_HOST_BUFFER_SIZE] = {0};
    strlcpy_P(host, host_, WIFLY_HOST_BUFFER_SIZE);
    return HttpClient::connect(host);
}
예제 #11
0
void runShellCommand(const __FlashStringHelper* command, char * retbuffer, uint8_t size)
{
strlcpy_P(commonlyUsedBuffer,(prog_char *)command,commonlyUsedBuffersize);
runShellCommand((char*) commonlyUsedBuffer, retbuffer,  size);
}