VZTECH / Mbed 2 deprecated header_main

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test.h Source File

test.h

00001 #ifndef __TEST_H__
00002 #define __TEST_H__
00003 
00004 typedef struct{
00005     uint8_t * buffer_ptr;
00006     volatile uint8_t * status_ptr;
00007     int * dest_ext;
00008     bool * __symbolic_flag__;
00009 }test_control;
00010 
00011 void _unit_test_( void const * args );
00012 
00013 //#define test_mode_on
00014 #ifdef test_mode_on
00015 
00016 void test_registry( void const * args );
00017 void test_aging_registry( void const * args );
00018 void __unit_test_invite__( void const * args );
00019 void test_many_cb_registry( void const * args );
00020 void change_buffer( void const * args );
00021 void unit_test_cb_to_server( void const * args );
00022 void unit_test_cb_from_server( void const * args );
00023 
00024 void change_buffer( void const * args ){
00025     if( args != NULL ){
00026         uint8_t * buffer = ( uint8_t *)args;
00027         uint8_t ref = 0x21;
00028         while( true ){
00029             for( register int i = 0; i < __CB_BUFFER_SIZE__ - 5 ; i++ ) buffer[ i ] = ref;
00030             ref++;
00031         }
00032     }
00033 }
00034 
00035 void unit_test_cb_to_server( void const * args ){
00036     if( args != NULL ){
00037         test_control * tc = ( test_control * )args;   
00038         
00039         /*  Como vai acontecer esse teste
00040             o que eu tenho que mudar no buffer
00041             mandar o invite da primeira chamada, depois mandar o invite da segunda chamada depois ficar trocando dados
00042         */     
00043         tc->buffer_ptr[ 0 ] = 0x03;
00044         tc->buffer_ptr[ 1 ] = 0x59; // ext 857
00045         tc->buffer_ptr[ 2 ] = 0x12;
00046         tc->buffer_ptr[ 3 ] = 0x12; // port 4626
00047         tc->buffer_ptr[ 4 ] = __INVITE__;
00048         *( tc->status_ptr ) = (uint8_t)0x01;
00049         while( *( tc->status_ptr ) == 0x01 ) continue;
00050         
00051         tc->buffer_ptr[ 0 ] = 0x03;
00052         tc->buffer_ptr[ 1 ] = 0x79; // ext 889
00053         tc->buffer_ptr[ 2 ] = 0x12;
00054         tc->buffer_ptr[ 3 ] = 0x13; // port 4627
00055         tc->buffer_ptr[ 4 ] = __INVITE__;
00056         *( tc->status_ptr ) = (uint8_t)0x01;
00057         while( *( tc->status_ptr ) == 0x01 ) continue;
00058         
00059         led3 = 1;
00060         tc->buffer_ptr[ 4 ] = __AUDIO__;
00061         Timer time_out;
00062         time_out.start();
00063         while( time_out.read() < 10 ){
00064             while( *( tc->status_ptr ) == 0x01 ) continue; //  nao posso escrever se isso nao estiver em 0
00065             tc->buffer_ptr[ 0 ] = 0x03;
00066             tc->buffer_ptr[ 1 ] = 0x59; // ext 857
00067             tc->buffer_ptr[ 2 ] = 0x12;
00068             tc->buffer_ptr[ 3 ] = 0x12; // port 4626
00069             *(tc->dest_ext) = 813;
00070             *(tc->status_ptr) = (uint8_t)0x01;
00071             
00072             while( *( tc->status_ptr ) == 0x01 ) continue; //  nao posso escrever se isso nao estiver em 0
00073             tc->buffer_ptr[ 0 ] = 0x03;
00074             tc->buffer_ptr[ 1 ] = 0x79; // ext 889
00075             tc->buffer_ptr[ 2 ] = 0x12;
00076             tc->buffer_ptr[ 3 ] = 0x13; // port 4627
00077             *(tc->dest_ext) = 814; // ??? confirmar nro do ramal
00078             *(tc->status_ptr) = (uint8_t)0x01;
00079         }
00080         led3 = 0;
00081     }   
00082 }
00083 
00084 void unit_test_cb_from_server( void const * args ){
00085     if( args != NULL ){
00086         test_control * tc = ( test_control * )args;        
00087 
00088         tc->buffer_ptr[ 0 ] = 0x03;
00089         tc->buffer_ptr[ 1 ] = 0x59; // ext 857
00090         tc->buffer_ptr[ 2 ] = 0x12;
00091         tc->buffer_ptr[ 3 ] = 0x12; // port 4626
00092         tc->buffer_ptr[ 4 ] = __INVITE__;
00093         *( tc->status_ptr ) = (uint8_t)0x01;
00094     
00095         while( *( tc->status_ptr ) == 0x01 ) continue;
00096         
00097         led3 = 1;
00098         tc->buffer_ptr[ 4 ] = __AUDIO__;
00099         Timer time_out;
00100         time_out.start();
00101         while( time_out.read() < 10 ){
00102         //  *(tc->status_ptr) = (uint8_t)0x01;
00103             *(tc->__symbolic_flag__) = false;  
00104         }
00105         led3 = 0;
00106     }   
00107 }
00108 
00109 void test_registry( void const * args ){
00110     if( args != NULL ){
00111         test_control * tc = ( test_control * )args;
00112         if( tc == NULL ) return;
00113         
00114         uint16_t cc = __checksum__( tc->buffer_ptr + __CHECKSUM_OFFSET__, __CB_BUFFER_SIZE__ - __CHECKSUM_OFFSET__ );
00115 
00116         tc->buffer_ptr[ 0 ] = 0x03;
00117         tc->buffer_ptr[ 1 ] = 0x5d; // 861
00118         tc->buffer_ptr[ 2 ] = 0x10;
00119         tc->buffer_ptr[ 3 ] = 0x11; // 4113
00120         tc->buffer_ptr[ 4 ] = ( uint8_t )( ( cc & 0xFF00 ) >> 8 );  
00121         tc->buffer_ptr[ 5 ] = ( uint8_t )( cc & 0x00FF );
00122         tc->buffer_ptr[ 6 ] = __REGISTRY__;
00123         tc->buffer_ptr[ 7 ] = 0x03; // seq
00124         for( register int i = 8; i < 8 + __CLOCK_SYNC_SIZE__; i++ )// clock
00125             tc->buffer_ptr[ i ] = 0x00;
00126         tc->buffer_ptr[ 10 ] = 0x23;
00127 
00128         *(tc->status_ptr) = (uint8_t)__READ__;
00129     }
00130 }
00131 
00132 void __unit_test_invite__( void const * args ){
00133     if( args != NULL ){
00134         test_control * tc = ( test_control * )args;        
00135         
00136         uint16_t cc = __checksum__( tc->buffer_ptr + __CHECKSUM_OFFSET__, __CB_BUFFER_SIZE__ - __CHECKSUM_OFFSET__ );
00137 
00138         tc->buffer_ptr[ 0 ] = 0x03;
00139         tc->buffer_ptr[ 1 ] = 0x5f; // 863
00140         tc->buffer_ptr[ 2 ] = 0x10;
00141         tc->buffer_ptr[ 3 ] = 0x11; // 4113
00142         tc->buffer_ptr[ 4 ] = ( uint8_t )( ( cc & 0xFF00 ) >> 8 );  
00143         tc->buffer_ptr[ 5 ] = ( uint8_t )( cc & 0x00FF );
00144         tc->buffer_ptr[ 6 ] = __INVITE__;
00145         tc->buffer_ptr[ 7 ] = 0x07; // seq
00146         for( register int i = 8; i < 8 + __CLOCK_SYNC_SIZE__; i++ )
00147             tc->buffer_ptr[ i ] = i;
00148         *(tc->status_ptr) = __READ__;
00149         
00150            tc->buffer_ptr[ 7 ] = 0x41; // seq
00151         for( register int i = 8; i < 8 + __CLOCK_SYNC_SIZE__; i++ )
00152             tc->buffer_ptr[ i ] = 0x41;
00153         while( *( tc->status_ptr ) == __READ__ ) continue;
00154         led3 = 1;
00155         tc->buffer_ptr[ 6 ] = __AUDIO__;
00156         Timer time_out;
00157         time_out.start();
00158         while( time_out.read() < 10 ){
00159             *(tc->status_ptr) = __READ__;
00160             *(tc->__symbolic_flag__) = false;
00161         }
00162         led3 = 0;
00163     }   
00164 }
00165 
00166 void test_aging_registry( void const * args ){    // single cb, try many
00167     if( args != NULL ){
00168         test_control * tc = ( test_control * )args;
00169         if( tc == NULL ) return;
00170         
00171         uint16_t cc = __checksum__( tc->buffer_ptr + __CHECKSUM_OFFSET__, __CB_BUFFER_SIZE__ - __CHECKSUM_OFFSET__ );
00172 
00173         tc->buffer_ptr[ 0 ] = 0x03;
00174         tc->buffer_ptr[ 1 ] = 0x5d; // 861
00175         tc->buffer_ptr[ 2 ] = 0x10;
00176         tc->buffer_ptr[ 3 ] = 0x11; // 4113
00177         tc->buffer_ptr[ 4 ] = ( uint8_t )( ( cc & 0xFF00 ) >> 8 );  
00178         tc->buffer_ptr[ 5 ] = ( uint8_t )( cc & 0x00FF );
00179         tc->buffer_ptr[ 6 ] = __REGISTRY__;
00180         tc->buffer_ptr[ 7 ] = 0x03; // seq
00181         for( register int i = 8; i < 8 + __CLOCK_SYNC_SIZE__; i++ )// clock
00182             tc->buffer_ptr[ i ] = 0x00;
00183         tc->buffer_ptr[ 10 ] = 0x23;
00184 
00185         *(tc->status_ptr) = (uint8_t)__READ__;
00186     }
00187 }
00188 
00189 
00190 void test_many_cb_registry( void const * args ){
00191     if( args != NULL ){
00192         test_control * tc = ( test_control * )args;
00193         if( tc == NULL ) return;
00194 
00195         tc->buffer_ptr[ 0 ] = 0x03;
00196         tc->buffer_ptr[ 1 ] = 0x53; // 851
00197         tc->buffer_ptr[ 2 ] = 0x1b;
00198         tc->buffer_ptr[ 3 ] = 0xbd; // 7101
00199         tc->buffer_ptr[ 6 ] = __REGISTRY__;
00200         tc->buffer_ptr[ 7 ] = 0x03; // seq
00201         for( register int i = 8; i < 8 + __CLOCK_SYNC_SIZE__; i++ )// clock
00202             tc->buffer_ptr[ i ] = 0x00;
00203         tc->buffer_ptr[ 11 ] = 0x23;
00204         uint16_t cc = __checksum__( tc->buffer_ptr + __CHECKSUM_OFFSET__, __CB_BUFFER_SIZE__ - __CHECKSUM_OFFSET__ );
00205         tc->buffer_ptr[ 4 ] = ( uint8_t )( ( cc & 0xFF00 ) >> 8 );  
00206         tc->buffer_ptr[ 5 ] = ( uint8_t )( cc & 0x00FF );
00207         
00208         *(tc->status_ptr) = (uint8_t)__READ__;
00209         while( *(tc->status_ptr) == (uint8_t)__READ__ );
00210         
00211         int ext = 851;
00212         int port = 7101;
00213         for( register int i = 0; i < 23; i++ ){
00214             *(tc->status_ptr) = (uint8_t)__READ__;
00215             tc->buffer_ptr[ 0 ] = ( uint8_t )( ( ext & 0xFF00 ) >> 8 );                                                                                      
00216             tc->buffer_ptr[ 1 ] = ( uint8_t )( ++ext & 0x00FF ); 
00217             tc->buffer_ptr[ 2 ] = ( uint8_t )( ( port & 0xFF00 ) >> 8 );                                                                                      
00218             tc->buffer_ptr[ 3 ] = ( uint8_t )( ++port & 0x00FF );
00219             uint16_t cc = __checksum__( tc->buffer_ptr + __CHECKSUM_OFFSET__, __CB_BUFFER_SIZE__ - __CHECKSUM_OFFSET__ );
00220             tc->buffer_ptr[ 4 ] = ( uint8_t )( ( cc & 0xFF00 ) >> 8 );  
00221             tc->buffer_ptr[ 5 ] = ( uint8_t )( cc & 0x00FF );
00222             *(tc->status_ptr) = (uint8_t)__READ__;
00223             while( *(tc->status_ptr) == (uint8_t)__READ__ );
00224       }
00225     }    
00226 }
00227 
00228 #endif // test_mode_on
00229 #endif // test.h