Changeset 1845


Ignore:
Timestamp:
04/29/12 23:08:36 (13 months ago)
Author:
thomas
Message:

basic client/server interaction

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/firmware/openos/bsp/boards/pc/board.c

    r1839 r1845  
    1414#include "radiotimer.h" 
    1515#include "eui64.h" 
     16// OpenSim environment 
     17#include "opensim_client.h" 
    1618 
    1719//=========================== variables ======================================= 
     
    2224 
    2325void board_init() { 
    24    // poipoipoi stub 
    25    printf("TODO board_init\r\n"); 
     26   //poipoiopensim_client_send(0); 
    2627} 
    2728 
    2829void board_sleep() { 
    29    // poipoipoi stub 
    30    printf("TODO board_sleep\r\n"); 
     30   //poipoiopensim_client_send(1); 
    3131} 
    3232 
  • trunk/firmware/openos/bsp/boards/pc/bsp_timer.c

    r1839 r1845  
    2222//=========================== public ========================================== 
    2323 
    24 /** 
    25 \brief Initialize this module. 
    26  
    27 This functions starts the timer, i.e. the counter increments, but doesn't set 
    28 any compare registers, so no interrupt will fire. 
    29 */ 
    3024void bsp_timer_init() { 
    3125    
     
    3731} 
    3832 
    39 /** 
    40 \brief Register a callback. 
    41  
    42 \param cb The function to be called when a compare event happens. 
    43 */ 
    4433void bsp_timer_set_callback(bsp_timer_cbt cb) { 
    4534   bsp_timer_vars.cb   = cb; 
    4635} 
    4736 
    48 /** 
    49 \brief Reset the timer. 
    50  
    51 This function does not stop the timer, it rather resets the value of the 
    52 counter, and cancels a possible pending compare event. 
    53 */ 
    5437void bsp_timer_reset() { 
    5538   // poipoipoi stub 
     
    5740} 
    5841 
    59 /** 
    60 \brief Schedule the callback to be called in some specified time. 
    61  
    62 The delay is expressed relative to the last compare event. It doesn't matter 
    63 how long it took to call this function after the last compare, the timer will 
    64 expire precisely delayTicks after the last one. 
    65  
    66 The only possible problem is that it took so long to call this function that 
    67 the delay specified is shorter than the time already elapsed since the last 
    68 compare. In that case, this function triggers the interrupt to fire right away. 
    69  
    70 This means that the interrupt may fire a bit off, but this inaccuracy does not 
    71 propagate to subsequent timers. 
    72  
    73 \param delayTicks Number of ticks before the timer expired, relative to the 
    74                   last compare event. 
    75 */ 
    7642void bsp_timer_scheduleIn(PORT_TIMER_WIDTH delayTicks) { 
    7743   // poipoipoi stub 
     
    7945} 
    8046 
    81 /** 
    82 \brief Cancel a running compare. 
    83 */ 
    8447void bsp_timer_cancel_schedule() { 
    8548   // poipoipoi stub 
  • trunk/firmware/openos/bsp/boards/pc/leds.c

    r1839 r1845  
    66 
    77#include "leds.h" 
     8#include "opensim_proto.h" 
    89 
    910//=========================== defines ========================================= 
     
    1617 
    1718void leds_init() { 
    18    // poipoipoi stub 
    19    printf("TODO leds_init\r\n"); 
     19   opensim_requ_leds_init_t requ; 
     20   opensim_repl_leds_init_t repl; 
     21    
     22   // prepare request 
     23   requ.cmdId = OPENSIM_CMD_leds_init; 
     24    
     25   // send request to server and get reply 
     26   opensim_client_send((void*)&requ, 
     27                       sizeof(opensim_requ_leds_init_t), 
     28                       (void*)&repl, 
     29                       sizeof(opensim_repl_leds_init_t)); 
     30                        
     31   // make sure server did not return any errors 
     32   if (repl.rc!=OPENSIM_ERR_NONE) { 
     33      printf("ERROR rc=%d for leds_init\n",repl.rc); 
     34   } 
    2035} 
    2136 
    2237void    leds_error_on() { 
    23    // poipoipoi stub 
    24    printf("TODO leds_error_on\r\n"); 
     38   opensim_requ_leds_error_on_t requ; 
     39   opensim_repl_leds_error_on_t repl; 
     40    
     41   // prepare request 
     42   requ.cmdId = OPENSIM_CMD_leds_error_on; 
     43    
     44   // send request to server and get reply 
     45   opensim_client_send((void*)&requ, 
     46                       sizeof(opensim_requ_leds_error_on_t), 
     47                       (void*)&repl, 
     48                       sizeof(opensim_repl_leds_error_on_t)); 
     49                        
     50   // make sure server did not return any errors 
     51   if (repl.rc!=OPENSIM_ERR_NONE) { 
     52      printf("ERROR rc=%d for leds_error_on\n",repl.rc); 
     53   } 
    2554} 
    2655void    leds_error_off() { 
    27    // poipoipoi stub 
    28    printf("TODO leds_error_off\r\n"); 
     56   opensim_requ_leds_error_off_t requ; 
     57   opensim_repl_leds_error_off_t repl; 
     58    
     59   // prepare request 
     60   requ.cmdId = OPENSIM_CMD_leds_error_off; 
     61    
     62   // send request to server and get reply 
     63   opensim_client_send((void*)&requ, 
     64                       sizeof(opensim_requ_leds_error_off_t), 
     65                       (void*)&repl, 
     66                       sizeof(opensim_repl_leds_error_off_t)); 
     67                        
     68   // make sure server did not return any errors 
     69   if (repl.rc!=OPENSIM_ERR_NONE) { 
     70      printf("ERROR rc=%d for leds_error_off\n",repl.rc); 
     71   } 
    2972} 
    3073void    leds_error_toggle() { 
    31    // poipoipoi stub 
    32    printf("TODO leds_error_toggle\r\n"); 
     74   opensim_requ_leds_error_toggle_t requ; 
     75   opensim_repl_leds_error_toggle_t repl; 
     76    
     77   // prepare request 
     78   requ.cmdId = OPENSIM_CMD_leds_error_toggle; 
     79    
     80   // send request to server and get reply 
     81   opensim_client_send((void*)&requ, 
     82                       sizeof(opensim_requ_leds_error_toggle_t), 
     83                       (void*)&repl, 
     84                       sizeof(opensim_repl_leds_error_toggle_t)); 
     85                        
     86   // make sure server did not return any errors 
     87   if (repl.rc!=OPENSIM_ERR_NONE) { 
     88      printf("ERROR rc=%d for leds_error_toggle\n",repl.rc); 
     89   } 
    3390} 
    3491uint8_t leds_error_isOn() { 
    35    // poipoipoi stub 
    36    printf("TODO leds_error_isOn\r\n"); 
     92   opensim_requ_leds_error_isOn_t requ; 
     93   opensim_repl_leds_error_isOn_t repl; 
     94    
     95   // prepare request 
     96   requ.cmdId = OPENSIM_CMD_leds_error_isOn; 
     97    
     98   // send request to server and get reply 
     99   opensim_client_send((void*)&requ, 
     100                       sizeof(opensim_requ_leds_error_isOn_t), 
     101                       (void*)&repl, 
     102                       sizeof(opensim_repl_leds_error_isOn_t)); 
     103                        
     104   // make sure server did not return any errors 
     105   if (repl.rc!=OPENSIM_ERR_NONE) { 
     106      printf("ERROR rc=%d for leds_error_isOn\n",repl.rc); 
     107   } 
    37108} 
    38109 
    39110void    leds_radio_on() { 
    40    // poipoipoi stub 
    41    printf("TODO leds_radio_on\r\n"); 
     111   opensim_requ_leds_radio_on_t requ; 
     112   opensim_repl_leds_radio_on_t repl; 
     113    
     114   // prepare request 
     115   requ.cmdId = OPENSIM_CMD_leds_radio_on; 
     116    
     117   // send request to server and get reply 
     118   opensim_client_send((void*)&requ, 
     119                       sizeof(opensim_requ_leds_radio_on_t), 
     120                       (void*)&repl, 
     121                       sizeof(opensim_repl_leds_radio_on_t)); 
     122                        
     123   // make sure server did not return any errors 
     124   if (repl.rc!=OPENSIM_ERR_NONE) { 
     125      printf("ERROR rc=%d for leds_radio_on\n",repl.rc); 
     126   } 
    42127} 
    43128void    leds_radio_off() { 
    44    // poipoipoi stub 
    45    printf("TODO leds_radio_off\r\n"); 
     129   opensim_requ_leds_radio_off_t requ; 
     130   opensim_repl_leds_radio_off_t repl; 
     131    
     132   // prepare request 
     133   requ.cmdId = OPENSIM_CMD_leds_radio_off; 
     134    
     135   // send request to server and get reply 
     136   opensim_client_send((void*)&requ, 
     137                       sizeof(opensim_requ_leds_radio_off_t), 
     138                       (void*)&repl, 
     139                       sizeof(opensim_repl_leds_radio_off_t)); 
     140                        
     141   // make sure server did not return any errors 
     142   if (repl.rc!=OPENSIM_ERR_NONE) { 
     143      printf("ERROR rc=%d for leds_radio_off\n",repl.rc); 
     144   } 
    46145} 
    47146void    leds_radio_toggle() { 
    48    // poipoipoi stub 
    49    printf("TODO leds_radio_toggle\r\n"); 
     147   opensim_requ_leds_radio_toggle_t requ; 
     148   opensim_repl_leds_radio_toggle_t repl; 
     149    
     150   // prepare request 
     151   requ.cmdId = OPENSIM_CMD_leds_radio_toggle; 
     152    
     153   // send request to server and get reply 
     154   opensim_client_send((void*)&requ, 
     155                       sizeof(opensim_requ_leds_radio_toggle_t), 
     156                       (void*)&repl, 
     157                       sizeof(opensim_repl_leds_radio_toggle_t)); 
     158                        
     159   // make sure server did not return any errors 
     160   if (repl.rc!=OPENSIM_ERR_NONE) { 
     161      printf("ERROR rc=%d for leds_radio_toggle\n",repl.rc); 
     162   } 
    50163} 
    51164uint8_t leds_radio_isOn() { 
    52    // poipoipoi stub 
    53    printf("TODO leds_radio_isOn\r\n"); 
     165   opensim_requ_leds_radio_isOn_t requ; 
     166   opensim_repl_leds_radio_isOn_t repl; 
     167    
     168   // prepare request 
     169   requ.cmdId = OPENSIM_CMD_leds_radio_isOn; 
     170    
     171   // send request to server and get reply 
     172   opensim_client_send((void*)&requ, 
     173                       sizeof(opensim_requ_leds_radio_isOn_t), 
     174                       (void*)&repl, 
     175                       sizeof(opensim_repl_leds_radio_isOn_t)); 
     176                        
     177   // make sure server did not return any errors 
     178   if (repl.rc!=OPENSIM_ERR_NONE) { 
     179      printf("ERROR rc=%d for leds_radio_isOn\n",repl.rc); 
     180   } 
    54181} 
    55182 
    56183// green 
    57184void    leds_sync_on() { 
    58    // poipoipoi stub 
    59    printf("TODO leds_sync_on\r\n"); 
     185   opensim_requ_leds_sync_on_t requ; 
     186   opensim_repl_leds_sync_on_t repl; 
     187    
     188   // prepare request 
     189   requ.cmdId = OPENSIM_CMD_leds_sync_on; 
     190    
     191   // send request to server and get reply 
     192   opensim_client_send((void*)&requ, 
     193                       sizeof(opensim_requ_leds_sync_on_t), 
     194                       (void*)&repl, 
     195                       sizeof(opensim_repl_leds_sync_on_t)); 
     196                        
     197   // make sure server did not return any errors 
     198   if (repl.rc!=OPENSIM_ERR_NONE) { 
     199      printf("ERROR rc=%d for leds_sync_on\n",repl.rc); 
     200   } 
    60201} 
    61202void    leds_sync_off() { 
    62    // poipoipoi stub 
    63    printf("TODO leds_sync_off\r\n"); 
     203   opensim_requ_leds_sync_off_t requ; 
     204   opensim_repl_leds_sync_off_t repl; 
     205    
     206   // prepare request 
     207   requ.cmdId = OPENSIM_CMD_leds_sync_off; 
     208    
     209   // send request to server and get reply 
     210   opensim_client_send((void*)&requ, 
     211                       sizeof(opensim_requ_leds_sync_off_t), 
     212                       (void*)&repl, 
     213                       sizeof(opensim_repl_leds_sync_off_t)); 
     214                        
     215   // make sure server did not return any errors 
     216   if (repl.rc!=OPENSIM_ERR_NONE) { 
     217      printf("ERROR rc=%d for leds_sync_off\n",repl.rc); 
     218   } 
    64219} 
    65220void    leds_sync_toggle() { 
    66    // poipoipoi stub 
    67    printf("TODO leds_sync_toggle\r\n"); 
     221   opensim_requ_leds_sync_toggle_t requ; 
     222   opensim_repl_leds_sync_toggle_t repl; 
     223    
     224   // prepare request 
     225   requ.cmdId = OPENSIM_CMD_leds_sync_toggle; 
     226    
     227   // send request to server and get reply 
     228   opensim_client_send((void*)&requ, 
     229                       sizeof(opensim_requ_leds_sync_toggle_t), 
     230                       (void*)&repl, 
     231                       sizeof(opensim_repl_leds_sync_toggle_t)); 
     232                        
     233   // make sure server did not return any errors 
     234   if (repl.rc!=OPENSIM_ERR_NONE) { 
     235      printf("ERROR rc=%d for leds_sync_toggle\n",repl.rc); 
     236   } 
    68237} 
    69238uint8_t leds_sync_isOn() { 
    70    // poipoipoi stub 
    71    printf("TODO leds_sync_isOn\r\n"); 
     239   opensim_requ_leds_sync_isOn_t requ; 
     240   opensim_repl_leds_sync_isOn_t repl; 
     241    
     242   // prepare request 
     243   requ.cmdId = OPENSIM_CMD_leds_sync_isOn; 
     244    
     245   // send request to server and get reply 
     246   opensim_client_send((void*)&requ, 
     247                       sizeof(opensim_requ_leds_sync_isOn_t), 
     248                       (void*)&repl, 
     249                       sizeof(opensim_repl_leds_sync_isOn_t)); 
     250                        
     251   // make sure server did not return any errors 
     252   if (repl.rc!=OPENSIM_ERR_NONE) { 
     253      printf("ERROR rc=%d for leds_sync_isOn\n",repl.rc); 
     254   } 
    72255} 
    73256 
    74257// yellow 
    75258void    leds_debug_on() { 
    76    // poipoipoi stub 
    77    printf("TODO leds_debug_on\r\n"); 
     259   opensim_requ_leds_debug_on_t requ; 
     260   opensim_repl_leds_debug_on_t repl; 
     261    
     262   // prepare request 
     263   requ.cmdId = OPENSIM_CMD_leds_debug_on; 
     264    
     265   // send request to server and get reply 
     266   opensim_client_send((void*)&requ, 
     267                       sizeof(opensim_requ_leds_debug_on_t), 
     268                       (void*)&repl, 
     269                       sizeof(opensim_repl_leds_debug_on_t)); 
     270                        
     271   // make sure server did not return any errors 
     272   if (repl.rc!=OPENSIM_ERR_NONE) { 
     273      printf("ERROR rc=%d for leds_debug_on\n",repl.rc); 
     274   } 
    78275} 
    79276void    leds_debug_off() { 
    80    // poipoipoi stub 
    81    printf("TODO leds_debug_off\r\n"); 
     277   opensim_requ_leds_debug_off_t requ; 
     278   opensim_repl_leds_debug_off_t repl; 
     279    
     280   // prepare request 
     281   requ.cmdId = OPENSIM_CMD_leds_debug_off; 
     282    
     283   // send request to server and get reply 
     284   opensim_client_send((void*)&requ, 
     285                       sizeof(opensim_requ_leds_debug_off_t), 
     286                       (void*)&repl, 
     287                       sizeof(opensim_repl_leds_debug_off_t)); 
     288                        
     289   // make sure server did not return any errors 
     290   if (repl.rc!=OPENSIM_ERR_NONE) { 
     291      printf("ERROR rc=%d for leds_debug_off\n",repl.rc); 
     292   } 
    82293} 
    83294void    leds_debug_toggle() { 
    84    // poipoipoi stub 
    85    printf("TODO leds_debug_toggle\r\n"); 
     295   opensim_requ_leds_debug_toggle_t requ; 
     296   opensim_repl_leds_debug_toggle_t repl; 
     297    
     298   // prepare request 
     299   requ.cmdId = OPENSIM_CMD_leds_debug_toggle; 
     300    
     301   // send request to server and get reply 
     302   opensim_client_send((void*)&requ, 
     303                       sizeof(opensim_requ_leds_debug_toggle_t), 
     304                       (void*)&repl, 
     305                       sizeof(opensim_repl_leds_debug_toggle_t)); 
     306                        
     307   // make sure server did not return any errors 
     308   if (repl.rc!=OPENSIM_ERR_NONE) { 
     309      printf("ERROR rc=%d for leds_debug_toggle\n",repl.rc); 
     310   } 
    86311} 
    87312uint8_t leds_debug_isOn() { 
    88    // poipoipoi stub 
    89    printf("TODO leds_debug_isOn\r\n"); 
     313   opensim_requ_leds_debug_isOn_t requ; 
     314   opensim_repl_leds_debug_isOn_t repl; 
     315    
     316   // prepare request 
     317   requ.cmdId = OPENSIM_CMD_leds_debug_isOn; 
     318    
     319   // send request to server and get reply 
     320   opensim_client_send((void*)&requ, 
     321                       sizeof(opensim_requ_leds_debug_isOn_t), 
     322                       (void*)&repl, 
     323                       sizeof(opensim_repl_leds_debug_isOn_t)); 
     324                        
     325   // make sure server did not return any errors 
     326   if (repl.rc!=OPENSIM_ERR_NONE) { 
     327      printf("ERROR rc=%d for leds_debug_isOn\n",repl.rc); 
     328   } 
    90329} 
    91330 
    92331void leds_all_on() { 
    93    // poipoipoi stub 
    94    printf("TODO leds_all_on\r\n"); 
     332   opensim_requ_leds_all_on_t requ; 
     333   opensim_repl_leds_all_on_t repl; 
     334    
     335   // prepare request 
     336   requ.cmdId = OPENSIM_CMD_leds_all_on; 
     337    
     338   // send request to server and get reply 
     339   opensim_client_send((void*)&requ, 
     340                       sizeof(opensim_requ_leds_all_on_t), 
     341                       (void*)&repl, 
     342                       sizeof(opensim_repl_leds_all_on_t)); 
     343                        
     344   // make sure server did not return any errors 
     345   if (repl.rc!=OPENSIM_ERR_NONE) { 
     346      printf("ERROR rc=%d for leds_all_on\n",repl.rc); 
     347   } 
    95348} 
    96349void leds_all_off() { 
    97    // poipoipoi stub 
    98    printf("TODO leds_all_off\r\n"); 
     350   opensim_requ_leds_all_off_t requ; 
     351   opensim_repl_leds_all_off_t repl; 
     352    
     353   // prepare request 
     354   requ.cmdId = OPENSIM_CMD_leds_all_off; 
     355    
     356   // send request to server and get reply 
     357   opensim_client_send((void*)&requ, 
     358                       sizeof(opensim_requ_leds_all_off_t), 
     359                       (void*)&repl, 
     360                       sizeof(opensim_repl_leds_all_off_t)); 
     361                        
     362   // make sure server did not return any errors 
     363   if (repl.rc!=OPENSIM_ERR_NONE) { 
     364      printf("ERROR rc=%d for leds_all_off\n",repl.rc); 
     365   } 
    99366} 
    100367void leds_all_toggle() { 
    101    // poipoipoi stub 
    102    printf("TODO leds_all_toggle\r\n"); 
     368   opensim_requ_leds_all_toggle_t requ; 
     369   opensim_repl_leds_all_toggle_t repl; 
     370    
     371   // prepare request 
     372   requ.cmdId = OPENSIM_CMD_leds_all_toggle; 
     373    
     374   // send request to server and get reply 
     375   opensim_client_send((void*)&requ, 
     376                       sizeof(opensim_requ_leds_all_toggle_t), 
     377                       (void*)&repl, 
     378                       sizeof(opensim_repl_leds_all_toggle_t)); 
     379                        
     380   // make sure server did not return any errors 
     381   if (repl.rc!=OPENSIM_ERR_NONE) { 
     382      printf("ERROR rc=%d for leds_all_toggle\n",repl.rc); 
     383   } 
    103384} 
    104385 
    105386void leds_circular_shift() { 
    106    // poipoipoi stub 
    107    printf("TODO leds_circular_shift\r\n"); 
     387   opensim_requ_leds_circular_shift_t requ; 
     388   opensim_repl_leds_circular_shift_t repl; 
     389    
     390   // prepare request 
     391   requ.cmdId = OPENSIM_CMD_leds_circular_shift; 
     392    
     393   // send request to server and get reply 
     394   opensim_client_send((void*)&requ, 
     395                       sizeof(opensim_requ_leds_circular_shift_t), 
     396                       (void*)&repl, 
     397                       sizeof(opensim_repl_leds_circular_shift_t)); 
     398                        
     399   // make sure server did not return any errors 
     400   if (repl.rc!=OPENSIM_ERR_NONE) { 
     401      printf("ERROR rc=%d for leds_circular_shift\n",repl.rc); 
     402   } 
    108403} 
    109404 
    110405void leds_increment() { 
    111    // poipoipoi stub 
    112    printf("TODO leds_increment\r\n"); 
     406   opensim_requ_leds_increment_t requ; 
     407   opensim_repl_leds_increment_t repl; 
     408    
     409   // prepare request 
     410   requ.cmdId = OPENSIM_CMD_leds_increment; 
     411    
     412   // send request to server and get reply 
     413   opensim_client_send((void*)&requ, 
     414                       sizeof(opensim_requ_leds_increment_t), 
     415                       (void*)&repl, 
     416                       sizeof(opensim_repl_leds_increment_t)); 
     417                        
     418   // make sure server did not return any errors 
     419   if (repl.rc!=OPENSIM_ERR_NONE) { 
     420      printf("ERROR rc=%d for leds_increment\n",repl.rc); 
     421   } 
    113422} 
    114423 
  • trunk/firmware/openos/bsp/boards/pc/opensim_client.c

    r1842 r1845  
    11/** 
    2 \brief Client program to the OpenSim engine 
     2\brief Client program to the OpenSim server. 
    33 
    44\author Thomas Watteyne <watteyne@eecs.berkeley.edu>, April 2012. 
     
    1010#include <string.h> 
    1111#include "tcp_port.h" 
     12#include "opensim_client.h" 
    1213 
    13 #define DEFAULT_SERVER_NAME "localhost" 
    14 #define DEFAULT_SERVER_PORT 14159 
     14//=========================== variables ======================================= 
    1515 
    16 void Usage(char* progname) { 
    17    fprintf(stderr,"Usage: %s -n [server_address name/IP address] -p [port_num] -l [iterations]\n", progname); 
    18    fprintf(stderr,"Where:\n\tprotocol is one of TCP or UDP\n"); 
    19    fprintf(stderr,"\t- server_address is the IP address or name of server_address\n"); 
    20    fprintf(stderr,"\t- port_num is the port to listen on\n"); 
    21    WSACleanup(); 
    22    exit(1); 
    23 } 
     16typedef struct { 
     17   char    txBuffer[OPENCLIENT_BUFSIZE]; 
     18   char    rxBuffer[OPENCLIENT_BUFSIZE]; 
     19   SOCKET  conn_socket; 
     20} opensim_client_vars_t; 
     21 
     22opensim_client_vars_t opensim_client_vars; 
     23 
     24//=========================== prototypes ====================================== 
     25 
     26void printUsage(char* progname); 
     27 
     28//=========================== main ============================================ 
    2429 
    2530int main(int argc, char **argv) { 
    26    char                 Buffer[12]; 
    2731   unsigned short       server_port; 
    2832   char*                server_name; 
     
    3135   int                  loopcount; 
    3236   int                  numloops; 
    33    SOCKET               conn_socket; 
    3437   int                  retval; 
    3538    
     
    5356                  break; 
    5457               default: 
    55                   Usage(argv[0]); 
     58                  printUsage(argv[0]); 
    5659                  break; 
    5760            } 
    5861         } else { 
    59             Usage(argv[0]); 
     62            printUsage(argv[0]); 
    6063         } 
    6164      } 
     
    6366    
    6467   // connect to the server 
    65    conn_socket = tcp_port_connect(server_name, server_port); 
     68   opensim_client_vars.conn_socket = tcp_port_connect(server_name, server_port); 
    6669    
    67    // send some data 
    68    while(numloops>0) { 
     70   // wait for command from the server 
     71   while(1) { 
    6972       
    70       // send to server 
    71       wsprintf(Buffer,"poipoipoipoi"); 
    72       retval = send(conn_socket, Buffer, sizeof(Buffer), 0); 
    73       if (retval == SOCKET_ERROR) { 
    74          fprintf(stderr,"ERROR: send() failed (error=%d)\n", WSAGetLastError()); 
    75          WSACleanup(); 
    76          return -1; 
    77       } 
    78       printf("poipoi sent"); 
    79  
    80       // receive from server 
    81       retval = recv(conn_socket, Buffer, sizeof(Buffer), 0); 
     73      // receive command from server 
     74      retval = recv(opensim_client_vars.conn_socket, 
     75                    opensim_client_vars.rxBuffer, 
     76                    sizeof(opensim_client_vars.rxBuffer), 
     77                    0); 
    8278      if (retval==SOCKET_ERROR) { 
    8379         fprintf(stderr,"ERROR: recv() failed (error=%d)\n", WSAGetLastError()); 
    84          closesocket(conn_socket); 
     80         closesocket(opensim_client_vars.conn_socket); 
    8581         WSACleanup(); 
    8682         return -1; 
     
    8884      if (retval == 0) { 
    8985         printf("WARNING: server closed connection.\n"); 
    90          closesocket(conn_socket); 
     86         closesocket(opensim_client_vars.conn_socket); 
    9187         WSACleanup(); 
    9288         return -1; 
    9389      } 
    94       printf("INFO: Received %d bytes, data \"%s\" from server_address.\n", retval, Buffer); 
    95        
    96       // decrement number of loops 
    97       numloops--; 
     90      printf("INFO: Received %d bytes, data \"%s\"\n", 
     91                   retval, 
     92                   opensim_client_vars.rxBuffer); 
     93                    
     94      mote_main(); 
    9895   } 
    9996    
    100    closesocket(conn_socket); 
     97   closesocket(opensim_client_vars.conn_socket); 
    10198   WSACleanup(); 
    10299   return 0; 
    103100} 
     101 
     102//=========================== public ========================================== 
     103 
     104int opensim_client_send(int* pTxData, 
     105                        int  txDataLength, 
     106                        int* pRxBuffer, 
     107                        int  maxRxBufferLength) { 
     108   int retval; 
     109    
     110   // send command to OpenSim server 
     111   retval = send(opensim_client_vars.conn_socket, 
     112                 pTxData, 
     113                 txDataLength, 
     114                 0); 
     115   if (retval == SOCKET_ERROR) { 
     116      fprintf(stderr,"ERROR: send() failed (error=%d)\n", WSAGetLastError()); 
     117      WSACleanup(); 
     118      exit(1); 
     119   } 
     120   printf("command sent\r\n"); 
     121    
     122   // wait for reply 
     123   retval = recv(opensim_client_vars.conn_socket, 
     124                 opensim_client_vars.rxBuffer, 
     125                 sizeof(opensim_client_vars.rxBuffer), 
     126                 0); 
     127   if (retval==SOCKET_ERROR) { 
     128      fprintf(stderr,"FATAL: recv failed (error=%d)\n", WSAGetLastError()); 
     129      closesocket(opensim_client_vars.conn_socket); 
     130      WSACleanup(); 
     131      exit(1); 
     132   } 
     133   if (retval==0) { 
     134      fprintf(stderr,"FATAL: server closed connection.\n"); 
     135      closesocket(opensim_client_vars.conn_socket); 
     136      WSACleanup(); 
     137      exit(1); 
     138   } 
     139   if (retval>maxRxBufferLength) { 
     140      fprintf(stderr,"FATAL: expected at most %d bytes, got %d.\n",maxRxBufferLength,retval); 
     141      closesocket(opensim_client_vars.conn_socket); 
     142      WSACleanup(); 
     143      exit(1); 
     144   } 
     145    
     146   // copy reply in pRxBuffer 
     147   memcpy(pRxBuffer,opensim_client_vars.rxBuffer,retval); 
     148    
     149   printf("INFO: received %d bytes\n",retval); 
     150   printf("ack received\r\n"); 
     151   return 0; 
     152} 
     153 
     154//=========================== private ========================================= 
     155 
     156void printUsage(char* progname) { 
     157   fprintf(stderr,"printUsage: %s -n [server_address name/IP address] -p [port_num] -l [iterations]\n", progname); 
     158   fprintf(stderr,"Where:\n\tprotocol is one of TCP or UDP\n"); 
     159   fprintf(stderr,"\t- server_address is the IP address or name of server_address\n"); 
     160   fprintf(stderr,"\t- port_num is the port to listen on\n"); 
     161   WSACleanup(); 
     162   exit(1); 
     163} 
  • trunk/firmware/openos/projects/common/01bsp_leds/SConscript

    r1832 r1845  
    1515library_files = [ 
    1616                   'libbsppc.lib', 
     17                   'ws2_32.lib', 
     18                   'user32.lib', 
    1719                ] 
    1820source_files =  ['01bsp_leds.c', 
     21                 os.path.join('#','firmware','openos','bsp','boards','pc','opensim_client.c'), 
     22                 os.path.join('#','firmware','openos','bsp','boards','pc','tcp_port.c'), 
    1923                ] 
    2024 
  • trunk/software/opensim/SimEngine/MoteHandler.py

    r1843 r1845  
    55import logging 
    66import os 
     7import time 
    78 
    89TCPRXBUFSIZE       = 4096    # size of the TCP reception buffer 
     
    4748        self.log.info('starting') 
    4849         
     50        self.conn.send('poipoi') 
     51         
    4952        while(1): 
    5053            try: 
     
    5457            else: 
    5558                self.log.info('received input='+str(input)) 
    56             self.conn.send('poipoipoipoi') 
     59             
     60            print len(input) 
     61             
     62            time.sleep(1) 
     63             
     64            self.conn.send(chr(0)) 
    5765     
    5866    #======================== private ========================================= 
Note: See TracChangeset for help on using the changeset viewer.