nova proba

Committer:
Bosko Lekovic
Date:
Mon Jan 18 14:46:46 2021 +0100
Revision:
28:49bafc8bb056
Parent:
26:c14d034d7459
novije

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