//*****************************************************************************
//
//Command: time24
//
// Set the current system time. Use format "HH:MM:SS"
//
//*****************************************************************************
int
CMD_time24(int argc, char **argv)
{
    const char *pcNext;

    //
    // Check the argument count and return errors for too many or too few.
    //
    if(argc == 1)
    {
        return(CMDLINE_TOO_FEW_ARGS);
    }
    if(argc > 2)
    {
        return(CMDLINE_TOO_MANY_ARGS);
    }

    //
    // Convert the user string to unsigned long hours and minutes.
    //
    g_ui32HourIdx = ustrtoul(argv[1], &pcNext, 10);
    g_ui32MinIdx = ustrtoul(pcNext + 1, NULL, 10);

    //
    // Perform the conversions to a time struct and store in the hibernate
    // module.  Also do some minimal checking on the input data.
    //
    if((g_ui32HourIdx < 24) && (g_ui32MinIdx < 60))
    {
        DateTimeSet();
    }

    return(0);
}
Esempio n. 2
0
//*****************************************************************************
//
// Command: date
//
// Set the current system date.  Use format "DD/MM/YYYY"
//
//*****************************************************************************
int
CMD_date(int argc, char **argv)
{
    const char *pcNext;

    //
    // Check the argument count and return errors for too many or too few.
    //
    if(argc == 1) {
        return(CMDLINE_TOO_FEW_ARGS);
    }
    if(argc > 2) {
        return(CMDLINE_TOO_MANY_ARGS);
    }

    //
    // Convert the date to unsigned long
    //
    g_ui32DayIdx = ustrtoul(argv[1], &pcNext, 10);
    g_ui32MonthIdx = ustrtoul(pcNext+1, &pcNext, 10) - 1;
    g_ui32YearIdx = (ustrtoul(pcNext+1, NULL, 10) - 2000);

    //
    // Perform the conversions to a time struct and store in the hibernate
    // module after doing a minimal amount of validation.
    //
    if((g_ui32DayIdx > 31) || (g_ui32MonthIdx > 11)) {
        return(CMDLINE_INVALID_ARG);
    }

    DateTimeSet();

    return(0);
}
//*****************************************************************************
//
//Command: time12
//
// Set the current system time.  Use format "HH:MM:SS:X" Where X is 'A' or 'P'
// for AM or PM. HH is hours. MM is minutes. SS is seconds.
//
//*****************************************************************************
int
CMD_time12(int argc, char **argv)
{
    const char *pcNext;

    //
    // Check the argument count and return errors for too many or too few.
    //
    if(argc == 1)
    {
        return(CMDLINE_TOO_FEW_ARGS);
    }
    if(argc > 2)
    {
        return(CMDLINE_TOO_MANY_ARGS);
    }

    //
    // Convert the user string to unsigned long hours and minutes.
    //
    g_ui32HourIdx = ustrtoul(argv[1], &pcNext, 10);
    g_ui32MinIdx = ustrtoul(pcNext + 1, &pcNext, 10);

    //
    // Accomodate the PM vs AM modification.  All times are stored internally
    // as 24 hour format.
    //
    if(ustrncmp(pcNext + 1, "PM", 2) == 0)
    {
        if(g_ui32HourIdx < 12)
        {
            g_ui32HourIdx += 12;
        }
    }
    else
    {
        if(g_ui32HourIdx > 11)
        {
            g_ui32HourIdx -= 12;
        }
    }

    //
    // Perform the conversions to a time struct and store in the hibernate
    // module.  Also do some minimal checking on the input data.
    //
    if((g_ui32HourIdx < 24) && (g_ui32MinIdx < 60))
    {
        DateTimeSet();
    }

    return(0);
}