N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/server/l4/orbisquartus-l4.cpp

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 
00036 #include <l4/thread/thread.h>
00037 #include <autoconfig.h>
00038 #include "oq_ore.h"
00039 #include <oq.h>
00040 #include <orbisquartus.h>
00041 #include <mini_mpi.h>
00042 #include <daemon.h>
00043 #include "ituner_lcd.h"
00044 
00045 
00046 void OrbisQuartus::_init()
00047 {
00048         ore_args_t args;
00049 
00050         /* print to LCD */
00051         ituner_lcd_init();
00052         ituner_lcd_print(1, " %, version %s", PACKAGE_NAME, PACKAGE_VERSION);
00053         ituner_lcd_print(2, "  Copyright %d.", COPYRIGHT_YEAR);
00054 
00055         args.debug = 0;
00056         args.events = 0;
00057         args.loopback_only = 0;
00058         strncpy(args.mac_address, "", MAC_ADDR_SIZE - 1);
00059 
00060         printf("initializing OQ ore routing\n");
00061         l4thread_create(oq_ore_routing, NULL,  L4THREAD_CREATE_ASYNC);
00062         // need to pass &args
00063 }
00064 
00065 
00066 int OrbisQuartus::_get_config(int argc, char *argv[])
00067 {
00068         int ctl_sock, flag = 0;
00069         //int i, numbytes, recvd_bytes;
00070         //int assign_len, cfg_len;
00071         //char len_str[INTEGER_STRING];
00072         //char *assignmt, *assgn, *sptr, *config;
00073 
00074         MPI_Initialized(&flag);
00075         if (flag == 0) {
00076                 MPI_Init(&argc, &argv);
00077                 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
00078                 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
00079         }
00080         MPI_Comm_socket(MPI_COMM_WORLD, &ctl_sock);
00081 #if 0 
00082         /* block until assignment arrives */
00083         if ((numbytes = recv(ctl_sock, len_str, INTEGER_STRING, 0)) < 0)
00084                 return numbytes;
00085         num_mynodes = atoi(len_str);
00086         assign_len = (2 * num_mynodes) - 1;
00087 
00088         assignmt = (char*) malloc(sizeof(char) * (assign_len + 1));
00089         if ((numbytes = recv(ctl_sock, assignmt, assign_len, 0)) < 0)
00090                 return numbytes;
00091 
00092         mynodes = (unsigned long*) malloc(sizeof(unsigned long) * num_mynodes);
00093         assgn = assignmt;
00094         for (i = 0; i < num_mynodes && 
00095                      (sptr = index(assgn, ',')) != NULL; i++) {
00096                 sptr = '\0';
00097                 sscanf(assgn, "%lu", &mynodes[i]);
00098                 assgn = sptr + 1;
00099         }
00100         sscanf(assgn, "%lu", &mynodes[i]);
00101         free(assignmt);
00102 
00103         /* record config */
00104         if ((numbytes = recv(ctl_sock, len_str, INTEGER_STRING, 0)) < 0)
00105                 return numbytes;
00106         cfg_len = atoi(len_str);
00107 
00108         numbytes = 0;
00109         config = (char*) malloc(sizeof(char) * (cfg_len + 1));
00110         while (numbytes < cfg_len) {
00111                 recvd_bytes = recv(ctl_sock, config, cfg_len, 0);
00112                 numbytes += recvd_bytes;
00113         }
00114         cfg.xml_to_cfg(config);
00115         free(config);
00116 #endif
00117         return 0;
00118 }
00119 
00120 
00121 void OrbisQuartus::stop(void)
00122 {
00123         daemon_quit();
00124         l4thread_shutdown(sim_thread);
00125         l4thread_shutdown(vt_thread);
00126         l4thread_shutdown(ctl_thread);
00127         MPI_Finalize();
00128 }


© 2007, Los Alamos National Security, LLC.