Skip to content

Commit

Permalink
Some work on uptime command, still not ready for use #125
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Jan 15, 2017
1 parent c4e52d4 commit 34f321b
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 15 deletions.
6 changes: 4 additions & 2 deletions apps/sh/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
#include <drv/cmos/rtc/rtc.h>
#include <sh/built-in/exit/exit.h>
#include <date/date.h>
#include <whoami/whoami.h>
#include <whoami/whoami.h>
#include <uptime/uptime.h>



Expand Down Expand Up @@ -77,7 +78,8 @@ struct cmd_t *cmds[] =
&cmd_logname,
&cmd_uname,
&cmd_date,
&cmd_whoami,
&cmd_whoami,
&cmd_uptime,
0
};

Expand Down
4 changes: 3 additions & 1 deletion bin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ CSRCS = \
date/date.c \
date/opts/main_date.c \
whoami/whoami.c \
whoami/opts/main_whoami.c
whoami/opts/main_whoami.c \
uptime/uptime.c \
uptime/opts/main_uptime.c

LIBNAME := bin

Expand Down
72 changes: 72 additions & 0 deletions bin/uptime/opts/main_uptime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
** This file is part of BoneOS.
**
** BoneOS is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
** BoneOS is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Ashish Ahuja
**
** @contributors:
** Ashish Ahuja<Fortunate-MAN>: start
**/

#include <misc/status_codes.h>
#include <sh/shell.h>
#include <drv/video/video.h>
#include <unistd/unistd.h>
#include <stdio/stdio.h>
#include <stdlib/stdlib.h>
#include <stdlib/itoa/itoa.h>
#include <string/string.h>
#include <sh/values.h>
#include <uptime/uptime.h>
#include <sh/shell.h>

int main_uptime_opt_handler (char *cmd)
{
size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);

rtc_t curr = rtc_get_time();
rtc_t time_since_start;
time_since_start.second = 0;
time_since_start.month = curr.month - start_time.month;
time_since_start.day = curr.day - start_time.day;
time_since_start.hour = curr.hour - start_time.hour;
time_since_start.minute = (uint8_t)(curr.minute - start_time.minute);
time_since_start.second =(uint8_t) (curr.second - start_time.second);
if (num_opts == 1)
{
printk ("%x:%x", time_since_start.minute, time_since_start.second);
return STATUS_OK;
}
else if (num_opts > 1)
{
if (strcmp (opts [1].str, "--help") == 0)
{
printk (cmd_uptime.help);
return STATUS_OK;
}
else
{
printk (cmd_uptime.invalid_use_msg);
return STATUS_OK;
}
}

return STATUS_OK;
}


63 changes: 63 additions & 0 deletions bin/uptime/uptime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
** This file is part of BoneOS.
**
** BoneOS is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
** BoneOS is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Ashish Ahuja
**
** @contributors:
** Ashish Ahuja<Fortunate-MAN>: start
**/

#include <misc/status_codes.h>
#include <sh/shell.h>
#include <drv/video/video.h>
#include <unistd/unistd.h>
#include <stdio/stdio.h>
#include <string/string.h>
#include <sh/values.h>
#include <uptime/uptime.h>
#include <uptime/opts/main_uptime.h>

struct cmd_opt_t* cmd_uptime_opts[] =
{
0
};

int cmd_uptime_handler (char *cmd)
{
main_uptime_opt_handler (cmd);
return STATUS_OK;
}

struct cmd_t cmd_uptime =
{
.name = "uptime",
.usage ="uptime [--help]",
.help = "uptime(1) \t\t\t\t BoneOS Terminal Manual \n"
"NAME : \n "
"\tuptime\n"
"SYNOPSIS : \n "
"\tuptime [option] [--help]\n"
"DESCRIPTION : \n "
"\tTells how long the system has been running.\n",
.cmd_opts = cmd_uptime_opts,
.handler = &cmd_uptime_handler,
.invalid_use_msg = "Invalid use of uptime command.\n"
"Type in uptime --help for more help.\n",
.privilege = USER
};


3 changes: 2 additions & 1 deletion include/apps/sh/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct typed_cmd
#define CMD_LOGNAME_INDEX 11
#define CMD_UNAME_INDEX 12
#define CMD_DATE_INDEX 13
#define CMD_WHOAMI_INDEX 14
#define CMD_WHOAMI_INDEX 14
#define CMD_UPTIME_INDEX 15

extern void init_terminal();
extern struct cmd_t *cmds[];
Expand Down
8 changes: 8 additions & 0 deletions include/bin/uptime/opts/main_uptime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _BIN_UPTIME_MAINOPT_H_
#define _BIN_UPTIME_MAINOPT_H_

int main_uptime_opt_handler (char *cmd);

#endif /*_BIN_UPTIME_MAINOPT_H_*/


6 changes: 6 additions & 0 deletions include/bin/uptime/uptime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _BIN_UPTIME_H_
#define _BIN_UPTIME_H_

extern struct cmd_t cmd_uptime;

#endif /*_BIN_UPTIME_H_*/
11 changes: 0 additions & 11 deletions platform/pc/drv/cmos/rtc/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ rtc_t rtc_get_time()

void rtc_print_date ()
{
/*printk("%s %s %x %x:%x:%x UTC %x%x\n",
date_to_text(rtc_get_weekday()),
month_to_text(rtc_get_month()),
rtc_get_day_month(),
rtc_get_hour(),
rtc_get_minute(),
rtc_get_second() ,
rtc_get_century(),
rtc_get_year());*/

rtc_t current_time = rtc_get_time();

printk("%s %s %x %x:%x:%x UTC %x%x\n",
Expand All @@ -165,6 +155,5 @@ void rtc_print_date ()
current_time.second,
current_time.century,
current_time.year);
//Tue Jan 3 16:06:48 UTC 2017
}

0 comments on commit 34f321b

Please sign in to comment.