Acquisition for GNSS1A1
Dependencies: F7_Ethernet X_NUCLEO_IKS01A2 mbed-rtos mbed
Fork of Test2Boards by
main.cpp
00001 /*QUESTA è LA VERSIONE PER IL GPS SU ethernet*/ 00002 00003 #include "mbed.h" 00004 #include "rtos/rtos.h" 00005 #include "Teseo-LIV3F.h" 00006 #include <cstdlib> 00007 #include <vector> 00008 #include "XNucleoIKS01A2.h" 00009 #include <algorithm> 00010 #include "EthernetInterface.h" 00011 #include "NTPClient.h" 00012 00013 00014 /*IP E AFFINI*/ 00015 00016 const char * IP = "192.168.1.206";//"169.254.112.125"; 00017 const char * MASK = "255.255.255.0"; 00018 const char * GATEWAY = "192.168.1.1"; 00019 00020 00021 00022 /*cose imu*/ 00023 00024 #define ECHO_SERVER_PORT 7 00025 00026 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); 00027 Timer t; 00028 00029 DigitalOut myled1(LED1); 00030 DigitalOut myled2(LED2); 00031 DigitalOut myled3(LED3); 00032 00033 00034 00035 /*cose per gps*/ 00036 static Thread t1; 00037 static Thread t2; 00038 00039 static Mutex message_access; 00040 00041 static Timer system_timer; 00042 static Serial usb_serial(USBTX, USBRX, 9600); 00043 static Serial *serial_debug= &usb_serial; 00044 00045 static std::vector<int> ids; 00046 00047 00048 00049 static Teseo_LIV3F Teseo(D8, D13, D6, PE_7, PE_8, &usb_serial); 00050 00051 00052 struct gps_coordinate{ 00053 float lat; 00054 char lat_cardinal; 00055 float longitud; 00056 char long_cardinal; 00057 bool valid; 00058 00059 00060 00061 }; 00062 00063 gps_coordinate myPosition; 00064 00065 00066 00067 /*cose per sensori*/ 00068 00069 static Thread t3; 00070 00071 00072 00073 00074 /* Retrieve the composing elements of the expansion board */ 00075 00076 00077 /*THIS FUNCTION IS SIMPLY USED TO PRINT ON SERIAL THE NMEA MSG*/ 00078 /* 00079 void print_function (enum nmea_msg_id id, char *buf, int len){ 00080 00081 if (id == NMEA_END__) { 00082 puts("Not found\n\r"); 00083 return; 00084 } 00085 00086 if (!len) { 00087 puts("Not valid\n\r"); 00088 return; 00089 } 00090 printf("notify: %d " , id); 00091 for (int i = 0; i < len; ++i) 00092 printf("%c",buf[i]); 00093 puts("\n\r"); 00094 00095 00096 00097 } 00098 */ 00099 /*THIS FUNCTION PRINT ONLY THE MESSAGE WITH ID SAVED IN STATIC VARIALBE ids*/ 00100 /* 00101 void getSpectificMsg (){ 00102 00103 enum nmea_msg_id id; 00104 00105 Teseo.Reset(serial_debug); 00106 Teseo.startListener(serial_debug); 00107 00108 while(1) { 00109 00110 osEvent evt = Teseo.queue.get(); 00111 if (evt.status == osEventMessage){ 00112 00113 00114 struct teseo_msg *message = (struct teseo_msg *)evt.value.p; 00115 if (message->len){ 00116 id = Teseo.MsgDetect(message->buf, message->len, serial_debug); 00117 } 00118 00119 if ( find(ids.begin(), ids.end(), id) != ids.end() ){ 00120 print_function (id, message->buf, message->len); 00121 } 00122 00123 00124 00125 00126 00127 Teseo.mpool.free(message); 00128 00129 } 00130 00131 00132 00133 00134 00135 00136 } 00137 00138 } 00139 00140 00141 00142 00143 */ 00144 00145 00146 int main() { 00147 00148 00149 00150 //cpose per comunicazioni 00151 00152 00153 00154 00155 EthernetInterface eth; 00156 eth.init(IP,MASK,GATEWAY); //Use DHCP 00157 eth.connect(); 00158 printf("IP Address is %s\n", eth.getIPAddress()); 00159 00160 00161 00162 00163 UDPSocket server; 00164 server.bind(ECHO_SERVER_PORT); 00165 00166 00167 Endpoint client; 00168 char buffer[256]; 00169 char outBuffer[256]; 00170 int32_t packetnumber =0; 00171 00172 00173 NTPClient ntp; 00174 ntp.setTime("169.254.92.70", 123); 00175 00176 00177 time_t ctTime; 00178 ctTime = time(NULL); 00179 printf("Time is set to (UTC): %s\r", ctime(&ctTime)); 00180 00181 while(1) { 00182 00183 printf("\nWaiting for UDP packet...\n"); 00184 00185 myled1=1; 00186 int n = server.receiveFrom(client, buffer, sizeof(buffer)); 00187 buffer[n] = '\0'; 00188 00189 printf("Received packet from: %s\n", client.get_address()); 00190 printf("Packet contents : '%s'\n",buffer); 00191 00192 00193 //set time 00194 NTPClient ntp; 00195 ntp.setTime(client.get_address(), 123,10000); 00196 00197 00198 time_t ctTime; 00199 ctTime = time(NULL); 00200 printf("Time is set to (UTC): %s\r", ctime(&ctTime)); 00201 time_t offset = time(NULL); 00202 t.start(); 00203 00204 00205 printf("Start Sending GPS messages\n"); 00206 00207 myled2=1; 00208 00209 myled3=1; 00210 printf ("start sending command\n"); 00211 server.sendTo(client, buffer, n); 00212 Teseo.SendCommand(Teseo_LIV3F::ENABLEALL); 00213 Teseo.SendCommand(Teseo_LIV3F::SAVE); 00214 Teseo.SendCommand(Teseo_LIV3F::REBOOT); 00215 Teseo.SendCommand(Teseo_LIV3F::ENABLEALL2); 00216 Teseo.SendCommand(Teseo_LIV3F::SAVE); 00217 Teseo.SendCommand(Teseo_LIV3F::REBOOT); 00218 printf ("ends sending command\n"); 00219 memset (&buffer[0], '\0', sizeof(buffer)); 00220 while (1){ 00221 packetnumber =packetnumber+1; 00222 //send imu 00223 00224 if (Teseo._uart.readable()) { 00225 int c = Teseo._uart.getc(); 00226 sprintf (buffer + strlen(buffer), "%c", c); 00227 //serial_debug->putc(c); 00228 if (c =='\n'){ 00229 // sprintf (outBuffer , "%d,%s",(t.read_ms()+(offset*1000)),buffer); 00230 sprintf (outBuffer , "%s",buffer); 00231 00232 n =sizeof (outBuffer); 00233 server.sendTo(client, outBuffer, n); 00234 memset (&buffer[0], '\0', sizeof(buffer)); 00235 memset (&outBuffer[0], '\0', sizeof(outBuffer)); 00236 00237 00238 } 00239 } 00240 00241 00242 00243 00244 //printf (buffer); 00245 00246 //wait (1); 00247 } 00248 00249 00250 00251 00252 } 00253 }
Generated on Sat Jul 16 2022 21:55:25 by
1.7.2
