Time example

Time example

Time_example
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> new str_temp[10]; new val_temp; main(){ Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE); // Init RS232, Baud rate: 9600, Word length: 8bit, Stop bit: 1, Parity: none Delay(1000); Wait_GPS(); // With GPS coordinates it get real time while(1){ write_buf(RS232, 5, "Now: "); // Print text via the RS232 val_temp = get_val(Sensor_GMT_year); // Get year snprintf(str_temp, 2, "%i", val_temp); // Convert integer to string write_buf(RS232, strlen(str_temp), str_temp); // Print string write_buf(RS232, 1, "-"); // Print "-" val_temp = get_val(Sensor_GMT_month); // Get month snprintf(str_temp, 2, "%i", val_temp); // Convert integer to string write_buf(RS232, strlen(str_temp), str_temp); // Print string write_buf(RS232, 1, "-"); // Print "-" val_temp = get_val(Sensor_GMT_day); // Get day snprintf(str_temp, 2, "%i", val_temp); // Convert integer to string write_buf(RS232, strlen(str_temp), str_temp); // Print string write_buf(RS232, 1, " "); // Print " " val_temp = get_val(Sensor_GMT_hour); // Get hours snprintf(str_temp, 2, "%i", val_temp); // Convert integer to string write_buf(RS232, strlen(str_temp), str_temp); // Print string write_buf(RS232, 1, ":"); // Print ":" val_temp = get_val(Sensor_GMT_min); // Get minutes snprintf(str_temp, 2, "%i", val_temp); // Convert integer to string write_buf(RS232, strlen(str_temp), str_temp); // Print string write_buf(RS232, 1, ":"); // Print ":" val_temp = get_val(Sensor_GMT_sec); // Get seconds snprintf(str_temp, 2, "%i", val_temp); // Convert integer to string write_buf(RS232, strlen(str_temp), str_temp); // Print string write_buf(RS232, 2, "\r\n"); // Print carriage return and new line Delay(1000); // Delay 1000ms } } Wait_GPS(){ new stat = 0; while(stat < 5){ stat = get_val(Sensor_Satelites); Delay(1000); write_buf(RS232, 16, "Waiting GPS...\r\n"); } }