Ejemplo n.º 1
0
/* Might be useful for other USB devices as well. static for now. */
static int parse_voltage(char *voltage)
{
	char *tmp = NULL;
	int i;
	int millivolt = 0, fraction = 0;

	if (!voltage || !strlen(voltage)) {
		msg_perr("Empty voltage= specified.\n");
		return -1;
	}
	millivolt = (int)strtol(voltage, &tmp, 0);
	voltage = tmp;
	/* Handle "," and "." as decimal point. Everything after it is assumed
	 * to be in decimal notation.
	 */
	if ((*voltage == '.') || (*voltage == ',')) {
		voltage++;
		for (i = 0; i < 3; i++) {
			fraction *= 10;
			/* Don't advance if the current character is invalid,
			 * but continue multiplying.
			 */
			if ((*voltage < '0') || (*voltage > '9'))
				continue;
			fraction += *voltage - '0';
			voltage++;
		}
		/* Throw away remaining digits. */
		voltage += strspn(voltage, "0123456789");
	}
	/* The remaining string must be empty or "mV" or "V". */
	tolower_string(voltage);

	/* No unit or "V". */
	if ((*voltage == '\0') || !strncmp(voltage, "v", 1)) {
		millivolt *= 1000;
		millivolt += fraction;
	} else if (!strncmp(voltage, "mv", 2) ||
		   !strncmp(voltage, "millivolt", 9)) {
		/* No adjustment. fraction is discarded. */
	} else {
		/* Garbage at the end of the string. */
		msg_perr("Garbage voltage= specified.\n");
		return -1;
	}
	return millivolt;
}
Ejemplo n.º 2
0
/*
***********************************************************
*    Function: create_file_name()
*
*    Description: Create a time-stamped file_name for send file.
*
*    Input:  none
*    Output: globals gFile_date_time, gFile_name, gExt_contact_id
*
*    Return: void
****************************************************************
*/
void create_file_name(void)
{
    char tmp[8];	/* lowercase clearing house id */
    time_t bintim = time((long)NULL);
    struct tm *lt = localtime(&bintim);

    strcpy(tmp, gCH_curr.clearing_house_id);
    tolower_string(tmp);

    /*  Create filename timestamp (14-chars) */
    sprintf(gFile_date_time,"%04d%02d%02d%02d%02d%02d",
            lt->tm_year + 1900, lt->tm_mon+1, lt->tm_mday,
            lt->tm_hour, lt->tm_min, lt->tm_sec);

    /*  Create filename (18-chars, assuming 3-char clearing_house_id) */
    sprintf(gFile_name, "%d.%s%s.%s", gExt_contact_id, tmp, &gFile_date_time[2],"Pain.008");
}