Lines Matching defs:instance

109 struct instance {
138 static void jupiter_canmsg (struct instance *, u_int);
140 static int jupiter_config (struct instance *);
144 static const char * jupiter_parse_t (struct instance *, u_short *);
145 static const char * jupiter_parse_gpos (struct instance *, u_short *);
146 static void jupiter_platform (struct instance *, u_int);
151 static int jupiter_ppsapi (struct instance *);
152 static int jupiter_pps (struct instance *);
154 static int jupiter_recv (struct instance *);
156 static void jupiter_reqmsg (struct instance *, u_int, u_int);
157 static void jupiter_reqonemsg(struct instance *, u_int);
158 static char * jupiter_send (struct instance *, struct jheader *);
189 struct instance *instance;
205 instance = emalloc_zero(sizeof(*instance));
206 instance->peer = peer;
215 free(instance);
218 pp->unitptr = instance;
228 instance->assert = 1;
229 instance->hardpps = 0;
234 if (time_pps_create(fd, &instance->pps_handle) < 0) {
235 instance->pps_handle = 0;
239 else if (!jupiter_ppsapi(instance))
244 if (!jupiter_config(instance))
261 struct instance *instance;
265 instance = pp->unitptr;
266 if (!instance)
270 if (instance->pps_handle) {
271 time_pps_destroy(instance->pps_handle);
272 instance->pps_handle = 0;
278 free(instance);
285 jupiter_config(struct instance *instance)
287 jupiter_debug(instance->peer, __func__, "init receiver");
292 instance->sloppyclockflag = instance->peer->procptr->sloppyclockflag;
293 instance->moving = !!(instance->sloppyclockflag & CLK_FLAG2);
294 if (instance->moving)
295 jupiter_debug(instance->peer, __func__, "mobile platform");
297 instance->pollcnt = 2;
298 instance->polled = 0;
299 instance->gpos_gweek = 0;
300 instance->gpos_sweek = 0;
301 instance->gweek = 0;
302 instance->lastsweek = 2 * WEEKSECS;
303 instance->timecode = 0;
304 instance->stime = 0;
305 instance->ssize = 0;
308 jupiter_canmsg(instance, JUPITER_ALL);
311 jupiter_reqonemsg(instance, JUPITER_O_ID);
314 instance->wantid = 1;
317 jupiter_reqmsg(instance, JUPITER_O_PULSE, 1);
320 jupiter_reqmsg(instance, JUPITER_O_GPOS, 1);
323 if (instance->moving)
324 jupiter_platform(instance, JUPITER_I_PLAT_MED);
326 jupiter_platform(instance, JUPITER_I_PLAT_LOW);
337 struct instance *instance /* unit structure pointer */
342 if (time_pps_getcap(instance->pps_handle, &capability) < 0) {
347 memset(&instance->pps_params, 0, sizeof(pps_params_t));
348 if (!instance->assert)
349 instance->pps_params.mode = capability & PPS_CAPTURECLEAR;
351 instance->pps_params.mode = capability & PPS_CAPTUREASSERT;
352 if (!(instance->pps_params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) {
355 instance->assert);
358 instance->pps_params.mode |= PPS_TSFMT_TSPEC;
359 if (time_pps_setparams(instance->pps_handle, &instance->pps_params) < 0) {
364 if (instance->hardpps) {
365 if (time_pps_kcbind(instance->pps_handle, PPS_KC_HARDPPS,
366 instance->pps_params.mode & ~PPS_TSFMT_TSPEC,
374 /* instance->peer->precision = PPS_PRECISION; */
378 time_pps_getparams(instance->pps_handle, &instance->pps_params);
379 jupiter_debug(instance->peer, __func__,
381 capability, instance->pps_params.api_version,
382 instance->pps_params.mode, instance->hardpps);
395 jupiter_pps(struct instance *instance)
405 if (instance->pps_handle == 0)
409 memcpy(&pps_info, &instance->pps_info, sizeof(pps_info_t));
410 if (time_pps_fetch(instance->pps_handle, PPS_TSFMT_TSPEC, &instance->pps_info,
413 if (instance->pps_params.mode & PPS_CAPTUREASSERT) {
415 instance->pps_info.assert_sequence)
417 ts = instance->pps_info.assert_timestamp;
418 } else if (instance->pps_params.mode & PPS_CAPTURECLEAR) {
420 instance->pps_info.clear_sequence)
422 ts = instance->pps_info.clear_timestamp;
426 if ((instance->ts.tv_sec == ts.tv_sec) && (instance->ts.tv_nsec == ts.tv_nsec))
428 instance->ts = ts;
433 instance->peer->procptr->lastrec = tstmp;
444 struct instance *instance;
448 instance = pp->unitptr;
459 if (instance->pollcnt > 0) {
460 instance->pollcnt--;
465 jupiter_reqonemsg(instance, JUPITER_O_ID);
466 instance->wantid = 0;
473 instance->polled = 1;
489 struct instance *instance;
493 instance = pp->unitptr;
495 DTOLFP(pp->fudgetime2, &instance->limit);
497 if (L_ISNEG(&instance->limit))
498 L_NEG(&instance->limit);
501 instance->assert = !(pp->sloppyclockflag & CLK_FLAG3);
502 jupiter_ppsapi(instance);
505 sloppyclockflag = instance->sloppyclockflag;
506 instance->sloppyclockflag = pp->sloppyclockflag;
507 if ((instance->sloppyclockflag & CLK_FLAG2) !=
511 jupiter_config(instance);
534 struct instance *instance;
540 instance = pp->unitptr;
546 if (bpcnt > sizeof(instance->sbuf) - instance->ssize)
547 bpcnt = sizeof(instance->sbuf) - instance->ssize;
550 memcpy((u_char *)instance->sbuf + instance->ssize, bp, bpcnt);
551 instance->ssize += bpcnt;
554 while (instance->ssize > (int)sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) {
555 instance->pollcnt = 2;
558 hp = (struct jheader *)instance->sbuf;
582 laststime = instance->stime;
583 instance->stime = DS2UI(((struct jpulse *)sp)->stime);
584 if (laststime != 0 && instance->stime - laststime <= 21) {
587 (double)instance->stime * 0.01, (double)laststime * 0.01);
592 ppsret = jupiter_pps(instance);
600 if (!L_ISGEQ(&tstamp, &instance->limit))
604 last_timecode = instance->timecode;
605 if ((cp = jupiter_parse_t(instance, sp)) != NULL) {
630 if (!instance->polled)
632 instance->polled = 0;
651 instance->polled = 0;
663 if ((cp = jupiter_parse_gpos(instance, sp)) != NULL) {
680 * just powered instance, it needs to be reconfigured.
689 if (instance->wantid)
690 instance->wantid = 0;
693 jupiter_config(instance);
698 instance->ssize = cc;
707 instance->ssize -= cc;
708 if (instance->ssize < 0) {
711 } else if (instance->ssize > 0)
712 memcpy(instance->sbuf, (u_char *)instance->sbuf + cc, instance->ssize);
717 jupiter_parse_t(struct instance *instance, u_short *sp)
743 if (instance->gweek == 0) {
744 if (!instance->gpos_gweek) {
748 instance->gweek = instance->gpos_gweek;
755 if (instance->gpos_sweek >= sweek) {
756 if ((instance->gpos_sweek - sweek) > WEEKSECS / 2)
757 ++instance->gweek;
760 if ((sweek - instance->gpos_sweek) > WEEKSECS / 2)
761 --instance->gweek;
764 else if (sweek == 0 && instance->lastsweek == WEEKSECS - 1) {
765 ++instance->gweek;
766 jupiter_debug(instance->peer, __func__,
767 "NEW gps week %u", instance->gweek);
782 if (instance->lastsweek == sweek)
783 jupiter_debug(instance->peer, __func__,
786 else if (instance->lastsweek != 2 * WEEKSECS &&
787 instance->lastsweek + 1 != sweek &&
788 !(sweek == 0 && instance->lastsweek == WEEKSECS - 1))
789 jupiter_debug(instance->peer, __func__,
791 instance->lastsweek, sweek);
792 instance->lastsweek = sweek;
795 last_timecode = instance->timecode;
796 instance->timecode =
797 GPS_EPOCH + (instance->gweek * WEEKSECS) + sweek;
801 jupiter_debug(instance->peer, __func__,
803 instance->gweek, sweek);
809 jupiter_debug(instance->peer, __func__,
811 cp, instance->gweek, sweek);
814 instance->peer->procptr->year = tm->tm_year + 1900;
815 instance->peer->procptr->day = tm->tm_yday + 1;
816 instance->peer->procptr->hour = tm->tm_hour;
817 instance->peer->procptr->minute = tm->tm_min;
818 instance->peer->procptr->second = tm->tm_sec;
825 refclock_report(instance->peer, CEVNT_BADTIME);
831 refclock_report(instance->peer, CEVNT_BADTIME);
839 jupiter_parse_gpos(struct instance *instance, u_short *sp)
853 instance->gpos_gweek = 0;
854 instance->gpos_sweek = 0;
858 instance->gpos_sweek = DS2UI(jg->sweek);
859 instance->gpos_gweek = get_full_week(get_base_week(),
866 while(instance->gpos_sweek >= WEEKSECS) {
867 instance->gpos_sweek -= WEEKSECS;
868 ++instance->gpos_gweek;
870 instance->gweek = 0;
872 t = GPS_EPOCH + (instance->gpos_gweek * WEEKSECS) + instance->gpos_sweek;
876 jupiter_debug(instance->peer, __func__,
878 cp, instance->gpos_gweek, instance->gpos_sweek);
915 jupiter_send(struct instance *instance, struct jheader *hp)
932 if ((cc = write(instance->peer->procptr->io.fd, (char *)hp, size)) < 0) {
956 jupiter_reqmsg(struct instance *instance, u_int id,
968 if ((cp = jupiter_send(instance, hp)) != NULL)
969 jupiter_debug(instance->peer, __func__, "%u: %s", id, cp);
980 jupiter_canmsg(struct instance *instance, u_int id)
987 if ((cp = jupiter_send(instance, hp)) != NULL)
988 jupiter_debug(instance->peer, __func__, "%u: %s", id, cp);
999 jupiter_reqonemsg(struct instance *instance, u_int id)
1006 if ((cp = jupiter_send(instance, hp)) != NULL)
1007 jupiter_debug(instance->peer, __func__, "%u: %s", id, cp);
1022 jupiter_platform(struct instance *instance, u_int platform)
1031 if ((cp = jupiter_send(instance, hp)) != NULL)
1032 jupiter_debug(instance->peer, __func__, "%u: %s", platform, cp);
1051 jupiter_recv(struct instance *instance)
1060 size = instance->ssize;
1065 sp = instance->sbuf;
1069 jupiter_debug(instance->peer, __func__, "syncing");
1075 jupiter_debug(instance->peer, __func__,
1085 jupiter_debug(instance->peer, __func__,
1092 jupiter_debug(instance->peer, __func__, "\n");
1098 instance->ssize = size;
1105 jupiter_debug(instance->peer, __func__, "bad header checksum!");
1107 instance->ssize = 0;
1122 jupiter_debug(instance->peer,
1125 instance->ssize = 0;