Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1090 → Rev 1091

/demos/trunk/bca/bca.c
1,224 → 1,224
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/* CVS : $Id: bca.c,v 1.1 2002-10-01 10:25:00 pj Exp $ */
 
/*
* Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.it>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
/****************************************************
* *
* file: bca.c *
* header file: bca.h *
* data: 15/09/2002 *
* creato da: Fabio CALABRESE *
* *
******************************************************
* *
* descrizione: e' il file in cui è descritto il task*
* main del programma S.Ha.R.K. *
* "(B)ase(C)ontr(A)rea". *
* Il codice del programma comprende *
* anche l'implementazione di altri task*
* distribuiti nei seguenti file che *
* quindi sono inclusi: *
* dummy.c *
* control.c *
* aereo.c *
* cannone.c *
* missile.c *
* esplo.c *
* Inoltre è incluso anche il file: *
* scenario.c *
* che descrive come disegnare lo *
* scenario grafico iniziale *
* *
******************************************************/
 
 
// *** Librerie S.Ha.R.K ***
#include <kernel/kern.h>
#include <drivers/keyb.h>
#include <ll/i386/cons.h>
#include <drivers/glib.h>
// *** Librerie Standard C ***
#include <stdlib.h>
// *** Librerie FAB ***
#include "FAB_LIB/FAB_msg.h"
#include "FAB_LIB/FAB_show.h"
#include "FAB_LIB/FAB_tool.h"
#include "FAB_LIB/FAB_grx.h"
// *** Librerie BCA ***
#include "BCA.h"
 
 
char * titolo[10];
 
void scenario();
void info();
#include"scenario.c"
 
PID crea_soft_dummy_radar ();
TASK dummy_radar(void *);
#include"dummy.c"
 
PID crea_soft_control();
TASK control(void *);
#include"control.c"
 
PID crea_soft_aereo_creator();
TASK aereo_creator();
PID crea_hard_aereo(int index);
PID crea_soft_aereo(int index);
TASK aereo(void * index);
#include"aereo.c"
 
PID crea_soft_cannone_creator();
TASK cannone_creator();
PID crea_hard_cannone(int index);
PID crea_soft_cannone(int index);
TASK cannone(void * index);
#include"cannone.c"
 
PID crea_hard_missile();
PID crea_soft_missile();
TASK missile();
#include"missile.c"
 
PID crea_soft_esplo();
TASK esplo(void *);
#include"esplo.c"
 
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
{
struct timespec t;
 
grx_close();
 
/* Default action for an kern exception is */
kern_cli();
ll_gettime(TIME_EXACT, &t),
kern_printf("\nS.Ha.R.K. Exception raised!!!"
"\nTime (s:ns) :%d:%d"
"\nException number:%d"
"\nPID :%d\n",
t.tv_sec, t.tv_nsec, info->si_value.sival_int,
info->si_task);
sys_end();
}
 
void my_close(void *arg)
{ FAB_grx_close();
place(0,0);
info();
}
 
void end_fun(KEY_EVT* k)
{ cprintf("Ending...\n");
sys_end();
}
void incrementa_aerei_fun(KEY_EVT* k)
{ if (aereo_count<AEREO_N_MAX) aereo_count++;
}
void decrementa_aerei_fun(KEY_EVT* k)
{ if (aereo_count>AEREO_N_MIN) aereo_count--;
}
void incrementa_cannoni_fun(KEY_EVT* k)
{ if (cannone_count<CANNONE_N_MAX) cannone_count++;
}
void decrementa_cannoni_fun(KEY_EVT* k)
{ if (cannone_count>CANNONE_N_MIN) cannone_count--;
}
 
int main(int argc, char **argv)
{
PID pid;
 
KEY_EVT k;
keyb_set_map(itaMap);
 
k.flag = 0;
k.scan = KEY_ENT;
k.ascii = 13;
keyb_hook(k,end_fun);
k.flag = 0;
k.scan = KEY_1;
k.ascii = '1';
keyb_hook(k,incrementa_aerei_fun);
k.flag = 0;
k.scan = KEY_2;
k.ascii = '2';
keyb_hook(k,decrementa_aerei_fun);
k.flag = 0;
k.scan = KEY_3;
k.ascii = '3';
keyb_hook(k,incrementa_cannoni_fun);
k.flag = 0;
k.scan = KEY_4;
k.ascii = '4';
keyb_hook(k,decrementa_cannoni_fun);
 
set_exchandler_grx();
 
sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);
 
FAB_grx_open(800,600);
 
/* inizializza il mutex grafico */
app_mutex_init(&grx_mutex);
 
scenario();
 
//---init---
srand(sys_gettime(NULL));
aereo_count = AEREO_N_MIN;
cannone_count = CANNONE_N_MIN;
 
pid=crea_soft_dummy_radar();
task_activate(pid);
 
pid=crea_soft_aereo_creator();
task_activate(pid);
 
pid=crea_soft_cannone_creator();
task_activate(pid);
 
