p1

Committer:
bosko001
Date:
Thu Jun 18 15:23:39 2020 +0000
Revision:
7:be56cf51685d
Parent:
5:ecaf089d1c8a
p1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 0:b01306ccbbe1 1 /* mbed Microcontroller Library
bosko001 0:b01306ccbbe1 2 * Copyright (c) 2019 ARM Limited
bosko001 0:b01306ccbbe1 3 * SPDX-License-Identifier: Apache-2.0
bosko001 0:b01306ccbbe1 4 */
bosko001 0:b01306ccbbe1 5
bosko001 0:b01306ccbbe1 6 #include "mbed.h"
bosko001 0:b01306ccbbe1 7 #include "platform/mbed_thread.h"
bosko001 0:b01306ccbbe1 8
bosko001 0:b01306ccbbe1 9 #include "EthernetInterface.h"
bosko001 0:b01306ccbbe1 10
bosko001 0:b01306ccbbe1 11 #include <stdio.h>
bosko001 0:b01306ccbbe1 12 #include <string.h>
bosko001 0:b01306ccbbe1 13 #include "TCPSocket.h"
bosko001 0:b01306ccbbe1 14
bosko001 4:0aec01df33d2 15 #include "PGSdisplay.h"
bosko001 7:be56cf51685d 16 #include "ParkareClient.h"
bosko001 7:be56cf51685d 17
bosko001 7:be56cf51685d 18
bosko001 4:0aec01df33d2 19
bosko001 0:b01306ccbbe1 20
bosko001 7:be56cf51685d 21 char MyIPaddress[]= "192.168.2.11";
bosko001 7:be56cf51685d 22 char MyNETmask []= "255.255.248.0";
bosko001 7:be56cf51685d 23 char MyGWaddress[]= "192.168.1.1";
bosko001 0:b01306ccbbe1 24
bosko001 7:be56cf51685d 25 char conf_server_ip[] = "192.168.2.254";
bosko001 7:be56cf51685d 26 int conf_server_port = 12197;
bosko001 0:b01306ccbbe1 27
bosko001 0:b01306ccbbe1 28
bosko001 7:be56cf51685d 29 Thread *threadGarColl = NULL;
bosko001 7:be56cf51685d 30
bosko001 0:b01306ccbbe1 31
bosko001 0:b01306ccbbe1 32 EthernetInterface eth;
bosko001 0:b01306ccbbe1 33 nsapi_error_t err;
bosko001 7:be56cf51685d 34 volatile int ethinic_flag = 0;
bosko001 7:be56cf51685d 35
bosko001 7:be56cf51685d 36 void theth_fun( void )
bosko001 7:be56cf51685d 37 {
bosko001 7:be56cf51685d 38
bosko001 7:be56cf51685d 39 // while( true )
bosko001 7:be56cf51685d 40 {
bosko001 7:be56cf51685d 41 // if(ethinic_flag==0)
bosko001 7:be56cf51685d 42 {
bosko001 7:be56cf51685d 43 printf(" setovanje ethernet mreze \n\r");
bosko001 7:be56cf51685d 44 if( (err = eth.set_network(MyIPaddress,MyNETmask,MyGWaddress))== NSAPI_ERROR_OK )
bosko001 7:be56cf51685d 45 {
bosko001 7:be56cf51685d 46 printf(" uspostavljanje konekcije \n\r");
bosko001 7:be56cf51685d 47 if( (err = eth.connect()) == NSAPI_ERROR_OK )
bosko001 7:be56cf51685d 48 {
bosko001 7:be56cf51685d 49
bosko001 7:be56cf51685d 50 printf( "MAC adresa: %s\n\r", eth.get_mac_address() );
bosko001 7:be56cf51685d 51 printf( "IP adresa: %s\n\r", eth.get_ip_address() );
bosko001 7:be56cf51685d 52 printf( "net mask: %s\n\r", eth.get_netmask() );
bosko001 7:be56cf51685d 53 printf( "GW adresa: %s\n\r", eth.get_gateway() );
bosko001 7:be56cf51685d 54 ethinic_flag = 1;
bosko001 7:be56cf51685d 55 }
bosko001 7:be56cf51685d 56 }
bosko001 7:be56cf51685d 57 }
bosko001 7:be56cf51685d 58 fflush( stdout);
bosko001 7:be56cf51685d 59 // thread_sleep_for( 1000 );
bosko001 7:be56cf51685d 60 }
bosko001 7:be56cf51685d 61 }
bosko001 7:be56cf51685d 62
bosko001 7:be56cf51685d 63
bosko001 0:b01306ccbbe1 64
markoc 1:10e2a0bef1b4 65 char * extract_string( char delimiter, char *ulazni_str, int n_str );
markoc 1:10e2a0bef1b4 66 void putOnDisp( char *s, char boja);
bosko001 0:b01306ccbbe1 67
bosko001 0:b01306ccbbe1 68 void tcpThread_fun( EthernetInterface *e);
markoc 1:10e2a0bef1b4 69 void requestMessage( EthernetInterface *e);
markoc 1:10e2a0bef1b4 70
bosko001 7:be56cf51685d 71 DigitalOut ledc(LED3,1);
bosko001 0:b01306ccbbe1 72
bosko001 0:b01306ccbbe1 73 int main(void)
bosko001 0:b01306ccbbe1 74 {
bosko001 7:be56cf51685d 75 printf("\n\r----------------Pocetak------------ \n\r"); fflush(stdout);
bosko001 2:4deba4264f65 76
bosko001 7:be56cf51685d 77 Thread ThEth;
bosko001 7:be56cf51685d 78 ThEth.start( theth_fun );
bosko001 2:4deba4264f65 79
bosko001 5:ecaf089d1c8a 80 init_disp( );
bosko001 7:be56cf51685d 81 putOnDisp("elcom",3);
bosko001 7:be56cf51685d 82
bosko001 7:be56cf51685d 83 ThEth.join( );
bosko001 7:be56cf51685d 84 printf(" Thread ethernet = %d \n\r", (int)&ThEth );
bosko001 7:be56cf51685d 85
bosko001 7:be56cf51685d 86 SocketAddress sa(conf_server_ip, conf_server_port);
bosko001 7:be56cf51685d 87 printf("socket inicijalizovan \n\r"); fflush(stdout);
bosko001 7:be56cf51685d 88
bosko001 7:be56cf51685d 89 putOnDisp("flash",2);
bosko001 7:be56cf51685d 90
bosko001 7:be56cf51685d 91 extern char crm_req[];
bosko001 7:be56cf51685d 92 extern char srm_req[];
bosko001 7:be56cf51685d 93 struct s_rm s_crm = { &eth, &sa, crm_req, crm_fun, 0 };
bosko001 7:be56cf51685d 94 struct s_rm s_srm = { &eth, &sa, srm_req, srm_fun, 0 };
markoc 1:10e2a0bef1b4 95
bosko001 0:b01306ccbbe1 96
bosko001 7:be56cf51685d 97 printf("Parkare server zahtev za katalog \n\r"); fflush(stdout);
bosko001 2:4deba4264f65 98
bosko001 2:4deba4264f65 99
bosko001 2:4deba4264f65 100 Thread CRMThread;
bosko001 2:4deba4264f65 101 CRMThread.start( callback( requestMessageThread, &s_crm ));
bosko001 2:4deba4264f65 102 CRMThread.join();
bosko001 0:b01306ccbbe1 103 int i=0;
bosko001 2:4deba4264f65 104 // thread_sleep_for(15000);
bosko001 2:4deba4264f65 105
bosko001 7:be56cf51685d 106 printf("ispred while-a\n\r");
bosko001 7:be56cf51685d 107 fflush(stdout);
bosko001 7:be56cf51685d 108
bosko001 2:4deba4264f65 109 while(true) {
bosko001 7:be56cf51685d 110 // ledc = !ledc;
bosko001 7:be56cf51685d 111 if( threadGarColl != NULL ) {delete threadGarColl; threadGarColl = NULL; }
bosko001 7:be56cf51685d 112
bosko001 2:4deba4264f65 113 thread_sleep_for(5000);
bosko001 2:4deba4264f65 114
bosko001 7:be56cf51685d 115 printf("Parkare server zahtev za broj \n\r"); fflush(stdout);
bosko001 2:4deba4264f65 116 Thread SRMThread;
bosko001 7:be56cf51685d 117 s_srm.response = 0;
bosko001 2:4deba4264f65 118 SRMThread.start( callback( requestMessageThread, &s_srm ));
bosko001 2:4deba4264f65 119 SRMThread.join();
bosko001 7:be56cf51685d 120 printf("PGSdisplay status response %d\n\r",s_srm.response);
bosko001 0:b01306ccbbe1 121 }
bosko001 2:4deba4264f65 122 // printf("\n\rmain: Kraj, error=%d\n\r",err); fflush(stdout);
bosko001 0:b01306ccbbe1 123 }
bosko001 0:b01306ccbbe1 124
bosko001 0:b01306ccbbe1 125
bosko001 0:b01306ccbbe1 126
bosko001 7:be56cf51685d 127 //
bosko001 7:be56cf51685d 128 //unsigned char sendBuffer[]= "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\nMarko je ovde"; // HTTP Message Body, length = 11
bosko001 7:be56cf51685d 129 //unsigned char sb[1000]="HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n";
bosko001 7:be56cf51685d 130 //
bosko001 7:be56cf51685d 131 //
bosko001 7:be56cf51685d 132 //
bosko001 7:be56cf51685d 133 //unsigned char txbuf[100]="test konekcije";
bosko001 7:be56cf51685d 134 //unsigned char rxbuf[100];
markoc 1:10e2a0bef1b4 135
markoc 1:10e2a0bef1b4 136
bosko001 0:b01306ccbbe1 137
bosko001 0:b01306ccbbe1 138 //
bosko001 0:b01306ccbbe1 139 //enum nsapi_error {
bosko001 0:b01306ccbbe1 140 // NSAPI_ERROR_OK = 0, /*!< no error */
bosko001 0:b01306ccbbe1 141 // NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */
bosko001 0:b01306ccbbe1 142 // NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */
bosko001 0:b01306ccbbe1 143 // NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */
bosko001 0:b01306ccbbe1 144 // NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */
bosko001 0:b01306ccbbe1 145 // NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */
bosko001 0:b01306ccbbe1 146 // NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */
bosko001 0:b01306ccbbe1 147 // NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */
bosko001 0:b01306ccbbe1 148 // NSAPI_ERROR_NO_SSID = -3008, /*!< ssid not found */
bosko001 0:b01306ccbbe1 149 // NSAPI_ERROR_DNS_FAILURE = -3009, /*!< DNS failed to complete successfully */
bosko001 0:b01306ccbbe1 150 // NSAPI_ERROR_DHCP_FAILURE = -3010, /*!< DHCP failed to complete successfully */
bosko001 0:b01306ccbbe1 151 // NSAPI_ERROR_AUTH_FAILURE = -3011, /*!< connection to access point failed */
bosko001 0:b01306ccbbe1 152 // NSAPI_ERROR_DEVICE_ERROR = -3012, /*!< failure interfacing with the network processor */
bosko001 0:b01306ccbbe1 153 // NSAPI_ERROR_IN_PROGRESS = -3013, /*!< operation (eg connect) in progress */
bosko001 0:b01306ccbbe1 154 // NSAPI_ERROR_ALREADY = -3014, /*!< operation (eg connect) already in progress */
bosko001 0:b01306ccbbe1 155 // NSAPI_ERROR_IS_CONNECTED = -3015, /*!< socket is already connected */
bosko001 0:b01306ccbbe1 156 // NSAPI_ERROR_CONNECTION_LOST = -3016, /*!< connection lost */
bosko001 0:b01306ccbbe1 157 // NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */
bosko001 0:b01306ccbbe1 158 //};
bosko001 0:b01306ccbbe1 159
bosko001 0:b01306ccbbe1 160