Skip to content

Commit

Permalink
Some work on 'watch', 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 268d457 commit 0824835
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 27 deletions.
9 changes: 4 additions & 5 deletions apps/sh/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@
#include <sh/built-in/exit/exit.h>
#include <date/date.h>
#include <whoami/whoami.h>
#include <uptime/uptime.h>


#include <uptime/uptime.h>
#include <watch/watch.h>

volatile bool TERMINAL_MODE = false;
volatile uint32_t cmd_active_index=0;


volatile uint32_t shell_instance_cnt = 0;

volatile struct typed_cmd cmd_active;
Expand All @@ -79,7 +77,8 @@ struct cmd_t *cmds[] =
&cmd_uname,
&cmd_date,
&cmd_whoami,
&cmd_uptime,
&cmd_uptime,
&cmd_watch,
0
};

Expand Down
26 changes: 13 additions & 13 deletions arch/i386/init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
**
** @contributors:
** Amanuel Bogale <amanuel2> : start
** Amanuel Bogale <amanuel2> : start
** Ashish Ahuja <Fortunate-MAN>
**/

/*DEBUG Defined by -DDEBUG Flag*/
Expand Down Expand Up @@ -89,27 +90,26 @@ static inline void kernel_init_early()
*/
void kernelMain(multiboot_info_t* multiboot_structure,uint32_t magicnumber)
{
if(multiboot_structure && magicnumber){};
init_cpu();
setup_driver_handler();
sti();
kernel_init_early();
if(multiboot_structure && magicnumber){};
init_cpu();
setup_driver_handler();
sti();
kernel_init_early();

video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();

video_drivers[VGA_VIDEO_DRIVER_INDEX]->clear();

//init_terminal();
if(pmm_init(multiboot_structure)!=STATUS_OK)
//init_terminal();
if(pmm_init(multiboot_structure)!=STATUS_OK)
panik("PHYSICAL MEMORY NOT INITALIZED CORRECTLY");

__debug_print_memory_size();
__debug_print_memory_size();
//printk("\n");
//__debug_print_cpu_info();

init_terminal();

while(1)
hlt();
while(1)
hlt();
}


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

LIBNAME := bin

Expand Down
4 changes: 2 additions & 2 deletions bin/boneshell/boneshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void loop_terminal()
if (shell_instance_cnt != 1)
printk("Shell #%d\n" , shell_instance_cnt);
printk ("%s release %s started at ", VAR_OSNAME, VAR_RELEASE);
rtc_print_date();
start_time = rtc_get_time();
rtc_print_struct(start_time);
while(1)
{
start_shell:;
Expand Down Expand Up @@ -118,7 +118,7 @@ void loop_terminal()

if(strcmp(cmd_active.value, "exit")==0)
{
shell_instance_cnt-=1;
shell_instance_cnt--;
printk("Exited shell instance #%d\n",shell_instance_cnt+1);
goto end_shell;
}
Expand Down
2 changes: 1 addition & 1 deletion bin/date/opts/main_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main_date_opt_handler (char *cmd)
}
else if (num_opts == 1)
{
rtc_print_date();
rtc_print_struct (rtc_get_time());
return STATUS_OK;
}
else
Expand Down
133 changes: 133 additions & 0 deletions bin/watch/opts/main_watch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
** 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 <string/string.h>
#include <sh/values.h>
#include <watch/watch.h>
#include <strcmp/strcmp.h>
#include <apps/sh/utils.h>
#include <libc/assertk.h>
#include <drv/pit/pit.h>
#include <drv/ps2/kbd/kbd.h>
#include <drv/driver.h>

