• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-12-stable/contrib/ntp/ntpd/

Lines Matching refs:instance

88  * instance->pp->leap indicator but only run this test in December and June for
268 struct instance {
359 #define rcvbuf instance->Rcvbuf
360 #define rcvptr instance->Rcvptr
365 static void oncore_consume (struct instance *);
366 static void oncore_read_config (struct instance *);
368 static int oncore_ppsapi (struct instance *);
369 static void oncore_get_timestamp (struct instance *, long, long);
370 static void oncore_init_shmem (struct instance *);
372 static void oncore_antenna_report (struct instance *, enum antenna_state);
373 static void oncore_chan_test (struct instance *);
374 static void oncore_check_almanac (struct instance *);
375 static void oncore_check_antenna (struct instance *);
376 static void oncore_check_leap_sec (struct instance *);
378 static void oncore_compute_dH (struct instance *);
379 static void oncore_load_almanac (struct instance *);
380 static void oncore_log (struct instance *, int, const char *);
381 static int oncore_log_f (struct instance *, int, const char *, ...)
383 static void oncore_print_Cb (struct instance *, u_char *);
385 static void oncore_print_posn (struct instance *);
386 static void oncore_sendmsg (struct instance *, u_char *, size_t);
387 static void oncore_set_posn (struct instance *);
388 static void oncore_set_traim (struct instance *);
389 static void oncore_shmem_get_3D (struct instance *);
390 static void oncore_ss (struct instance *);
391 static int oncore_wait_almanac (struct instance *);
392 static void oncore_feed_clockproc (struct instance *);
394 static void oncore_msg_any (struct instance *, u_char *, size_t, int);
395 static void oncore_msg_Adef (struct instance *, u_char *, size_t);
396 static void oncore_msg_Ag (struct instance *, u_char *, size_t);
397 static void oncore_msg_As (struct instance *, u_char *, size_t);
398 static void oncore_msg_At (struct instance *, u_char *, size_t);
399 static void oncore_msg_Ay (struct instance *, u_char *, size_t);
400 static void oncore_msg_Az (struct instance *, u_char *, size_t);
401 static void oncore_msg_BaEaHa (struct instance *, u_char *, size_t);
402 static void oncore_msg_Bd (struct instance *, u_char *, size_t);
403 static void oncore_msg_Bj (struct instance *, u_char *, size_t);
404 static void oncore_msg_Bl (struct instance *, u_char *, size_t);
405 static void oncore_msg_BnEnHn (struct instance *, u_char *, size_t);
406 static void oncore_msg_CaFaIa (struct instance *, u_char *, size_t);
407 static void oncore_msg_Cb (struct instance *, u_char *, size_t);
408 static void oncore_msg_Cf (struct instance *, u_char *, size_t);
409 static void oncore_msg_Cj (struct instance *, u_char *, size_t);
410 static void oncore_msg_Cj_id (struct instance *, u_char *, size_t);
411 static void oncore_msg_Cj_init (struct instance *, u_char *, size_t);
412 static void oncore_msg_Ga (struct instance *, u_char *, size_t);
413 static void oncore_msg_Gb (struct instance *, u_char *, size_t);
414 static void oncore_msg_Gc (struct instance *, u_char *, size_t);
415 static void oncore_msg_Gj (struct instance *, u_char *, size_t);
416 static void oncore_msg_Sz (struct instance *, u_char *, size_t);
436 void (*handler) (struct instance *, u_char *, size_t);
597 register struct instance *instance;
605 /* create instance structure for this unit */
607 instance = emalloc(sizeof(*instance));
608 memset(instance, 0, sizeof(*instance));
613 instance->pp = pp;
614 instance->unit = unit;
615 instance->peer = peer;
616 instance->assert = 1;
617 instance->once = 1;
619 instance->Bj_day = -1;
620 instance->traim = -1;
621 instance->traim_in = -1;
622 instance->chan_in = -1;
623 instance->pps_control = -1; /* PPS control, M12 only */
624 instance->pps_control_msg_seen = -1; /* Have seen response to Gc msg */
625 instance->model = ONCORE_UNKNOWN;
626 instance->mode = MODE_UNKNOWN;
627 instance->site_survey = ONCORE_SS_UNKNOWN;
628 instance->Ag = 0xff; /* Satellite mask angle, unset by user */
629 instance->ant_state = ONCORE_ANTENNA_UNKNOWN;
638 oncore_log(instance, LOG_NOTICE, "ONCORE DRIVER -- CONFIGURING");
639 instance->o_state = ONCORE_NO_IDEA;
640 oncore_log(instance, LOG_NOTICE, "state = ONCORE_NO_IDEA");
675 oncore_log_f(instance, LOG_ERR, "Can't stat fd1 (%s)",
682 oncore_log_f(instance, LOG_ERR, "Can't stat fd2 (%s) %d %m",
689 oncore_log_f(instance, LOG_ERR, "Can't open fd1 (%s)",
706 oncore_log_f(instance, LOG_ERR,
714 if (time_pps_create(fd2, &instance->pps_h) < 0) {
715 oncore_log(instance, LOG_ERR, "exit, PPSAPI not found in kernel");
721 instance->ttyfd = fd1;
722 instance->ppsfd = fd2;
726 oncore_read_config(instance);
728 if (!oncore_ppsapi(instance))
736 oncore_log(instance, LOG_ERR, "can't do io_addclock");
739 free(instance);
742 pp->unitptr = instance;
751 oncore_init_shmem(instance);
759 instance->o_state = ONCORE_CHECK_ID;
760 oncore_log(instance, LOG_NOTICE, "state = ONCORE_CHECK_ID");
762 instance->timeout = 4;
763 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Set Posn Fix mode (not Idle (VP)) */
764 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
766 instance->pollcnt = 2;
781 register struct instance *instance;
785 instance = pp->unitptr;
790 if (instance != NULL) {
791 time_pps_destroy (instance->pps_h);
793 close(instance->ttyfd);
795 if ((instance->ppsfd != -1) && (instance->ppsfd != instance->ttyfd))
796 close(instance->ppsfd);
798 if (instance->shmemfd)
799 close(instance->shmemfd);
801 free(instance);
817 struct instance *instance;
819 instance = peer->procptr->unitptr;
820 if (instance->timeout) {
821 instance->timeout--;
822 if (instance->timeout == 0) {
823 oncore_log(instance, LOG_ERR,
827 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
828 oncore_log(instance, LOG_WARNING, "Oncore: Resend @@Cj");
833 if (!instance->pollcnt)
836 instance->pollcnt--;
838 instance->polled = 1;
849 struct instance *instance
855 if (time_pps_getcap(instance->pps_h, &cap) < 0) {
856 oncore_log_f(instance, LOG_ERR, "time_pps_getcap failed: %m");
860 if (time_pps_getparams(instance->pps_h, &instance->pps_p) < 0) {
861 oncore_log_f(instance, LOG_ERR, "time_pps_getparams failed: %m");
869 if (instance->assert) {
878 oncore_log_f(instance, LOG_INFO, "Initializing timing to %s.",
882 oncore_log_f(instance, LOG_ERR,
888 oncore_log_f(instance, LOG_NOTICE,
896 instance->pps_p.mode = (mode | mode1 | PPS_TSFMT_TSPEC) & cap;
898 if (time_pps_setparams(instance->pps_h, &instance->pps_p) < 0) {
899 oncore_log_f(instance, LOG_ERR, "ONCORE: time_pps_setparams fails %m");
905 if (instance->hardpps) {
908 oncore_log(instance, LOG_INFO, "HARDPPS Set.");
910 if (instance->assert)
917 if (time_pps_kcbind(instance->pps_h, PPS_KC_HARDPPS, i,
919 oncore_log_f(instance, LOG_ERR, "time_pps_kcbind failed: %m");
920 oncore_log(instance, LOG_ERR, "HARDPPS failed, abort...");
934 struct instance *instance
944 * The first thing we do is see if there is an instance->shmem_fname file (still)
951 if ((fd = open(instance->shmem_fname, O_RDONLY)) < 0)
952 oncore_log(instance, LOG_WARNING, "ONCORE: Can't open SHMEM file");
965 if ((instance->shmemfd = open(instance->shmem_fname, O_RDWR|O_CREAT|O_TRUNC, 0644)) < 0) {
966 oncore_log(instance, LOG_WARNING, "ONCORE: Can't open shmem");
980 instance->shmem_Cb = n;
984 instance->shmem_Ba = n;
988 instance->shmem_Ea = n;
992 instance->shmem_Ha = n;
1050 i = write(instance->shmemfd, buf, shmem_length);
1054 oncore_log(instance, LOG_ERR, "ONCORE: error writing shmem");
1055 close(instance->shmemfd);
1059 instance->shmem = (u_char *) mmap(0, shmem_length,
1064 MAP_SHARED, instance->shmemfd, (off_t)0);
1066 if (instance->shmem == (u_char *)MAP_FAILED) {
1067 instance->shmem = 0;
1068 close(instance->shmemfd);
1072 oncore_log_f(instance, LOG_NOTICE,
1074 (u_long) shmem_length, instance->shmem_fname);
1086 struct instance *instance
1225 cp, instance->unit); /* try "ntp.oncore.0 */
1229 cp, instance->unit); /* try "ntp.oncore0" */
1238 instance->init_type = 4;
1280 instance->shmem_fname = estrdup(ca);
1297 instance->ss_lat = sign*1000*(fabs(f3) + 60*(fabs(f2) + 60*f1)); /*miliseconds*/
1307 instance->ss_long = sign*1000*(fabs(f3) + 60*(fabs(f2) + 60*f1)); /*miliseconds*/
1315 instance->ss_ht = 100 * f1; /* cm */
1332 oncore_log_f(instance, LOG_WARNING,
1336 instance->delay = f1; /* delay in ns */
1352 oncore_log_f(instance, LOG_WARNING,
1356 instance->offset = f1; /* offset in ns */
1362 instance->assert = 1;
1364 instance->assert = 0;
1366 instance->hardpps = 1;
1368 instance->shmem_Posn = 2;
1370 instance->shmem_Posn = 3;
1374 instance->chan_in = i;
1376 instance->traim_in = 1; /* so TRAIM alone is YES */
1378 instance->traim_in = 0;
1382 instance->Ag = mask; /* Satellite mask angle */
1385 instance->pps_control = 1; /* PPS always on */
1387 instance->pps_control = 2; /* PPS on when satellite is available */
1389 instance->pps_control = 3; /* PPS on when TRAIM status is OK */
1391 oncore_log_f(instance, LOG_WARNING,
1404 instance->posn_set = 1;
1406 oncore_log_f(instance, LOG_WARNING,
1408 instance->posn_set = 0;
1410 oncore_log_f(instance, LOG_WARNING,
1416 instance->init_type = mode;
1418 oncore_log_f(instance, LOG_INFO, "Input mode = %d", mode);
1435 struct instance *instance;
1438 instance = peer->procptr->unitptr;
1446 oncore_log_f(instance, LOG_DEBUG,
1454 oncore_log(instance, LOG_DEBUG, Msg);
1461 oncore_log(instance, LOG_DEBUG, Msg);
1470 oncore_consume(instance);
1481 struct instance *instance
1494 oncore_log_f(instance, LOG_DEBUG,
1512 oncore_log_f(instance, LOG_DEBUG,
1524 oncore_log_f(instance, LOG_DEBUG,
1526 instance->unit, rcvbuf[2],
1539 oncore_log(instance, LOG_DEBUG, "NO <CR><LF> at end of message");
1543 if (instance->shmem != NULL) {
1544 instance->shmem[oncore_messages[m].shmem + 2]++;
1545 memcpy(instance->shmem + oncore_messages[m].shmem + 3,
1548 oncore_msg_any(instance, rcvbuf, (size_t) (l-3), m);
1550 oncore_messages[m].handler(instance, rcvbuf, (size_t) (l-3));
1556 oncore_log(instance, LOG_ERR, "Checksum mismatch!");
1563 oncore_log(instance, LOG_DEBUG, Msg);
1578 struct instance *instance,
1599 peer = instance->peer;
1608 if ((instance->site_survey == ONCORE_SS_DONE) && (instance->mode != MODE_0D)) {
1612 if ((instance->site_survey != ONCORE_SS_DONE) || (instance->mode != MODE_0D)) {
1620 if (instance->rsm.bad_almanac) {
1631 if (instance->count5) {
1632 instance->count5--;
1637 j = instance->ev_serial;
1640 if (time_pps_fetch(instance->pps_h, PPS_TSFMT_TSPEC, &pps_i,
1642 oncore_log_f(instance, LOG_ERR,
1648 if (instance->assert) {
1657 oncore_log_f(instance, LOG_DEBUG,
1662 oncore_log_f(instance, LOG_DEBUG,
1671 oncore_log(instance, LOG_NOTICE, "ONCORE: oncore_get_timestamp, error serial pps");
1676 instance->ev_serial = pps_i.assert_sequence;
1686 oncore_log_f(instance, LOG_DEBUG,
1691 oncore_log_f(instance, LOG_DEBUG,
1700 oncore_log(instance, LOG_ERR, "oncore_get_timestamp, error serial pps");
1704 instance->ev_serial = pps_i.clear_sequence;
1741 if (instance->assert)
1742 instance->pps_p.assert_offset.tv_nsec = -dt2;
1744 instance->pps_p.clear_offset.tv_nsec = -dt2;
1747 * using the saved instance->pps_p, since some other process on the
1759 if (time_pps_getcap(instance->pps_h, &current_mode) < 0) {
1760 oncore_log_f(instance, LOG_ERR,
1766 if (time_pps_getparams(instance->pps_h, &current_params) < 0) {
1767 oncore_log_f(instance, LOG_ERR,
1774 current_params.mode |= instance->pps_p.mode;
1783 if (time_pps_setparams(instance->pps_h, &current_params))
1784 oncore_log(instance, LOG_ERR, "ONCORE: Error doing time_pps_setparams");
1789 instance->pp->lastrec = ts;
1799 if (instance->chan == 6)
1800 Rsm = instance->BEHa[64];
1801 else if (instance->chan == 8)
1802 Rsm = instance->BEHa[72];
1803 else if (instance->chan == 12)
1804 Rsm = ((instance->BEHa[129]<<8) | instance->BEHa[130]);
1806 if (instance->chan == 6 || instance->chan == 8) {
1808 if (instance->traim) {
1810 instance->BEHn[21]);
1812 instance->BEHn[22]);
1814 instance->BEHn[23] * 256 +
1815 instance->BEHn[24]);
1817 (s_char)instance->BEHn[25]);
1827 instance->pp->year, instance->pp->day,
1828 instance->pp->hour, instance->pp->minute, instance->pp->second,
1830 Rsm, 0.1*(256*instance->BEHa[35]+instance->BEHa[36]),
1832 instance->BEHa[38], instance->BEHa[39], instance->traim, f1, f2,
1836 /*sat*/ instance->BEHa[41], instance->BEHa[45], instance->BEHa[49], instance->BEHa[53],
1837 instance->BEHa[57], instance->BEHa[61], instance->BEHa[65], instance->BEHa[69]
1839 } else if (instance->chan == 12) {
1841 if (instance->traim) {
1843 instance->BEHn[6]);
1845 instance->BEHn[7]);
1847 instance->BEHn[12] * 256 +
1848 instance->BEHn[13]);
1850 (s_char)instance->BEHn[14]);
1860 instance->pp->year, instance->pp->day,
1861 instance->pp->hour, instance->pp->minute, instance->pp->second,
1863 Rsm, 0.1*(256*instance->BEHa[53]+instance->BEHa[54]),
1865 instance->BEHa[55], instance->BEHa[56], instance->traim, f1, f2,
1869 /*sat*/ instance->BEHa[58], instance->BEHa[64], instance->BEHa[70], instance->BEHa[76],
1870 instance->BEHa[82], instance->BEHa[88], instance->BEHa[94], instance->BEHa[100],
1871 instance->BEHa[106], instance->BEHa[112], instance->BEHa[118], instance->BEHa[124]
1878 oncore_feed_clockproc(instance);
1880 if (!refclock_process(instance->pp)) {
1887 oncore_log(instance, LOG_INFO, Msg); /* this is long message above */
1888 instance->pollcnt = 2;
1890 if (instance->polled) {
1891 instance->polled = 0;
1892 /* instance->pp->dispersion = instance->pp->skew = 0; */
1893 instance->pp->lastref = instance->pp->lastrec;
1894 refclock_receive(instance->peer);
1909 struct instance *instance,
1935 oncore_log(instance, LOG_DEBUG, "%ld.%06ld",
1946 oncore_log(instance, LOG_DEBUG, Msg);
1956 oncore_log(instance, LOG_DEBUG, Msg);
1964 oncore_log(instance, LOG_DEBUG, Msg);
1976 struct instance *instance,
1989 struct instance *instance,
1997 if (instance->o_state == ONCORE_RUN)
2000 instance->Ag = buf[4];
2001 oncore_log_f(instance, LOG_INFO,
2003 (int)instance->Ag);
2014 struct instance *instance,
2019 instance->ss_lat = buf_w32(&buf[4]);
2020 instance->ss_long = buf_w32(&buf[8]);
2021 instance->ss_ht = buf_w32(&buf[12]);
2024 oncore_print_posn(instance);
2036 struct instance *instance,
2041 instance->saw_At = 1;
2042 if (instance->site_survey == ONCORE_SS_TESTING) {
2044 oncore_log(instance, LOG_NOTICE,
2047 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_HW");
2048 instance->site_survey = ONCORE_SS_HW;
2062 struct instance *instance,
2067 if (instance->saw_Ay)
2070 instance->saw_Ay = 1;
2072 instance->offset = buf_w32(&buf[4]);
2074 oncore_log_f(instance, LOG_INFO, "PPS Offset is set to %ld ns",
2075 instance->offset);
2086 struct instance *instance,
2091 if (instance->saw_Az)
2094 instance->saw_Az = 1;
2096 instance->delay = buf_w32(&buf[4]);
2098 oncore_log_f(instance, LOG_INFO, "Cable delay is set to %ld ns",
2099 instance->delay);
2108 struct instance *instance,
2125 if (instance->o_state == ONCORE_CHECK_CHAN) { /* here while checking for the # chan */
2127 if (instance->chan_ck < 6) instance->chan_ck = 6;
2129 if (instance->chan_ck < 8) instance->chan_ck = 8;
2131 if (instance->chan_ck < 12) instance->chan_ck = 12;
2134 if (instance->count3++ < 5)
2137 instance->count3 = 0;
2139 if (instance->chan_in != -1) /* set in Input */
2140 instance->chan = instance->chan_in;
2142 instance->chan = instance->chan_ck;
2144 oncore_log_f(instance, LOG_INFO, "Input says chan = %d",
2145 instance->chan_in);
2146 oncore_log_f(instance, LOG_INFO, "Model # says chan = %d",
2147 instance->chan_id);
2148 oncore_log_f(instance, LOG_INFO, "Testing says chan = %d",
2149 instance->chan_ck);
2150 oncore_log_f(instance, LOG_INFO, "Using chan = %d",
2151 instance->chan);
2153 instance->o_state = ONCORE_HAVE_CHAN;
2154 oncore_log(instance, LOG_NOTICE, "state = ONCORE_HAVE_CHAN");
2156 instance->timeout = 4;
2157 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2161 if (instance->o_state != ONCORE_ALMANAC && instance->o_state != ONCORE_RUN)
2166 if (instance->count) {
2167 if (instance->count++ < 5)
2169 instance->count = 0;
2172 memcpy(instance->BEHa, buf, (size_t) (len+3)); /* Ba, Ea or Ha */
2176 if (instance->pps_control_msg_seen != -2) {
2177 if ((instance->pps_control_msg_seen == -1) && (instance->pps_control != -1)) {
2178 oncore_log(instance, LOG_INFO, "PPSCONTROL set, but not implemented (not M12)");
2180 instance->pps_control_msg_seen = -2;
2185 oncore_check_almanac(instance);
2186 oncore_check_antenna(instance);
2191 if (instance->o_state == ONCORE_ALMANAC)
2192 if (oncore_wait_almanac(instance))
2197 if (instance->once) {
2198 instance->once = 0;
2199 instance->count2 = 1;
2204 if (instance->chan != 12 && !instance->saw_At) {
2205 oncore_log(instance, LOG_NOTICE,
2207 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
2215 mode = instance->init_type;
2220 instance->site_survey = ONCORE_SS_DONE;
2221 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
2226 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_TESTING");
2227 instance->site_survey = ONCORE_SS_TESTING;
2228 instance->count1 = 1;
2229 if (instance->chan == 12)
2230 oncore_sendmsg(instance, oncore_cmd_Gd3, sizeof(oncore_cmd_Gd3)); /* M12+T */
2232 oncore_sendmsg(instance, oncore_cmd_At2, sizeof(oncore_cmd_At2)); /* not GT, arg not VP */
2239 oncore_sendmsg(instance, oncore_cmd_Ayx, sizeof(oncore_cmd_Ayx));
2243 oncore_sendmsg(instance, oncore_cmd_Azx, sizeof(oncore_cmd_Azx));
2247 oncore_sendmsg(instance, oncore_cmd_Agx, sizeof(oncore_cmd_Agx));
2258 if (instance->site_survey == ONCORE_SS_TESTING) {
2259 if (instance->chan == 12) {
2260 if (instance->count1) {
2261 if (instance->count1++ > 5 || instance->BEHa[130]&0x10) {
2262 instance->count1 = 0;
2263 if (instance->BEHa[130]&0x10) {
2264 oncore_log(instance, LOG_NOTICE,
2267 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_HW");
2268 instance->site_survey = ONCORE_SS_HW;
2270 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_SW");
2271 instance->site_survey = ONCORE_SS_SW;
2276 if (instance->count1) {
2277 if (instance->count1++ > 5) {
2278 instance->count1 = 0;
2280 * For instance->site_survey to still be ONCORE_SS_TESTING, then after a 5sec
2297 oncore_log_f(instance, LOG_INFO,
2301 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_SW");
2302 instance->site_survey = ONCORE_SS_SW;
2304 instance->ss_lat = instance->ss_long = instance->ss_ht = 0;
2305 if (instance->chan == 12)
2306 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* disable */
2308 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* disable */
2309 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* disable */
2318 if (instance->chan == 6) {
2319 if (instance->BEHa[64]&0x8)
2320 instance->mode = MODE_0D;
2321 else if (instance->BEHa[64]&0x10)
2322 instance->mode = MODE_2D;
2323 else if (instance->BEHa[64]&0x20)
2324 instance->mode = MODE_3D;
2325 } else if (instance->chan == 8) {
2326 if (instance->BEHa[72]&0x8)
2327 instance->mode = MODE_0D;
2328 else if (instance->BEHa[72]&0x10)
2329 instance->mode = MODE_2D;
2330 else if (instance->BEHa[72]&0x20)
2331 instance->mode = MODE_3D;
2332 } else if (instance->chan == 12) {
2335 bits = (instance->BEHa[129]>>5) & 0x7; /* actually Ha */
2337 instance->mode = MODE_0D;
2339 instance->mode = MODE_2D;
2341 instance->mode = MODE_3D;
2346 if (instance->shmem) {
2350 switch(instance->chan) {
2351 case 6: smp = &instance->shmem[instance->shmem_Ba]; break;
2352 case 8: smp = &instance->shmem[instance->shmem_Ea]; break;
2353 case 12: smp = &instance->shmem[instance->shmem_Ha]; break;
2357 switch (instance->mode) {
2376 if (instance->traim_delay) {
2377 if (instance->traim_delay++ > 5) {
2378 instance->traim = 0;
2379 instance->traim_delay = 0;
2381 oncore_log(instance, LOG_INFO, cp);
2383 oncore_set_traim(instance);
2391 if (!instance->have_dH && !instance->traim_delay)
2392 oncore_compute_dH(instance);
2399 instance->pp->year = buf[6]*256+buf[7];
2400 instance->pp->day = ymd2yd(buf[6]*256+buf[7], buf[4], buf[5]);
2401 instance->pp->hour = buf[8];
2402 instance->pp->minute = buf[9];
2403 instance->pp->second = buf[10];
2409 if (instance->site_survey == ONCORE_SS_HW || instance->site_survey == ONCORE_SS_SW)
2410 oncore_ss(instance);
2414 if (instance->count2) {
2415 if (instance->count2++ > 5) { /* this delay to check on @@Ay command */
2416 instance->count2 = 0;
2421 if (!instance->saw_Ay && instance->offset) {
2422 oncore_log(instance, LOG_INFO, "No @@Ay command, PPS OFFSET ignored");
2423 instance->offset = 0;
2432 oncore_check_leap_sec(instance);
2438 if (instance->shmem && !instance->shmem_bad_Ea && instance->shmem_Posn && (instance->site_survey == ONCORE_SS_DONE))
2439 oncore_shmem_get_3D(instance);
2441 if (!instance->traim) /* NO traim, no BnEnHn, go get tick */
2442 oncore_get_timestamp(instance, instance->offset, instance->offset);
2451 struct instance *instance,
2456 oncore_log_f(instance, LOG_NOTICE,
2477 struct instance *instance,
2484 instance->saw_Bj = 1;
2488 instance->pp->leap = LEAP_ADDSECOND;
2492 instance->pp->leap = LEAP_DELSECOND;
2497 instance->pp->leap = LEAP_NOWARNING;
2501 oncore_log(instance, LOG_NOTICE, cp);
2508 struct instance *instance,
2528 if ((!instance->Bl.lsf_flg && !instance->Bl.wn_flg) && (subframe == 4 && page == 18 && valid == 10)) {
2529 instance->Bl.dt_ls = buf[32];
2530 instance->Bl.WN_lsf = buf[33];
2531 instance->Bl.DN_lsf = buf[34];
2532 instance->Bl.dt_lsf = buf[35];
2533 instance->Bl.lsf_flg++;
2535 if ((instance->Bl.lsf_flg && !instance->Bl.wn_flg) && (subframe == 1 && valid == 10)) {
2537 instance->Bl.WN = i >> 6;
2542 instance->Bl.DN = tow/57600L + 1;
2543 instance->Bl.wn_flg++;
2545 if (instance->Bl.wn_flg && instance->Bl.lsf_flg) {
2546 instance->Bl.wn_flg = instance->Bl.lsf_flg = 0;
2548 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof oncore_cmd_Bl);
2551 i = instance->Bl.WN&01400;
2552 instance->Bl.WN_lsf |= i;
2556 i = (instance->Bl.WN_lsf - instance->Bl.WN);
2559 day_now = instance->Bl.DN;
2560 day_lsf = 7*i + instance->Bl.DN_lsf;
2567 if (day_lsf - day_now < 28 || instance->BEHa[5] < 20) {
2568 i = instance->Bl.dt_lsf - instance->Bl.dt_ls;
2586 instance->peer->leap = LEAP_NOWARNING;
2590 instance->peer->leap = LEAP_DELSECOND;
2594 instance->peer->leap = LEAP_ADDSECOND;
2601 oncore_log(instance, LOG_NOTICE, cp);
2603 i = instance->Bl.dt_lsf-instance->Bl.dt_ls;
2606 oncore_log_f(instance, LOG_NOTICE,
2618 oncore_log_f(instance, LOG_DEBUG,
2620 instance->Bl.dt_ls, instance->Bl.dt_lsf,
2621 instance->Bl.WN, instance->Bl.DN,
2622 instance->Bl.WN_lsf, instance->Bl.DN_lsf,
2623 instance->Bl.wn_flg, instance->Bl.lsf_flg,
2624 instance->Bl.Bl_day);
2631 struct instance *instance,
2638 if (instance->o_state != ONCORE_RUN)
2641 if (instance->traim_delay) { /* flag that @@Bn/@@En/Hn returned */
2642 instance->traim_ck = 1;
2643 instance->traim_delay = 0;
2644 oncore_log(instance, LOG_NOTICE, "ONCORE: Detected TRAIM, TRAIM = ON");
2646 oncore_set_traim(instance);
2649 memcpy(instance->BEHn, buf, (size_t) len); /* Bn or En or Hn */
2651 if (!instance->traim) /* BnEnHn will be turned off in any case */
2657 if (instance->BEHn[6]) { /* bad TRAIM */
2658 oncore_log(instance, LOG_WARNING, "BAD TRAIM");
2662 dt1 = instance->saw_tooth + instance->offset; /* dt this time step */
2663 instance->saw_tooth = (s_char) instance->BEHn[14]; /* update for next time Hn[14] */
2664 dt2 = instance->saw_tooth + instance->offset; /* dt next time step */
2666 if (instance->BEHn[21]) /* bad TRAIM */
2669 dt1 = instance->saw_tooth + instance->offset; /* dt this time step */
2670 instance->saw_tooth = (s_char) instance->BEHn[25]; /* update for next time Bn[25], En[25] */
2671 dt2 = instance->saw_tooth + instance->offset; /* dt next time step */
2674 oncore_get_timestamp(instance, dt1, dt2);
2697 struct instance *instance,
2704 if (instance->o_state == ONCORE_TEST_SENT) {
2707 instance->timeout = 0;
2712 oncore_log_f(instance, LOG_DEBUG,
2716 oncore_log_f(instance, LOG_DEBUG,
2729 oncore_log_f(instance, LOG_ERR,
2733 oncore_log_f(instance, LOG_ERR,
2737 oncore_log(instance, LOG_ERR,
2740 refclock_report(instance->peer, CEVNT_FAULT);
2741 oncore_shutdown(instance->unit, instance->peer);
2747 oncore_antenna_report(instance, antenna);
2749 instance->o_state = ONCORE_INIT;
2750 oncore_log(instance, LOG_NOTICE, "state = ONCORE_INIT");
2752 instance->timeout = 4;
2753 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2765 struct instance *instance,
2772 if (instance->shmem == NULL)
2784 oncore_log(instance, LOG_NOTICE, "Cb: Response is NO ALMANAC");
2789 instance->shmem[instance->shmem_Cb + i + 2]++;
2790 memcpy(instance->shmem + instance->shmem_Cb + i + 3, buf, (size_t) (len + 3));
2793 oncore_log_f(instance, LOG_DEBUG, "See Cb [%d,%d]", buf[4],
2807 struct instance *instance,
2812 if (instance->o_state == ONCORE_RESET_SENT) {
2813 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Return to Posn Fix mode */
2815 instance->o_state = ONCORE_TEST_SENT;
2816 oncore_log(instance, LOG_NOTICE, "state = ONCORE_TEST_SENT");
2818 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2841 struct instance *instance,
2848 memcpy(instance->Cj, buf, len);
2850 instance->timeout = 0;
2851 if (instance->o_state == ONCORE_CHECK_ID) {
2852 oncore_msg_Cj_id(instance, buf, len);
2853 oncore_chan_test(instance);
2854 } else if (instance->o_state == ONCORE_HAVE_CHAN) {
2855 mode = instance->init_type;
2857 instance->o_state = ONCORE_RESET_SENT;
2858 oncore_log(instance, LOG_NOTICE, "state = ONCORE_RESET_SENT");
2859 oncore_sendmsg(instance, oncore_cmd_Cf, sizeof(oncore_cmd_Cf));
2861 instance->o_state = ONCORE_TEST_SENT;
2862 oncore_log(instance, LOG_NOTICE, "state = ONCORE_TEST_SENT");
2866 if (instance->o_state == ONCORE_TEST_SENT) {
2867 if (instance->chan == 6)
2868 oncore_sendmsg(instance, oncore_cmd_Ca, sizeof(oncore_cmd_Ca));
2869 else if (instance->chan == 8)
2870 oncore_sendmsg(instance, oncore_cmd_Fa, sizeof(oncore_cmd_Fa));
2871 else if (instance->chan == 12)
2872 oncore_sendmsg(instance, oncore_cmd_Ia, sizeof(oncore_cmd_Ia));
2873 } else if (instance->o_state == ONCORE_INIT)
2874 oncore_msg_Cj_init(instance, buf, len);
2893 struct instance *instance,
2903 instance->Cj[294] = '\0';
2904 for (cp= (char *)instance->Cj; cp< (char *) &instance->Cj[294]; ) {
2907 cpw = (char *)&instance->Cj[294];
2909 oncore_log(instance, LOG_NOTICE, cp);
2916 instance->version = atoi((char *) &instance->Cj[83]);
2917 instance->revision = atoi((char *) &instance->Cj[111]);
2922 for (cp= (char *) &instance->Cj[160]; *cp == ' '; cp++) /* start right after 'Model #' */
2933 instance->model = ONCORE_PVT6;
2936 instance->model = ONCORE_BASIC;
2939 instance->model = ONCORE_VP;
2942 instance->model = ONCORE_M12;
2946 instance->model = ONCORE_GT;
2949 instance->model = ONCORE_GTPLUS;
2952 instance->model = ONCORE_UT;
2955 instance->model = ONCORE_UTPLUS;
2958 instance->model = ONCORE_SL;
2961 instance->model = ONCORE_UNKNOWN;
2965 instance->model = ONCORE_UNKNOWN;
2970 oncore_log_f(instance, LOG_INFO,
2972 cp, instance->version, instance->revision);
2974 instance->chan_id = 8; /* default */
2975 if (instance->model == ONCORE_BASIC || instance->model == ONCORE_PVT6)
2976 instance->chan_id = 6;
2977 else if (instance->model == ONCORE_VP || instance->model == ONCORE_UT || instance->model == ONCORE_UTPLUS)
2978 instance->chan_id = 8;
2979 else if (instance->model == ONCORE_M12)
2980 instance->chan_id = 12;
2982 instance->traim_id = 0; /* default */
2983 if (instance->model == ONCORE_BASIC || instance->model == ONCORE_PVT6)
2984 instance->traim_id = 0;
2985 else if (instance->model == ONCORE_VP || instance->model == ONCORE_UT || instance->model == ONCORE_UTPLUS)
2986 instance->traim_id = 1;
2987 else if (instance->model == ONCORE_M12)
2988 instance->traim_id = -1;
2990 oncore_log_f(instance, LOG_INFO, "Channels = %d, TRAIM = %s",
2991 instance->chan_id,
2992 ((instance->traim_id < 0)
2994 : (instance->traim_id > 0)
3009 struct instance *instance,
3024 if (instance->chan == 12) {
3025 instance->shmem_bad_Ea = 1;
3026 oncore_log_f(instance, LOG_NOTICE,
3028 instance->version, instance->revision);
3031 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Return to Posn Fix mode */
3032 oncore_sendmsg(instance, oncore_cmd_Bb, sizeof(oncore_cmd_Bb)); /* turn on for shmem (6/8/12) */
3033 oncore_sendmsg(instance, oncore_cmd_Ek, sizeof(oncore_cmd_Ek)); /* turn off (VP) */
3034 oncore_sendmsg(instance, oncore_cmd_Aw, sizeof(oncore_cmd_Aw)); /* UTC time (6/8/12) */
3035 oncore_sendmsg(instance, oncore_cmd_AB, sizeof(oncore_cmd_AB)); /* Appl type static (VP) */
3036 oncore_sendmsg(instance, oncore_cmd_Be, sizeof(oncore_cmd_Be)); /* Tell us the Almanac for shmem (6/8/12) */
3037 oncore_sendmsg(instance, oncore_cmd_Bd, sizeof(oncore_cmd_Bd)); /* Tell us when Almanac changes */
3039 mode = instance->init_type;
3046 if (instance->posn_set) {
3047 oncore_log(instance, LOG_INFO, "Setting Posn from input data");
3048 oncore_set_posn(instance); /* this should print posn indirectly thru the As cmd */
3050 if (instance->chan != 12)
3051 oncore_sendmsg(instance, oncore_cmd_Atx, sizeof(oncore_cmd_Atx));
3056 w32_buf(&Cmd[-2+4], (int)instance->delay);
3057 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Az)); /* 6,8,12 */
3061 w32_buf(&Cmd[-2+4], instance->offset); /* will check for hw response */
3062 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ay));
3066 if (instance->Ag != 0xff) { /* will have 0xff in it if not set by user */
3068 Cmd[-2+4] = instance->Ag;
3069 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ag));
3080 if (instance->chan == 6) { /* start 6chan, kill 8,12chan commands, possibly testing VP in 6chan mode */
3081 oncore_sendmsg(instance, oncore_cmd_Ea0, sizeof(oncore_cmd_Ea0));
3082 oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
3083 oncore_sendmsg(instance, oncore_cmd_Ha0, sizeof(oncore_cmd_Ha0));
3084 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3085 oncore_sendmsg(instance, oncore_cmd_Ba, sizeof(oncore_cmd_Ba ));
3086 } else if (instance->chan == 8) { /* start 8chan, kill 6,12chan commands */
3087 oncore_sendmsg(instance, oncore_cmd_Ba0, sizeof(oncore_cmd_Ba0));
3088 oncore_sendmsg(instance, oncore_cmd_Bn0, sizeof(oncore_cmd_Bn0));
3089 oncore_sendmsg(instance, oncore_cmd_Ha0, sizeof(oncore_cmd_Ha0));
3090 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3091 oncore_sendmsg(instance, oncore_cmd_Ea, sizeof(oncore_cmd_Ea ));
3092 } else if (instance->chan == 12){ /* start 12chan, kill 6,12chan commands */
3093 oncore_sendmsg(instance, oncore_cmd_Ba0, sizeof(oncore_cmd_Ba0));
3094 oncore_sendmsg(instance, oncore_cmd_Bn0, sizeof(oncore_cmd_Bn0));
3095 oncore_sendmsg(instance, oncore_cmd_Ea0, sizeof(oncore_cmd_Ea0));
3096 oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
3097 oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha ));
3098 oncore_cmd_Gc[2] = (instance->pps_control < 0) ? 1 : instance->pps_control;
3099 oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* PPS off/continuous/Tracking 1+sat/TRAIM */
3102 instance->count = 1;
3103 instance->o_state = ONCORE_ALMANAC;
3104 oncore_log(instance, LOG_NOTICE, "state = ONCORE_ALMANAC");
3113 struct instance *instance,
3134 oncore_log_f(instance, LOG_NOTICE,
3138 instance->ss_lat = lat;
3139 instance->ss_long = lon;
3140 instance->ss_ht = ht;
3142 oncore_print_posn(instance);
3151 struct instance *instance,
3171 oncore_log_f(instance, LOG_NOTICE,
3182 struct instance *instance,
3189 instance->pps_control_msg_seen = 1;
3190 oncore_log_f(instance, LOG_INFO, "PPS Control set to %s",
3201 struct instance *instance,
3214 instance->saw_Gj = 1; /* flag, saw_Gj, dont need to try Bj in check_leap */
3220 oncore_log_f(instance, LOG_INFO,
3241 oncore_log_f(instance, LOG_NOTICE,
3249 instance->pp->leap = LEAP_NOWARNING;
3252 if (buf[6] == instance->BEHa[6] && buf[7] == instance->BEHa[7] && /* year */
3253 buf[8] == instance->BEHa[4]) { /* month */
3256 instance->pp->leap = LEAP_DELSECOND;
3259 instance->pp->leap = LEAP_ADDSECOND;
3264 oncore_log(instance, LOG_INFO, cp);
3273 struct instance *instance,
3278 if (instance && instance->peer) {
3279 oncore_log(instance, LOG_ERR, "Oncore: System Failure at Power On");
3280 oncore_shutdown(instance->unit, instance->peer);
3289 struct instance *instance,
3294 if (instance->ant_state == new_state)
3305 instance->ant_state = new_state;
3306 oncore_log(instance, LOG_NOTICE, cp);
3313 struct instance *instance
3325 instance->o_state = ONCORE_CHECK_CHAN;
3326 oncore_log(instance, LOG_NOTICE, "state = ONCORE_CHECK_CHAN");
3328 instance->count3 = 1;
3329 oncore_sendmsg(instance, oncore_cmd_Ba, sizeof(oncore_cmd_Ba));
3330 oncore_sendmsg(instance, oncore_cmd_Ea, sizeof(oncore_cmd_Ea));
3331 oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha));
3340 struct instance *instance
3343 if (instance->chan == 6) {
3344 instance->rsm.bad_almanac = instance->BEHa[64]&0x1;
3345 instance->rsm.bad_fix = instance->BEHa[64]&0x52;
3346 } else if (instance->chan == 8) {
3347 instance->rsm.bad_almanac = instance->BEHa[72]&0x1;
3348 instance->rsm.bad_fix = instance->BEHa[72]&0x52;
3349 } else if (instance->chan == 12) {
3352 bits1 = (instance->BEHa[129]>>5) & 0x7; /* actually Ha */
3353 bits2 = instance->BEHa[130];
3354 instance->rsm.bad_almanac = (bits2 & 0x80);
3355 instance->rsm.bad_fix = (bits2 & 0x8) || (bits1 == 0x2);
3358 bits3 = instance->BEHa[141]; /* UTC parameters */
3359 if (!instance->count5_set && (bits3 & 0xC0)) {
3360 instance->count5 = 4; /* was 2 [Bug 1766] */
3361 instance->count5_set = 1;
3364 oncore_log_f(instance, LOG_DEBUG,
3366 instance->BEHa[129], instance->BEHa[130],
3368 instance->mode == MODE_0D,
3369 instance->mode == MODE_2D,
3370 instance->mode == MODE_3D,
3371 instance->rsm.bad_almanac,
3372 instance->rsm.bad_fix);
3384 struct instance *instance
3389 if (instance->chan == 12)
3390 antenna = (instance->BEHa[130] & 0x6 ) >> 1;
3392 antenna = (instance->BEHa[37] & 0xc0) >> 6; /* prob unset 6, set GT, UT unset VP */
3394 oncore_antenna_report (instance, antenna);
3424 struct instance *instance
3428 if (instance->Bj_day != instance->BEHa[5]) { /* do this 1/day */
3429 instance->Bj_day = instance->BEHa[5];
3431 if (instance->saw_Gj < 0) { /* -1 DONT have Gj use Bj */
3432 if ((instance->BEHa[4] == 6) || (instance->BEHa[4] == 12))
3433 oncore_sendmsg(instance, oncore_cmd_Bj, sizeof(oncore_cmd_Bj));
3434 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof(oncore_cmd_Bl));
3438 if (instance->saw_Gj == 0) /* 0 is dont know if we have Gj */
3439 instance->count4 = 1;
3441 oncore_sendmsg(instance, oncore_cmd_Gj, sizeof(oncore_cmd_Gj));
3449 if (instance->count4) { /* delay, waiting for Gj response */
3450 if (instance->saw_Gj == 1)
3451 instance->count4 = 0;
3452 else if (instance->count4++ > 5) { /* delay, waiting for Gj response */
3453 instance->saw_Gj = -1; /* didnt see it, will use Bj */
3454 instance->count4 = 0;
3455 if ((instance->BEHa[4] == 6) || (instance->BEHa[4] == 12)) {
3456 oncore_sendmsg(instance, oncore_cmd_Bj, sizeof(oncore_cmd_Bj));
3457 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof(oncore_cmd_Bl));
3489 struct instance *instance
3497 instance->have_dH = 1;
3498 if (instance->chan == 12) {
3499 GPS = buf_w32(&instance->BEHa[39]);
3500 MSL = buf_w32(&instance->BEHa[43]);
3502 GPS = buf_w32(&instance->BEHa[23]);
3503 MSL = buf_w32(&instance->BEHa[27]);
3505 instance->dH = GPS - MSL;
3506 instance->dH /= 100.;
3511 oncore_log_f(instance, LOG_INFO,
3512 "dH = (GPS - MSL) = %.2fm", instance->dH);
3523 struct instance *instance
3531 if (!instance->shmem)
3535 for (cp = instance->shmem + 4; (n = 256 * (*(cp-3)) + *(cp-2));
3540 write(instance->ttyfd, cp, n);
3541 oncore_print_Cb(instance, cp);
3545 for (cp = instance->shmem + 4; (n = 256 * (*(cp-3)) + *(cp-2));
3547 oncore_log_f(instance, LOG_DEBUG, "See %c%c%c%c %d",
3551 oncore_print_Cb(instance, cp);
3554 oncore_log(instance, LOG_DEBUG, "GOOD SF");
3555 write(instance->ttyfd, cp, n);
3557 oncore_log(instance, LOG_DEBUG, "BAD SF");
3559 oncore_log(instance, LOG_DEBUG, "BAD CHECKSUM");
3566 if (!instance->posn_set) { /* if we input a posn use it, else from SHMEM */
3567 oncore_log(instance, LOG_NOTICE, "Loading Posn from SHMEM");
3568 for (cp=instance->shmem+4; (n = 256*(*(cp-3)) + *(cp-2)); cp+=(n+3)) {
3569 if ((instance->chan == 6 && (!strncmp((char *) cp, "@@Ba", 4) && oncore_checksum_ok(cp, 68))) ||
3570 (instance->chan == 8 && (!strncmp((char *) cp, "@@Ea", 4) && oncore_checksum_ok(cp, 76))) ||
3571 (instance->chan == 12 && (!strncmp((char *) cp, "@@Ha", 4) && oncore_checksum_ok(cp, 154)))) {
3574 instance->posn_set = 1;
3579 oncore_log_f(instance, LOG_DEBUG,
3581 (long)(cp-instance->shmem),
3585 instance->ss_lat = ii;
3586 instance->ss_long = jj;
3587 instance->ss_ht = kk;
3592 oncore_set_posn(instance);
3600 oncore_log_f(instance, LOG_DEBUG, "DATE %d %d %d, %d %d %d",
3604 if (instance->chan == 12) {
3616 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Gb));
3620 oncore_sendmsg(instance, oncore_cmd_Ab, sizeof(oncore_cmd_Ab));
3627 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ac));
3633 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Aa));
3636 oncore_log(instance, LOG_INFO, "Setting Posn and Time after Loading Almanac");
3645 struct instance *instance,
3653 oncore_log_f(instance, LOG_DEBUG, "DEBUG: See: %c%c%c%c", *(cp),
3662 oncore_log(instance, LOG_DEBUG, Msg);
3664 oncore_log_f(instance, LOG_DEBUG, "Debug: Cb: [%d,%d]", *(cp+4),
3695 struct instance *instance
3703 oncore_log(instance, LOG_INFO, "Posn:");
3705 lon = instance->ss_long;
3712 lat = instance->ss_lat;
3718 hm = instance->ss_ht/100.;
3723 oncore_log_f(instance, LOG_INFO,
3733 oncore_log_f(instance, LOG_INFO,
3743 oncore_log_f(instance, LOG_INFO,
3756 struct instance *instance,
3764 fd = instance->ttyfd;
3767 oncore_log_f(instance, LOG_DEBUG, "ONCORE: Send @@%c%c %d",
3783 struct instance *instance
3792 if (instance->chan == 12)
3793 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* (12) */
3795 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* (6/8) */
3796 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* (6/8) */
3799 mode = instance->init_type;
3803 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3804 w32_buf(&Cmd[-2+8], (int) instance->ss_long);
3805 w32_buf(&Cmd[-2+12], (int) instance->ss_ht);
3807 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_As)); /* posn hold 3D posn (6/8/12) */
3810 w32_buf(&Cmd[-2+4], (int) instance->ss_ht);
3812 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Au)); /* altitude hold (6/8/12 not UT, M12T) */
3816 if (instance->chan == 12) {
3818 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3819 w32_buf(&Cmd[-2+8], (int) instance->ss_long);
3820 w32_buf(&Cmd[-2+12],(int) instance->ss_ht);
3822 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ga)); /* 3d posn (12) */
3825 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3826 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ad)); /* lat (6/8) */
3829 w32_buf(&Cmd[-2+4], (int) instance->ss_long);
3830 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ae)); /* long (6/8) */
3833 w32_buf(&Cmd[-2+4], (int) instance->ss_ht);
3835 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Af)); /* ht (6/8) */
3840 if (instance->chan == 12)
3841 oncore_sendmsg(instance, oncore_cmd_Gd1, sizeof(oncore_cmd_Gd1));
3843 oncore_sendmsg(instance, oncore_cmd_At1, sizeof(oncore_cmd_At1));
3851 struct instance *instance
3854 if (instance->traim_in != -1) /* set in Input */
3855 instance->traim = instance->traim_in;
3857 instance->traim = instance->traim_ck;
3859 oncore_log_f(instance, LOG_INFO, "Input says TRAIM = %d",
3860 instance->traim_in);
3861 oncore_log_f(instance, LOG_INFO, "Model # says TRAIM = %d",
3862 instance->traim_id);
3863 oncore_log_f(instance, LOG_INFO, "Testing says TRAIM = %d",
3864 instance->traim_ck);
3865 oncore_log_f(instance, LOG_INFO, "Using TRAIM = %d",
3866 instance->traim);
3868 if (instance->traim_ck == 1 && instance->traim == 0) {
3871 if (instance->chan == 6)
3872 oncore_sendmsg(instance, oncore_cmd_Bnx, sizeof(oncore_cmd_Bnx));
3873 else if (instance->chan == 8)
3874 oncore_sendmsg(instance, oncore_cmd_Enx, sizeof(oncore_cmd_Enx));
3876 oncore_sendmsg(instance, oncore_cmd_Ge0, sizeof(oncore_cmd_Ge0));
3877 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3889 struct instance *instance
3892 if (instance->pp->second%15 == 3) { /* start the sequence */ /* by changing mode */
3893 instance->shmem_reset = 1;
3894 if (instance->chan == 12) {
3895 if (instance->shmem_Posn == 2)
3896 oncore_sendmsg(instance, oncore_cmd_Gd2, sizeof(oncore_cmd_Gd2)); /* 2D */
3898 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* 3D */
3900 if (instance->saw_At) { /* out of 0D -> 3D mode */
3901 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0));
3902 if (instance->shmem_Posn == 2) /* 3D -> 2D mode */
3903 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
3905 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0));
3907 } else if (instance->shmem_reset || (instance->mode != MODE_0D)) {
3908 instance->shmem_reset = 0;
3909 if (instance->chan == 12)
3910 oncore_sendmsg(instance, oncore_cmd_Gd1, sizeof(oncore_cmd_Gd1)); /* 0D */
3912 if (instance->saw_At) {
3913 if (instance->mode == MODE_2D) /* 2D -> 3D or 0D mode */
3914 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0));
3915 oncore_sendmsg(instance, oncore_cmd_At1, sizeof(oncore_cmd_At1)); /* to 0D mode */
3917 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
3933 struct instance *instance
3939 if (instance->site_survey == ONCORE_SS_HW) {
3944 if ((instance->chan == 8 && !(instance->BEHa[37] & 0x20)) ||
3945 (instance->chan == 12 && !(instance->BEHa[130] & 0x10))) {
3946 oncore_log(instance, LOG_INFO, "Now in 0D mode");
3948 if (instance->chan == 12)
3949 oncore_sendmsg(instance, oncore_cmd_Gax, sizeof(oncore_cmd_Gax));
3951 oncore_sendmsg(instance, oncore_cmd_Asx, sizeof(oncore_cmd_Asx));
3953 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
3954 instance->site_survey = ONCORE_SS_DONE;
3961 if (instance->rsm.bad_fix) /* Not if poor geometry or less than 3 sats */
3964 if (instance->mode != MODE_3D) /* Use only 3D Fixes */
3967 instance->ss_lat += buf_w32(&instance->BEHa[15]);
3968 instance->ss_long += buf_w32(&instance->BEHa[19]);
3969 instance->ss_ht += buf_w32(&instance->BEHa[23]); /* GPS ellipsoid */
3970 instance->ss_count++;
3972 if (instance->ss_count != POS_HOLD_AVERAGE)
3975 instance->ss_lat /= POS_HOLD_AVERAGE;
3976 instance->ss_long /= POS_HOLD_AVERAGE;
3977 instance->ss_ht /= POS_HOLD_AVERAGE;
3979 oncore_log_f(instance, LOG_NOTICE,
3981 instance->ss_lat, instance->ss_long,
3982 instance->ss_ht);
3983 lat = instance->ss_lat/3600000.;
3984 lon = instance->ss_long/3600000.;
3985 ht = instance->ss_ht/100;
3986 oncore_log_f(instance, LOG_NOTICE,
3990 oncore_set_posn(instance);
3992 oncore_log(instance, LOG_INFO, "Now in 0D mode");
3994 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
3995 instance->site_survey = ONCORE_SS_DONE;
4003 struct instance *instance
4006 if (instance->rsm.bad_almanac) {
4007 instance->counta++;
4008 if (instance->counta%5 == 0)
4009 oncore_log(instance, LOG_INFO, "Waiting for Almanac");
4016 if (!instance->almanac_from_shmem) {
4017 instance->almanac_from_shmem = 1;
4018 oncore_load_almanac(instance);
4025 if (instance->chan == 6)
4026 oncore_sendmsg(instance, oncore_cmd_Bn, sizeof(oncore_cmd_Bn));
4027 else if (instance->chan == 8)
4028 oncore_sendmsg(instance, oncore_cmd_En, sizeof(oncore_cmd_En));
4029 else if (instance->chan == 12) {
4030 oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* 1PPS on, continuous */
4031 oncore_sendmsg(instance, oncore_cmd_Ge, sizeof(oncore_cmd_Ge)); /* TRAIM on */
4032 oncore_sendmsg(instance, oncore_cmd_Hn, sizeof(oncore_cmd_Hn)); /* TRAIM status 1/s */
4034 instance->traim_delay = 1;
4036 oncore_log(instance, LOG_NOTICE, "Have now loaded an ALMANAC");
4038 instance->o_state = ONCORE_RUN;
4039 oncore_log(instance, LOG_NOTICE, "state = ONCORE_RUN");
4047 struct instance * instance
4050 struct peer * const peer = instance->peer;
4051 struct refclockproc * const pp = instance->pp;
4094 struct instance *instance,
4099 msyslog(log_level, "ONCORE[%d]: %s", instance->unit, msg);
4100 mprintf_clock_stats(&instance->peer->srcadr, "ONCORE[%d]: %s",
4101 instance->unit, msg);
4107 struct instance * instance,
4120 oncore_log(instance, log_level, msg);
4123 instance->max_len = max(strlen(msg), instance->max_len);
4124 instance->max_count++;
4125 if (instance->max_count % 100 == 0)
4126 oncore_log_f(instance, LOG_INFO,
4128 instance->max_len);