Project Embedded Systems E-ict Denayer
Dependencies: BSP_DISCO_F746NG F7_Ethernet LCD_DISCO_F746NG TS_DISCO_F746NG mbed-rtos mbed
main.cpp@1:a2f7adf6db3d, 2017-01-24 (annotated)
- Committer:
- Ayrton_L
- Date:
- Tue Jan 24 00:23:30 2017 +0000
- Revision:
- 1:a2f7adf6db3d
- Parent:
- 0:16bcf70d262e
- Child:
- 2:1a5565ee8219
Latest stable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ayrton_L | 0:16bcf70d262e | 1 | #include "main.h" |
Ayrton_L | 0:16bcf70d262e | 2 | |
Ayrton_L | 1:a2f7adf6db3d | 3 | uint32_t ul_ResetDisplay( void ) |
Ayrton_L | 0:16bcf70d262e | 4 | { |
Ayrton_L | 0:16bcf70d262e | 5 | display.Clear( LCD_COLOR_WHITE ); |
Ayrton_L | 0:16bcf70d262e | 6 | display.SetBackColor( LCD_COLOR_WHITE ); |
Ayrton_L | 0:16bcf70d262e | 7 | display.SetTextColor( LCD_COLOR_BLACK ); |
Ayrton_L | 0:16bcf70d262e | 8 | return 0; |
Ayrton_L | 0:16bcf70d262e | 9 | } |
Ayrton_L | 0:16bcf70d262e | 10 | |
Ayrton_L | 1:a2f7adf6db3d | 11 | /*-----------------------------------------------------------*/ |
Ayrton_L | 1:a2f7adf6db3d | 12 | |
Ayrton_L | 1:a2f7adf6db3d | 13 | uint32_t ul_CheckDHCP( void ) |
Ayrton_L | 0:16bcf70d262e | 14 | { |
Ayrton_L | 1:a2f7adf6db3d | 15 | uint32_t ul_MyReturn = 2; |
Ayrton_L | 1:a2f7adf6db3d | 16 | Network *x_DynNetwork = mpool.alloc(); |
Ayrton_L | 1:a2f7adf6db3d | 17 | |
Ayrton_L | 0:16bcf70d262e | 18 | if( Eth.init( ) == 0 ) |
Ayrton_L | 0:16bcf70d262e | 19 | { |
Ayrton_L | 0:16bcf70d262e | 20 | char c_NewIP[16]; |
Ayrton_L | 0:16bcf70d262e | 21 | Eth.connect( ); |
Ayrton_L | 0:16bcf70d262e | 22 | strncpy( c_NewIP, Eth.getIPAddress( ), 16 ); |
Ayrton_L | 1:a2f7adf6db3d | 23 | if( strcmp( x_DynNetwork->c_IPAddress, c_NewIP ) == false ) |
Ayrton_L | 0:16bcf70d262e | 24 | { |
Ayrton_L | 1:a2f7adf6db3d | 25 | strncpy( x_DynNetwork->c_IPAddress, c_NewIP, 16 ); |
Ayrton_L | 1:a2f7adf6db3d | 26 | strncpy( x_DynNetwork->c_MACAddress, Eth.getMACAddress( ), 16 ); |
Ayrton_L | 1:a2f7adf6db3d | 27 | strncpy( x_DynNetwork->c_Netmask, Eth.getNetworkMask( ), 16 ); |
Ayrton_L | 1:a2f7adf6db3d | 28 | strncpy( x_DynNetwork->c_Gateway, Eth.getGateway( ), 16 ); |
Ayrton_L | 1:a2f7adf6db3d | 29 | queue.put(x_DynNetwork); |
Ayrton_L | 0:16bcf70d262e | 30 | } |
Ayrton_L | 1:a2f7adf6db3d | 31 | ul_MyReturn = 0; |
Ayrton_L | 1:a2f7adf6db3d | 32 | } |
Ayrton_L | 1:a2f7adf6db3d | 33 | else |
Ayrton_L | 1:a2f7adf6db3d | 34 | { |
Ayrton_L | 1:a2f7adf6db3d | 35 | ul_MyReturn =1; |
Ayrton_L | 1:a2f7adf6db3d | 36 | } |
Ayrton_L | 1:a2f7adf6db3d | 37 | return ul_MyReturn; |
Ayrton_L | 1:a2f7adf6db3d | 38 | } |
Ayrton_L | 1:a2f7adf6db3d | 39 | |
Ayrton_L | 1:a2f7adf6db3d | 40 | /*-----------------------------------------------------------*/ |
Ayrton_L | 1:a2f7adf6db3d | 41 | |
Ayrton_L | 1:a2f7adf6db3d | 42 | uint32_t ul_CheckInternet( void ) |
Ayrton_L | 1:a2f7adf6db3d | 43 | { |
Ayrton_L | 1:a2f7adf6db3d | 44 | uint32_t ul_Counter = 0; |
Ayrton_L | 1:a2f7adf6db3d | 45 | uint32_t ul_PingCounter = 0; |
Ayrton_L | 1:a2f7adf6db3d | 46 | ip_addr_t x_PingTarget = { 0x08080808 }; |
Ayrton_L | 1:a2f7adf6db3d | 47 | for( ul_Counter = 0; ul_Counter < 4; ul_Counter++) |
Ayrton_L | 1:a2f7adf6db3d | 48 | { |
Ayrton_L | 1:a2f7adf6db3d | 49 | if( ul_Ping( &x_PingTarget ) == 0 ) |
Ayrton_L | 1:a2f7adf6db3d | 50 | { |
Ayrton_L | 1:a2f7adf6db3d | 51 | ul_PingCounter++; |
Ayrton_L | 1:a2f7adf6db3d | 52 | } |
Ayrton_L | 1:a2f7adf6db3d | 53 | } |
Ayrton_L | 1:a2f7adf6db3d | 54 | if( ul_PingCounter >= 3 ) |
Ayrton_L | 1:a2f7adf6db3d | 55 | { |
Ayrton_L | 1:a2f7adf6db3d | 56 | return 0; |
Ayrton_L | 0:16bcf70d262e | 57 | } |
Ayrton_L | 0:16bcf70d262e | 58 | else |
Ayrton_L | 0:16bcf70d262e | 59 | { |
Ayrton_L | 0:16bcf70d262e | 60 | return 1; |
Ayrton_L | 0:16bcf70d262e | 61 | } |
Ayrton_L | 1:a2f7adf6db3d | 62 | |
Ayrton_L | 0:16bcf70d262e | 63 | } |
Ayrton_L | 0:16bcf70d262e | 64 | |
Ayrton_L | 1:a2f7adf6db3d | 65 | /*-----------------------------------------------------------*/ |
Ayrton_L | 0:16bcf70d262e | 66 | |
Ayrton_L | 1:a2f7adf6db3d | 67 | uint32_t ul_ShowDevices( void ) |
Ayrton_L | 0:16bcf70d262e | 68 | { |
Ayrton_L | 1:a2f7adf6db3d | 69 | uint32_t ul_GenIP = 0; |
Ayrton_L | 1:a2f7adf6db3d | 70 | uint32_t ul_MyIP = 0; |
Ayrton_L | 1:a2f7adf6db3d | 71 | uint32_t ul_Counter =0; |
Ayrton_L | 1:a2f7adf6db3d | 72 | uint32_t ul_DevCounter = 0; |
Ayrton_L | 1:a2f7adf6db3d | 73 | |
Ayrton_L | 1:a2f7adf6db3d | 74 | ip_addr_t x_ActDev[255]; //max 255 adressen binnen sub, beter is malloc gebruik en redefine van array/vector => max IP adressen haalbaar: 4228250625 |
Ayrton_L | 1:a2f7adf6db3d | 75 | |
Ayrton_L | 1:a2f7adf6db3d | 76 | osEvent x_Evt = queue.get(); |
Ayrton_L | 1:a2f7adf6db3d | 77 | if (x_Evt.status == osEventMessage) |
Ayrton_L | 1:a2f7adf6db3d | 78 | { |
Ayrton_L | 1:a2f7adf6db3d | 79 | Network *x_DynNetwork = (Network*)x_Evt.value.p; |
Ayrton_L | 1:a2f7adf6db3d | 80 | ul_MyIP = ( uint32_t ) x_DynNetwork->c_IPAddress ; |
Ayrton_L | 1:a2f7adf6db3d | 81 | mpool.free(x_DynNetwork); |
Ayrton_L | 1:a2f7adf6db3d | 82 | |
Ayrton_L | 1:a2f7adf6db3d | 83 | ul_GenIP = ul_MyIP & 0xFFFFFF00; |
Ayrton_L | 1:a2f7adf6db3d | 84 | |
Ayrton_L | 1:a2f7adf6db3d | 85 | for( ul_Counter = 1; ul_Counter < 255; ul_Counter++) |
Ayrton_L | 1:a2f7adf6db3d | 86 | { |
Ayrton_L | 1:a2f7adf6db3d | 87 | ul_GenIP++; |
Ayrton_L | 1:a2f7adf6db3d | 88 | if( ul_Ping( ( ip_addr_t * ) ul_GenIP ) == 0 ) |
Ayrton_L | 1:a2f7adf6db3d | 89 | { |
Ayrton_L | 1:a2f7adf6db3d | 90 | ip_addr_t x_ConIP = { ul_GenIP }; |
Ayrton_L | 1:a2f7adf6db3d | 91 | x_ActDev[ul_DevCounter] = x_ConIP; //voor een of andere reden is dit de enige manier dat werkt |
Ayrton_L | 1:a2f7adf6db3d | 92 | ul_DevCounter++; |
Ayrton_L | 1:a2f7adf6db3d | 93 | } |
Ayrton_L | 1:a2f7adf6db3d | 94 | } |
Ayrton_L | 1:a2f7adf6db3d | 95 | } |
Ayrton_L | 1:a2f7adf6db3d | 96 | |
Ayrton_L | 0:16bcf70d262e | 97 | return 0; |
Ayrton_L | 0:16bcf70d262e | 98 | } |
Ayrton_L | 0:16bcf70d262e | 99 | |
Ayrton_L | 1:a2f7adf6db3d | 100 | uint32_t ul_CreateMenu( void ) |
Ayrton_L | 0:16bcf70d262e | 101 | { |
Ayrton_L | 1:a2f7adf6db3d | 102 | //480x272 |
Ayrton_L | 1:a2f7adf6db3d | 103 | display.DrawRect( 0, 0, 125, 68); |
Ayrton_L | 1:a2f7adf6db3d | 104 | display.DisplayStringAt( 2, 34, ( uint8_t * )"Settings", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 105 | display.DrawRect( 0, 68, 125, 68); |
Ayrton_L | 1:a2f7adf6db3d | 106 | display.DisplayStringAt( 2, 102, ( uint8_t * )"PING", LEFT_MODE ); |
Ayrton_L | 0:16bcf70d262e | 107 | return 0; |
Ayrton_L | 0:16bcf70d262e | 108 | } |
Ayrton_L | 0:16bcf70d262e | 109 | |
Ayrton_L | 1:a2f7adf6db3d | 110 | /*-----------------------------------------------------------*/ |
Ayrton_L | 1:a2f7adf6db3d | 111 | |
Ayrton_L | 1:a2f7adf6db3d | 112 | uint32_t ul_ShowSettings( void ) |
Ayrton_L | 0:16bcf70d262e | 113 | { |
Ayrton_L | 1:a2f7adf6db3d | 114 | osEvent x_Evt = queue.get(); |
Ayrton_L | 1:a2f7adf6db3d | 115 | if (x_Evt.status == osEventMessage) |
Ayrton_L | 1:a2f7adf6db3d | 116 | { |
Ayrton_L | 1:a2f7adf6db3d | 117 | Network *x_DynNetwork = (Network*)x_Evt.value.p; |
Ayrton_L | 1:a2f7adf6db3d | 118 | ul_ResetDisplay( ); |
Ayrton_L | 1:a2f7adf6db3d | 119 | ul_CreateMenu( ); |
Ayrton_L | 1:a2f7adf6db3d | 120 | display.SetFont( &Font16 ); |
Ayrton_L | 1:a2f7adf6db3d | 121 | display.DisplayStringAt( 130, 10, ( uint8_t * )"IP address: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 122 | display.DisplayStringAt( 270, 10, ( uint8_t * )x_DynNetwork->c_IPAddress, LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 123 | display.DisplayStringAt( 130, 30, ( uint8_t * )"MAC Address: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 124 | display.DisplayStringAt( 270, 30, ( uint8_t * )x_DynNetwork->c_MACAddress, LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 125 | display.DisplayStringAt( 130, 50, ( uint8_t * )"Netmask: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 126 | display.DisplayStringAt( 270, 50, ( uint8_t * )x_DynNetwork->c_Netmask, LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 127 | display.DisplayStringAt( 130, 70, ( uint8_t * )"Gateway: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 128 | display.DisplayStringAt( 270, 70, ( uint8_t * )x_DynNetwork->c_Gateway, LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 129 | display.DisplayStringAt( 130, 90, ( uint8_t * )"Internet: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 130 | if( ul_CheckInternet == 0 ) |
Ayrton_L | 1:a2f7adf6db3d | 131 | { |
Ayrton_L | 1:a2f7adf6db3d | 132 | display.DisplayStringAt( 270, 90, ( uint8_t * )"connected", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 133 | } |
Ayrton_L | 1:a2f7adf6db3d | 134 | else |
Ayrton_L | 1:a2f7adf6db3d | 135 | { |
Ayrton_L | 1:a2f7adf6db3d | 136 | display.DisplayStringAt( 270, 90, ( uint8_t * )"not connected", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 137 | } |
Ayrton_L | 1:a2f7adf6db3d | 138 | mpool.free(x_DynNetwork); |
Ayrton_L | 1:a2f7adf6db3d | 139 | } |
Ayrton_L | 0:16bcf70d262e | 140 | return 0; |
Ayrton_L | 0:16bcf70d262e | 141 | } |
Ayrton_L | 0:16bcf70d262e | 142 | |
Ayrton_L | 1:a2f7adf6db3d | 143 | /*-----------------------------------------------------------*/ |
Ayrton_L | 1:a2f7adf6db3d | 144 | |
Ayrton_L | 0:16bcf70d262e | 145 | void v_TouchThread( void const *args ) |
Ayrton_L | 0:16bcf70d262e | 146 | { |
Ayrton_L | 1:a2f7adf6db3d | 147 | Timer x_Timer1; |
Ayrton_L | 1:a2f7adf6db3d | 148 | uint32_t ul_Time =0; |
Ayrton_L | 1:a2f7adf6db3d | 149 | uint32_t ul_Counter =0; |
Ayrton_L | 0:16bcf70d262e | 150 | TS_StateTypeDef Touch_State; |
Ayrton_L | 1:a2f7adf6db3d | 151 | ip_addr_t x_PingTarget = { 0x08080808 }; |
Ayrton_L | 0:16bcf70d262e | 152 | |
Ayrton_L | 0:16bcf70d262e | 153 | Touch.Init( 420, 272 ); |
Ayrton_L | 0:16bcf70d262e | 154 | |
Ayrton_L | 0:16bcf70d262e | 155 | while( 1 ) |
Ayrton_L | 0:16bcf70d262e | 156 | { |
Ayrton_L | 0:16bcf70d262e | 157 | Touch.GetState( &Touch_State ); |
Ayrton_L | 0:16bcf70d262e | 158 | if( ( Touch_State.touchDetected )&& ( Touch_State.touchX[0] < 125 )&& ( Touch_State.touchY[0] < 69 ) ) |
Ayrton_L | 0:16bcf70d262e | 159 | { |
Ayrton_L | 1:a2f7adf6db3d | 160 | ul_ResetDisplay( ); |
Ayrton_L | 1:a2f7adf6db3d | 161 | ul_CreateMenu( ); |
Ayrton_L | 1:a2f7adf6db3d | 162 | ul_ShowSettings( ); |
Ayrton_L | 0:16bcf70d262e | 163 | } |
Ayrton_L | 0:16bcf70d262e | 164 | else if( ( Touch_State.touchDetected )&& ( Touch_State.touchX[0] < 125 )&& ( Touch_State.touchY[0] > 68 )&& ( Touch_State.touchY[0] < 137 ) ) |
Ayrton_L | 1:a2f7adf6db3d | 165 | { |
Ayrton_L | 1:a2f7adf6db3d | 166 | for( ul_Counter = 0; ul_Counter < 4; ul_Counter++) |
Ayrton_L | 1:a2f7adf6db3d | 167 | { |
Ayrton_L | 1:a2f7adf6db3d | 168 | x_Timer1.start( ); |
Ayrton_L | 1:a2f7adf6db3d | 169 | ul_Ping( &x_PingTarget ); |
Ayrton_L | 1:a2f7adf6db3d | 170 | x_Timer1.stop( ); |
Ayrton_L | 1:a2f7adf6db3d | 171 | ul_Time = ul_Time + x_Timer1; |
Ayrton_L | 1:a2f7adf6db3d | 172 | } |
Ayrton_L | 1:a2f7adf6db3d | 173 | ul_ResetDisplay( ); |
Ayrton_L | 1:a2f7adf6db3d | 174 | ul_CreateMenu( ); |
Ayrton_L | 1:a2f7adf6db3d | 175 | ul_Time = ul_Time/4; |
Ayrton_L | 1:a2f7adf6db3d | 176 | display.DisplayStringAt( 130, 10, ( uint8_t * )"Internet: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 177 | if( ul_CheckInternet == 0 ) |
Ayrton_L | 1:a2f7adf6db3d | 178 | { |
Ayrton_L | 1:a2f7adf6db3d | 179 | display.DisplayStringAt( 270, 90, ( uint8_t * )"connected", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 180 | } |
Ayrton_L | 1:a2f7adf6db3d | 181 | else |
Ayrton_L | 1:a2f7adf6db3d | 182 | { |
Ayrton_L | 1:a2f7adf6db3d | 183 | display.DisplayStringAt( 270, 90, ( uint8_t * )"not connected", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 184 | } |
Ayrton_L | 1:a2f7adf6db3d | 185 | display.DisplayStringAt( 130, 30, ( uint8_t * )"PING: ", LEFT_MODE ); |
Ayrton_L | 1:a2f7adf6db3d | 186 | display.DisplayStringAt( 270, 30, ( uint8_t * )ul_Time, LEFT_MODE ); |
Ayrton_L | 0:16bcf70d262e | 187 | } |
Ayrton_L | 0:16bcf70d262e | 188 | } |
Ayrton_L | 0:16bcf70d262e | 189 | } |
Ayrton_L | 0:16bcf70d262e | 190 | |
Ayrton_L | 1:a2f7adf6db3d | 191 | /*-----------------------------------------------------------*/ |
Ayrton_L | 1:a2f7adf6db3d | 192 | |
Ayrton_L | 1:a2f7adf6db3d | 193 | int main( void ) |
Ayrton_L | 0:16bcf70d262e | 194 | { |
Ayrton_L | 1:a2f7adf6db3d | 195 | while( ul_CheckDHCP( ) != 0 ) |
Ayrton_L | 0:16bcf70d262e | 196 | { |
Ayrton_L | 1:a2f7adf6db3d | 197 | ul_ResetDisplay( ); |
Ayrton_L | 1:a2f7adf6db3d | 198 | ul_CreateMenu( ); |
Ayrton_L | 1:a2f7adf6db3d | 199 | |
Ayrton_L | 1:a2f7adf6db3d | 200 | Thread t_Touch( v_TouchThread ); |
Ayrton_L | 1:a2f7adf6db3d | 201 | t_Touch.set_priority( osPriorityNormal ); |
Ayrton_L | 1:a2f7adf6db3d | 202 | |
Ayrton_L | 1:a2f7adf6db3d | 203 | ul_ShowSettings( ); |
Ayrton_L | 1:a2f7adf6db3d | 204 | ul_CheckInternet( ); |
Ayrton_L | 1:a2f7adf6db3d | 205 | |
Ayrton_L | 1:a2f7adf6db3d | 206 | wait_ms(500); //kleinde delay => geen 1000 keer uitvoeren van checkdhcp => efficienter maar misschien iets trager |
Ayrton_L | 0:16bcf70d262e | 207 | } |
Ayrton_L | 0:16bcf70d262e | 208 | return 0; |
Ayrton_L | 0:16bcf70d262e | 209 | } |