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