TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TTEAPITestApplication.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "TTEAPITestApplication.h"
17 
18 
19 #include "tte_api.h"
20 
21 namespace TTEthernetModel {
22 
23 Define_Module(TTEAPITestApplication);
24 
25 void testCallback(void* arg){
26  std::string teststring = (const char *)arg;
27  ev << "CALLBACK EXECUTED! " << teststring << endl << endl;
28 }
29 
30 unsigned int main(){
31  //tte_init();
32  tte_buffer_t testbuffer;
33  if(tte_get_ct_output_buf(0, 100, &testbuffer) != ETT_SUCCESS){
34  ev << "MIST1!" << endl << endl;
35  return -1;
36  }
37 
38  ev << "tte_get_channel_cnt(): " << tte_get_controller_cnt() << endl << endl;
39 
40  uint8_t mac[6];
41 
42  tte_get_var(0, TTE_VAR_MAC_ADDRESS,sizeof(mac), mac);
43 
44  ev.printf("TTE_VAR_MAC_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n\n", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
45 
46  if(tte_set_buf_var(&testbuffer, TTE_BUFVAR_TRANSMIT_CB, sizeof(void(*)(void*)), (void*)&testCallback) != ETT_SUCCESS){
47  ev << "MIST21!" << endl << endl;
48  return -1;
49  }
50  if(tte_set_buf_var(&testbuffer, TTE_BUFVAR_CB_ARG, 5, "SENT") != ETT_SUCCESS){
51  ev << "MIST22!" << endl << endl;
52  return -1;
53  }
54 
55  tte_frame_t frame;
56  frame.length=46;
57 
58  frame.eth_hdr.src_mac[0] = 0x00;
59  frame.eth_hdr.src_mac[1] = 0x00;
60  frame.eth_hdr.src_mac[2] = 0x00;
61  frame.eth_hdr.src_mac[3] = 0x00;
62  frame.eth_hdr.src_mac[4] = 0x00;
63  frame.eth_hdr.src_mac[5] = 0x00;
64 
65  frame.eth_hdr.dst_mac[0] = 0x00;
66  frame.eth_hdr.dst_mac[1] = 0x00;
67  frame.eth_hdr.dst_mac[2] = 0x00;
68  frame.eth_hdr.dst_mac[3] = 0x00;
69  frame.eth_hdr.dst_mac[4] = 0x00;
70  frame.eth_hdr.dst_mac[5] = 0x00;
71 
72  if(tte_open_output_buf(&testbuffer, &frame) != ETT_SUCCESS){
73  ev << "MIST2!" << endl << endl;
74  return -1;
75  }
76  if(tte_close_output_buf(&testbuffer) != ETT_SUCCESS){
77  ev << "MIST3!" << endl << endl;
78  return -1;
79  }
80 
81  tte_buffer_t testbuffer2;
82  if(tte_get_ct_output_buf(0, 100, &testbuffer2) != ETT_SUCCESS){
83  ev << "MIST4!" << endl << endl;
84  return -1;
85  }
86  if(tte_set_buf_var(&testbuffer2, TTE_BUFVAR_RECEIVE_CB, sizeof(void(*)(void*)), (void*)&testCallback) != ETT_SUCCESS){
87  ev << "MIST41!" << endl << endl;
88  return -1;
89  }
90  if(tte_set_buf_var(&testbuffer2, TTE_BUFVAR_CB_ARG, 9, "RECEIVED") != ETT_SUCCESS){
91  ev << "MIST42!" << endl << endl;
92  return -1;
93  }
94 
95  return 0;
96 }
97 
99  main();
100 }
101 
102 
103 
104 } //namespace