bosko lekovic
/
EthToCom_11
nova proba
main.cpp@21:2232f5a34eb4, 2020-05-25 (annotated)
- Committer:
- bosko001
- Date:
- Mon May 25 22:19:36 2020 +0200
- Revision:
- 21:2232f5a34eb4
- Parent:
- 20:d8277082f4e3
- Child:
- 22:11279d24a105
zapocet tcp socket
Signed-off-by: Bosko Lekovic <bosko001@gmail.com>
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 0:fe8cd064ea08 | 1 | #include "mbed.h" |
bosko001 | 2:45b351b4fc2a | 2 | #include "clubbing.h" |
bosko001 | 2:45b351b4fc2a | 3 | #include "EthernetSetup.h" |
bosko001 | 21:2232f5a34eb4 | 4 | #include "UdpClients.h" |
Bosko Lekovic |
18:5ee53205451a | 5 | #include "TcpClients.h" |
bosko001 | 21:2232f5a34eb4 | 6 | #include "SerialCom.h" |
bosko001 | 2:45b351b4fc2a | 7 | #include "TcpServerToFlash.h" |
bosko001 | 21:2232f5a34eb4 | 8 | //#include "dxml.h" |
bosko001 | 2:45b351b4fc2a | 9 | #include "doHTML.h" |
bosko001 | 3:1196befeace0 | 10 | #include "dataFlash.h" |
bosko001 | 0:fe8cd064ea08 | 11 | |
bosko001 | 5:c9a908749d4c | 12 | |
bosko001 | 5:c9a908749d4c | 13 | |
bosko001 | 5:c9a908749d4c | 14 | |
bosko001 | 5:c9a908749d4c | 15 | |
bosko001 | 2:45b351b4fc2a | 16 | volatile PFV pfv = NULL; |
bosko001 | 1:e1bde4e82763 | 17 | |
bosko001 | 1:e1bde4e82763 | 18 | |
bosko001 | 2:45b351b4fc2a | 19 | DigitalOut GLed(LED2,1); |
bosko001 | 21:2232f5a34eb4 | 20 | DigitalOut BLed(LED3,1); |
bosko001 | 21:2232f5a34eb4 | 21 | DigitalOut *p_led; |
bosko001 | 1:e1bde4e82763 | 22 | |
bosko001 | 2:45b351b4fc2a | 23 | void pfv_fun( void ) |
bosko001 | 1:e1bde4e82763 | 24 | { |
bosko001 | 2:45b351b4fc2a | 25 | while(true) |
bosko001 | 2:45b351b4fc2a | 26 | { |
bosko001 | 2:45b351b4fc2a | 27 | if(pfv) {pfv(); pfv = NULL;} |
bosko001 | 2:45b351b4fc2a | 28 | cleanTcpServerToFlashThread( ); |
bosko001 | 2:45b351b4fc2a | 29 | |
bosko001 | 2:45b351b4fc2a | 30 | } |
bosko001 | 1:e1bde4e82763 | 31 | } |
Bosko Lekovic |
18:5ee53205451a | 32 | Thread pfv_thread(pfv_fun, osPriorityNormal, 1000); |
bosko001 | 1:e1bde4e82763 | 33 | |
bosko001 | 7:7ea932eb31f6 | 34 | |
bosko001 | 7:7ea932eb31f6 | 35 | void input_fun( void ) |
bosko001 | 7:7ea932eb31f6 | 36 | { |
bosko001 | 7:7ea932eb31f6 | 37 | while(true) |
bosko001 | 7:7ea932eb31f6 | 38 | { |
bosko001 | 7:7ea932eb31f6 | 39 | unsigned char uc; |
Bosko Lekovic |
18:5ee53205451a | 40 | int fltip, kanal, fleg; |
bosko001 | 7:7ea932eb31f6 | 41 | uc = (unsigned char)getchar( ); |
bosko001 | 7:7ea932eb31f6 | 42 | printf( "\n\runesen karakter %c\n\r", uc); |
Bosko Lekovic |
18:5ee53205451a | 43 | |
Bosko Lekovic |
18:5ee53205451a | 44 | switch( uc ) |
bosko001 | 7:7ea932eb31f6 | 45 | { |
Bosko Lekovic |
18:5ee53205451a | 46 | case 'h': |
Bosko Lekovic |
18:5ee53205451a | 47 | { |
bosko001 | 7:7ea932eb31f6 | 48 | extern C_HTMLparse *gpc_html; |
bosko001 | 7:7ea932eb31f6 | 49 | auto c = gpc_html->getHTML_free( ); |
bosko001 | 7:7ea932eb31f6 | 50 | printf("\n\r%s\n\r", c); |
bosko001 | 7:7ea932eb31f6 | 51 | free(c); |
Bosko Lekovic |
18:5ee53205451a | 52 | } |
Bosko Lekovic |
18:5ee53205451a | 53 | break; |
Bosko Lekovic |
18:5ee53205451a | 54 | case 'c': |
Bosko Lekovic |
18:5ee53205451a | 55 | fltip = 1; |
Bosko Lekovic |
18:5ee53205451a | 56 | break; |
Bosko Lekovic |
18:5ee53205451a | 57 | case 'f': |
Bosko Lekovic |
18:5ee53205451a | 58 | fltip = 2; |
Bosko Lekovic |
18:5ee53205451a | 59 | break; |
Bosko Lekovic |
18:5ee53205451a | 60 | case '0': case '1': case '2': case '3': |
Bosko Lekovic |
18:5ee53205451a | 61 | if(fltip == 1) kanal = uc - '0'; |
Bosko Lekovic |
18:5ee53205451a | 62 | else fleg = uc - '0'; |
Bosko Lekovic |
18:5ee53205451a | 63 | break; |
Bosko Lekovic |
18:5ee53205451a | 64 | case 'd': |
Bosko Lekovic |
18:5ee53205451a | 65 | { |
Bosko Lekovic |
18:5ee53205451a | 66 | // extern void tcpRxThreadCancel( int i, int flag); |
Bosko Lekovic |
18:5ee53205451a | 67 | // tcpRxThreadCancel( kanal, fleg ); |
Bosko Lekovic |
18:5ee53205451a | 68 | printf(" komanda za tred[%d] fleg=%d\n\r", kanal, fleg); |
Bosko Lekovic |
18:5ee53205451a | 69 | } |
Bosko Lekovic |
18:5ee53205451a | 70 | break; |
bosko001 | 19:7bdb1a10043f | 71 | case 'P': case 'p': |
bosko001 | 19:7bdb1a10043f | 72 | restart_TcpClients( ); |
bosko001 | 19:7bdb1a10043f | 73 | break; |
bosko001 | 19:7bdb1a10043f | 74 | case 'S': case 's': |
Bosko Lekovic |
18:5ee53205451a | 75 | { |
bosko001 | 19:7bdb1a10043f | 76 | //get_rxStatus( int i ) |
bosko001 | 19:7bdb1a10043f | 77 | puts("TCP Clients Threads satatus:\n\r"); |
bosko001 | 19:7bdb1a10043f | 78 | printf("\n\r TCP statusi T[0]=%d T[1]=%d T[2]=%d T[3]=%d \n\r", get_rxStatus(0), get_rxStatus(1), get_rxStatus(2), get_rxStatus(3)); |
bosko001 | 19:7bdb1a10043f | 79 | printf(" TCP validy T[0]=%d T[1]=%d T[2]=%d T[3]=%d \n\r", get_rxValidy(0), get_rxValidy(1), get_rxValidy(2), get_rxValidy(3)); |
bosko001 | 20:d8277082f4e3 | 80 | printf("status ethernet mreze %d\n\r", getEthernetStatus( )); |
Bosko Lekovic |
18:5ee53205451a | 81 | } |
Bosko Lekovic |
18:5ee53205451a | 82 | break; |
bosko001 | 19:7bdb1a10043f | 83 | case 'T': case 't': |
bosko001 | 19:7bdb1a10043f | 84 | { |
bosko001 | 19:7bdb1a10043f | 85 | puts("TCP Clients Thread controll, thread number input:"); |
bosko001 | 19:7bdb1a10043f | 86 | char no = getchar()-'0'; |
bosko001 | 19:7bdb1a10043f | 87 | puts("\n\rTCP Clients Thread controll, thread flag input:"); |
bosko001 | 19:7bdb1a10043f | 88 | char fl = getchar()-'0'; |
bosko001 | 19:7bdb1a10043f | 89 | void restart_TcpClient( int noClient, int typeRestart ); |
bosko001 | 19:7bdb1a10043f | 90 | restart_TcpClientConnection( no, fl & 7 ); |
bosko001 | 19:7bdb1a10043f | 91 | printf("\n\rthread = %d, flag =%d\n\r", no, fl); |
bosko001 | 19:7bdb1a10043f | 92 | } |
Bosko Lekovic |
18:5ee53205451a | 93 | break; |
Bosko Lekovic |
18:5ee53205451a | 94 | case 'R': |
Bosko Lekovic |
18:5ee53205451a | 95 | printf("systemInit()\n\r"); |
Bosko Lekovic |
18:5ee53205451a | 96 | SystemInit(); |
Bosko Lekovic |
18:5ee53205451a | 97 | //goto __main; |
Bosko Lekovic |
18:5ee53205451a | 98 | break; |
bosko001 | 7:7ea932eb31f6 | 99 | } |
bosko001 | 7:7ea932eb31f6 | 100 | } |
bosko001 | 7:7ea932eb31f6 | 101 | } |
Bosko Lekovic |
18:5ee53205451a | 102 | Thread input_thread(input_fun, osPriorityNormal, 1000); |
bosko001 | 7:7ea932eb31f6 | 103 | |
bosko001 | 7:7ea932eb31f6 | 104 | |
bosko001 | 5:c9a908749d4c | 105 | C_HTMLparse *gpc_html; |
bosko001 | 7:7ea932eb31f6 | 106 | |
bosko001 | 7:7ea932eb31f6 | 107 | |
Bosko Lekovic |
18:5ee53205451a | 108 | |
bosko001 | 0:fe8cd064ea08 | 109 | |
bosko001 | 0:fe8cd064ea08 | 110 | int main(void) |
bosko001 | 0:fe8cd064ea08 | 111 | { |
bosko001 | 1:e1bde4e82763 | 112 | |
Bosko Lekovic |
18:5ee53205451a | 113 | printf("\n\r\n\n---------- POCETAK ------------- \n\n\r"); |
bosko001 | 3:1196befeace0 | 114 | |
bosko001 | 3:1196befeace0 | 115 | init_FlashData( ); |
bosko001 | 3:1196befeace0 | 116 | |
bosko001 | 5:c9a908749d4c | 117 | gpc_html = new C_HTMLparse; |
Bosko Lekovic |
18:5ee53205451a | 118 | C_HTMLparse *p_temp_html = new C_HTMLparse; |
bosko001 | 3:1196befeace0 | 119 | |
Bosko Lekovic |
18:5ee53205451a | 120 | // PROVERA KONZISTENCIJE FLASH PODATAKA |
Bosko Lekovic |
18:5ee53205451a | 121 | putFLASHintoHTML( p_temp_html ); |
bosko001 | 12:cbfc10c15437 | 122 | |
Bosko Lekovic |
18:5ee53205451a | 123 | if( test_FlashDataProbity( )) |
Bosko Lekovic |
18:5ee53205451a | 124 | { |
Bosko Lekovic |
18:5ee53205451a | 125 | printf( "MAIN: dobri Flash podaci\n\r"); |
Bosko Lekovic |
18:5ee53205451a | 126 | putFLASHintoHTML( gpc_html ); |
Bosko Lekovic |
18:5ee53205451a | 127 | } |
Bosko Lekovic |
18:5ee53205451a | 128 | else |
Bosko Lekovic |
18:5ee53205451a | 129 | { |
Bosko Lekovic |
18:5ee53205451a | 130 | printf("MAIN: losi FLASH podaci\n\r"); |
Bosko Lekovic |
18:5ee53205451a | 131 | putHTMLintoFLASH( gpc_html ); |
Bosko Lekovic |
18:5ee53205451a | 132 | putFLASHintoHTML( gpc_html ); |
Bosko Lekovic |
18:5ee53205451a | 133 | } |
Bosko Lekovic |
18:5ee53205451a | 134 | delete p_temp_html; |
Bosko Lekovic |
18:5ee53205451a | 135 | |
Bosko Lekovic |
18:5ee53205451a | 136 | // showFlashData( ); |
bosko001 | 3:1196befeace0 | 137 | |
bosko001 | 1:e1bde4e82763 | 138 | |
bosko001 | 21:2232f5a34eb4 | 139 | //extern EthernetInterface *gp_eth; |
bosko001 | 12:cbfc10c15437 | 140 | |
bosko001 | 21:2232f5a34eb4 | 141 | |
bosko001 | 21:2232f5a34eb4 | 142 | |
bosko001 | 12:cbfc10c15437 | 143 | |
bosko001 | 21:2232f5a34eb4 | 144 | if( ethernet_setup( ) ) |
bosko001 | 21:2232f5a34eb4 | 145 | { |
bosko001 | 21:2232f5a34eb4 | 146 | start_TcpClients( ); |
bosko001 | 21:2232f5a34eb4 | 147 | start_UdpClients( ); |
bosko001 | 21:2232f5a34eb4 | 148 | inic_TcpServerToFlash( ); |
bosko001 | 21:2232f5a34eb4 | 149 | p_led = &GLed; |
bosko001 | 21:2232f5a34eb4 | 150 | } |
bosko001 | 21:2232f5a34eb4 | 151 | else p_led = &BLed; |
bosko001 | 16:c4e0e8b4d8fc | 152 | |
bosko001 | 21:2232f5a34eb4 | 153 | start_SerialCom( ); |
bosko001 | 12:cbfc10c15437 | 154 | |
bosko001 | 4:7abcf4543282 | 155 | extern void test_HTML(void); |
bosko001 | 12:cbfc10c15437 | 156 | // test_HTML( ); |
bosko001 | 4:7abcf4543282 | 157 | |
bosko001 | 2:45b351b4fc2a | 158 | |
bosko001 | 2:45b351b4fc2a | 159 | int i=0; |
bosko001 | 21:2232f5a34eb4 | 160 | |
bosko001 | 21:2232f5a34eb4 | 161 | int s = getEthernetStatus(); |
bosko001 | 21:2232f5a34eb4 | 162 | if( s == 1 ) p_led = &GLed; |
bosko001 | 21:2232f5a34eb4 | 163 | else p_led = &BLed; |
bosko001 | 21:2232f5a34eb4 | 164 | int k = s; |
bosko001 | 21:2232f5a34eb4 | 165 | |
bosko001 | 2:45b351b4fc2a | 166 | while(true) |
bosko001 | 2:45b351b4fc2a | 167 | { |
bosko001 | 21:2232f5a34eb4 | 168 | if(i++ >10 ) |
bosko001 | 21:2232f5a34eb4 | 169 | { |
bosko001 | 21:2232f5a34eb4 | 170 | i=0; |
bosko001 | 21:2232f5a34eb4 | 171 | s = getEthernetStatus(); |
bosko001 | 21:2232f5a34eb4 | 172 | if( s != k) |
bosko001 | 21:2232f5a34eb4 | 173 | { |
bosko001 | 21:2232f5a34eb4 | 174 | *p_led = 1; |
bosko001 | 21:2232f5a34eb4 | 175 | if( s == 1 ) p_led = &GLed; |
bosko001 | 21:2232f5a34eb4 | 176 | else if( s == 3) p_led = &BLed; |
bosko001 | 21:2232f5a34eb4 | 177 | k = s; |
bosko001 | 21:2232f5a34eb4 | 178 | } |
bosko001 | 21:2232f5a34eb4 | 179 | else *p_led = !*p_led; |
bosko001 | 21:2232f5a34eb4 | 180 | |
bosko001 | 21:2232f5a34eb4 | 181 | } |
bosko001 | 2:45b351b4fc2a | 182 | wait(0.01); |
bosko001 | 0:fe8cd064ea08 | 183 | } |
bosko001 | 3:1196befeace0 | 184 | |
Bosko Lekovic |
18:5ee53205451a | 185 | // deinit_FlashData( ); |
bosko001 | 3:1196befeace0 | 186 | |
bosko001 | 3:1196befeace0 | 187 | |
bosko001 | 0:fe8cd064ea08 | 188 | } |
bosko001 | 0:fe8cd064ea08 | 189 | |
bosko001 | 1:e1bde4e82763 | 190 | |
bosko001 | 2:45b351b4fc2a | 191 | |
bosko001 | 2:45b351b4fc2a | 192 | |
bosko001 | 2:45b351b4fc2a | 193 | |
bosko001 | 1:e1bde4e82763 | 194 | |
bosko001 | 1:e1bde4e82763 | 195 | |
bosko001 | 1:e1bde4e82763 | 196 | |
bosko001 | 0:fe8cd064ea08 | 197 | // |
bosko001 | 0:fe8cd064ea08 | 198 | //enum nsapi_error { |
bosko001 | 0:fe8cd064ea08 | 199 | // NSAPI_ERROR_OK = 0, /*!< no error */ |
bosko001 | 0:fe8cd064ea08 | 200 | // NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */ |
bosko001 | 0:fe8cd064ea08 | 201 | // NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */ |
bosko001 | 0:fe8cd064ea08 | 202 | // NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */ |
bosko001 | 0:fe8cd064ea08 | 203 | // NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */ |
bosko001 | 0:fe8cd064ea08 | 204 | // NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */ |
bosko001 | 0:fe8cd064ea08 | 205 | // NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */ |
bosko001 | 0:fe8cd064ea08 | 206 | // NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */ |
bosko001 | 0:fe8cd064ea08 | 207 | // NSAPI_ERROR_NO_SSID = -3008, /*!< ssid not found */ |
bosko001 | 0:fe8cd064ea08 | 208 | // NSAPI_ERROR_DNS_FAILURE = -3009, /*!< DNS failed to complete successfully */ |
bosko001 | 0:fe8cd064ea08 | 209 | // NSAPI_ERROR_DHCP_FAILURE = -3010, /*!< DHCP failed to complete successfully */ |
bosko001 | 0:fe8cd064ea08 | 210 | // NSAPI_ERROR_AUTH_FAILURE = -3011, /*!< connection to access point failed */ |
bosko001 | 0:fe8cd064ea08 | 211 | // NSAPI_ERROR_DEVICE_ERROR = -3012, /*!< failure interfacing with the network processor */ |
bosko001 | 0:fe8cd064ea08 | 212 | // NSAPI_ERROR_IN_PROGRESS = -3013, /*!< operation (eg connect) in progress */ |
bosko001 | 0:fe8cd064ea08 | 213 | // NSAPI_ERROR_ALREADY = -3014, /*!< operation (eg connect) already in progress */ |
bosko001 | 0:fe8cd064ea08 | 214 | // NSAPI_ERROR_IS_CONNECTED = -3015, /*!< socket is already connected */ |
bosko001 | 0:fe8cd064ea08 | 215 | // NSAPI_ERROR_CONNECTION_LOST = -3016, /*!< connection lost */ |
bosko001 | 0:fe8cd064ea08 | 216 | // NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */ |
bosko001 | 0:fe8cd064ea08 | 217 | //}; |