]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
Created fake wifi agent program for testing purposes
authorTuka Martin <tukamart@fel.cvut.cz>
Sun, 18 Mar 2012 17:48:08 +0000 (18:48 +0100)
committerTuka Martin <tukamart@fel.cvut.cz>
Sun, 18 Mar 2012 17:48:08 +0000 (18:48 +0100)
src/fwp/fwp/demo/fake_wifi_agent.c [new file with mode: 0644]

diff --git a/src/fwp/fwp/demo/fake_wifi_agent.c b/src/fwp/fwp/demo/fake_wifi_agent.c
new file mode 100644 (file)
index 0000000..90f36e2
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ *     @brief fake wifi agent - creates a station manually and send data to frm
+ *
+ */
+
+#include <forb.h>
+#include <stdio.h>
+#include "wifi_agent_idl.h"
+#include "wifi_agent.h"
+
+int atoint(char a)
+{
+       if( (a >= '0') && (a <= '9') )
+               return a - '0';
+       else if ( (a >= 'A') && (a <= 'F') ) 
+               return a - 'A' + 10;
+       else if ( (a >= 'a') && (a <= 'f') ) 
+               return a - 'a' + 10;
+       return 0;
+}
+
+long long mac_addr_string_to_number(char * mac)
+{
+       long long number;
+       long long help;
+       int ix;
+       int ix2;
+       char mac_num[12];
+
+       mac_num[0] = mac[0];
+       mac_num[1] = mac[1];
+       mac_num[2] = mac[3];
+       mac_num[3] = mac[4];
+       mac_num[4] = mac[6];
+       mac_num[5] = mac[7];
+       mac_num[6] = mac[9];
+       mac_num[7] = mac[10];
+       mac_num[8] = mac[12];
+       mac_num[9] = mac[13];
+       mac_num[10] = mac[15];
+       mac_num[11] = mac[16];
+
+       number = 0;
+
+       for(ix = 0; ix <= 12 ; ix++)
+       {       
+               help = 1;
+               for(ix2 = 1; ix2 < 12 - ix; ix2++)
+                       help *= 16;  
+               number += atoint(mac_num[ix]) * help;
+
+       }
+       
+       printf("%llu \n", number);
+       return number;
+}
+
+int main(int argc, char **argv)
+{
+       forb_orb fwp_orb;
+        wifi_agent_idl wai;
+        CORBA_Environment env;
+
+       int rate;
+       char mac_addr[20];
+       int opt;
+       bool opt_daemon = false;
+       char *opt_pidfile = NULL;
+
+       rate = 1;
+
+       opterr = 0;
+       while ((opt = getopt (argc, argv, "d:a:r:")) != -1) {
+
+               switch (opt) {
+                       case 'd':
+                               opt_daemon = true;
+                               opt_pidfile = optarg;
+                               break;
+                       case 'a':
+                               strcpy(mac_addr, optarg);
+                               break;
+                       case 'r':
+                               rate = atoi(optarg);
+                               break;
+                       case '?':
+                               printf("Usage: %s -a mac_addr -r rate\n",
+                                               argv[0]);
+               }
+       }
+
+       if (opt_daemon)
+               forb_daemon_prepare(opt_pidfile);
+
+       fwp_orb = forb_init(&argc, &argv, NULL); /* FORB initialization */
+
+       /* Find our implementation */
+        wai = forb_resolve_reference(fwp_orb, "net.sourceforge.frsh-forb.wai");
+       if(wai == NULL)
+               fprintf(stderr, "failed to create connection\n");       
+       else
+       {       printf("%d \n", rate);
+               wifi_agent_idl_add(wai, rate / 10, mac_addr_string_to_number(mac_addr), &env);
+
+               //TODO: Print state is just for testing purposes - delete                       
+               wifi_agent_idl_print_state(wai, &env);
+       }
+
+       return 0;
+}
+