nova verzija tcp+udp->serial com

Committer:
bosko001
Date:
Thu Jun 11 10:41:11 2020 +0200
Revision:
22:11279d24a105
Parent:
21:2232f5a34eb4
Child:
23:766819b4c453
uradjen  soft reset

Who changed what in which revision?

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