int main_watch_opt_handler (char *cmd)
{
size_t num_opts = get_opt_count(cmd);
str_t opts[num_opts];
get_opt(cmd,opts);
unsigned interval = 2 * 1000;
char command [125];
command [0] = '\0';
int actual_command_index = 0;

if (num_opts == 1)
{
printk (cmd_watch.invalid_use_msg);
return STATUS_OK;
}
else if (num_opts > 1)
{
if (strcmp (opts [1].str, "--help") == 0)
{
printk (cmd_watch.help);
return STATUS_OK;
}
else
{
for (unsigned i = 1; i < num_opts; i ++)
{
if (!strcmp (opts [i].str, "-n"))
{
if (i == (num_opts - 1))
{
printk (cmd_watch.invalid_use_msg);
return STATUS_OK;
}
else
{
interval = atoi (opts [i + 1].str);
interval *= 1000;
i ++;
}
}
else
{
if (strlen (command) == 0)
{
strcpy (command, opts [i].str);
}
else
{
command [strlen (command)] = ' ';
strcpy (command + (strlen (command)), opts [i].str);
}
if (!actual_command_index)
{
actual_command_index = i;
}
}
}

for(int i=0; cmds[i]; i++)
{
if(termcmp(cmds[i]->name, opts [actual_command_index].str)==0)
{
again: cmds[i]->handler(command);
printk (command);
assertkm(device_initalized(PIT_DRIVER_INDEX) , "PIT NOT INITALIZED FOR SLEEP()");
int64_t expiry = pit_ticks + ((uint64_t)interval * IRQ_SEC_HIT) / 1000;

while (pit_ticks < expiry)
{
kbd_info.scancode = kbd_enc_read_input_buf();
if(kbd_info.scancode & 0x80);
else
{
kbd_info.key = key_press(kbd_info.scancode);
if (kbd_info.key == 'q')
{
return STATUS_OK;
}
}
}

goto again;
}
}

printk (cmd_watch.invalid_use_msg);
return STATUS_OK;
}
}

return STATUS_OK;
}


71 changes: 71 additions & 0 deletions bin/watch/watch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
** 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 <watch/watch.h>
#include <watch/opts/main_watch.h>

struct cmd_opt_t* cmd_watch_opts[] =
{
0
};

int cmd_watch_handler (char *cmd)
{
size_t num_opts = get_opt_count(cmd);
if (num_opts == 1)
{
printk (cmd_watch.invalid_use_msg);
return STATUS_OK;
}
main_watch_opt_handler (cmd);
return STATUS_OK;
}

struct cmd_t cmd_watch =
{
.name = "watch",
.usage ="watch [--help]",
.help = "watch(1) \t\t\t\t BoneOS Terminal Manual \n"
"NAME : \n "
"\twatch\n"
"SYNOPSIS : \n "
"\twatch [option] [command]\n"
"DESCRIPTION : \n "
"\tPrints out the current user.\n"
"OPTIONS : \n "
"[-n <seconds>] Sets the interval to the number of seconds specified.\n",
.cmd_opts = cmd_watch_opts,
.handler = &cmd_watch_handler,
.invalid_use_msg = "Invalid use of watch command.\n"
"Type in watch --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 @@ -51,7 +51,8 @@ struct typed_cmd
#define CMD_UNAME_INDEX 12
#define CMD_DATE_INDEX 13
#define CMD_WHOAMI_INDEX 14
#define CMD_UPTIME_INDEX 15
#define CMD_UPTIME_INDEX 15
#define CMD_WATCH_INDEX 16

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

int main_watch_opt_handler (char *cmd);

#endif /*_BIN_WATCH_MAINOPT_H_*/


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

extern struct cmd_t cmd_watch;

#endif /*_BIN_WATCH_H_*/
3 changes: 2 additions & 1 deletion include/platform/pc/drv/cmos/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ extern uint8_t rtc_get_year();
extern uint8_t rtc_get_century();

extern rtc_t rtc_get_time();
extern void rtc_print_date ();
extern void rtc_print_date ();
void rtc_print_struct (rtc_t current_time);

#endif // _DRV_CMOS_RTC_H_

Expand Down
6 changes: 4 additions & 2 deletions include/platform/pc/drv/ps2/kbd/kbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ extern int uninit_kbd();
* Keyboard Utility Commands
*/
extern const char QWERTY_EN_NOSHIFT[] ;
extern const char QWERTY_EN_SHIFT[];
extern const char QWERTY_EN_SHIFT[];
extern int key_press(uint8_t scancode);
extern uint8_t kbd_ctrl_read_status_reg();
extern void kbd_ctrl_send_cmd(uint8_t cmd);
extern uint8_t kbd_enc_read_input_buf();
Expand Down Expand Up @@ -106,7 +107,8 @@ kbd_info_t
}tests;

uint8_t scancode;
bool is_shift;
bool is_shift;
bool is_ctrl;
bool is_enter;
bool is_caps;
uint32_t current_kbd_layout_index;
Expand Down
13 changes: 13 additions & 0 deletions platform/pc/drv/cmos/rtc/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,16 @@ void rtc_print_date ()
current_time.year);
}

void rtc_print_struct (rtc_t current_time)
{
printk("%s %s %x %x:%x:%x UTC %x%x\n",
date_to_text(current_time.weekday),
month_to_text(current_time.month),
current_time.day,
current_time.hour,
current_time.minute,
current_time.second,
current_time.century,
current_time.year);
}

Loading

0 comments on commit 0824835

Please sign in to comment.