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