Lines Matching +full:pulse +full:- +full:code
8 * 1. Redistributions of source code must retain the above copyright
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.
170 * jupiter_start - open the devices and initialize data for processing
178 struct refclockproc * const pp = peer->procptr;
187 fd = refclock_open(&peer->srcadr, gpsdev, SPEED232, LDISC_RAW);
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;
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;
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;
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);
266 * jupiter_config - Configure the receiver
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;
293 up->wantid = 1;
295 /* Request perodic time mark pulse messages */
302 if (up->moving)
319 if (jupiter_pps(up) || !up->piv_next.weeks)
322 /* check delay between pulse message and pulse. */
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;
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)
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);
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) {
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);
514 sloppyclockflag = up->sloppyclockflag;
515 up->sloppyclockflag = pp->sloppyclockflag;
516 if ((up->sloppyclockflag & CLK_FLAG2) !=
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)) {
569 "pulse: len %d != %u",
578 * the pulse message; in addition to the one per
579 * second messages, we get an extra pulse
585 * pulse is found we can simply ignore that and
588 if ((cp = jupiter_parse_t(up, sp, rbufp->recv_time)) != NULL) {
590 "pulse: %s", cp);
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;
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);
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);
697 * important value in the pulse message).
700 * or chan if we can. Of course, the PULSE message can be in UTC
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(
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);
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),
850 hp->id = putshort(id);
852 rp->trigger = putshort(interval == 0);
853 rp->interval = putshort(interval);
855 jupiter_debug(up->peer, __func__, "%u: %s", id, cp);
875 hp->id = putshort(id);
877 jupiter_debug(up->peer, __func__, "%u: %s", id, cp);
897 hp->id = putshort(id);
899 jupiter_debug(up->peer, __func__, "%u: %s", id, cp);
908 putshort((sizeof(struct jplat) / sizeof(u_short)) - 1), 0,
925 pp->platform = putshort(platform);
927 jupiter_debug(up->peer, __func__, "%u: %s", platform, cp);
937 while (len-- > 0) {
957 size = up->ssize;
962 sp = up->sbuf;
964 if (getshort(hp->sync) != JUPITER_SYNC) {
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;