Lines Matching full: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");
959 oncore_log(instance, LOG_WARNING,
967 if ((instance->shmemfd = open(instance->shmem_fname, O_RDWR|O_CREAT|O_TRUNC, 0644)) < 0) {
968 oncore_log(instance, LOG_WARNING, "ONCORE: Can't open shmem");
982 instance->shmem_Cb = n;
986 instance->shmem_Ba = n;
990 instance->shmem_Ea = n;
994 instance->shmem_Ha = n;
1052 i = write(instance->shmemfd, buf, shmem_length);
1056 oncore_log(instance, LOG_ERR, "ONCORE: error writing shmem");
1057 close(instance->shmemfd);
1061 instance->shmem = (u_char *) mmap(0, shmem_length,
1066 MAP_SHARED, instance->shmemfd, (off_t)0);
1068 if (instance->shmem == (u_char *)MAP_FAILED) {
1069 instance->shmem = 0;
1070 close(instance->shmemfd);
1074 oncore_log_f(instance, LOG_NOTICE,
1076 (u_long) shmem_length, instance->shmem_fname);
1088 struct instance *instance
1227 cp, instance->unit); /* try "ntp.oncore.0 */
1231 cp, instance->unit); /* try "ntp.oncore0" */
1240 instance->init_type = 4;
1282 instance->shmem_fname = estrdup(ca);
1299 instance->ss_lat = sign*1000*(fabs(f3) + 60*(fabs(f2) + 60*f1)); /*miliseconds*/
1309 instance->ss_long = sign*1000*(fabs(f3) + 60*(fabs(f2) + 60*f1)); /*miliseconds*/
1317 instance->ss_ht = 100 * f1; /* cm */
1334 oncore_log_f(instance, LOG_WARNING,
1338 instance->delay = f1; /* delay in ns */
1354 oncore_log_f(instance, LOG_WARNING,
1358 instance->offset = f1; /* offset in ns */
1364 instance->assert = 1;
1366 instance->assert = 0;
1368 instance->hardpps = 1;
1370 instance->shmem_Posn = 2;
1372 instance->shmem_Posn = 3;
1376 instance->chan_in = i;
1378 instance->traim_in = 1; /* so TRAIM alone is YES */
1380 instance->traim_in = 0;
1384 instance->Ag = mask; /* Satellite mask angle */
1387 instance->pps_control = 1; /* PPS always on */
1389 instance->pps_control = 2; /* PPS on when satellite is available */
1391 instance->pps_control = 3; /* PPS on when TRAIM status is OK */
1393 oncore_log_f(instance, LOG_WARNING,
1406 instance->posn_set = 1;
1408 oncore_log_f(instance, LOG_WARNING,
1410 instance->posn_set = 0;
1412 oncore_log_f(instance, LOG_WARNING,
1418 instance->init_type = mode;
1420 oncore_log_f(instance, LOG_INFO, "Input mode = %d", mode);
1437 struct instance *instance;
1440 instance = peer->procptr->unitptr;
1448 oncore_log_f(instance, LOG_DEBUG,
1456 oncore_log(instance, LOG_DEBUG, Msg);
1463 oncore_log(instance, LOG_DEBUG, Msg);
1472 oncore_consume(instance);
1483 struct instance *instance
1496 oncore_log_f(instance, LOG_DEBUG,
1514 oncore_log_f(instance, LOG_DEBUG,
1526 oncore_log_f(instance, LOG_DEBUG,
1528 instance->unit, rcvbuf[2],
1541 oncore_log(instance, LOG_DEBUG, "NO <CR><LF> at end of message");
1545 if (instance->shmem != NULL) {
1546 instance->shmem[oncore_messages[m].shmem + 2]++;
1547 memcpy(instance->shmem + oncore_messages[m].shmem + 3,
1550 oncore_msg_any(instance, rcvbuf, (size_t) (l-3), m);
1552 oncore_messages[m].handler(instance, rcvbuf, (size_t) (l-3));
1558 oncore_log(instance, LOG_ERR, "Checksum mismatch!");
1565 oncore_log(instance, LOG_DEBUG, Msg);
1580 struct instance *instance,
1601 peer = instance->peer;
1610 if ((instance->site_survey == ONCORE_SS_DONE) && (instance->mode != MODE_0D)) {
1614 if ((instance->site_survey != ONCORE_SS_DONE) || (instance->mode != MODE_0D)) {
1622 if (instance->rsm.bad_almanac) {
1633 if (instance->count5) {
1634 instance->count5--;
1639 j = instance->ev_serial;
1642 if (time_pps_fetch(instance->pps_h, PPS_TSFMT_TSPEC, &pps_i,
1644 oncore_log_f(instance, LOG_ERR,
1650 if (instance->assert) {
1659 oncore_log_f(instance, LOG_DEBUG,
1664 oncore_log_f(instance, LOG_DEBUG,
1673 oncore_log(instance, LOG_NOTICE, "ONCORE: oncore_get_timestamp, error serial pps");
1678 instance->ev_serial = pps_i.assert_sequence;
1688 oncore_log_f(instance, LOG_DEBUG,
1693 oncore_log_f(instance, LOG_DEBUG,
1702 oncore_log(instance, LOG_ERR, "oncore_get_timestamp, error serial pps");
1706 instance->ev_serial = pps_i.clear_sequence;
1743 if (instance->assert)
1744 instance->pps_p.assert_offset.tv_nsec = -dt2;
1746 instance->pps_p.clear_offset.tv_nsec = -dt2;
1749 * using the saved instance->pps_p, since some other process on the
1761 if (time_pps_getcap(instance->pps_h, ¤t_mode) < 0) {
1762 oncore_log_f(instance, LOG_ERR,
1768 if (time_pps_getparams(instance->pps_h, ¤t_params) < 0) {
1769 oncore_log_f(instance, LOG_ERR,
1776 current_params.mode |= instance->pps_p.mode;
1785 if (time_pps_setparams(instance->pps_h, ¤t_params))
1786 oncore_log(instance, LOG_ERR, "ONCORE: Error doing time_pps_setparams");
1791 instance->pp->lastrec = ts;
1801 if (instance->chan == 6)
1802 Rsm = instance->BEHa[64];
1803 else if (instance->chan == 8)
1804 Rsm = instance->BEHa[72];
1805 else if (instance->chan == 12)
1806 Rsm = ((instance->BEHa[129]<<8) | instance->BEHa[130]);
1808 if (instance->chan == 6 || instance->chan == 8) {
1810 if (instance->traim) {
1812 instance->BEHn[21]);
1814 instance->BEHn[22]);
1816 instance->BEHn[23] * 256 +
1817 instance->BEHn[24]);
1819 (s_char)instance->BEHn[25]);
1829 instance->pp->year, instance->pp->day,
1830 instance->pp->hour, instance->pp->minute, instance->pp->second,
1832 Rsm, 0.1*(256*instance->BEHa[35]+instance->BEHa[36]),
1834 instance->BEHa[38], instance->BEHa[39], instance->traim, f1, f2,
1838 /*sat*/ instance->BEHa[41], instance->BEHa[45], instance->BEHa[49], instance->BEHa[53],
1839 instance->BEHa[57], instance->BEHa[61], instance->BEHa[65], instance->BEHa[69]
1841 } else if (instance->chan == 12) {
1843 if (instance->traim) {
1845 instance->BEHn[6]);
1847 instance->BEHn[7]);
1849 instance->BEHn[12] * 256 +
1850 instance->BEHn[13]);
1852 (s_char)instance->BEHn[14]);
1862 instance->pp->year, instance->pp->day,
1863 instance->pp->hour, instance->pp->minute, instance->pp->second,
1865 Rsm, 0.1*(256*instance->BEHa[53]+instance->BEHa[54]),
1867 instance->BEHa[55], instance->BEHa[56], instance->traim, f1, f2,
1871 /*sat*/ instance->BEHa[58], instance->BEHa[64], instance->BEHa[70], instance->BEHa[76],
1872 instance->BEHa[82], instance->BEHa[88], instance->BEHa[94], instance->BEHa[100],
1873 instance->BEHa[106], instance->BEHa[112], instance->BEHa[118], instance->BEHa[124]
1880 oncore_feed_clockproc(instance);
1882 if (!refclock_process(instance->pp)) {
1889 oncore_log(instance, LOG_INFO, Msg); /* this is long message above */
1890 instance->pollcnt = 2;
1892 if (instance->polled) {
1893 instance->polled = 0;
1894 /* instance->pp->dispersion = instance->pp->skew = 0; */
1895 instance->pp->lastref = instance->pp->lastrec;
1896 refclock_receive(instance->peer);
1911 struct instance *instance,
1937 oncore_log(instance, LOG_DEBUG, "%ld.%06ld",
1948 oncore_log(instance, LOG_DEBUG, Msg);
1958 oncore_log(instance, LOG_DEBUG, Msg);
1966 oncore_log(instance, LOG_DEBUG, Msg);
1978 struct instance *instance,
1991 struct instance *instance,
1999 if (instance->o_state == ONCORE_RUN)
2002 instance->Ag = buf[4];
2003 oncore_log_f(instance, LOG_INFO,
2005 (int)instance->Ag);
2016 struct instance *instance,
2021 instance->ss_lat = buf_w32(&buf[4]);
2022 instance->ss_long = buf_w32(&buf[8]);
2023 instance->ss_ht = buf_w32(&buf[12]);
2026 oncore_print_posn(instance);
2038 struct instance *instance,
2043 instance->saw_At = 1;
2044 if (instance->site_survey == ONCORE_SS_TESTING) {
2046 oncore_log(instance, LOG_NOTICE,
2049 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_HW");
2050 instance->site_survey = ONCORE_SS_HW;
2064 struct instance *instance,
2069 if (instance->saw_Ay)
2072 instance->saw_Ay = 1;
2074 instance->offset = buf_w32(&buf[4]);
2076 oncore_log_f(instance, LOG_INFO, "PPS Offset is set to %ld ns",
2077 instance->offset);
2088 struct instance *instance,
2093 if (instance->saw_Az)
2096 instance->saw_Az = 1;
2098 instance->delay = buf_w32(&buf[4]);
2100 oncore_log_f(instance, LOG_INFO, "Cable delay is set to %ld ns",
2101 instance->delay);
2110 struct instance *instance,
2127 if (instance->o_state == ONCORE_CHECK_CHAN) { /* here while checking for the # chan */
2129 if (instance->chan_ck < 6) instance->chan_ck = 6;
2131 if (instance->chan_ck < 8) instance->chan_ck = 8;
2133 if (instance->chan_ck < 12) instance->chan_ck = 12;
2136 if (instance->count3++ < 5)
2139 instance->count3 = 0;
2141 if (instance->chan_in != -1) /* set in Input */
2142 instance->chan = instance->chan_in;
2144 instance->chan = instance->chan_ck;
2146 oncore_log_f(instance, LOG_INFO, "Input says chan = %d",
2147 instance->chan_in);
2148 oncore_log_f(instance, LOG_INFO, "Model # says chan = %d",
2149 instance->chan_id);
2150 oncore_log_f(instance, LOG_INFO, "Testing says chan = %d",
2151 instance->chan_ck);
2152 oncore_log_f(instance, LOG_INFO, "Using chan = %d",
2153 instance->chan);
2155 instance->o_state = ONCORE_HAVE_CHAN;
2156 oncore_log(instance, LOG_NOTICE, "state = ONCORE_HAVE_CHAN");
2158 instance->timeout = 4;
2159 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2163 if (instance->o_state != ONCORE_ALMANAC && instance->o_state != ONCORE_RUN)
2168 if (instance->count) {
2169 if (instance->count++ < 5)
2171 instance->count = 0;
2174 memcpy(instance->BEHa, buf, (size_t) (len+3)); /* Ba, Ea or Ha */
2178 if (instance->pps_control_msg_seen != -2) {
2179 if ((instance->pps_control_msg_seen == -1) && (instance->pps_control != -1)) {
2180 oncore_log(instance, LOG_INFO, "PPSCONTROL set, but not implemented (not M12)");
2182 instance->pps_control_msg_seen = -2;
2187 oncore_check_almanac(instance);
2188 oncore_check_antenna(instance);
2193 if (instance->o_state == ONCORE_ALMANAC)
2194 if (oncore_wait_almanac(instance))
2199 if (instance->once) {
2200 instance->once = 0;
2201 instance->count2 = 1;
2206 if (instance->chan != 12 && !instance->saw_At) {
2207 oncore_log(instance, LOG_NOTICE,
2209 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
2217 mode = instance->init_type;
2222 instance->site_survey = ONCORE_SS_DONE;
2223 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
2228 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_TESTING");
2229 instance->site_survey = ONCORE_SS_TESTING;
2230 instance->count1 = 1;
2231 if (instance->chan == 12)
2232 oncore_sendmsg(instance, oncore_cmd_Gd3, sizeof(oncore_cmd_Gd3)); /* M12+T */
2234 oncore_sendmsg(instance, oncore_cmd_At2, sizeof(oncore_cmd_At2)); /* not GT, arg not VP */
2241 oncore_sendmsg(instance, oncore_cmd_Ayx, sizeof(oncore_cmd_Ayx));
2245 oncore_sendmsg(instance, oncore_cmd_Azx, sizeof(oncore_cmd_Azx));
2249 oncore_sendmsg(instance, oncore_cmd_Agx, sizeof(oncore_cmd_Agx));
2260 if (instance->site_survey == ONCORE_SS_TESTING) {
2261 if (instance->chan == 12) {
2262 if (instance->count1) {
2263 if (instance->count1++ > 5 || instance->BEHa[130]&0x10) {
2264 instance->count1 = 0;
2265 if (instance->BEHa[130]&0x10) {
2266 oncore_log(instance, LOG_NOTICE,
2269 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_HW");
2270 instance->site_survey = ONCORE_SS_HW;
2272 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_SW");
2273 instance->site_survey = ONCORE_SS_SW;
2278 if (instance->count1) {
2279 if (instance->count1++ > 5) {
2280 instance->count1 = 0;
2282 * For instance->site_survey to still be ONCORE_SS_TESTING, then after a 5sec
2299 oncore_log_f(instance, LOG_INFO,
2303 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_SW");
2304 instance->site_survey = ONCORE_SS_SW;
2306 instance->ss_lat = instance->ss_long = instance->ss_ht = 0;
2307 if (instance->chan == 12)
2308 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* disable */
2310 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* disable */
2311 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* disable */
2320 if (instance->chan == 6) {
2321 if (instance->BEHa[64]&0x8)
2322 instance->mode = MODE_0D;
2323 else if (instance->BEHa[64]&0x10)
2324 instance->mode = MODE_2D;
2325 else if (instance->BEHa[64]&0x20)
2326 instance->mode = MODE_3D;
2327 } else if (instance->chan == 8) {
2328 if (instance->BEHa[72]&0x8)
2329 instance->mode = MODE_0D;
2330 else if (instance->BEHa[72]&0x10)
2331 instance->mode = MODE_2D;
2332 else if (instance->BEHa[72]&0x20)
2333 instance->mode = MODE_3D;
2334 } else if (instance->chan == 12) {
2337 bits = (instance->BEHa[129]>>5) & 0x7; /* actually Ha */
2339 instance->mode = MODE_0D;
2341 instance->mode = MODE_2D;
2343 instance->mode = MODE_3D;
2348 if (instance->shmem) {
2352 switch(instance->chan) {
2353 case 6: smp = &instance->shmem[instance->shmem_Ba]; break;
2354 case 8: smp = &instance->shmem[instance->shmem_Ea]; break;
2355 case 12: smp = &instance->shmem[instance->shmem_Ha]; break;
2359 switch (instance->mode) {
2378 if (instance->traim_delay) {
2379 if (instance->traim_delay++ > 5) {
2380 instance->traim = 0;
2381 instance->traim_delay = 0;
2383 oncore_log(instance, LOG_INFO, cp);
2385 oncore_set_traim(instance);
2393 if (!instance->have_dH && !instance->traim_delay)
2394 oncore_compute_dH(instance);
2401 instance->pp->year = buf[6]*256+buf[7];
2402 instance->pp->day = ymd2yd(buf[6]*256+buf[7], buf[4], buf[5]);
2403 instance->pp->hour = buf[8];
2404 instance->pp->minute = buf[9];
2405 instance->pp->second = buf[10];
2411 if (instance->site_survey == ONCORE_SS_HW || instance->site_survey == ONCORE_SS_SW)
2412 oncore_ss(instance);
2416 if (instance->count2) {
2417 if (instance->count2++ > 5) { /* this delay to check on @@Ay command */
2418 instance->count2 = 0;
2423 if (!instance->saw_Ay && instance->offset) {
2424 oncore_log(instance, LOG_INFO, "No @@Ay command, PPS OFFSET ignored");
2425 instance->offset = 0;
2434 oncore_check_leap_sec(instance);
2440 if (instance->shmem && !instance->shmem_bad_Ea && instance->shmem_Posn && (instance->site_survey == ONCORE_SS_DONE))
2441 oncore_shmem_get_3D(instance);
2443 if (!instance->traim) /* NO traim, no BnEnHn, go get tick */
2444 oncore_get_timestamp(instance, instance->offset, instance->offset);
2453 struct instance *instance,
2458 oncore_log_f(instance, LOG_NOTICE,
2479 struct instance *instance,
2486 instance->saw_Bj = 1;
2490 instance->pp->leap = LEAP_ADDSECOND;
2494 instance->pp->leap = LEAP_DELSECOND;
2499 instance->pp->leap = LEAP_NOWARNING;
2503 oncore_log(instance, LOG_NOTICE, cp);
2510 struct instance *instance,
2530 if ((!instance->Bl.lsf_flg && !instance->Bl.wn_flg) && (subframe == 4 && page == 18 && valid == 10)) {
2531 instance->Bl.dt_ls = buf[32];
2532 instance->Bl.WN_lsf = buf[33];
2533 instance->Bl.DN_lsf = buf[34];
2534 instance->Bl.dt_lsf = buf[35];
2535 instance->Bl.lsf_flg++;
2537 if ((instance->Bl.lsf_flg && !instance->Bl.wn_flg) && (subframe == 1 && valid == 10)) {
2539 instance->Bl.WN = i >> 6;
2544 instance->Bl.DN = tow/57600L + 1;
2545 instance->Bl.wn_flg++;
2547 if (instance->Bl.wn_flg && instance->Bl.lsf_flg) {
2548 instance->Bl.wn_flg = instance->Bl.lsf_flg = 0;
2550 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof oncore_cmd_Bl);
2553 i = instance->Bl.WN&01400;
2554 instance->Bl.WN_lsf |= i;
2558 i = (instance->Bl.WN_lsf - instance->Bl.WN);
2561 day_now = instance->Bl.DN;
2562 day_lsf = 7*i + instance->Bl.DN_lsf;
2569 if (day_lsf - day_now < 28 || instance->BEHa[5] < 20) {
2570 i = instance->Bl.dt_lsf - instance->Bl.dt_ls;
2588 instance->peer->leap = LEAP_NOWARNING;
2592 instance->peer->leap = LEAP_DELSECOND;
2596 instance->peer->leap = LEAP_ADDSECOND;
2603 oncore_log(instance, LOG_NOTICE, cp);
2605 i = instance->Bl.dt_lsf-instance->Bl.dt_ls;
2608 oncore_log_f(instance, LOG_NOTICE,
2620 oncore_log_f(instance, LOG_DEBUG,
2622 instance->Bl.dt_ls, instance->Bl.dt_lsf,
2623 instance->Bl.WN, instance->Bl.DN,
2624 instance->Bl.WN_lsf, instance->Bl.DN_lsf,
2625 instance->Bl.wn_flg, instance->Bl.lsf_flg,
2626 instance->Bl.Bl_day);
2633 struct instance *instance,
2640 if (instance->o_state != ONCORE_RUN)
2643 if (instance->traim_delay) { /* flag that @@Bn/@@En/Hn returned */
2644 instance->traim_ck = 1;
2645 instance->traim_delay = 0;
2646 oncore_log(instance, LOG_NOTICE, "ONCORE: Detected TRAIM, TRAIM = ON");
2648 oncore_set_traim(instance);
2651 memcpy(instance->BEHn, buf, (size_t) len); /* Bn or En or Hn */
2653 if (!instance->traim) /* BnEnHn will be turned off in any case */
2659 if (instance->BEHn[6]) { /* bad TRAIM */
2660 oncore_log(instance, LOG_WARNING, "BAD TRAIM");
2664 dt1 = instance->saw_tooth + instance->offset; /* dt this time step */
2665 instance->saw_tooth = (s_char) instance->BEHn[14]; /* update for next time Hn[14] */
2666 dt2 = instance->saw_tooth + instance->offset; /* dt next time step */
2668 if (instance->BEHn[21]) /* bad TRAIM */
2671 dt1 = instance->saw_tooth + instance->offset; /* dt this time step */
2672 instance->saw_tooth = (s_char) instance->BEHn[25]; /* update for next time Bn[25], En[25] */
2673 dt2 = instance->saw_tooth + instance->offset; /* dt next time step */
2676 oncore_get_timestamp(instance, dt1, dt2);
2699 struct instance *instance,
2706 if (instance->o_state == ONCORE_TEST_SENT) {
2709 instance->timeout = 0;
2714 oncore_log_f(instance, LOG_DEBUG,
2718 oncore_log_f(instance, LOG_DEBUG,
2731 oncore_log_f(instance, LOG_ERR,
2735 oncore_log_f(instance, LOG_ERR,
2739 oncore_log(instance, LOG_ERR,
2742 refclock_report(instance->peer, CEVNT_FAULT);
2743 oncore_shutdown(instance->unit, instance->peer);
2749 oncore_antenna_report(instance, antenna);
2751 instance->o_state = ONCORE_INIT;
2752 oncore_log(instance, LOG_NOTICE, "state = ONCORE_INIT");
2754 instance->timeout = 4;
2755 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2767 struct instance *instance,
2774 if (instance->shmem == NULL)
2786 oncore_log(instance, LOG_NOTICE, "Cb: Response is NO ALMANAC");
2791 instance->shmem[instance->shmem_Cb + i + 2]++;
2792 memcpy(instance->shmem + instance->shmem_Cb + i + 3, buf, (size_t) (len + 3));
2795 oncore_log_f(instance, LOG_DEBUG, "See Cb [%d,%d]", buf[4],
2809 struct instance *instance,
2814 if (instance->o_state == ONCORE_RESET_SENT) {
2815 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Return to Posn Fix mode */
2817 instance->o_state = ONCORE_TEST_SENT;
2818 oncore_log(instance, LOG_NOTICE, "state = ONCORE_TEST_SENT");
2820 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2843 struct instance *instance,
2850 memcpy(instance->Cj, buf, len);
2852 instance->timeout = 0;
2853 if (instance->o_state == ONCORE_CHECK_ID) {
2854 oncore_msg_Cj_id(instance, buf, len);
2855 oncore_chan_test(instance);
2856 } else if (instance->o_state == ONCORE_HAVE_CHAN) {
2857 mode = instance->init_type;
2859 instance->o_state = ONCORE_RESET_SENT;
2860 oncore_log(instance, LOG_NOTICE, "state = ONCORE_RESET_SENT");
2861 oncore_sendmsg(instance, oncore_cmd_Cf, sizeof(oncore_cmd_Cf));
2863 instance->o_state = ONCORE_TEST_SENT;
2864 oncore_log(instance, LOG_NOTICE, "state = ONCORE_TEST_SENT");
2868 if (instance->o_state == ONCORE_TEST_SENT) {
2869 if (instance->chan == 6)
2870 oncore_sendmsg(instance, oncore_cmd_Ca, sizeof(oncore_cmd_Ca));
2871 else if (instance->chan == 8)
2872 oncore_sendmsg(instance, oncore_cmd_Fa, sizeof(oncore_cmd_Fa));
2873 else if (instance->chan == 12)
2874 oncore_sendmsg(instance, oncore_cmd_Ia, sizeof(oncore_cmd_Ia));
2875 } else if (instance->o_state == ONCORE_INIT)
2876 oncore_msg_Cj_init(instance, buf, len);
2895 struct instance *instance,
2905 instance->Cj[294] = '\0';
2906 for (cp= (char *)instance->Cj; cp< (char *) &instance->Cj[294]; ) {
2909 cpw = (char *)&instance->Cj[294];
2911 oncore_log(instance, LOG_NOTICE, cp);
2918 instance->version = atoi((char *) &instance->Cj[83]);
2919 instance->revision = atoi((char *) &instance->Cj[111]);
2924 for (cp= (char *) &instance->Cj[160]; *cp == ' '; cp++) /* start right after 'Model #' */
2935 instance->model = ONCORE_PVT6;
2938 instance->model = ONCORE_BASIC;
2941 instance->model = ONCORE_VP;
2944 instance->model = ONCORE_M12;
2948 instance->model = ONCORE_GT;
2951 instance->model = ONCORE_GTPLUS;
2954 instance->model = ONCORE_UT;
2957 instance->model = ONCORE_UTPLUS;
2960 instance->model = ONCORE_SL;
2963 instance->model = ONCORE_UNKNOWN;
2967 instance->model = ONCORE_UNKNOWN;
2972 oncore_log_f(instance, LOG_INFO,
2974 cp, instance->version, instance->revision);
2976 instance->chan_id = 8; /* default */
2977 if (instance->model == ONCORE_BASIC || instance->model == ONCORE_PVT6)
2978 instance->chan_id = 6;
2979 else if (instance->model == ONCORE_VP || instance->model == ONCORE_UT || instance->model == ONCORE_UTPLUS)
2980 instance->chan_id = 8;
2981 else if (instance->model == ONCORE_M12)
2982 instance->chan_id = 12;
2984 instance->traim_id = 0; /* default */
2985 if (instance->model == ONCORE_BASIC || instance->model == ONCORE_PVT6)
2986 instance->traim_id = 0;
2987 else if (instance->model == ONCORE_VP || instance->model == ONCORE_UT || instance->model == ONCORE_UTPLUS)
2988 instance->traim_id = 1;
2989 else if (instance->model == ONCORE_M12)
2990 instance->traim_id = -1;
2992 oncore_log_f(instance, LOG_INFO, "Channels = %d, TRAIM = %s",
2993 instance->chan_id,
2994 ((instance->traim_id < 0)
2996 : (instance->traim_id > 0)
3011 struct instance *instance,
3026 if (instance->chan == 12) {
3027 instance->shmem_bad_Ea = 1;
3028 oncore_log_f(instance, LOG_NOTICE,
3030 instance->version, instance->revision);
3033 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Return to Posn Fix mode */
3034 oncore_sendmsg(instance, oncore_cmd_Bb, sizeof(oncore_cmd_Bb)); /* turn on for shmem (6/8/12) */
3035 oncore_sendmsg(instance, oncore_cmd_Ek, sizeof(oncore_cmd_Ek)); /* turn off (VP) */
3036 oncore_sendmsg(instance, oncore_cmd_Aw, sizeof(oncore_cmd_Aw)); /* UTC time (6/8/12) */
3037 oncore_sendmsg(instance, oncore_cmd_AB, sizeof(oncore_cmd_AB)); /* Appl type static (VP) */
3038 oncore_sendmsg(instance, oncore_cmd_Be, sizeof(oncore_cmd_Be)); /* Tell us the Almanac for shmem (6/8/12) */
3039 oncore_sendmsg(instance, oncore_cmd_Bd, sizeof(oncore_cmd_Bd)); /* Tell us when Almanac changes */
3041 mode = instance->init_type;
3048 if (instance->posn_set) {
3049 oncore_log(instance, LOG_INFO, "Setting Posn from input data");
3050 oncore_set_posn(instance); /* this should print posn indirectly thru the As cmd */
3052 if (instance->chan != 12)
3053 oncore_sendmsg(instance, oncore_cmd_Atx, sizeof(oncore_cmd_Atx));
3058 w32_buf(&Cmd[-2+4], (int)instance->delay);
3059 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Az)); /* 6,8,12 */
3063 w32_buf(&Cmd[-2+4], instance->offset); /* will check for hw response */
3064 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ay));
3068 if (instance->Ag != 0xff) { /* will have 0xff in it if not set by user */
3070 Cmd[-2+4] = instance->Ag;
3071 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ag));
3082 if (instance->chan == 6) { /* start 6chan, kill 8,12chan commands, possibly testing VP in 6chan mode */
3083 oncore_sendmsg(instance, oncore_cmd_Ea0, sizeof(oncore_cmd_Ea0));
3084 oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
3085 oncore_sendmsg(instance, oncore_cmd_Ha0, sizeof(oncore_cmd_Ha0));
3086 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3087 oncore_sendmsg(instance, oncore_cmd_Ba, sizeof(oncore_cmd_Ba ));
3088 } else if (instance->chan == 8) { /* start 8chan, kill 6,12chan commands */
3089 oncore_sendmsg(instance, oncore_cmd_Ba0, sizeof(oncore_cmd_Ba0));
3090 oncore_sendmsg(instance, oncore_cmd_Bn0, sizeof(oncore_cmd_Bn0));
3091 oncore_sendmsg(instance, oncore_cmd_Ha0, sizeof(oncore_cmd_Ha0));
3092 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3093 oncore_sendmsg(instance, oncore_cmd_Ea, sizeof(oncore_cmd_Ea ));
3094 } else if (instance->chan == 12){ /* start 12chan, kill 6,12chan commands */
3095 oncore_sendmsg(instance, oncore_cmd_Ba0, sizeof(oncore_cmd_Ba0));
3096 oncore_sendmsg(instance, oncore_cmd_Bn0, sizeof(oncore_cmd_Bn0));
3097 oncore_sendmsg(instance, oncore_cmd_Ea0, sizeof(oncore_cmd_Ea0));
3098 oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
3099 oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha ));
3100 oncore_cmd_Gc[2] = (instance->pps_control < 0) ? 1 : instance->pps_control;
3101 oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* PPS off/continuous/Tracking 1+sat/TRAIM */
3104 instance->count = 1;
3105 instance->o_state = ONCORE_ALMANAC;
3106 oncore_log(instance, LOG_NOTICE, "state = ONCORE_ALMANAC");
3115 struct instance *instance,
3136 oncore_log_f(instance, LOG_NOTICE,
3140 instance->ss_lat = lat;
3141 instance->ss_long = lon;
3142 instance->ss_ht = ht;
3144 oncore_print_posn(instance);
3153 struct instance *instance,
3173 oncore_log_f(instance, LOG_NOTICE,
3184 struct instance *instance,
3191 instance->pps_control_msg_seen = 1;
3192 oncore_log_f(instance, LOG_INFO, "PPS Control set to %s",
3203 struct instance *instance,
3216 instance->saw_Gj = 1; /* flag, saw_Gj, dont need to try Bj in check_leap */
3222 oncore_log_f(instance, LOG_INFO,
3243 oncore_log_f(instance, LOG_NOTICE,
3251 instance->pp->leap = LEAP_NOWARNING;
3254 if (buf[6] == instance->BEHa[6] && buf[7] == instance->BEHa[7] && /* year */
3255 buf[8] == instance->BEHa[4]) { /* month */
3258 instance->pp->leap = LEAP_DELSECOND;
3261 instance->pp->leap = LEAP_ADDSECOND;
3266 oncore_log(instance, LOG_INFO, cp);
3275 struct instance *instance,
3280 if (instance && instance->peer) {
3281 oncore_log(instance, LOG_ERR, "Oncore: System Failure at Power On");
3282 oncore_shutdown(instance->unit, instance->peer);
3291 struct instance *instance,
3296 if (instance->ant_state == new_state)
3307 instance->ant_state = new_state;
3308 oncore_log(instance, LOG_NOTICE, cp);
3315 struct instance *instance
3327 instance->o_state = ONCORE_CHECK_CHAN;
3328 oncore_log(instance, LOG_NOTICE, "state = ONCORE_CHECK_CHAN");
3330 instance->count3 = 1;
3331 oncore_sendmsg(instance, oncore_cmd_Ba, sizeof(oncore_cmd_Ba));
3332 oncore_sendmsg(instance, oncore_cmd_Ea, sizeof(oncore_cmd_Ea));
3333 oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha));
3342 struct instance *instance
3345 if (instance->chan == 6) {
3346 instance->rsm.bad_almanac = instance->BEHa[64]&0x1;
3347 instance->rsm.bad_fix = instance->BEHa[64]&0x52;
3348 } else if (instance->chan == 8) {
3349 instance->rsm.bad_almanac = instance->BEHa[72]&0x1;
3350 instance->rsm.bad_fix = instance->BEHa[72]&0x52;
3351 } else if (instance->chan == 12) {
3354 bits1 = (instance->BEHa[129]>>5) & 0x7; /* actually Ha */
3355 bits2 = instance->BEHa[130];
3356 instance->rsm.bad_almanac = (bits2 & 0x80);
3357 instance->rsm.bad_fix = (bits2 & 0x8) || (bits1 == 0x2);
3360 bits3 = instance->BEHa[141]; /* UTC parameters */
3361 if (!instance->count5_set && (bits3 & 0xC0)) {
3362 instance->count5 = 4; /* was 2 [Bug 1766] */
3363 instance->count5_set = 1;
3366 oncore_log_f(instance, LOG_DEBUG,
3368 instance->BEHa[129], instance->BEHa[130],
3370 instance->mode == MODE_0D,
3371 instance->mode == MODE_2D,
3372 instance->mode == MODE_3D,
3373 instance->rsm.bad_almanac,
3374 instance->rsm.bad_fix);
3386 struct instance *instance
3391 if (instance->chan == 12)
3392 antenna = (instance->BEHa[130] & 0x6 ) >> 1;
3394 antenna = (instance->BEHa[37] & 0xc0) >> 6; /* prob unset 6, set GT, UT unset VP */
3396 oncore_antenna_report (instance, antenna);
3426 struct instance *instance
3430 if (instance->Bj_day != instance->BEHa[5]) { /* do this 1/day */
3431 instance->Bj_day = instance->BEHa[5];
3433 if (instance->saw_Gj < 0) { /* -1 DONT have Gj use Bj */
3434 if ((instance->BEHa[4] == 6) || (instance->BEHa[4] == 12))
3435 oncore_sendmsg(instance, oncore_cmd_Bj, sizeof(oncore_cmd_Bj));
3436 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof(oncore_cmd_Bl));
3440 if (instance->saw_Gj == 0) /* 0 is dont know if we have Gj */
3441 instance->count4 = 1;
3443 oncore_sendmsg(instance, oncore_cmd_Gj, sizeof(oncore_cmd_Gj));
3451 if (instance->count4) { /* delay, waiting for Gj response */
3452 if (instance->saw_Gj == 1)
3453 instance->count4 = 0;
3454 else if (instance->count4++ > 5) { /* delay, waiting for Gj response */
3455 instance->saw_Gj = -1; /* didnt see it, will use Bj */
3456 instance->count4 = 0;
3457 if ((instance->BEHa[4] == 6) || (instance->BEHa[4] == 12)) {
3458 oncore_sendmsg(instance, oncore_cmd_Bj, sizeof(oncore_cmd_Bj));
3459 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof(oncore_cmd_Bl));
3491 struct instance *instance
3499 instance->have_dH = 1;
3500 if (instance->chan == 12) {
3501 GPS = buf_w32(&instance->BEHa[39]);
3502 MSL = buf_w32(&instance->BEHa[43]);
3504 GPS = buf_w32(&instance->BEHa[23]);
3505 MSL = buf_w32(&instance->BEHa[27]);
3507 instance->dH = GPS - MSL;
3508 instance->dH /= 100.;
3513 oncore_log_f(instance, LOG_INFO,
3514 "dH = (GPS - MSL) = %.2fm", instance->dH);
3525 struct instance *instance
3533 if (!instance->shmem)
3537 for (cp = instance->shmem + 4; (n = 256 * (*(cp-3)) + *(cp-2));
3542 refclock_fdwrite(instance->peer, instance->ttyfd,
3544 oncore_print_Cb(instance, cp);
3548 for (cp = instance->shmem + 4; (n = 256 * (*(cp-3)) + *(cp-2));
3550 oncore_log_f(instance, LOG_DEBUG, "See %c%c%c%c %d",
3554 oncore_print_Cb(instance, cp);
3557 oncore_log(instance, LOG_DEBUG, "GOOD SF");
3558 write(instance->ttyfd, cp, n);
3560 oncore_log(instance, LOG_DEBUG, "BAD SF");
3562 oncore_log(instance, LOG_DEBUG, "BAD CHECKSUM");
3569 if (!instance->posn_set) { /* if we input a posn use it, else from SHMEM */
3570 oncore_log(instance, LOG_NOTICE, "Loading Posn from SHMEM");
3571 for (cp=instance->shmem+4; (n = 256*(*(cp-3)) + *(cp-2)); cp+=(n+3)) {
3572 if ((instance->chan == 6 && (!strncmp((char *) cp, "@@Ba", 4) && oncore_checksum_ok(cp, 68))) ||
3573 (instance->chan == 8 && (!strncmp((char *) cp, "@@Ea", 4) && oncore_checksum_ok(cp, 76))) ||
3574 (instance->chan == 12 && (!strncmp((char *) cp, "@@Ha", 4) && oncore_checksum_ok(cp, 154)))) {
3577 instance->posn_set = 1;
3582 oncore_log_f(instance, LOG_DEBUG,
3584 (long)(cp-instance->shmem),
3588 instance->ss_lat = ii;
3589 instance->ss_long = jj;
3590 instance->ss_ht = kk;
3595 oncore_set_posn(instance);
3603 oncore_log_f(instance, LOG_DEBUG, "DATE %d %d %d, %d %d %d",
3607 if (instance->chan == 12) {
3619 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Gb));
3623 oncore_sendmsg(instance, oncore_cmd_Ab, sizeof(oncore_cmd_Ab));
3630 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ac));
3636 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Aa));
3639 oncore_log(instance, LOG_INFO, "Setting Posn and Time after Loading Almanac");
3648 struct instance *instance,
3656 oncore_log_f(instance, LOG_DEBUG, "DEBUG: See: %c%c%c%c", *(cp),
3665 oncore_log(instance, LOG_DEBUG, Msg);
3667 oncore_log_f(instance, LOG_DEBUG, "Debug: Cb: [%d,%d]", *(cp+4),
3698 struct instance *instance
3706 oncore_log(instance, LOG_INFO, "Posn:");
3708 lon = instance->ss_long;
3715 lat = instance->ss_lat;
3721 hm = instance->ss_ht/100.;
3726 oncore_log_f(instance, LOG_INFO,
3736 oncore_log_f(instance, LOG_INFO,
3746 oncore_log_f(instance, LOG_INFO,
3759 struct instance *instance,
3768 fd = instance->ttyfd;
3769 peer = instance->peer;
3772 oncore_log_f(instance, LOG_DEBUG, "ONCORE: Send @@%c%c %d",
3788 struct instance *instance
3797 if (instance->chan == 12)
3798 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* (12) */
3800 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* (6/8) */
3801 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* (6/8) */
3804 mode = instance->init_type;
3808 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3809 w32_buf(&Cmd[-2+8], (int) instance->ss_long);
3810 w32_buf(&Cmd[-2+12], (int) instance->ss_ht);
3812 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_As)); /* posn hold 3D posn (6/8/12) */
3815 w32_buf(&Cmd[-2+4], (int) instance->ss_ht);
3817 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Au)); /* altitude hold (6/8/12 not UT, M12T) */
3821 if (instance->chan == 12) {
3823 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3824 w32_buf(&Cmd[-2+8], (int) instance->ss_long);
3825 w32_buf(&Cmd[-2+12],(int) instance->ss_ht);
3827 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ga)); /* 3d posn (12) */
3830 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3831 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ad)); /* lat (6/8) */
3834 w32_buf(&Cmd[-2+4], (int) instance->ss_long);
3835 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ae)); /* long (6/8) */
3838 w32_buf(&Cmd[-2+4], (int) instance->ss_ht);
3840 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Af)); /* ht (6/8) */
3845 if (instance->chan == 12)
3846 oncore_sendmsg(instance, oncore_cmd_Gd1, sizeof(oncore_cmd_Gd1));
3848 oncore_sendmsg(instance, oncore_cmd_At1, sizeof(oncore_cmd_At1));
3856 struct instance *instance
3859 if (instance->traim_in != -1) /* set in Input */
3860 instance->traim = instance->traim_in;
3862 instance->traim = instance->traim_ck;
3864 oncore_log_f(instance, LOG_INFO, "Input says TRAIM = %d",
3865 instance->traim_in);
3866 oncore_log_f(instance, LOG_INFO, "Model # says TRAIM = %d",
3867 instance->traim_id);
3868 oncore_log_f(instance, LOG_INFO, "Testing says TRAIM = %d",
3869 instance->traim_ck);
3870 oncore_log_f(instance, LOG_INFO, "Using TRAIM = %d",
3871 instance->traim);
3873 if (instance->traim_ck == 1 && instance->traim == 0) {
3876 if (instance->chan == 6)
3877 oncore_sendmsg(instance, oncore_cmd_Bnx, sizeof(oncore_cmd_Bnx));
3878 else if (instance->chan == 8)
3879 oncore_sendmsg(instance, oncore_cmd_Enx, sizeof(oncore_cmd_Enx));
3881 oncore_sendmsg(instance, oncore_cmd_Ge0, sizeof(oncore_cmd_Ge0));
3882 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3894 struct instance *instance
3897 if (instance->pp->second%15 == 3) { /* start the sequence */ /* by changing mode */
3898 instance->shmem_reset = 1;
3899 if (instance->chan == 12) {
3900 if (instance->shmem_Posn == 2)
3901 oncore_sendmsg(instance, oncore_cmd_Gd2, sizeof(oncore_cmd_Gd2)); /* 2D */
3903 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* 3D */
3905 if (instance->saw_At) { /* out of 0D -> 3D mode */
3906 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0));
3907 if (instance->shmem_Posn == 2) /* 3D -> 2D mode */
3908 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
3910 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0));
3912 } else if (instance->shmem_reset || (instance->mode != MODE_0D)) {
3913 instance->shmem_reset = 0;
3914 if (instance->chan == 12)
3915 oncore_sendmsg(instance, oncore_cmd_Gd1, sizeof(oncore_cmd_Gd1)); /* 0D */
3917 if (instance->saw_At) {
3918 if (instance->mode == MODE_2D) /* 2D -> 3D or 0D mode */
3919 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0));
3920 oncore_sendmsg(instance, oncore_cmd_At1, sizeof(oncore_cmd_At1)); /* to 0D mode */
3922 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
3938 struct instance *instance
3944 if (instance->site_survey == ONCORE_SS_HW) {
3949 if ((instance->chan == 8 && !(instance->BEHa[37] & 0x20)) ||
3950 (instance->chan == 12 && !(instance->BEHa[130] & 0x10))) {
3951 oncore_log(instance, LOG_INFO, "Now in 0D mode");
3953 if (instance->chan == 12)
3954 oncore_sendmsg(instance, oncore_cmd_Gax, sizeof(oncore_cmd_Gax));
3956 oncore_sendmsg(instance, oncore_cmd_Asx, sizeof(oncore_cmd_Asx));
3958 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
3959 instance->site_survey = ONCORE_SS_DONE;
3966 if (instance->rsm.bad_fix) /* Not if poor geometry or less than 3 sats */
3969 if (instance->mode != MODE_3D) /* Use only 3D Fixes */
3972 instance->ss_lat += buf_w32(&instance->BEHa[15]);
3973 instance->ss_long += buf_w32(&instance->BEHa[19]);
3974 instance->ss_ht += buf_w32(&instance->BEHa[23]); /* GPS ellipsoid */
3975 instance->ss_count++;
3977 if (instance->ss_count != POS_HOLD_AVERAGE)
3980 instance->ss_lat /= POS_HOLD_AVERAGE;
3981 instance->ss_long /= POS_HOLD_AVERAGE;
3982 instance->ss_ht /= POS_HOLD_AVERAGE;
3984 oncore_log_f(instance, LOG_NOTICE,
3986 instance->ss_lat, instance->ss_long,
3987 instance->ss_ht);
3988 lat = instance->ss_lat/3600000.;
3989 lon = instance->ss_long/3600000.;
3990 ht = instance->ss_ht/100;
3991 oncore_log_f(instance, LOG_NOTICE,
3995 oncore_set_posn(instance);
3997 oncore_log(instance, LOG_INFO, "Now in 0D mode");
3999 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
4000 instance->site_survey = ONCORE_SS_DONE;
4008 struct instance *instance
4011 if (instance->rsm.bad_almanac) {
4012 instance->counta++;
4013 if (instance->counta%5 == 0)
4014 oncore_log(instance, LOG_INFO, "Waiting for Almanac");
4021 if (!instance->almanac_from_shmem) {
4022 instance->almanac_from_shmem = 1;
4023 oncore_load_almanac(instance);
4030 if (instance->chan == 6)
4031 oncore_sendmsg(instance, oncore_cmd_Bn, sizeof(oncore_cmd_Bn));
4032 else if (instance->chan == 8)
4033 oncore_sendmsg(instance, oncore_cmd_En, sizeof(oncore_cmd_En));
4034 else if (instance->chan == 12) {
4035 oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* 1PPS on, continuous */
4036 oncore_sendmsg(instance, oncore_cmd_Ge, sizeof(oncore_cmd_Ge)); /* TRAIM on */
4037 oncore_sendmsg(instance, oncore_cmd_Hn, sizeof(oncore_cmd_Hn)); /* TRAIM status 1/s */
4039 instance->traim_delay = 1;
4041 oncore_log(instance, LOG_NOTICE, "Have now loaded an ALMANAC");
4043 instance->o_state = ONCORE_RUN;
4044 oncore_log(instance, LOG_NOTICE, "state = ONCORE_RUN");
4052 struct instance * instance
4055 struct peer * const peer = instance->peer;
4056 struct refclockproc * const pp = instance->pp;
4099 struct instance *instance,
4104 msyslog(log_level, "ONCORE[%d]: %s", instance->unit, msg);
4105 mprintf_clock_stats(&instance->peer->srcadr, "ONCORE[%d]: %s",
4106 instance->unit, msg);
4112 struct instance * instance,
4125 oncore_log(instance, log_level, msg);
4128 instance->max_len = max(strlen(msg), instance->max_len);
4129 instance->max_count++;
4130 if (instance->max_count % 100 == 0)
4131 oncore_log_f(instance, LOG_INFO,
4133 instance->max_len);