Lines Matching +full:up +full:-

69  * gadget box and 1-PPS level converter, such as described in the
70 * Pulse-per-second (PPS) Signal Interfacing page.
85 #define PRECISION (-18) /* precision assumed (about 4 us) */
94 * since 0000-12-31 to 1980-01-06 in the proleptic Gregorian Calendar.
160 jupiter_start, /* start up driver */
170 * jupiter_start - open the devices and initialize data for processing
178 struct refclockproc * const pp = peer->procptr;
179 struct instance * up;
187 fd = refclock_open(&peer->srcadr, gpsdev, SPEED232, LDISC_RAW);
195 up = emalloc_zero(sizeof(*up));
196 up->peer = peer;
197 pp->io.clock_recv = jupiter_receive;
198 pp->io.srcclock = peer;
199 pp->io.datalen = 0;
200 pp->io.fd = fd;
201 if (!io_addclock(&pp->io)) {
203 pp->io.fd = -1;
204 free(up);
207 pp->unitptr = up;
212 peer->precision = PRECISION;
213 pp->clockdesc = DESCRIPTION;
214 memcpy((char *)&pp->refid, REFID, 4);
216 up->assert = 1;
217 up->hardpps = 0;
222 if (time_pps_create(fd, &up->pps_handle) < 0) {
223 up->pps_handle = 0;
227 else if (!jupiter_ppsapi(up))
231 if (!jupiter_config(up))
234 jupiter_pps(up); /* get current PPS state */
239 pp->unitptr = 0;
244 * jupiter_shutdown - shut down the clock
249 struct refclockproc * const pp = peer->procptr;
250 struct instance * const up = pp->unitptr;
252 if (!up)
255 if (up->pps_handle) {
256 time_pps_destroy(up->pps_handle);
257 up->pps_handle = 0;
260 if (pp->io.fd != -1)
261 io_closeclock(&pp->io);
262 free(up);
266 * jupiter_config - Configure the receiver
269 jupiter_config(struct instance * const up)
271 jupiter_debug(up->peer, __func__, "init receiver");
276 up->sloppyclockflag = up->peer->procptr->sloppyclockflag;
277 up->moving = !!(up->sloppyclockflag & CLK_FLAG2);
278 if (up->moving)
279 jupiter_debug(up->peer, __func__, "mobile platform");
281 ZERO(up->rcv_next);
282 ZERO(up->ref_next);
283 ZERO(up->piv_next);
284 up->ssize = 0;
287 jupiter_canmsg(up, JUPITER_ALL);
290 jupiter_reqonemsg(up, JUPITER_O_ID);
293 up->wantid = 1;
296 jupiter_reqmsg(up, JUPITER_O_PULSE, 1);
299 jupiter_reqmsg(up, JUPITER_O_GPOS, 1);
302 if (up->moving)
303 jupiter_platform(up, JUPITER_I_PLAT_MED);
305 jupiter_platform(up, JUPITER_I_PLAT_LOW);
313 struct instance * const up
319 if (jupiter_pps(up) || !up->piv_next.weeks)
323 delta = up->rcv_pps; /* set by jupiter_pps() */
324 L_SUB(&delta, &up->rcv_next); /* recv time pulse message */
326 up->ref_next.weeks = 0; /* consider as consumed... */
330 pp->lastrec = up->rcv_pps;
331 tstamp = ntpfp_from_gpsdatum(&up->ref_next);
332 refclock_process_offset(pp, tstamp, up->rcv_pps, pp->fudgetime1);
333 up->rcvtout = 2;
335 gpscal_to_calendar(&cd, &up->ref_next);
337 (size_t)-1);
338 up->ref_next.weeks = 0; /* consumed... */
342 * jupiter_ticker - process periodic checks
347 struct refclockproc * const pp = peer->procptr;
348 struct instance * const up = pp->unitptr;
350 if (!up)
354 jupiter_checkpps(pp, up);
357 if (up->piv_hold && !--up->piv_hold)
358 ZERO(up->piv_next);
360 if (up->rcvtout)
361 --up->rcvtout;
362 else if (pp->coderecv != pp->codeproc)
371 struct instance * const up /* unit structure pointer */
376 if (time_pps_getcap(up->pps_handle, &capability) < 0) {
381 memset(&up->pps_params, 0, sizeof(pps_params_t));
382 if (!up->assert)
383 up->pps_params.mode = capability & PPS_CAPTURECLEAR;
385 up->pps_params.mode = capability & PPS_CAPTUREASSERT;
386 if (!(up->pps_params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) {
389 up->assert);
392 up->pps_params.mode |= PPS_TSFMT_TSPEC;
393 if (time_pps_setparams(up->pps_handle, &up->pps_params) < 0) {
398 if (up->hardpps) {
399 if (time_pps_kcbind(up->pps_handle, PPS_KC_HARDPPS,
400 up->pps_params.mode & ~PPS_TSFMT_TSPEC,
408 /* up->peer->precision = PPS_PRECISION; */
412 time_pps_getparams(up->pps_handle, &up->pps_params);
413 jupiter_debug(up->peer, __func__,
415 capability, up->pps_params.api_version,
416 up->pps_params.mode, up->hardpps);
429 jupiter_pps(struct instance * const up)
438 if (up->pps_handle == 0)
442 memcpy(&pps_info, &up->pps_info, sizeof(pps_info_t));
443 if (time_pps_fetch(up->pps_handle, PPS_TSFMT_TSPEC, &up->pps_info,
446 if (up->pps_params.mode & PPS_CAPTUREASSERT) {
448 up->pps_info.assert_sequence)
450 ts = up->pps_info.assert_timestamp;
451 } else if (up->pps_params.mode & PPS_CAPTURECLEAR) {
453 up->pps_info.clear_sequence)
455 ts = up->pps_info.clear_timestamp;
461 if (L_ISEQU(&tstmp, &up->rcv_pps))
464 up->rcv_pps = tstmp;
469 * jupiter_poll - jupiter watchdog routine
474 struct refclockproc * const pp = peer->procptr;
475 struct instance * const up = pp->unitptr;
477 pp->polls++;
483 if (pp->coderecv != pp->codeproc) {
490 jupiter_reqonemsg(up, JUPITER_O_ID);
491 up->wantid = 0;
496 * jupiter_control - fudge control
506 struct refclockproc * const pp = peer->procptr;
507 struct instance * const up = pp->unitptr;
511 up->assert = !(pp->sloppyclockflag & CLK_FLAG3);
512 jupiter_ppsapi(up);
514 sloppyclockflag = up->sloppyclockflag;
515 up->sloppyclockflag = pp->sloppyclockflag;
516 if ((up->sloppyclockflag & CLK_FLAG2) !=
520 jupiter_config(up);
526 * jupiter_receive - receive gps data
532 struct peer * const peer = rbufp->recv_peer;
533 struct refclockproc * const pp = peer->procptr;
534 struct instance * const up = pp->unitptr;
545 bp = (u_char *)rbufp->recv_buffer;
546 bpcnt = rbufp->recv_length;
549 if (bpcnt > sizeof(up->sbuf) - up->ssize)
550 bpcnt = sizeof(up->sbuf) - up->ssize;
553 memcpy((u_char *)up->sbuf + up->ssize, bp, bpcnt);
554 up->ssize += bpcnt;
557 while (up->ssize > (int)sizeof(*hp) && (cc = jupiter_recv(up)) > 0) {
558 hp = (struct jheader *)up->sbuf;
560 size = cc - sizeof(*hp);
561 switch (getshort(hp->id)) {
565 jupiter_checkpps(pp, up);
588 if ((cp = jupiter_parse_t(up, sp, rbufp->recv_time)) != NULL) {
603 if ((cp = jupiter_parse_gpos(up, sp)) != NULL) {
625 ip->chans, ip->vers, ip->date, ip->opts);
628 ip->chans, ip->vers, ip->date, ip->opts);
629 if (up->wantid)
630 up->wantid = 0;
633 jupiter_config(up);
638 up->ssize = cc;
644 getshort(hp->id));
647 up->ssize -= cc;
648 if (up->ssize < 0) {
651 } else if (up->ssize > 0)
652 memcpy(up->sbuf, (u_char *)up->sbuf + cc, up->ssize);
658 struct instance * const up,
669 flags = getshort(jp->flags);
675 refclock_report(up->peer, CEVNT_BADTIME);
679 up->rcv_next = rcvtime; /* remember when this happened */
682 sweek = DS2UI(jp->sweek) % WEEKSECS;
686 tofs.tv_sec = getshort(jp->offs);
687 tofs.tv_nsec = DS2I(jp->offns);
709 if (up->piv_next.weeks) {
710 up->ref_next = gpscal_from_weektime2(
711 sweek, fofs, &up->piv_next);
712 up->piv_next = up->ref_next;
714 up->ref_next = gpscal_from_weektime1(
725 struct instance * const up,
738 if (jg->navval != 0) {
746 raw_week = getshort(jg->gweek);
747 raw_secs = DS2UI(jg->sweek);
749 tofs.tv_nsec = DS2UI(jg->nsweek);
750 up->piv_next = gpscal_from_gpsweek(raw_week, raw_secs,
752 up->piv_hold = 60;
754 gpscal_to_calendar(&tref, &up->piv_next);
756 jupiter_debug(up->peer, __func__,
763 * jupiter_debug - print debug messages
782 record_clock_stats(&peer->srcadr, buffer);
796 struct instance * const up,
806 hp->hsum = putshort(jupiter_cksum((u_short *)hp,
807 (size / sizeof(u_short)) - 1));
808 len = getshort(hp->len);
815 if ((cc = write(up->peer->procptr->io.fd, (char *)hp, size)) < 0) {
831 putshort((sizeof(struct jrequest) / sizeof(u_short)) - 1),
840 struct instance * const up,
850 hp->id = putshort(id);
852 rp->trigger = putshort(interval == 0);
853 rp->interval = putshort(interval);
854 if ((cp = jupiter_send(up, hp)) != NULL)
855 jupiter_debug(up->peer, __func__, "%u: %s", id, cp);
867 struct instance * const up,
875 hp->id = putshort(id);
876 if ((cp = jupiter_send(up, hp)) != NULL)
877 jupiter_debug(up->peer, __func__, "%u: %s", id, cp);
889 struct instance * const up,
897 hp->id = putshort(id);
898 if ((cp = jupiter_send(up, hp)) != NULL)
899 jupiter_debug(up->peer, __func__, "%u: %s", id, cp);
908 putshort((sizeof(struct jplat) / sizeof(u_short)) - 1), 0,
915 struct instance * const up,
925 pp->platform = putshort(platform);
926 if ((cp = jupiter_send(up, hp)) != NULL)
927 jupiter_debug(up->peer, __func__, "%u: %s", platform, cp);
937 while (len-- > 0) {
947 struct instance * const up
957 size = up->ssize;
962 sp = up->sbuf;
964 if (getshort(hp->sync) != JUPITER_SYNC) {
965 /* Wasn't at the front, sync up */
966 jupiter_debug(up->peer, __func__, "syncing");
972 jupiter_debug(up->peer, __func__,
976 --n;
982 jupiter_debug(up->peer, __func__,
986 n -= 2;
989 jupiter_debug(up->peer, __func__, "\n");
995 up->ssize = size;
996 if (size < cc || hp->sync != JUPITER_SYNC)
1000 if (jupiter_cksum(sp, (cc / sizeof(u_short) - 1)) !=
1001 getshort(hp->hsum)) {
1002 jupiter_debug(up->peer, __func__, "bad header checksum!");
1004 up->ssize = 0;
1009 len = getshort(hp->len);
1019 jupiter_debug(up->peer,
1022 up->ssize = 0;