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/Vaike/linux/system-addons/apps/vehicle-classify.c

Go to the documentation of this file.
00001 
00002 #include <int_fft.h>
00003 
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <ipc.h>
00007 #include <sensor_app.h>
00008 
00009 int long_len = sizeof(long);
00010 
00011 long classify(long fft_array[], long array_len)
00012 {
00013     long classifier = 0;
00014 
00015     /* determine vehicle class */
00016 
00017     produce(Soap_Long, (unsigned char*)&classifier, long_len);
00018 }
00019 
00020 int ipc_data_port, ipc_cmd_port;
00021 const long s=100, a=22;
00022 const char *my_app = "vehicle-classify";
00023 
00024 void sensor_app()
00025 {
00026     long i = 0, a_size=256;
00027     long s_val, a_val[a_size], fft_val[a_size];
00028 
00029     consume("raw-seismic", (unsigned char*)&s_val, &long_len);
00030     if (s_val  > s ) {  /* seismic trigger */
00031         consume("raw-acoustic", (unsigned char*)&a_val[0], &long_len);
00032         if (a_val[0]  > a ) {  /* acoustic trigger */
00033             while (i < a_size) {
00034                 /* accumulate enough acoustic readings */
00035                 consume("raw-acoustic", (unsigned char*)&a_val[i], &long_len);
00036                 if (a_val[i]  )
00037                     i++;
00038             }
00039             /* external integer FFT algorithm */
00040             fix_fft(fft_val, a_val, a_size, 0);
00041 
00042             /* classification algorithm above */
00043             classify(fft_val, a_size);
00044         }
00045     }
00046 }
00047 
00048 
00049 int main(int argc, char *argv[])
00050 {
00051         if (argc != 3)
00052                 fprintf(stderr, "Usage: %s <data port> <cmd port>", argv[0]);
00053         ipc_data_port = atoi(argv[1]);
00054         ipc_cmd_port = atoi(argv[2]);
00055 
00056        initialize_ipc(-1);
00057 
00058         while (!quitting()) {
00059                 sensor_app();
00060         }
00061        pthread_join(data_thread, NULL);
00062        pthread_join(cmd_thread, NULL);
00063 
00064         return 0;
00065 }
00066 
00067 


© 2007, Los Alamos National Security, LLC.