Lines Matching defs:instance

88  * instance->pp->leap indicator but only run this test in December and June for
267 struct instance {
358 #define rcvbuf instance->Rcvbuf
359 #define rcvptr instance->Rcvptr
364 static void oncore_consume (struct instance *);
365 static void oncore_read_config (struct instance *);
367 static int oncore_ppsapi (struct instance *);
368 static void oncore_get_timestamp (struct instance *, long, long);
369 static void oncore_init_shmem (struct instance *);
371 static void oncore_antenna_report (struct instance *, enum antenna_state);
372 static void oncore_chan_test (struct instance *);
373 static void oncore_check_almanac (struct instance *);
374 static void oncore_check_antenna (struct instance *);
375 static void oncore_check_leap_sec (struct instance *);
377 static void oncore_compute_dH (struct instance *);
378 static void oncore_load_almanac (struct instance *);
379 static void oncore_log (struct instance *, int, const char *);
380 static int oncore_log_f (struct instance *, int, const char *, ...)
382 static void oncore_print_Cb (struct instance *, u_char *);
384 static void oncore_print_posn (struct instance *);
385 static void oncore_sendmsg (struct instance *, u_char *, size_t);
386 static void oncore_set_posn (struct instance *);
387 static void oncore_set_traim (struct instance *);
388 static void oncore_shmem_get_3D (struct instance *);
389 static void oncore_ss (struct instance *);
390 static int oncore_wait_almanac (struct instance *);
392 static void oncore_msg_any (struct instance *, u_char *, size_t, int);
393 static void oncore_msg_Adef (struct instance *, u_char *, size_t);
394 static void oncore_msg_Ag (struct instance *, u_char *, size_t);
395 static void oncore_msg_As (struct instance *, u_char *, size_t);
396 static void oncore_msg_At (struct instance *, u_char *, size_t);
397 static void oncore_msg_Ay (struct instance *, u_char *, size_t);
398 static void oncore_msg_Az (struct instance *, u_char *, size_t);
399 static void oncore_msg_BaEaHa (struct instance *, u_char *, size_t);
400 static void oncore_msg_Bd (struct instance *, u_char *, size_t);
401 static void oncore_msg_Bj (struct instance *, u_char *, size_t);
402 static void oncore_msg_Bl (struct instance *, u_char *, size_t);
403 static void oncore_msg_BnEnHn (struct instance *, u_char *, size_t);
404 static void oncore_msg_CaFaIa (struct instance *, u_char *, size_t);
405 static void oncore_msg_Cb (struct instance *, u_char *, size_t);
406 static void oncore_msg_Cf (struct instance *, u_char *, size_t);
407 static void oncore_msg_Cj (struct instance *, u_char *, size_t);
408 static void oncore_msg_Cj_id (struct instance *, u_char *, size_t);
409 static void oncore_msg_Cj_init (struct instance *, u_char *, size_t);
410 static void oncore_msg_Ga (struct instance *, u_char *, size_t);
411 static void oncore_msg_Gb (struct instance *, u_char *, size_t);
412 static void oncore_msg_Gc (struct instance *, u_char *, size_t);
413 static void oncore_msg_Gj (struct instance *, u_char *, size_t);
414 static void oncore_msg_Sz (struct instance *, u_char *, size_t);
434 void (*handler) (struct instance *, u_char *, size_t);
595 register struct instance *instance;
603 /* create instance structure for this unit */
605 instance = emalloc(sizeof(*instance));
606 memset(instance, 0, sizeof(*instance));
611 instance->pp = pp;
612 instance->unit = unit;
613 instance->peer = peer;
614 instance->assert = 1;
615 instance->once = 1;
617 instance->Bj_day = -1;
618 instance->traim = -1;
619 instance->traim_in = -1;
620 instance->chan_in = -1;
621 instance->pps_control = -1; /* PPS control, M12 only */
622 instance->pps_control_msg_seen = -1; /* Have seen response to Gc msg */
623 instance->model = ONCORE_UNKNOWN;
624 instance->mode = MODE_UNKNOWN;
625 instance->site_survey = ONCORE_SS_UNKNOWN;
626 instance->Ag = 0xff; /* Satellite mask angle, unset by user */
627 instance->ant_state = ONCORE_ANTENNA_UNKNOWN;
636 oncore_log(instance, LOG_NOTICE, "ONCORE DRIVER -- CONFIGURING");
637 instance->o_state = ONCORE_NO_IDEA;
638 oncore_log(instance, LOG_NOTICE, "state = ONCORE_NO_IDEA");
673 oncore_log_f(instance, LOG_ERR, "Can't stat fd1 (%s)",
680 oncore_log_f(instance, LOG_ERR, "Can't stat fd2 (%s) %d %m",
687 oncore_log_f(instance, LOG_ERR, "Can't open fd1 (%s)",
704 oncore_log_f(instance, LOG_ERR,
712 if (time_pps_create(fd2, &instance->pps_h) < 0) {
713 oncore_log(instance, LOG_ERR, "exit, PPSAPI not found in kernel");
719 instance->ttyfd = fd1;
720 instance->ppsfd = fd2;
724 oncore_read_config(instance);
726 if (!oncore_ppsapi(instance))
734 oncore_log(instance, LOG_ERR, "can't do io_addclock");
737 free(instance);
740 pp->unitptr = instance;
749 oncore_init_shmem(instance);
757 instance->o_state = ONCORE_CHECK_ID;
758 oncore_log(instance, LOG_NOTICE, "state = ONCORE_CHECK_ID");
760 instance->timeout = 4;
761 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Set Posn Fix mode (not Idle (VP)) */
762 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
764 instance->pollcnt = 2;
779 register struct instance *instance;
783 instance = pp->unitptr;
788 if (instance != NULL) {
789 time_pps_destroy (instance->pps_h);
791 close(instance->ttyfd);
793 if ((instance->ppsfd != -1) && (instance->ppsfd != instance->ttyfd))
794 close(instance->ppsfd);
796 if (instance->shmemfd)
797 close(instance->shmemfd);
799 free(instance);
815 struct instance *instance;
817 instance = peer->procptr->unitptr;
818 if (instance->timeout) {
819 instance->timeout--;
820 if (instance->timeout == 0) {
821 oncore_log(instance, LOG_ERR,
825 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
826 oncore_log(instance, LOG_WARNING, "Oncore: Resend @@Cj");
831 if (!instance->pollcnt)
834 instance->pollcnt--;
836 instance->polled = 1;
847 struct instance *instance
853 if (time_pps_getcap(instance->pps_h, &cap) < 0) {
854 oncore_log_f(instance, LOG_ERR, "time_pps_getcap failed: %m");
858 if (time_pps_getparams(instance->pps_h, &instance->pps_p) < 0) {
859 oncore_log_f(instance, LOG_ERR, "time_pps_getparams failed: %m");
867 if (instance->assert) {
876 oncore_log_f(instance, LOG_INFO, "Initializing timing to %s.",
880 oncore_log_f(instance, LOG_ERR,
886 oncore_log_f(instance, LOG_NOTICE,
894 instance->pps_p.mode = (mode | mode1 | PPS_TSFMT_TSPEC) & cap;
896 if (time_pps_setparams(instance->pps_h, &instance->pps_p) < 0) {
897 oncore_log_f(instance, LOG_ERR, "ONCORE: time_pps_setparams fails %m");
903 if (instance->hardpps) {
906 oncore_log(instance, LOG_INFO, "HARDPPS Set.");
908 if (instance->assert)
915 if (time_pps_kcbind(instance->pps_h, PPS_KC_HARDPPS, i,
917 oncore_log_f(instance, LOG_ERR, "time_pps_kcbind failed: %m");
918 oncore_log(instance, LOG_ERR, "HARDPPS failed, abort...");
932 struct instance *instance
942 * The first thing we do is see if there is an instance->shmem_fname file (still)
949 if ((fd = open(instance->shmem_fname, O_RDONLY)) < 0)
950 oncore_log(instance, LOG_WARNING, "ONCORE: Can't open SHMEM file");
963 if ((instance->shmemfd = open(instance->shmem_fname, O_RDWR|O_CREAT|O_TRUNC, 0644)) < 0) {
964 oncore_log(instance, LOG_WARNING, "ONCORE: Can't open shmem");
978 instance->shmem_Cb = n;
982 instance->shmem_Ba = n;
986 instance->shmem_Ea = n;
990 instance->shmem_Ha = n;
1048 i = write(instance->shmemfd, buf, shmem_length);
1052 oncore_log(instance, LOG_ERR, "ONCORE: error writing shmem");
1053 close(instance->shmemfd);
1057 instance->shmem = (u_char *) mmap(0, shmem_length,
1062 MAP_SHARED, instance->shmemfd, (off_t)0);
1064 if (instance->shmem == (u_char *)MAP_FAILED) {
1065 instance->shmem = 0;
1066 close(instance->shmemfd);
1070 oncore_log_f(instance, LOG_NOTICE,
1072 (u_long) shmem_length, instance->shmem_fname);
1084 struct instance *instance
1223 cp, instance->unit); /* try "ntp.oncore.0 */
1227 cp, instance->unit); /* try "ntp.oncore0" */
1236 instance->init_type = 4;
1278 instance->shmem_fname = estrdup(ca);
1295 instance->ss_lat = sign*1000*(fabs(f3) + 60*(fabs(f2) + 60*f1)); /*miliseconds*/
1305 instance->ss_long = sign*1000*(fabs(f3) + 60*(fabs(f2) + 60*f1)); /*miliseconds*/
1313 instance->ss_ht = 100 * f1; /* cm */
1330 oncore_log_f(instance, LOG_WARNING,
1334 instance->delay = f1; /* delay in ns */
1350 oncore_log_f(instance, LOG_WARNING,
1354 instance->offset = f1; /* offset in ns */
1360 instance->assert = 1;
1362 instance->assert = 0;
1364 instance->hardpps = 1;
1366 instance->shmem_Posn = 2;
1368 instance->shmem_Posn = 3;
1372 instance->chan_in = i;
1374 instance->traim_in = 1; /* so TRAIM alone is YES */
1376 instance->traim_in = 0;
1380 instance->Ag = mask; /* Satellite mask angle */
1383 instance->pps_control = 1; /* PPS always on */
1385 instance->pps_control = 2; /* PPS on when satellite is available */
1387 instance->pps_control = 3; /* PPS on when TRAIM status is OK */
1389 oncore_log_f(instance, LOG_WARNING,
1402 instance->posn_set = 1;
1404 oncore_log_f(instance, LOG_WARNING,
1406 instance->posn_set = 0;
1408 oncore_log_f(instance, LOG_WARNING,
1414 instance->init_type = mode;
1416 oncore_log_f(instance, LOG_INFO, "Input mode = %d", mode);
1433 struct instance *instance;
1436 instance = peer->procptr->unitptr;
1444 oncore_log_f(instance, LOG_DEBUG,
1452 oncore_log(instance, LOG_DEBUG, Msg);
1459 oncore_log(instance, LOG_DEBUG, Msg);
1468 oncore_consume(instance);
1479 struct instance *instance
1492 oncore_log_f(instance, LOG_DEBUG,
1510 oncore_log_f(instance, LOG_DEBUG,
1522 oncore_log_f(instance, LOG_DEBUG,
1524 instance->unit, rcvbuf[2],
1537 oncore_log(instance, LOG_DEBUG, "NO <CR><LF> at end of message");
1541 if (instance->shmem != NULL) {
1542 instance->shmem[oncore_messages[m].shmem + 2]++;
1543 memcpy(instance->shmem + oncore_messages[m].shmem + 3,
1546 oncore_msg_any(instance, rcvbuf, (size_t) (l-3), m);
1548 oncore_messages[m].handler(instance, rcvbuf, (size_t) (l-3));
1554 oncore_log(instance, LOG_ERR, "Checksum mismatch!");
1561 oncore_log(instance, LOG_DEBUG, Msg);
1576 struct instance *instance,
1597 peer = instance->peer;
1606 if ((instance->site_survey == ONCORE_SS_DONE) && (instance->mode != MODE_0D)) {
1610 if ((instance->site_survey != ONCORE_SS_DONE) || (instance->mode != MODE_0D)) {
1618 if (instance->rsm.bad_almanac) {
1629 if (instance->count5) {
1630 instance->count5--;
1635 j = instance->ev_serial;
1638 if (time_pps_fetch(instance->pps_h, PPS_TSFMT_TSPEC, &pps_i,
1640 oncore_log_f(instance, LOG_ERR,
1646 if (instance->assert) {
1655 oncore_log_f(instance, LOG_DEBUG,
1660 oncore_log_f(instance, LOG_DEBUG,
1669 oncore_log(instance, LOG_NOTICE, "ONCORE: oncore_get_timestamp, error serial pps");
1674 instance->ev_serial = pps_i.assert_sequence;
1684 oncore_log_f(instance, LOG_DEBUG,
1689 oncore_log_f(instance, LOG_DEBUG,
1698 oncore_log(instance, LOG_ERR, "oncore_get_timestamp, error serial pps");
1702 instance->ev_serial = pps_i.clear_sequence;
1739 if (instance->assert)
1740 instance->pps_p.assert_offset.tv_nsec = -dt2;
1742 instance->pps_p.clear_offset.tv_nsec = -dt2;
1745 * using the saved instance->pps_p, since some other process on the
1757 if (time_pps_getcap(instance->pps_h, &current_mode) < 0) {
1758 oncore_log_f(instance, LOG_ERR,
1764 if (time_pps_getparams(instance->pps_h, &current_params) < 0) {
1765 oncore_log_f(instance, LOG_ERR,
1772 current_params.mode |= instance->pps_p.mode;
1781 if (time_pps_setparams(instance->pps_h, &current_params))
1782 oncore_log(instance, LOG_ERR, "ONCORE: Error doing time_pps_setparams");
1787 instance->pp->lastrec = ts;
1797 if (instance->chan == 6)
1798 Rsm = instance->BEHa[64];
1799 else if (instance->chan == 8)
1800 Rsm = instance->BEHa[72];
1801 else if (instance->chan == 12)
1802 Rsm = ((instance->BEHa[129]<<8) | instance->BEHa[130]);
1804 if (instance->chan == 6 || instance->chan == 8) {
1806 if (instance->traim) {
1808 instance->BEHn[21]);
1810 instance->BEHn[22]);
1812 instance->BEHn[23] * 256 +
1813 instance->BEHn[24]);
1815 (s_char)instance->BEHn[25]);
1825 instance->pp->year, instance->pp->day,
1826 instance->pp->hour, instance->pp->minute, instance->pp->second,
1828 Rsm, 0.1*(256*instance->BEHa[35]+instance->BEHa[36]),
1830 instance->BEHa[38], instance->BEHa[39], instance->traim, f1, f2,
1834 /*sat*/ instance->BEHa[41], instance->BEHa[45], instance->BEHa[49], instance->BEHa[53],
1835 instance->BEHa[57], instance->BEHa[61], instance->BEHa[65], instance->BEHa[69]
1837 } else if (instance->chan == 12) {
1839 if (instance->traim) {
1841 instance->BEHn[6]);
1843 instance->BEHn[7]);
1845 instance->BEHn[12] * 256 +
1846 instance->BEHn[13]);
1848 (s_char)instance->BEHn[14]);
1858 instance->pp->year, instance->pp->day,
1859 instance->pp->hour, instance->pp->minute, instance->pp->second,
1861 Rsm, 0.1*(256*instance->BEHa[53]+instance->BEHa[54]),
1863 instance->BEHa[55], instance->BEHa[56], instance->traim, f1, f2,
1867 /*sat*/ instance->BEHa[58], instance->BEHa[64], instance->BEHa[70], instance->BEHa[76],
1868 instance->BEHa[82], instance->BEHa[88], instance->BEHa[94], instance->BEHa[100],
1869 instance->BEHa[106], instance->BEHa[112], instance->BEHa[118], instance->BEHa[124]
1875 if (!refclock_process(instance->pp)) {
1876 refclock_report(instance->peer, CEVNT_BADTIME);
1881 oncore_log(instance, LOG_INFO, Msg); /* this is long message above */
1882 instance->pollcnt = 2;
1884 if (instance->polled) {
1885 instance->polled = 0;
1886 /* instance->pp->dispersion = instance->pp->skew = 0; */
1887 instance->pp->lastref = instance->pp->lastrec;
1888 refclock_receive(instance->peer);
1903 struct instance *instance,
1929 oncore_log(instance, LOG_DEBUG, "%ld.%06ld",
1940 oncore_log(instance, LOG_DEBUG, Msg);
1950 oncore_log(instance, LOG_DEBUG, Msg);
1958 oncore_log(instance, LOG_DEBUG, Msg);
1970 struct instance *instance,
1983 struct instance *instance,
1991 if (instance->o_state == ONCORE_RUN)
1994 instance->Ag = buf[4];
1995 oncore_log_f(instance, LOG_INFO,
1997 (int)instance->Ag);
2008 struct instance *instance,
2013 instance->ss_lat = buf_w32(&buf[4]);
2014 instance->ss_long = buf_w32(&buf[8]);
2015 instance->ss_ht = buf_w32(&buf[12]);
2018 oncore_print_posn(instance);
2030 struct instance *instance,
2035 instance->saw_At = 1;
2036 if (instance->site_survey == ONCORE_SS_TESTING) {
2038 oncore_log(instance, LOG_NOTICE,
2041 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_HW");
2042 instance->site_survey = ONCORE_SS_HW;
2056 struct instance *instance,
2061 if (instance->saw_Ay)
2064 instance->saw_Ay = 1;
2066 instance->offset = buf_w32(&buf[4]);
2068 oncore_log_f(instance, LOG_INFO, "PPS Offset is set to %ld ns",
2069 instance->offset);
2080 struct instance *instance,
2085 if (instance->saw_Az)
2088 instance->saw_Az = 1;
2090 instance->delay = buf_w32(&buf[4]);
2092 oncore_log_f(instance, LOG_INFO, "Cable delay is set to %ld ns",
2093 instance->delay);
2102 struct instance *instance,
2119 if (instance->o_state == ONCORE_CHECK_CHAN) { /* here while checking for the # chan */
2121 if (instance->chan_ck < 6) instance->chan_ck = 6;
2123 if (instance->chan_ck < 8) instance->chan_ck = 8;
2125 if (instance->chan_ck < 12) instance->chan_ck = 12;
2128 if (instance->count3++ < 5)
2131 instance->count3 = 0;
2133 if (instance->chan_in != -1) /* set in Input */
2134 instance->chan = instance->chan_in;
2136 instance->chan = instance->chan_ck;
2138 oncore_log_f(instance, LOG_INFO, "Input says chan = %d",
2139 instance->chan_in);
2140 oncore_log_f(instance, LOG_INFO, "Model # says chan = %d",
2141 instance->chan_id);
2142 oncore_log_f(instance, LOG_INFO, "Testing says chan = %d",
2143 instance->chan_ck);
2144 oncore_log_f(instance, LOG_INFO, "Using chan = %d",
2145 instance->chan);
2147 instance->o_state = ONCORE_HAVE_CHAN;
2148 oncore_log(instance, LOG_NOTICE, "state = ONCORE_HAVE_CHAN");
2150 instance->timeout = 4;
2151 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2155 if (instance->o_state != ONCORE_ALMANAC && instance->o_state != ONCORE_RUN)
2160 if (instance->count) {
2161 if (instance->count++ < 5)
2163 instance->count = 0;
2166 memcpy(instance->BEHa, buf, (size_t) (len+3)); /* Ba, Ea or Ha */
2170 if (instance->pps_control_msg_seen != -2) {
2171 if ((instance->pps_control_msg_seen == -1) && (instance->pps_control != -1)) {
2172 oncore_log(instance, LOG_INFO, "PPSCONTROL set, but not implemented (not M12)");
2174 instance->pps_control_msg_seen = -2;
2179 oncore_check_almanac(instance);
2180 oncore_check_antenna(instance);
2185 if (instance->o_state == ONCORE_ALMANAC)
2186 if (oncore_wait_almanac(instance))
2191 if (instance->once) {
2192 instance->once = 0;
2193 instance->count2 = 1;
2198 if (instance->chan != 12 && !instance->saw_At) {
2199 oncore_log(instance, LOG_NOTICE,
2201 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
2209 mode = instance->init_type;
2214 instance->site_survey = ONCORE_SS_DONE;
2215 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
2220 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_TESTING");
2221 instance->site_survey = ONCORE_SS_TESTING;
2222 instance->count1 = 1;
2223 if (instance->chan == 12)
2224 oncore_sendmsg(instance, oncore_cmd_Gd3, sizeof(oncore_cmd_Gd3)); /* M12+T */
2226 oncore_sendmsg(instance, oncore_cmd_At2, sizeof(oncore_cmd_At2)); /* not GT, arg not VP */
2233 oncore_sendmsg(instance, oncore_cmd_Ayx, sizeof(oncore_cmd_Ayx));
2237 oncore_sendmsg(instance, oncore_cmd_Azx, sizeof(oncore_cmd_Azx));
2241 oncore_sendmsg(instance, oncore_cmd_Agx, sizeof(oncore_cmd_Agx));
2252 if (instance->site_survey == ONCORE_SS_TESTING) {
2253 if (instance->chan == 12) {
2254 if (instance->count1) {
2255 if (instance->count1++ > 5 || instance->BEHa[130]&0x10) {
2256 instance->count1 = 0;
2257 if (instance->BEHa[130]&0x10) {
2258 oncore_log(instance, LOG_NOTICE,
2261 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_HW");
2262 instance->site_survey = ONCORE_SS_HW;
2264 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_SW");
2265 instance->site_survey = ONCORE_SS_SW;
2270 if (instance->count1) {
2271 if (instance->count1++ > 5) {
2272 instance->count1 = 0;
2274 * For instance->site_survey to still be ONCORE_SS_TESTING, then after a 5sec
2291 oncore_log_f(instance, LOG_INFO,
2295 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_SW");
2296 instance->site_survey = ONCORE_SS_SW;
2298 instance->ss_lat = instance->ss_long = instance->ss_ht = 0;
2299 if (instance->chan == 12)
2300 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* disable */
2302 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* disable */
2303 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* disable */
2312 if (instance->chan == 6) {
2313 if (instance->BEHa[64]&0x8)
2314 instance->mode = MODE_0D;
2315 else if (instance->BEHa[64]&0x10)
2316 instance->mode = MODE_2D;
2317 else if (instance->BEHa[64]&0x20)
2318 instance->mode = MODE_3D;
2319 } else if (instance->chan == 8) {
2320 if (instance->BEHa[72]&0x8)
2321 instance->mode = MODE_0D;
2322 else if (instance->BEHa[72]&0x10)
2323 instance->mode = MODE_2D;
2324 else if (instance->BEHa[72]&0x20)
2325 instance->mode = MODE_3D;
2326 } else if (instance->chan == 12) {
2329 bits = (instance->BEHa[129]>>5) & 0x7; /* actually Ha */
2331 instance->mode = MODE_0D;
2333 instance->mode = MODE_2D;
2335 instance->mode = MODE_3D;
2340 if (instance->shmem) {
2344 switch(instance->chan) {
2345 case 6: smp = &instance->shmem[instance->shmem_Ba]; break;
2346 case 8: smp = &instance->shmem[instance->shmem_Ea]; break;
2347 case 12: smp = &instance->shmem[instance->shmem_Ha]; break;
2351 switch (instance->mode) {
2370 if (instance->traim_delay) {
2371 if (instance->traim_delay++ > 5) {
2372 instance->traim = 0;
2373 instance->traim_delay = 0;
2375 oncore_log(instance, LOG_INFO, cp);
2377 oncore_set_traim(instance);
2385 if (!instance->have_dH && !instance->traim_delay)
2386 oncore_compute_dH(instance);
2393 instance->pp->year = buf[6]*256+buf[7];
2394 instance->pp->day = ymd2yd(buf[6]*256+buf[7], buf[4], buf[5]);
2395 instance->pp->hour = buf[8];
2396 instance->pp->minute = buf[9];
2397 instance->pp->second = buf[10];
2403 if (instance->site_survey == ONCORE_SS_HW || instance->site_survey == ONCORE_SS_SW)
2404 oncore_ss(instance);
2408 if (instance->count2) {
2409 if (instance->count2++ > 5) { /* this delay to check on @@Ay command */
2410 instance->count2 = 0;
2415 if (!instance->saw_Ay && instance->offset) {
2416 oncore_log(instance, LOG_INFO, "No @@Ay command, PPS OFFSET ignored");
2417 instance->offset = 0;
2426 oncore_check_leap_sec(instance);
2432 if (instance->shmem && !instance->shmem_bad_Ea && instance->shmem_Posn && (instance->site_survey == ONCORE_SS_DONE))
2433 oncore_shmem_get_3D(instance);
2435 if (!instance->traim) /* NO traim, no BnEnHn, go get tick */
2436 oncore_get_timestamp(instance, instance->offset, instance->offset);
2445 struct instance *instance,
2450 oncore_log_f(instance, LOG_NOTICE,
2471 struct instance *instance,
2478 instance->saw_Bj = 1;
2482 instance->pp->leap = LEAP_ADDSECOND;
2486 instance->pp->leap = LEAP_DELSECOND;
2491 instance->pp->leap = LEAP_NOWARNING;
2495 oncore_log(instance, LOG_NOTICE, cp);
2502 struct instance *instance,
2522 if ((!instance->Bl.lsf_flg && !instance->Bl.wn_flg) && (subframe == 4 && page == 18 && valid == 10)) {
2523 instance->Bl.dt_ls = buf[32];
2524 instance->Bl.WN_lsf = buf[33];
2525 instance->Bl.DN_lsf = buf[34];
2526 instance->Bl.dt_lsf = buf[35];
2527 instance->Bl.lsf_flg++;
2529 if ((instance->Bl.lsf_flg && !instance->Bl.wn_flg) && (subframe == 1 && valid == 10)) {
2531 instance->Bl.WN = i >> 6;
2536 instance->Bl.DN = tow/57600L + 1;
2537 instance->Bl.wn_flg++;
2539 if (instance->Bl.wn_flg && instance->Bl.lsf_flg) {
2540 instance->Bl.wn_flg = instance->Bl.lsf_flg = 0;
2542 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof oncore_cmd_Bl);
2545 i = instance->Bl.WN&01400;
2546 instance->Bl.WN_lsf |= i;
2550 i = (instance->Bl.WN_lsf - instance->Bl.WN);
2553 day_now = instance->Bl.DN;
2554 day_lsf = 7*i + instance->Bl.DN_lsf;
2561 if (day_lsf - day_now < 28 || instance->BEHa[5] < 20) {
2562 i = instance->Bl.dt_lsf - instance->Bl.dt_ls;
2580 instance->peer->leap = LEAP_NOWARNING;
2584 instance->peer->leap = LEAP_DELSECOND;
2588 instance->peer->leap = LEAP_ADDSECOND;
2595 oncore_log(instance, LOG_NOTICE, cp);
2597 i = instance->Bl.dt_lsf-instance->Bl.dt_ls;
2600 oncore_log_f(instance, LOG_NOTICE,
2612 oncore_log_f(instance, LOG_DEBUG,
2614 instance->Bl.dt_ls, instance->Bl.dt_lsf,
2615 instance->Bl.WN, instance->Bl.DN,
2616 instance->Bl.WN_lsf, instance->Bl.DN_lsf,
2617 instance->Bl.wn_flg, instance->Bl.lsf_flg,
2618 instance->Bl.Bl_day);
2625 struct instance *instance,
2632 if (instance->o_state != ONCORE_RUN)
2635 if (instance->traim_delay) { /* flag that @@Bn/@@En/Hn returned */
2636 instance->traim_ck = 1;
2637 instance->traim_delay = 0;
2638 oncore_log(instance, LOG_NOTICE, "ONCORE: Detected TRAIM, TRAIM = ON");
2640 oncore_set_traim(instance);
2643 memcpy(instance->BEHn, buf, (size_t) len); /* Bn or En or Hn */
2645 if (!instance->traim) /* BnEnHn will be turned off in any case */
2651 if (instance->BEHn[6]) { /* bad TRAIM */
2652 oncore_log(instance, LOG_WARNING, "BAD TRAIM");
2656 dt1 = instance->saw_tooth + instance->offset; /* dt this time step */
2657 instance->saw_tooth = (s_char) instance->BEHn[14]; /* update for next time Hn[14] */
2658 dt2 = instance->saw_tooth + instance->offset; /* dt next time step */
2660 if (instance->BEHn[21]) /* bad TRAIM */
2663 dt1 = instance->saw_tooth + instance->offset; /* dt this time step */
2664 instance->saw_tooth = (s_char) instance->BEHn[25]; /* update for next time Bn[25], En[25] */
2665 dt2 = instance->saw_tooth + instance->offset; /* dt next time step */
2668 oncore_get_timestamp(instance, dt1, dt2);
2691 struct instance *instance,
2698 if (instance->o_state == ONCORE_TEST_SENT) {
2701 instance->timeout = 0;
2706 oncore_log_f(instance, LOG_DEBUG,
2710 oncore_log_f(instance, LOG_DEBUG,
2723 oncore_log_f(instance, LOG_ERR,
2727 oncore_log_f(instance, LOG_ERR,
2731 oncore_log(instance, LOG_ERR,
2734 refclock_report(instance->peer, CEVNT_FAULT);
2735 oncore_shutdown(instance->unit, instance->peer);
2741 oncore_antenna_report(instance, antenna);
2743 instance->o_state = ONCORE_INIT;
2744 oncore_log(instance, LOG_NOTICE, "state = ONCORE_INIT");
2746 instance->timeout = 4;
2747 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2759 struct instance *instance,
2766 if (instance->shmem == NULL)
2778 oncore_log(instance, LOG_NOTICE, "Cb: Response is NO ALMANAC");
2783 instance->shmem[instance->shmem_Cb + i + 2]++;
2784 memcpy(instance->shmem + instance->shmem_Cb + i + 3, buf, (size_t) (len + 3));
2787 oncore_log_f(instance, LOG_DEBUG, "See Cb [%d,%d]", buf[4],
2801 struct instance *instance,
2806 if (instance->o_state == ONCORE_RESET_SENT) {
2807 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Return to Posn Fix mode */
2809 instance->o_state = ONCORE_TEST_SENT;
2810 oncore_log(instance, LOG_NOTICE, "state = ONCORE_TEST_SENT");
2812 oncore_sendmsg(instance, oncore_cmd_Cj, sizeof(oncore_cmd_Cj));
2835 struct instance *instance,
2842 memcpy(instance->Cj, buf, len);
2844 instance->timeout = 0;
2845 if (instance->o_state == ONCORE_CHECK_ID) {
2846 oncore_msg_Cj_id(instance, buf, len);
2847 oncore_chan_test(instance);
2848 } else if (instance->o_state == ONCORE_HAVE_CHAN) {
2849 mode = instance->init_type;
2851 instance->o_state = ONCORE_RESET_SENT;
2852 oncore_log(instance, LOG_NOTICE, "state = ONCORE_RESET_SENT");
2853 oncore_sendmsg(instance, oncore_cmd_Cf, sizeof(oncore_cmd_Cf));
2855 instance->o_state = ONCORE_TEST_SENT;
2856 oncore_log(instance, LOG_NOTICE, "state = ONCORE_TEST_SENT");
2860 if (instance->o_state == ONCORE_TEST_SENT) {
2861 if (instance->chan == 6)
2862 oncore_sendmsg(instance, oncore_cmd_Ca, sizeof(oncore_cmd_Ca));
2863 else if (instance->chan == 8)
2864 oncore_sendmsg(instance, oncore_cmd_Fa, sizeof(oncore_cmd_Fa));
2865 else if (instance->chan == 12)
2866 oncore_sendmsg(instance, oncore_cmd_Ia, sizeof(oncore_cmd_Ia));
2867 } else if (instance->o_state == ONCORE_INIT)
2868 oncore_msg_Cj_init(instance, buf, len);
2887 struct instance *instance,
2897 instance->Cj[294] = '\0';
2898 for (cp= (char *)instance->Cj; cp< (char *) &instance->Cj[294]; ) {
2901 cpw = (char *)&instance->Cj[294];
2903 oncore_log(instance, LOG_NOTICE, cp);
2910 instance->version = atoi((char *) &instance->Cj[83]);
2911 instance->revision = atoi((char *) &instance->Cj[111]);
2916 for (cp= (char *) &instance->Cj[160]; *cp == ' '; cp++) /* start right after 'Model #' */
2927 instance->model = ONCORE_PVT6;
2930 instance->model = ONCORE_BASIC;
2933 instance->model = ONCORE_VP;
2936 instance->model = ONCORE_M12;
2940 instance->model = ONCORE_GT;
2943 instance->model = ONCORE_GTPLUS;
2946 instance->model = ONCORE_UT;
2949 instance->model = ONCORE_UTPLUS;
2952 instance->model = ONCORE_SL;
2955 instance->model = ONCORE_UNKNOWN;
2959 instance->model = ONCORE_UNKNOWN;
2964 oncore_log_f(instance, LOG_INFO,
2966 cp, instance->version, instance->revision);
2968 instance->chan_id = 8; /* default */
2969 if (instance->model == ONCORE_BASIC || instance->model == ONCORE_PVT6)
2970 instance->chan_id = 6;
2971 else if (instance->model == ONCORE_VP || instance->model == ONCORE_UT || instance->model == ONCORE_UTPLUS)
2972 instance->chan_id = 8;
2973 else if (instance->model == ONCORE_M12)
2974 instance->chan_id = 12;
2976 instance->traim_id = 0; /* default */
2977 if (instance->model == ONCORE_BASIC || instance->model == ONCORE_PVT6)
2978 instance->traim_id = 0;
2979 else if (instance->model == ONCORE_VP || instance->model == ONCORE_UT || instance->model == ONCORE_UTPLUS)
2980 instance->traim_id = 1;
2981 else if (instance->model == ONCORE_M12)
2982 instance->traim_id = -1;
2984 oncore_log_f(instance, LOG_INFO, "Channels = %d, TRAIM = %s",
2985 instance->chan_id,
2986 ((instance->traim_id < 0)
2988 : (instance->traim_id > 0)
3003 struct instance *instance,
3018 if (instance->chan == 12) {
3019 instance->shmem_bad_Ea = 1;
3020 oncore_log_f(instance, LOG_NOTICE,
3022 instance->version, instance->revision);
3025 oncore_sendmsg(instance, oncore_cmd_Cg, sizeof(oncore_cmd_Cg)); /* Return to Posn Fix mode */
3026 oncore_sendmsg(instance, oncore_cmd_Bb, sizeof(oncore_cmd_Bb)); /* turn on for shmem (6/8/12) */
3027 oncore_sendmsg(instance, oncore_cmd_Ek, sizeof(oncore_cmd_Ek)); /* turn off (VP) */
3028 oncore_sendmsg(instance, oncore_cmd_Aw, sizeof(oncore_cmd_Aw)); /* UTC time (6/8/12) */
3029 oncore_sendmsg(instance, oncore_cmd_AB, sizeof(oncore_cmd_AB)); /* Appl type static (VP) */
3030 oncore_sendmsg(instance, oncore_cmd_Be, sizeof(oncore_cmd_Be)); /* Tell us the Almanac for shmem (6/8/12) */
3031 oncore_sendmsg(instance, oncore_cmd_Bd, sizeof(oncore_cmd_Bd)); /* Tell us when Almanac changes */
3033 mode = instance->init_type;
3040 if (instance->posn_set) {
3041 oncore_log(instance, LOG_INFO, "Setting Posn from input data");
3042 oncore_set_posn(instance); /* this should print posn indirectly thru the As cmd */
3044 if (instance->chan != 12)
3045 oncore_sendmsg(instance, oncore_cmd_Atx, sizeof(oncore_cmd_Atx));
3050 w32_buf(&Cmd[-2+4], (int)instance->delay);
3051 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Az)); /* 6,8,12 */
3055 w32_buf(&Cmd[-2+4], instance->offset); /* will check for hw response */
3056 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ay));
3060 if (instance->Ag != 0xff) { /* will have 0xff in it if not set by user */
3062 Cmd[-2+4] = instance->Ag;
3063 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ag));
3074 if (instance->chan == 6) { /* start 6chan, kill 8,12chan commands, possibly testing VP in 6chan mode */
3075 oncore_sendmsg(instance, oncore_cmd_Ea0, sizeof(oncore_cmd_Ea0));
3076 oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
3077 oncore_sendmsg(instance, oncore_cmd_Ha0, sizeof(oncore_cmd_Ha0));
3078 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3079 oncore_sendmsg(instance, oncore_cmd_Ba, sizeof(oncore_cmd_Ba ));
3080 } else if (instance->chan == 8) { /* start 8chan, kill 6,12chan commands */
3081 oncore_sendmsg(instance, oncore_cmd_Ba0, sizeof(oncore_cmd_Ba0));
3082 oncore_sendmsg(instance, oncore_cmd_Bn0, sizeof(oncore_cmd_Bn0));
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_Ea, sizeof(oncore_cmd_Ea ));
3086 } else if (instance->chan == 12){ /* start 12chan, 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_Ea0, sizeof(oncore_cmd_Ea0));
3090 oncore_sendmsg(instance, oncore_cmd_En0, sizeof(oncore_cmd_En0));
3091 oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha ));
3092 oncore_cmd_Gc[2] = (instance->pps_control < 0) ? 1 : instance->pps_control;
3093 oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* PPS off/continuous/Tracking 1+sat/TRAIM */
3096 instance->count = 1;
3097 instance->o_state = ONCORE_ALMANAC;
3098 oncore_log(instance, LOG_NOTICE, "state = ONCORE_ALMANAC");
3107 struct instance *instance,
3128 oncore_log_f(instance, LOG_NOTICE,
3132 instance->ss_lat = lat;
3133 instance->ss_long = lon;
3134 instance->ss_ht = ht;
3136 oncore_print_posn(instance);
3145 struct instance *instance,
3165 oncore_log_f(instance, LOG_NOTICE,
3176 struct instance *instance,
3183 instance->pps_control_msg_seen = 1;
3184 oncore_log_f(instance, LOG_INFO, "PPS Control set to %s",
3195 struct instance *instance,
3208 instance->saw_Gj = 1; /* flag, saw_Gj, dont need to try Bj in check_leap */
3214 oncore_log_f(instance, LOG_INFO,
3235 oncore_log_f(instance, LOG_NOTICE,
3243 instance->pp->leap = LEAP_NOWARNING;
3246 if (buf[6] == instance->BEHa[6] && buf[7] == instance->BEHa[7] && /* year */
3247 buf[8] == instance->BEHa[4]) { /* month */
3250 instance->pp->leap = LEAP_DELSECOND;
3253 instance->pp->leap = LEAP_ADDSECOND;
3258 oncore_log(instance, LOG_INFO, cp);
3267 struct instance *instance,
3272 if (instance && instance->peer) {
3273 oncore_log(instance, LOG_ERR, "Oncore: System Failure at Power On");
3274 oncore_shutdown(instance->unit, instance->peer);
3283 struct instance *instance,
3288 if (instance->ant_state == new_state)
3299 instance->ant_state = new_state;
3300 oncore_log(instance, LOG_NOTICE, cp);
3307 struct instance *instance
3319 instance->o_state = ONCORE_CHECK_CHAN;
3320 oncore_log(instance, LOG_NOTICE, "state = ONCORE_CHECK_CHAN");
3322 instance->count3 = 1;
3323 oncore_sendmsg(instance, oncore_cmd_Ba, sizeof(oncore_cmd_Ba));
3324 oncore_sendmsg(instance, oncore_cmd_Ea, sizeof(oncore_cmd_Ea));
3325 oncore_sendmsg(instance, oncore_cmd_Ha, sizeof(oncore_cmd_Ha));
3334 struct instance *instance
3337 if (instance->chan == 6) {
3338 instance->rsm.bad_almanac = instance->BEHa[64]&0x1;
3339 instance->rsm.bad_fix = instance->BEHa[64]&0x52;
3340 } else if (instance->chan == 8) {
3341 instance->rsm.bad_almanac = instance->BEHa[72]&0x1;
3342 instance->rsm.bad_fix = instance->BEHa[72]&0x52;
3343 } else if (instance->chan == 12) {
3346 bits1 = (instance->BEHa[129]>>5) & 0x7; /* actually Ha */
3347 bits2 = instance->BEHa[130];
3348 instance->rsm.bad_almanac = (bits2 & 0x80);
3349 instance->rsm.bad_fix = (bits2 & 0x8) || (bits1 == 0x2);
3352 bits3 = instance->BEHa[141]; /* UTC parameters */
3353 if (!instance->count5_set && (bits3 & 0xC0)) {
3354 instance->count5 = 4; /* was 2 [Bug 1766] */
3355 instance->count5_set = 1;
3358 oncore_log_f(instance, LOG_DEBUG,
3360 instance->BEHa[129], instance->BEHa[130],
3362 instance->mode == MODE_0D,
3363 instance->mode == MODE_2D,
3364 instance->mode == MODE_3D,
3365 instance->rsm.bad_almanac,
3366 instance->rsm.bad_fix);
3378 struct instance *instance
3383 if (instance->chan == 12)
3384 antenna = (instance->BEHa[130] & 0x6 ) >> 1;
3386 antenna = (instance->BEHa[37] & 0xc0) >> 6; /* prob unset 6, set GT, UT unset VP */
3388 oncore_antenna_report (instance, antenna);
3418 struct instance *instance
3422 if (instance->Bj_day != instance->BEHa[5]) { /* do this 1/day */
3423 instance->Bj_day = instance->BEHa[5];
3425 if (instance->saw_Gj < 0) { /* -1 DONT have Gj use Bj */
3426 if ((instance->BEHa[4] == 6) || (instance->BEHa[4] == 12))
3427 oncore_sendmsg(instance, oncore_cmd_Bj, sizeof(oncore_cmd_Bj));
3428 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof(oncore_cmd_Bl));
3432 if (instance->saw_Gj == 0) /* 0 is dont know if we have Gj */
3433 instance->count4 = 1;
3435 oncore_sendmsg(instance, oncore_cmd_Gj, sizeof(oncore_cmd_Gj));
3443 if (instance->count4) { /* delay, waiting for Gj response */
3444 if (instance->saw_Gj == 1)
3445 instance->count4 = 0;
3446 else if (instance->count4++ > 5) { /* delay, waiting for Gj response */
3447 instance->saw_Gj = -1; /* didnt see it, will use Bj */
3448 instance->count4 = 0;
3449 if ((instance->BEHa[4] == 6) || (instance->BEHa[4] == 12)) {
3450 oncore_sendmsg(instance, oncore_cmd_Bj, sizeof(oncore_cmd_Bj));
3451 oncore_sendmsg(instance, oncore_cmd_Bl, sizeof(oncore_cmd_Bl));
3483 struct instance *instance
3491 instance->have_dH = 1;
3492 if (instance->chan == 12) {
3493 GPS = buf_w32(&instance->BEHa[39]);
3494 MSL = buf_w32(&instance->BEHa[43]);
3496 GPS = buf_w32(&instance->BEHa[23]);
3497 MSL = buf_w32(&instance->BEHa[27]);
3499 instance->dH = GPS - MSL;
3500 instance->dH /= 100.;
3505 oncore_log_f(instance, LOG_INFO,
3506 "dH = (GPS - MSL) = %.2fm", instance->dH);
3517 struct instance *instance
3525 if (!instance->shmem)
3529 for (cp = instance->shmem + 4; (n = 256 * (*(cp-3)) + *(cp-2));
3534 write(instance->ttyfd, cp, n);
3535 oncore_print_Cb(instance, cp);
3539 for (cp = instance->shmem + 4; (n = 256 * (*(cp-3)) + *(cp-2));
3541 oncore_log_f(instance, LOG_DEBUG, "See %c%c%c%c %d",
3545 oncore_print_Cb(instance, cp);
3548 oncore_log(instance, LOG_DEBUG, "GOOD SF");
3549 write(instance->ttyfd, cp, n);
3551 oncore_log(instance, LOG_DEBUG, "BAD SF");
3553 oncore_log(instance, LOG_DEBUG, "BAD CHECKSUM");
3560 if (!instance->posn_set) { /* if we input a posn use it, else from SHMEM */
3561 oncore_log(instance, LOG_NOTICE, "Loading Posn from SHMEM");
3562 for (cp=instance->shmem+4; (n = 256*(*(cp-3)) + *(cp-2)); cp+=(n+3)) {
3563 if ((instance->chan == 6 && (!strncmp((char *) cp, "@@Ba", 4) && oncore_checksum_ok(cp, 68))) ||
3564 (instance->chan == 8 && (!strncmp((char *) cp, "@@Ea", 4) && oncore_checksum_ok(cp, 76))) ||
3565 (instance->chan == 12 && (!strncmp((char *) cp, "@@Ha", 4) && oncore_checksum_ok(cp, 154)))) {
3568 instance->posn_set = 1;
3573 oncore_log_f(instance, LOG_DEBUG,
3575 (long)(cp-instance->shmem),
3579 instance->ss_lat = ii;
3580 instance->ss_long = jj;
3581 instance->ss_ht = kk;
3586 oncore_set_posn(instance);
3594 oncore_log_f(instance, LOG_DEBUG, "DATE %d %d %d, %d %d %d",
3598 if (instance->chan == 12) {
3610 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Gb));
3614 oncore_sendmsg(instance, oncore_cmd_Ab, sizeof(oncore_cmd_Ab));
3621 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ac));
3627 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Aa));
3630 oncore_log(instance, LOG_INFO, "Setting Posn and Time after Loading Almanac");
3639 struct instance *instance,
3647 oncore_log_f(instance, LOG_DEBUG, "DEBUG: See: %c%c%c%c", *(cp),
3656 oncore_log(instance, LOG_DEBUG, Msg);
3658 oncore_log_f(instance, LOG_DEBUG, "Debug: Cb: [%d,%d]", *(cp+4),
3689 struct instance *instance
3697 oncore_log(instance, LOG_INFO, "Posn:");
3699 lon = instance->ss_long;
3706 lat = instance->ss_lat;
3712 hm = instance->ss_ht/100.;
3717 oncore_log_f(instance, LOG_INFO,
3727 oncore_log_f(instance, LOG_INFO,
3737 oncore_log_f(instance, LOG_INFO,
3750 struct instance *instance,
3758 fd = instance->ttyfd;
3761 oncore_log_f(instance, LOG_DEBUG, "ONCORE: Send @@%c%c %d",
3777 struct instance *instance
3786 if (instance->chan == 12)
3787 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* (12) */
3789 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0)); /* (6/8) */
3790 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0)); /* (6/8) */
3793 mode = instance->init_type;
3797 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3798 w32_buf(&Cmd[-2+8], (int) instance->ss_long);
3799 w32_buf(&Cmd[-2+12], (int) instance->ss_ht);
3801 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_As)); /* posn hold 3D posn (6/8/12) */
3804 w32_buf(&Cmd[-2+4], (int) instance->ss_ht);
3806 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Au)); /* altitude hold (6/8/12 not UT, M12T) */
3810 if (instance->chan == 12) {
3812 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3813 w32_buf(&Cmd[-2+8], (int) instance->ss_long);
3814 w32_buf(&Cmd[-2+12],(int) instance->ss_ht);
3816 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ga)); /* 3d posn (12) */
3819 w32_buf(&Cmd[-2+4], (int) instance->ss_lat);
3820 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ad)); /* lat (6/8) */
3823 w32_buf(&Cmd[-2+4], (int) instance->ss_long);
3824 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Ae)); /* long (6/8) */
3827 w32_buf(&Cmd[-2+4], (int) instance->ss_ht);
3829 oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Af)); /* ht (6/8) */
3834 if (instance->chan == 12)
3835 oncore_sendmsg(instance, oncore_cmd_Gd1, sizeof(oncore_cmd_Gd1));
3837 oncore_sendmsg(instance, oncore_cmd_At1, sizeof(oncore_cmd_At1));
3845 struct instance *instance
3848 if (instance->traim_in != -1) /* set in Input */
3849 instance->traim = instance->traim_in;
3851 instance->traim = instance->traim_ck;
3853 oncore_log_f(instance, LOG_INFO, "Input says TRAIM = %d",
3854 instance->traim_in);
3855 oncore_log_f(instance, LOG_INFO, "Model # says TRAIM = %d",
3856 instance->traim_id);
3857 oncore_log_f(instance, LOG_INFO, "Testing says TRAIM = %d",
3858 instance->traim_ck);
3859 oncore_log_f(instance, LOG_INFO, "Using TRAIM = %d",
3860 instance->traim);
3862 if (instance->traim_ck == 1 && instance->traim == 0) {
3865 if (instance->chan == 6)
3866 oncore_sendmsg(instance, oncore_cmd_Bnx, sizeof(oncore_cmd_Bnx));
3867 else if (instance->chan == 8)
3868 oncore_sendmsg(instance, oncore_cmd_Enx, sizeof(oncore_cmd_Enx));
3870 oncore_sendmsg(instance, oncore_cmd_Ge0, sizeof(oncore_cmd_Ge0));
3871 oncore_sendmsg(instance, oncore_cmd_Hn0, sizeof(oncore_cmd_Hn0));
3883 struct instance *instance
3886 if (instance->pp->second%15 == 3) { /* start the sequence */ /* by changing mode */
3887 instance->shmem_reset = 1;
3888 if (instance->chan == 12) {
3889 if (instance->shmem_Posn == 2)
3890 oncore_sendmsg(instance, oncore_cmd_Gd2, sizeof(oncore_cmd_Gd2)); /* 2D */
3892 oncore_sendmsg(instance, oncore_cmd_Gd0, sizeof(oncore_cmd_Gd0)); /* 3D */
3894 if (instance->saw_At) { /* out of 0D -> 3D mode */
3895 oncore_sendmsg(instance, oncore_cmd_At0, sizeof(oncore_cmd_At0));
3896 if (instance->shmem_Posn == 2) /* 3D -> 2D mode */
3897 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
3899 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0));
3901 } else if (instance->shmem_reset || (instance->mode != MODE_0D)) {
3902 instance->shmem_reset = 0;
3903 if (instance->chan == 12)
3904 oncore_sendmsg(instance, oncore_cmd_Gd1, sizeof(oncore_cmd_Gd1)); /* 0D */
3906 if (instance->saw_At) {
3907 if (instance->mode == MODE_2D) /* 2D -> 3D or 0D mode */
3908 oncore_sendmsg(instance, oncore_cmd_Av0, sizeof(oncore_cmd_Av0));
3909 oncore_sendmsg(instance, oncore_cmd_At1, sizeof(oncore_cmd_At1)); /* to 0D mode */
3911 oncore_sendmsg(instance, oncore_cmd_Av1, sizeof(oncore_cmd_Av1));
3927 struct instance *instance
3933 if (instance->site_survey == ONCORE_SS_HW) {
3938 if ((instance->chan == 8 && !(instance->BEHa[37] & 0x20)) ||
3939 (instance->chan == 12 && !(instance->BEHa[130] & 0x10))) {
3940 oncore_log(instance, LOG_INFO, "Now in 0D mode");
3942 if (instance->chan == 12)
3943 oncore_sendmsg(instance, oncore_cmd_Gax, sizeof(oncore_cmd_Gax));
3945 oncore_sendmsg(instance, oncore_cmd_Asx, sizeof(oncore_cmd_Asx));
3947 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
3948 instance->site_survey = ONCORE_SS_DONE;
3955 if (instance->rsm.bad_fix) /* Not if poor geometry or less than 3 sats */
3958 if (instance->mode != MODE_3D) /* Use only 3D Fixes */
3961 instance->ss_lat += buf_w32(&instance->BEHa[15]);
3962 instance->ss_long += buf_w32(&instance->BEHa[19]);
3963 instance->ss_ht += buf_w32(&instance->BEHa[23]); /* GPS ellipsoid */
3964 instance->ss_count++;
3966 if (instance->ss_count != POS_HOLD_AVERAGE)
3969 instance->ss_lat /= POS_HOLD_AVERAGE;
3970 instance->ss_long /= POS_HOLD_AVERAGE;
3971 instance->ss_ht /= POS_HOLD_AVERAGE;
3973 oncore_log_f(instance, LOG_NOTICE,
3975 instance->ss_lat, instance->ss_long,
3976 instance->ss_ht);
3977 lat = instance->ss_lat/3600000.;
3978 lon = instance->ss_long/3600000.;
3979 ht = instance->ss_ht/100;
3980 oncore_log_f(instance, LOG_NOTICE,
3984 oncore_set_posn(instance);
3986 oncore_log(instance, LOG_INFO, "Now in 0D mode");
3988 oncore_log(instance, LOG_NOTICE, "SSstate = ONCORE_SS_DONE");
3989 instance->site_survey = ONCORE_SS_DONE;
3997 struct instance *instance
4000 if (instance->rsm.bad_almanac) {
4001 instance->counta++;
4002 if (instance->counta%5 == 0)
4003 oncore_log(instance, LOG_INFO, "Waiting for Almanac");
4010 if (!instance->almanac_from_shmem) {
4011 instance->almanac_from_shmem = 1;
4012 oncore_load_almanac(instance);
4019 if (instance->chan == 6)
4020 oncore_sendmsg(instance, oncore_cmd_Bn, sizeof(oncore_cmd_Bn));
4021 else if (instance->chan == 8)
4022 oncore_sendmsg(instance, oncore_cmd_En, sizeof(oncore_cmd_En));
4023 else if (instance->chan == 12) {
4024 oncore_sendmsg(instance, oncore_cmd_Gc, sizeof(oncore_cmd_Gc)); /* 1PPS on, continuous */
4025 oncore_sendmsg(instance, oncore_cmd_Ge, sizeof(oncore_cmd_Ge)); /* TRAIM on */
4026 oncore_sendmsg(instance, oncore_cmd_Hn, sizeof(oncore_cmd_Hn)); /* TRAIM status 1/s */
4028 instance->traim_delay = 1;
4030 oncore_log(instance, LOG_NOTICE, "Have now loaded an ALMANAC");
4032 instance->o_state = ONCORE_RUN;
4033 oncore_log(instance, LOG_NOTICE, "state = ONCORE_RUN");
4042 struct instance *instance,
4047 msyslog(log_level, "ONCORE[%d]: %s", instance->unit, msg);
4048 mprintf_clock_stats(&instance->peer->srcadr, "ONCORE[%d]: %s",
4049 instance->unit, msg);
4055 struct instance * instance,
4068 oncore_log(instance, log_level, msg);
4071 instance->max_len = max(strlen(msg), instance->max_len);
4072 instance->max_count++;
4073 if (instance->max_count % 100 == 0)
4074 oncore_log_f(instance, LOG_INFO,
4076 instance->max_len);