Project Embedded Systems E-ict Denayer
Dependencies: BSP_DISCO_F746NG F7_Ethernet LCD_DISCO_F746NG TS_DISCO_F746NG mbed-rtos mbed
main.cpp
- Committer:
- Ayrton_L
- Date:
- 2017-08-17
- Revision:
- 4:860566e5814e
- Parent:
- 3:7aef6c427f97
- Child:
- 5:0518cef07365
File content as of revision 4:860566e5814e:
#include "main.h" int32_t l_ResetDisplay( void ) { display.Clear( LCD_COLOR_WHITE ); display.SetBackColor( LCD_COLOR_WHITE ); display.SetTextColor( LCD_COLOR_BLACK ); return 0; } /*-----------------------------------------------------------*/ int32_t l_ShowSettings( void ) { l_ResetDisplay( ); display.SetFont( &Font16 ); display.DisplayStringAt( 10, 10, ( uint8_t * )"Starting application", LEFT_MODE ); display.DisplayStringAt( 10, 30, ( uint8_t * )"Initiating EthernetInterface", LEFT_MODE ); if( Eth.init( ) == 0 ) { display.DisplayStringAt( 10, 50, ( uint8_t * )"Initiating EthernetInterface: done", LEFT_MODE ); display.DisplayStringAt( 10, 70, ( uint8_t * )"Connecting to EthernetInterface", LEFT_MODE ); char c_NewIP[16]; Eth.connect( ); display.DisplayStringAt( 10, 90, ( uint8_t * )"Initiating EthernetInterface: done", LEFT_MODE ); display.DisplayStringAt( 10, 110, ( uint8_t * )"Receiving network information", LEFT_MODE ); strncpy( c_NewIP, Eth.getIPAddress( ), 16 ); l_ResetDisplay( ); display.DisplayStringAt( 130, 10, ( uint8_t * )"IP address: ", LEFT_MODE ); display.DisplayStringAt( 270, 10, ( uint8_t * )c_NewIP, LEFT_MODE ); display.DisplayStringAt( 130, 30, ( uint8_t * )"Netmask: ", LEFT_MODE ); display.DisplayStringAt( 270, 30, ( uint8_t * )Eth.getNetworkMask( ), LEFT_MODE ); display.DisplayStringAt( 130, 50, ( uint8_t * )"Gateway: ", LEFT_MODE ); display.DisplayStringAt( 270, 50, ( uint8_t * )Eth.getGateway( ), LEFT_MODE ); display.DisplayStringAt( 130, 70, ( uint8_t * )"Internet: ", LEFT_MODE ); l_sendNTPpacket(); } return 0; } /*-----------------------------------------------------------*/ int32_t l_sendNTPpacket(void) { UDPSocket x_Sock; int32_t l_ErrorCatch; uint32_t ul_Epoch; uint16_t us_LowWord; uint16_t us_HighWord; uint8_t uc_PacketBuffer[NTP_PACKET_SIZE]; uc_PacketBuffer[0] = 0b11100011; uc_PacketBuffer[1] = 0; uc_PacketBuffer[2] = 6; uc_PacketBuffer[3] = 0xEC; uc_PacketBuffer[12] = 49; uc_PacketBuffer[13] = 0x4E; uc_PacketBuffer[14] = 49; uc_PacketBuffer[15] = 52; l_ErrorCatch = x_Sock.init(); if( l_ErrorCatch == -1 ) { display.DisplayStringAt( 270, 70, ( uint8_t * )"Not Connected" , LEFT_MODE ); return -1; } Endpoint x_NTPServer; l_ErrorCatch = x_NTPServer.set_address(NTP_SERVER_ADDRESS, NTP_SERVER_PORT); if( l_ErrorCatch == -1 ) { l_ErrorCatch = x_NTPServer.set_address(NTP_SERVER_ADDRESS_IP, NTP_SERVER_PORT); if( l_ErrorCatch == -1 ) { display.DisplayStringAt( 270, 70, ( uint8_t * )"Not Connected" , LEFT_MODE ); return -2; } } l_ErrorCatch= x_Sock.sendTo(x_NTPServer, ( char* )uc_PacketBuffer, NTP_PACKET_SIZE); if( l_ErrorCatch == -1 ) { display.DisplayStringAt( 270, 70, ( uint8_t * )"Not Connected" , LEFT_MODE ); return -1; } l_ErrorCatch = x_Sock.receiveFrom(x_NTPServer, ( char* ) uc_PacketBuffer, NTP_PACKET_SIZE); if( l_ErrorCatch == -1 ) { display.DisplayStringAt( 270, 70, ( uint8_t * )"Not Connected" , LEFT_MODE ); return -1; } us_HighWord = (uc_PacketBuffer[40] << 8 ) | uc_PacketBuffer[41]; us_LowWord = (uc_PacketBuffer[42] << 8 ) | uc_PacketBuffer[43]; ul_Epoch = ((us_HighWord << 16) | us_LowWord ); ul_Epoch = ul_Epoch - 2208988800; display.SetFont( &Font16 ); display.DisplayStringAt( 270, 70, ( uint8_t * )"Connected" , LEFT_MODE ); x_Sock.close(); return 0; } /*-----------------------------------------------------------*/ int main( void ) { l_ShowSettings( ); Eth.disconnect(); }