pid=crea_soft_control();
task_activate(pid);
//----------
}
 
 
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/* CVS : $Id: bca.c,v 1.2 2002-10-01 10:33:51 pj Exp $ */
 
/*
* Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.it>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
/****************************************************
* *
* file: bca.c *
* header file: bca.h *
* data: 15/09/2002 *
* creato da: Fabio CALABRESE *
* *
******************************************************
* *
* descrizione: e' il file in cui è descritto il task*
* main del programma S.Ha.R.K. *
* "(B)ase(C)ontr(A)rea". *
* Il codice del programma comprende *
* anche l'implementazione di altri task*
* distribuiti nei seguenti file che *
* quindi sono inclusi: *
* dummy.c *
* control.c *
* aereo.c *
* cannone.c *
* missile.c *
* esplo.c *
* Inoltre è incluso anche il file: *
* scenario.c *
* che descrive come disegnare lo *
* scenario grafico iniziale *
* *
******************************************************/
 
 
// *** Librerie S.Ha.R.K ***
#include <kernel/kern.h>
#include <drivers/keyb.h>
#include <ll/i386/cons.h>
#include <drivers/glib.h>
// *** Librerie Standard C ***
#include <stdlib.h>
// *** Librerie FAB ***
#include "fab_lib/fab_msg.h"
#include "fab_lib/fab_show.h"
#include "fab_lib/fab_tool.h"
#include "fab_lib/fab_grx.h"
// *** Librerie BCA ***
#include "bca.h"
 
 
char * titolo[10];
 
void scenario();
void info();
#include"scenario.c"
 
PID crea_soft_dummy_radar ();
TASK dummy_radar(void *);
#include"dummy.c"
 
PID crea_soft_control();
TASK control(void *);
#include"control.c"
 
PID crea_soft_aereo_creator();
TASK aereo_creator();
PID crea_hard_aereo(int index);
PID crea_soft_aereo(int index);
TASK aereo(void * index);
#include"aereo.c"
 
PID crea_soft_cannone_creator();
TASK cannone_creator();
PID crea_hard_cannone(int index);
PID crea_soft_cannone(int index);
TASK cannone(void * index);
#include"cannone.c"
 
PID crea_hard_missile();
PID crea_soft_missile();
TASK missile();
#include"missile.c"
 
PID crea_soft_esplo();
TASK esplo(void *);
#include"esplo.c"
 
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
{
struct timespec t;
 
grx_close();
 
/* Default action for an kern exception is */
kern_cli();
ll_gettime(TIME_EXACT, &t),
kern_printf("\nS.Ha.R.K. Exception raised!!!"
"\nTime (s:ns) :%d:%d"
"\nException number:%d"
"\nPID :%d\n",
t.tv_sec, t.tv_nsec, info->si_value.sival_int,
info->si_task);
sys_end();
}
 
void my_close(void *arg)
{ FAB_grx_close();
place(0,0);
info();
}
 
void end_fun(KEY_EVT* k)
{ cprintf("Ending...\n");
sys_end();
}
void incrementa_aerei_fun(KEY_EVT* k)
{ if (aereo_count<AEREO_N_MAX) aereo_count++;
}
void decrementa_aerei_fun(KEY_EVT* k)
{ if (aereo_count>AEREO_N_MIN) aereo_count--;
}
void incrementa_cannoni_fun(KEY_EVT* k)
{ if (cannone_count<CANNONE_N_MAX) cannone_count++;
}
void decrementa_cannoni_fun(KEY_EVT* k)
{ if (cannone_count>CANNONE_N_MIN) cannone_count--;
}
 
int main(int argc, char **argv)
{
PID pid;
 
KEY_EVT k;
keyb_set_map(itaMap);
 
k.flag = 0;
k.scan = KEY_ENT;
k.ascii = 13;
keyb_hook(k,end_fun);
k.flag = 0;
k.scan = KEY_1;
k.ascii = '1';
keyb_hook(k,incrementa_aerei_fun);
k.flag = 0;
k.scan = KEY_2;
k.ascii = '2';
keyb_hook(k,decrementa_aerei_fun);
k.flag = 0;
k.scan = KEY_3;
k.ascii = '3';
keyb_hook(k,incrementa_cannoni_fun);
k.flag = 0;
k.scan = KEY_4;
k.ascii = '4';
keyb_hook(k,decrementa_cannoni_fun);
 
set_exchandler_grx();
 
sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);
 
FAB_grx_open(800,600);
 
/* inizializza il mutex grafico */
app_mutex_init(&grx_mutex);
 
scenario();
 
//---init---
srand(sys_gettime(NULL));
aereo_count = AEREO_N_MIN;
cannone_count = CANNONE_N_MIN;
 
pid=crea_soft_dummy_radar();
task_activate(pid);
 
pid=crea_soft_aereo_creator();
task_activate(pid);
 
pid=crea_soft_cannone_creator();
task_activate(pid);
 
pid=crea_soft_control();
task_activate(pid);
//----------
}