00001 // This file is part of MOS, the MANTIS Operating System 00002 // See http://mantis.cs.colorado.edu/ 00003 // 00004 // Copyright (c) 2002 - 2007 University of Colorado, Boulder 00005 // 00006 // All rights reserved. 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are 00010 // met: 00011 // 00012 // * Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // * Redistributions in binary form must reproduce the above 00015 // copyright notice, this list of conditions and the following 00016 // disclaimer in the documentation and/or other materials provided 00017 // with the distribution. 00018 // * Neither the name of the MANTIS Project nor the names of its 00019 // contributors may be used to endorse or promote products derived 00020 // from this software without specific prior written permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 // POSSIBILITY OF SUCH DAMAGE. 00034 00035 00042 #ifndef GEVENT_H_ 00043 #define GEVENT_H_ 00044 00045 #include "mos.h" 00046 00047 /* The default address for the simulation server is localhost. 00048 * Use -vizaddress on the command line to change it. 00049 */ 00050 #define GEVENT_ADDRESS "127.0.0.1" 00051 /* The default port for the sending to the simulation server is 1521. 00052 * Use -vizsendport on the command line to change it. 00053 */ 00054 #define GEVENT_SEND_PORT 1521 00055 /* The default port for receiving events from the simulation server is the 00056 * value of the node's ID. Use -vizrecvport on the command line to change it. 00057 */ 00058 00059 /* These event types should match those in src/tools/tenodera/modules/events.py 00060 * Some of these are not used in XMOS, but are included so you know they are 00061 * already reserved. 00062 */ 00063 #define NEW_NODE_EVENT 1 00064 #define REMOVE_NODE_EVENT 2 00065 #define RADIO_PACKET_EVENT 3 00066 #define NET_SUBSCRIBE_EVENT 4 00067 #define NET_UNSUBSCRIBE_EVENT 5 00068 #define LED_EVENT 6 00069 #define EXIT_EVENT 7 00070 #define MOVE_NODE_EVENT 8 00071 #define RADIO_MODEL_LINK 9 00072 #define REMOVE_ALL_EVENT 10 00073 #define RADIO_MODEL_FORWARD 11 00074 #define LAUNCH_NODE_EVENT 12 00075 #define DISCONNECT_NODE_EVENT 13 00076 #define KILL_NODE_EVENT 14 00077 00078 #define MAX_EVENT_TYPE 14 00079 00080 #define MAX_EVENT_SIZE 256 00081 00082 /* This stuff only works in XMOS. */ 00083 #ifdef PLATFORM_LINUX 00084 00085 #include <stdint.h> 00086 00087 /* Set to non-zero if we have successfully connected to the simulation server. 00088 * Unset this if the connection has had an unrecoverable error. 00089 */ 00090 extern int gevent_connected; 00091 00092 /* Set up connection to the simulation server and start the receive thread. 00093 * You must start the node with the -viz argument if you want to connect 00094 * to the simulation server. 00095 * Returns 0 on success, -1 on error. 00096 */ 00097 int gevent_init(); 00098 00099 /* Format the arguments into a packet. Format string tells how to 00100 * pack the data: 00101 * 00102 * Ni - next N arguments are 32-bit ints 00103 * Ns - next argument points to an array of char, copy N chars from it 00104 * x - get N from next argument, then copy N chars from subsequent argument 00105 * 00106 * If the server is not up, output the arguments with printf() using 'message' 00107 * as the format string. 00108 * Returns 0 on success, -1 on error. 00109 */ 00110 int gevent_send(uint32_t type, const char* format, const char* message, ...); 00111 00112 /* Receive and parse an event from the simulation server. 00113 * This function blocks until an event is available. 00114 * Format string tells how to fill in arguments: 00115 * 00116 * Ni - next N arguments are pointers to 32-bit ints 00117 * Ns - copy N chars to the next argument, which points to a char array 00118 * x - copy the rest of the packet into a char array 00119 * 00120 * Returns size of event on success, -1 on error. 00121 */ 00122 int gevent_recv(uint32_t type, const char* format, ...); 00123 00124 #else /* We are compiling for the sensor node; the gevent functions do nothing. */ 00125 00126 #define gevent_connected 0 00127 #define gevent_init() 0 00128 #define gevent_send(type,format,msg,args...) 0 00129 #define gevent_recv(type,format,args...) 0 00130 00131 #endif /* PLATFORM_LINUX */ 00132 00133 #endif /* GEVENT_H_ */
1.4.6