Changeset 575

Show
Ignore:
Timestamp:
05/04/08 18:29:26 (2 weeks ago)
Author:
agr
Message:

SAMPL gateway calibration update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nano-RK/projects/SAMPL/slip-clients/tests/stats-pkt/main.c

    r548 r575  
    296296        printf( "  dst mac\t\t0x%x\n",gw_pkt->dst_mac); 
    297297        printf( "  last hop mac\t\t0x%x\n",gw_pkt->last_hop_mac); 
    298         printf( "  rssi\t\t0x%x\n",gw_pkt->rssi); 
     298        printf( "  rssi\t\t\t%d\n",(int8_t)gw_pkt->rssi); 
    299299        printf( "Payload Data: " ); 
    300300        for(i=0; i<gw_pkt->payload_len; i++ ) 
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/ff_config.txt

    r566 r575  
    2929# 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x78 0x64 0xd3 0x00 0x00 0x00 0x00 0x00 
    3030# 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x78 0x64 0xd3 0x00 0x00 0x00 0x00 0x00 
    31 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0xf0 0x32 0xd3 0x00 0x00 0x00 0x00 0x00 
     310x01 0x01 0x39 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x10 0x32 0xd3 0x00 0x00 0x00 0x00 0x00 
    3232 
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/main.c

    r572 r575  
    1414#include "globals.h" 
    1515#include "xmpp_pkt_writer.h" 
     16#include "sensor_cal.h" 
    1617 
    1718#define SEQ_CACHE_SIZE  24 
     
    5960SAMPL_DOWNSTREAM_PKT_T ds_pkt; 
    6061 
    61 int main (int argc, char *argv[]) 
    62 
    63   FILE *fp; 
     62char slip_server[128]; 
     63uint32_t slip_port; 
     64FILE *fp; 
     65char buf[1024]; 
     66 
     67void *main_publish_loop(gpointer data) 
     68
     69 
    6470  uint8_t tx_buf[128]; 
    6571  uint8_t rx_buf[128]; 
     
    7076  int32_t tmp; 
    7177  time_t reply_timeout, nav_timeout,t; 
    72   uint8_t cmd_ready,error,param,ret; 
    73   char buf[1024]; 
     78  uint8_t cmd_ready,error,ret; 
     79  char token[64]; 
    7480  char name[64]; 
    75   char token[64]; 
    76   char username[64]; 
    77   char xmpp_file_name[128]; 
    78   char sampl_file_name[128]; 
    79   char password[64]; 
    80   char xmpp_server[64]; 
    81   char xmpp_ssl_fingerprint[64]; 
    82   char pubsub_server[64]; 
    83   uint32_t xmpp_server_port; 
    84    
    85  
    86 debug_txt_flag=0; 
    87 xmpp_flag=0; 
    88 no_slip_flag=0; 
    89 print_input_flag=0; 
    90 connection=NULL; 
    91  
    92   if (argc < 3 || argc > 6) { 
    93     printf ("Usage: server port [-vxnf] [xmmp_config_name] [sampl_config_name]\n"); 
    94     printf ("  v Print Verbose Debug\n"); 
    95     printf ("  x Send data to XMPP server\n"); 
    96     printf ("  n Don't send SLIP packets (but receive them)\n"); 
    97     printf ("  f Use the following config files instead of the defaults\n"); 
    98     exit (1); 
    99   } 
    100  
    101   strcpy( xmpp_file_name, "xmpp_config.txt" ); 
    102   strcpy( sampl_file_name, "ff_config.txt" ); 
    103   if(argc>3) 
    104         { 
    105         // Grab dash command line options 
    106         if(strstr(argv[3],"v")!=NULL ) 
    107                 { 
    108                 printf( "Verbose Mode ON\n" ); 
    109                 debug_txt_flag=1; 
    110                 } 
    111         if(strstr(argv[3],"x")!=NULL ) 
    112                 {        
    113                 printf( "XMPP ON\n" ); 
    114                 xmpp_flag=1; 
    115                 } 
    116         if(strstr(argv[3],"n")!=NULL ) 
    117                 {        
    118                 printf( "SLIP TX OFF\n" ); 
    119                 no_slip_flag=1; 
    120                 } 
    121         if(strstr(argv[3],"f")!=NULL ) 
    122                 { 
    123                         printf( "Loading XMPP config: " ); 
    124                         strcpy(xmpp_file_name, argv[4]); 
    125                         printf( "%s\n",xmpp_file_name ); 
    126                         printf( "Loading SAMPL config: " ); 
    127                         strcpy(sampl_file_name, argv[5]); 
    128                         printf( "%s\n",sampl_file_name ); 
    129                 } 
    130         } 
    131  
    132   if(xmpp_flag) 
    133   { 
    134   fp=fopen( xmpp_file_name,"r" ); 
    135   if(fp==NULL) 
    136         { 
    137         printf( "XMPP config: No %s file!\n",xmpp_file_name ); 
    138         exit(0); 
    139         } 
    140         param=0; 
    141         do { 
    142           v=fscanf( fp, "%[^\n]\n", buf); 
    143           if(buf[0]!='#' && v!=-1) 
    144           {      
    145                 switch(param) 
    146                 { 
    147                 case 0: strcpy(username,buf);  break; 
    148                 case 1: strcpy(password,buf);  break; 
    149                 case 2: strcpy(xmpp_server,buf);  break; 
    150                 case 3: xmpp_server_port=atoi(buf);  break; 
    151                 case 4: strcpy(pubsub_server,buf); break; 
    152                 case 5: strcpy(xmpp_ssl_fingerprint,buf); break; 
    153                 } 
    154                 param++; 
    155           } 
    156  
    157         }while(v!=-1 && param<6 ); 
    158         if(debug_txt_flag) 
    159         { 
    160         printf( "XMPP Client Configuration:\n" ); 
    161         printf( "  username: %s\n",username ); 
    162         printf( "  password: %s\n",password); 
    163         printf( "  xmpp server: %s\n",xmpp_server); 
    164         printf( "  xmpp server port: %d\n",xmpp_server_port); 
    165         printf( "  xmpp pubsub server: %s\n",pubsub_server); 
    166         printf( "  xmpp ssl fingerprint: %s\n\n",xmpp_ssl_fingerprint); 
    167         } 
    168         if(param<4) 
    169         { 
    170         printf( "Not enough xmpp configuration parameters in xmpp_config.txt\n" ); 
    171         exit(0); 
    172         } 
    173          
    174         connection = start_xmpp_client(username,  
    175                                 password,  
    176                                 xmpp_server,  
    177                                 xmpp_server_port,  
    178                                 xmpp_ssl_fingerprint,  
    179                                 pubsub_server,  
    180                                 NULL); 
    181  
    182         if(connection == NULL) { 
    183                 g_printerr("Could not start client.\n"); 
    184                 return -1; 
    185         } 
    186      fclose(fp); 
    187      if(debug_txt_flag) printf("Initialized XMPP client\n"); 
    188   } 
    189  
    190  
    191   fp=fopen( sampl_file_name,"r" ); 
    192   if(fp==NULL) { 
    193         printf( "SAMPL config: No %s file!\n",sampl_file_name ); 
    194         printf( "This is required for sending control commands\n" ); 
    195         exit(0); 
    196   } 
    197  
    198   // clear list of nodes 
    199   node_list_init(); 
    200   seq_num_cache_init(); 
    201  
    202   sscanf(username,"%[^@]",name); 
    203   node_list_add(name); 
    204  
    205   if(xmpp_flag==1) 
    206   { 
    207         // generate parent node for gateway 
    208         ret = create_event_node(connection, name,NULL,FALSE); 
    209         if(ret != XMPP_NO_ERROR) { 
    210                 if(ret == XMPP_ERROR_NODE_EXISTS) 
    211                         if(debug_txt_flag) printf("Node '%s' already exists\n",name); 
    212                 else { 
    213                 g_printerr("Could not create event node '%s'. Error='%s'\n",name,ERROR_MESSAGE(ret)); 
    214                 return -1; 
    215                 } 
    216     } else if(debug_txt_flag) printf("Created event node '%s'\n",name); 
    217  
    218   } 
    219  
    220  
    221  
    222   v=slipstream_open(argv[1],atoi(argv[2]),NONBLOCKING); 
     81 
     82 
     83 
     84  v=slipstream_open(slip_server,slip_port,NONBLOCKING); 
     85  //v=slipstream_open(argv[1],atoi(argv[2]),NONBLOCKING); 
    22386  seq_num = 0; 
    22487 
     
    317180 
    318181} 
     182 
     183 
     184 
     185 
     186 
     187} 
     188 
     189 
     190int main (int argc, char *argv[]) 
     191{ 
     192  GThread *main_thread = NULL; 
     193  GError *error = NULL; 
     194  GMainLoop *main_loop = NULL; 
     195 
     196  char name[64]; 
     197  char username[64]; 
     198  char xmpp_file_name[128]; 
     199  char sampl_file_name[128]; 
     200  char password[64]; 
     201  char xmpp_server[64]; 
     202  char xmpp_ssl_fingerprint[64]; 
     203  char pubsub_server[64]; 
     204  uint32_t xmpp_server_port; 
     205  uint8_t param;  
     206  int32_t v,ret; 
     207  
     208debug_txt_flag=0; 
     209xmpp_flag=0; 
     210no_slip_flag=0; 
     211print_input_flag=0; 
     212connection=NULL; 
     213 
     214  if (argc < 3 || argc > 6) { 
     215    printf ("Usage: server port [-vxnf] [xmmp_config_name] [sampl_config_name]\n"); 
     216    printf ("  v Print Verbose Debug\n"); 
     217    printf ("  x Send data to XMPP server\n"); 
     218    printf ("  n Don't send SLIP packets (but receive them)\n"); 
     219    printf ("  f Use the following config files instead of the defaults\n"); 
     220    exit (1); 
     221  } 
     222 
     223  strcpy( xmpp_file_name, "xmpp_config.txt" ); 
     224  strcpy( sampl_file_name, "ff_config.txt" ); 
     225  if(argc>3) 
     226        { 
     227        // Grab dash command line options 
     228        if(strstr(argv[3],"v")!=NULL ) 
     229                { 
     230                printf( "Verbose Mode ON\n" ); 
     231                debug_txt_flag=1; 
     232                } 
     233        if(strstr(argv[3],"x")!=NULL ) 
     234                {        
     235                printf( "XMPP ON\n" ); 
     236                xmpp_flag=1; 
     237                } 
     238        if(strstr(argv[3],"n")!=NULL ) 
     239                {        
     240                printf( "SLIP TX OFF\n" ); 
     241                no_slip_flag=1; 
     242                } 
     243        if(strstr(argv[3],"f")!=NULL ) 
     244                { 
     245                        printf( "Loading XMPP config: " ); 
     246                        strcpy(xmpp_file_name, argv[4]); 
     247                        printf( "%s\n",xmpp_file_name ); 
     248                        printf( "Loading SAMPL config: " ); 
     249                        strcpy(sampl_file_name, argv[5]); 
     250                        printf( "%s\n",sampl_file_name ); 
     251                } 
     252        } 
     253 
     254  if(xmpp_flag) 
     255  { 
     256  fp=fopen( xmpp_file_name,"r" ); 
     257  if(fp==NULL) 
     258        { 
     259        printf( "XMPP config: No %s file!\n",xmpp_file_name ); 
     260        exit(0); 
     261        } 
     262        param=0; 
     263        do { 
     264          v=fscanf( fp, "%[^\n]\n", buf); 
     265          if(buf[0]!='#' && v!=-1) 
     266          {      
     267                switch(param) 
     268                { 
     269                case 0: strcpy(username,buf);  break; 
     270                case 1: strcpy(password,buf);  break; 
     271                case 2: strcpy(xmpp_server,buf);  break; 
     272                case 3: xmpp_server_port=atoi(buf);  break; 
     273                case 4: strcpy(pubsub_server,buf); break; 
     274                case 5: strcpy(xmpp_ssl_fingerprint,buf); break; 
     275                } 
     276                param++; 
     277          } 
     278 
     279        }while(v!=-1 && param<6 ); 
     280 
     281        if(debug_txt_flag) 
     282        { 
     283        printf( "XMPP Client Configuration:\n" ); 
     284        printf( "  username: %s\n",username ); 
     285        printf( "  password: %s\n",password); 
     286        printf( "  xmpp server: %s\n",xmpp_server); 
     287        printf( "  xmpp server port: %d\n",xmpp_server_port); 
     288        printf( "  xmpp pubsub server: %s\n",pubsub_server); 
     289        printf( "  xmpp ssl fingerprint: %s\n\n",xmpp_ssl_fingerprint); 
     290        } 
     291        if(param<4) 
     292        { 
     293        printf( "Not enough xmpp configuration parameters in xmpp_config.txt\n" ); 
     294        exit(0); 
     295        } 
     296         
     297        connection = start_xmpp_client(username,  
     298                                password,  
     299                                xmpp_server,  
     300                                xmpp_server_port,  
     301                                xmpp_ssl_fingerprint,  
     302                                pubsub_server,  
     303                                NULL); 
     304 
     305        if(connection == NULL) { 
     306                g_printerr("Could not start client.\n"); 
     307                return -1; 
     308        } 
     309     fclose(fp); 
     310     if(debug_txt_flag) printf("Initialized XMPP client\n"); 
     311  } 
     312 
     313 
     314  fp=fopen( sampl_file_name,"r" ); 
     315  if(fp==NULL) { 
     316        printf( "SAMPL config: No %s file!\n",sampl_file_name ); 
     317        printf( "This is required for sending control commands\n" ); 
     318        exit(0); 
     319  } 
     320 
     321  // clear list of nodes 
     322  node_list_init(); 
     323  seq_num_cache_init(); 
     324 
     325  cal_load_params("sensor_cal.txt"); 
     326 
     327  g_thread_init (NULL); 
     328   
     329 
     330   main_loop = g_main_loop_new(NULL,FALSE); 
     331 
     332   main_thread = 
     333   g_thread_create ((GThreadFunc) main_publish_loop, connection, TRUE, &error); 
     334        if (error != NULL) { 
     335                g_printerr ("Thread creation error: <%s>\n", error->message); 
     336                return -1; 
     337        } 
     338 
     339  strcpy(slip_server,argv[1]); 
     340  slip_port=atoi(argv[2]); 
     341if(xmpp_flag==1) 
     342{ 
     343  sscanf(username,"%[^@]",name); 
     344  node_list_add(name); 
     345} 
     346 
     347  if(xmpp_flag==1) 
     348  { 
     349        // generate parent node for gateway 
     350        ret = create_event_node(connection, name,NULL,FALSE); 
     351        if(ret != XMPP_NO_ERROR) { 
     352                if(ret == XMPP_ERROR_NODE_EXISTS) 
     353                        if(debug_txt_flag) printf("Node '%s' already exists\n",name); 
     354                else { 
     355                g_printerr("Could not create event node '%s'. Error='%s'\n",name,ERROR_MESSAGE(ret)); 
     356                return -1; 
     357                } 
     358    } else if(debug_txt_flag) printf("Created event node '%s'\n",name); 
     359 
     360  } 
     361 
     362 
     363   g_print("created thread\n"); 
     364   g_main_loop_run (main_loop); 
     365 
     366 
     367 
    319368} 
    320369 
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/makefile

    r566 r575  
    33 
    44CC=gcc 
    5 LIBS=-llm-library 
     5LIBS=-llm-library -lgthread-2.0 -lm 
    66INCLUDE=-I. -I$(GLIB_INCLUDE) -I$(GLIB_LIB_INCLUDE) -I$(LOUDMOUTH_INCLUDE) -I$(XMPP_LIBRARY_PATH) -I../../include/ -I../../app_pkt_handlers/ 
    77 
    88CFLAGS=-Wall $(INCLUDE) 
    9 LDFLAGS=-L. -L$(XMPP_LIBRARY_PATH) $(LIBS) 
    10 SOURCES=main.c slipstream.c ../../include/pkt_packer.c node_list.c ../../app_pkt_handlers/ping_pkt.c ../../app_pkt_handlers/xmpp_pkt.c ../../app_pkt_handlers/ack_pkt.c xmpp_pkt_writer.c  ../../app_pkt_handlers/ff_basic_sensor_pkt.c 
     9LDFLAGS=-L. -L$(XMPP_LIBRARY_PATH) -L$(GLIB_LIB) $(LIBS) 
     10SOURCES=main.c slipstream.c ../../include/pkt_packer.c node_list.c sensor_cal.c ../../app_pkt_handlers/ping_pkt.c ../../app_pkt_handlers/xmpp_pkt.c ../../app_pkt_handlers/ack_pkt.c xmpp_pkt_writer.c  ../../app_pkt_handlers/ff_basic_sensor_pkt.c 
    1111OBJS=$(SOURCES:.c=.o) 
    1212 
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/xmpp_pkt_writer.c

    r572 r575  
    1010#include <ack_pkt.h> 
    1111#include <ff_basic_sensor_pkt.h> 
     12#include <sensor_cal.h> 
    1213 
    1314char buf[1024]; 
     
    137138time_t timestamp; 
    138139int i,ret,error; 
     140uint32_t c_mac; 
    139141 
    140142if(gw_pkt->payload_len==0) 
     
    147149for(i=0; i<gw_pkt->num_msgs; i++ ) 
    148150  { 
     151   float temp_cal; 
     152   uint16_t light_cal; 
     153 
    149154        sensor_short_pkt_get(&p, gw_pkt->payload, i); 
    150155        sprintf(node_name,"%02x%02x%02x%02x",gw_pkt->subnet_mac[2], 
     
    152157                gw_pkt->subnet_mac[0], 
    153158                p.mac_addr);  
     159 
     160 
     161        c_mac=gw_pkt->subnet_mac[2]<<24 | gw_pkt->subnet_mac[1]<<16 | gw_pkt->subnet_mac[0]<<8 | p.mac_addr; 
     162 
     163        temp_cal=cal_get_temp(p.temperature,((float)(p.battery+100))/100)+cal_get_temp_offset(c_mac); 
     164        light_cal=cal_get_light(p.light, ((float)(p.battery+100))/100)+cal_get_light_offset(c_mac); 
    154165        if(debug_txt_flag==1) printf( "Data for node: %s\n",node_name ); 
    155166        // Check nodes and add them if need be 
     
    163174        { 
    164175         case 1: 
    165                 sprintf(buf,"<Node id=\"%s\" type=\"FIREFLY\" timestamp=\"%s\"> <Sensor name=\"Light\" value=\"%d\"/> <Sensor name=\"Temperature\" value=\"%d\"/> <Sensor name=\"Acceleration\" value=\"%d\"/> <Sensor name=\"Voltage\" value=\"%d\"/> <Sensor name=\"Audio\" value=\"%d\"/> </Node>", 
    166                 node_name,timeStr, p.light, p.temperature, p.acceleration, (p.battery+100),p.sound_level); 
     176                sprintf(buf,"<Node id=\"%s\" type=\"FIREFLY\" timestamp=\"%s\"> <Sensor name=\"Light\" value=\"%d\"/> <Sensor name=\"Temperature\" value=\"%2.2f\"/> <Sensor name=\"Acceleration\" value=\"%d\"/> <Sensor name=\"Voltage\" value=\"%1.2f\"/> <Sensor name=\"Audio\" value=\"%d\"/> </Node>", 
     177                node_name,timeStr, light_cal, temp_cal, p.acceleration, ((float)(p.battery+100))/100,p.sound_level); 
    167178                break; 
    168179         default: