summaryrefslogtreecommitdiff
path: root/digital/beacon/simu/beacon.c
diff options
context:
space:
mode:
Diffstat (limited to 'digital/beacon/simu/beacon.c')
-rw-r--r--digital/beacon/simu/beacon.c108
1 files changed, 39 insertions, 69 deletions
diff --git a/digital/beacon/simu/beacon.c b/digital/beacon/simu/beacon.c
index 5ea8a263..73fc1c8a 100644
--- a/digital/beacon/simu/beacon.c
+++ b/digital/beacon/simu/beacon.c
@@ -22,85 +22,55 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
+
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "position.h"
-#include "common.h"
/* Globals Declaration */
-beacon_value_s beacon;
-opponent_s opponent;
-
-void syntax (void)
-{
- fprintf (stderr,
- "beacon sources_number source1 angle1 ... sourceX angleX\n"
- "example: beacon 2,1,3.2,3,0.82\n"
- );
- exit (1);
-}
-
-void read_tab (const char *s, double *tab, int n)
-{
- assert (n > 0);
- while (n)
- {
- char *sp;
- double v;
- v = strtod (s, &sp);
- if (sp == s)
- syntax ();
- if ((n > 1 && *sp != ',')
- || (n == 1 && *sp != '\0'))
- syntax ();
- s = sp + 1;
- *tab++ = v;
- n--;
- }
-}
+extern opponent_s opponent[MAX_OBSTACLE];
int main (int argc, char **argv)
{
- if (argc < 8 || argc > 10)
- syntax ();
-
- double input[7] = {0};
+ char saisie[30];
+ char ret = 0;
+ int id = 0;
+ float angle = 0;
+ int angle_id = 0;
+ int i = 0;
/* Init global structures */
- init_struct();
-
-
- /* Read Beacon num */
- read_tab (argv[2], input, 1);
-
- /* Read Beacon angle */
- read_tab (argv[3], input+1, 1);
-
- /* Read Beacon num */
- read_tab (argv[4], input+2, 1);
-
- /* Read Beacon angle */
- read_tab (argv[5], input+3, 1);
-
- /* Read Activate filter */
- read_tab (argv[6],input+4, 1);
-
- /* Read last x */
- read_tab (argv[7],input+5, 1);
-
- /* Read last y */
- read_tab (argv[8],input+6, 1);
-
-// printf("Balise %d --- Angle %f\n",(int)input[0],input[1]);
-// printf("Balise %d --- Angle %f\n",(int)input[2],input[3]);
+ init_struct();
- /* Compute position */
- update_position(input[0],input[1]);
- update_position(input[2],input[3]);
-
- /* Return position to the simulator */
- printf("%d\n",(int)opponent.x);
- printf("%d\n",(int)opponent.y);
-
+ while(1)
+ {
+ ret = fgets (saisie, sizeof saisie, stdin);
+ if(ret != NULL)
+ {
+ id = strtol (saisie, NULL, 10);
+ }
+ ret = fgets (saisie, sizeof saisie, stdin);
+ if(ret != NULL)
+ {
+ angle = strtod (saisie, NULL);
+ }
+ ret = fgets (saisie, sizeof saisie, stdin);
+ if(ret != NULL)
+ {
+ angle_id = strtod (saisie, NULL);
+ }
+
+ update_position(id,angle_id,angle);
+
+ /* Return position to the simulator */
+ for(i=1;i<=MAX_OBSTACLE;i++)
+ {
+ printf("%d\n",(int)opponent[i].x);
+ printf("%d\n",(int)opponent[i].y);
+ printf("%d\n",(int)opponent[i].trust);
+ }
+ fflush(stdout);
+ }
return 0;
}
+