main() { int count,hi_hour,lo_hour,hi_min,lo_min,hi_sec,lo_sec,local_hr,t; int error, err_test, y1, y2, y3, y4, y5, day, month, year; int julian1, julian2, julian3, julian4, julian5, julian6, julian7, julian8; str utc_hour[3],slocal_hr[3],set_dos_time[20]="time ",set_dos_date[20]="date "; str juldatestr[10] = " "; str geordatestr[10] = " "; str monthstr[3], daystr[3], yearstr[4]; int integerdate; // Initialize variables error=1; //Indicates that time info is yet to be decoded properly err_test=-1; //Used to detect if time info is properly recieved hi_hour=-1; //Receives hi byte of hour time info lo_hour=-1; //Receives lo byte of hour time info hi_min=-1; //Recieves hi byte of minute time info lo_min=-1; //Receives lo byte of minute time info hi_sec=-1; //Receives hi byte of second time info lo_sec=-1; //Recieves lo byte of second time info julian1=-1; julian2=-1; julian3=-1; julian4=-1; julian5=-1; _alarm_on = 0; _sound_on = 0; //Show opening TIMESET display clear_scr(); prints("Welcome to Timeset!!!"); prints("Now dialing The Naval Observertory for the time..."); //Dial for the time set_cparams(1200,0,8,1); if(!dial("m1-202-653-0351",10)) { prints("Can not contact the Naval Observatory! Aborting."); tone(300,1); return; //After 10 tries can't reach the time. Abort. } //Decode the time info received while(error) { if(!waitfor("UTC",10)) { prints("Timeout error, aborting!"); hangup(); return; //Time info is not flowing right. Abort. } if(!waitfor("*",3)) { prints("Timeout error, aborting!"); hangup(); return; //Time info is not flowing right. Abort. } flushbuf(); count=2; //Amount of bytes to wait until date data should start while(count) { while(cgetc()==-1) { } count=count-1; } while(julian1==-1) { julian1=cgetc(); } while(julian2==-1) { julian2=cgetc(); } while(julian3==-1) { julian3=cgetc(); } while(julian4==-1) { julian4=cgetc(); } while(julian5==-1) { julian5=cgetc(); } count=5; //Amount of bytes to wait until time data should start while(count) { while(cgetc()==-1) { } count=count-1; } //Receive the time data while(hi_hour==-1) { hi_hour=cgetc(); } while(lo_hour==-1) { lo_hour=cgetc(); } while(hi_min==-1) { hi_min=cgetc(); } while(lo_min==-1) { lo_min=cgetc(); } while(hi_sec==-1) { hi_sec=cgetc(); } while(lo_sec==-1) { lo_sec=cgetc(); } if(waitfor("UTC",2)) { error = 0; } } //Start building the DOS set time command strcat(utc_hour,hi_hour); strcat(utc_hour,lo_hour); local_hr=stoi(utc_hour); // ****************** Adjust UTC time to local time here ***************** //Pacific Daylight time is - 7 hours //Pacific Standard time is - 8 hours local_hr=local_hr-7; // *********************************************************************** // *********************************************************************** if(local_hr<0) { local_hr=local_hr+24; } itos(local_hr,slocal_hr); //Set DOS time strcat(set_dos_time,slocal_hr); strcat(set_dos_time,":"); strcat(set_dos_time,hi_min); strcat(set_dos_time,lo_min); strcat(set_dos_time,":"); strcat(set_dos_time,hi_sec); strcat(set_dos_time,lo_sec); dos(set_dos_time,0); clear_scr(); prints(""); prints(""); prints(""); prints(""); prints(""); prints(""); gotoxy(28,gety()); prints("SUCCESSFULLY set time"); //Hangup the modem and clear extra received data hangup(); flushbuf(); //Set DOS date strcat(juldatestr,"24"); // Add epoch strcat(juldatestr,julian1); strcat(juldatestr,julian2); strcat(juldatestr,julian3); strcat(juldatestr,julian4); strcat(juldatestr,julian5); integerdate = stoi(juldatestr); y1 = integerdate + 68569; y2 = (4 * y1) / 146097; y3 = y1 - (((146097 * y2) + 3) / 4); year = (4000 * (y3 + 1)) / 1461001; y4 = (y3 - ((1461 * year) / 4)) + 31; month = (80 * y4) / 2447; day = y4 - ((2447 * month) / 80); day = day + 1; y5 = month / 11; month = month + 2 - (12 * y5); year = 100 * (y2 - 49) + year + y5; itos(integerdate, geordatestr ); itos(month, monthstr ); itos(day, daystr ); itos(year, yearstr ); //Set DOS date strcat(set_dos_date,monthstr); strcat(set_dos_date,"-"); strcat(set_dos_date,daystr); strcat(set_dos_date,"-"); strcat(set_dos_date,yearstr); dos(set_dos_date,0); //Display current time continuosly _scr_chk_key=0; //Disable keyboard scan so inkey will work properly cursor_onoff(0); //Disable the cursor because it is annoying clear_scr(); run("c:\rolex", "", 2); clear_scr(); prints("Thank you for using TIMESET!"); exittelix(0, 1); }