Beispiel #1
0
void tai_tai64(char s[TAI_TAI64], const struct tai *ta)
{
  unsigned char buf[TAI_PACK];
  unsigned int i;

  tai_pack(buf, ta);
  for (i = 0; i < 8; ++i) {
    s[i * 2 + 0] = hex[(buf[i] >> 4) & 15];
    s[i * 2 + 1] = hex[buf[i] & 15];
  }
}
Beispiel #2
0
int32_t leapsecs_sub(struct tai *lt)
{
#ifndef DISABLE_LEAPS
    char out[101],x[TAI_PACK]; double packerr;
    int32_t weekday,yearday,i,j,s; uint64_t u; struct tai t,t2; struct taitime ct2;
    if ( leaptais[0].x == 0 )
    {
        for (i=0; i<sizeof(leapseconds)/sizeof(*leapseconds); i++)
        {
            t = taidate_scan(leapseconds[i],i);
            if ( t.x == 0 )
                printf("unable to parse.(%s)\n",leapseconds[i]);
            else
            {
                //t = taitime2tai(ct);
                leaptais[i] = t;
                ct2 = tai2time(t,&weekday,&yearday);
                tai_pack(x,&t);
                tai_unpack(x,&t2);
                tai_sub(&t2,&t2,&t);
                packerr = tai_approx(&t2);
                for (j=0; j<TAI_PACK; j++)
                    printf("%2.2x",(uint32_t)(uint8_t)x[j]);
                if ( packerr != 0 )
                    printf(" packerr=%f",packerr);
                taitime_str(out,ct2);
                printf(" %03d  %s %s",yearday,dayname[weekday],out);
                printf("\n");
            }
        }
    }
    u = lt->x;
    if ( u > leaptais[sizeof(leaptais)/sizeof(*leaptais)-1].x )
        lt->x -= (sizeof(leaptais)/sizeof(*leaptais) - 1);
    else
    {
        s = 0;
        for (i=0; i<sizeof(leaptais)/sizeof(*leaptais); i++)
        {
            if ( u < leaptais[i].x )
                break;
            ++s;
            if ( u == leaptais[i].x )
            {
                lt->x = u - s;
                return(1);
            }
        }
        lt->x = u - s;
    }
#endif
    return(0);
}
Beispiel #3
0
int main() {
  tai_t t = TAI_INIT;
  uint64_t x;
  char buf[TAI_PACK_SIZE];
  
  tai_now(&t);
  x = t.sec;
  
  tai_pack(&buf[0], &t);
  tai_unpack(&t, &buf[0]);
  
  if (t.sec == x)
    return 0;
    
  return 1;
}
Beispiel #4
0
void
taia_pack(char * s, const struct taia * t)
{
    unsigned long x;

    tai_pack(s, &t->sec);
    s += 8;

    x = t->nano;
    s[3] = x & 255;
    x >>= 8;
    s[2] = x & 255;
    x >>= 8;
    s[1] = x & 255;
    x >>= 8;
    s[0] = x;
}
Beispiel #5
0
main()
{
  struct caldate cd;
  struct tai t;
  char x[TAI_PACK];
  long leaps = 0;

  while (fgets(line,sizeof line,stdin))
    if (line[0] == '+')
      if (caldate_scan(line + 1,&cd)) {
	t.x = (caldate_mjd(&cd) + 1) * 86400ULL + 4611686014920671114ULL + leaps++;
        tai_pack(x,&t);
	fwrite(x,TAI_PACK,1,stdout);
      }
      
  exit(0);
}
Beispiel #6
0
void taia_pack(const struct taia *ta, char *s)
{
    unsigned long x;

    tai_pack(&ta->sec, s);
    s += 8;
    x = ta->atto;
    s[7] = x & 255; x >>= 8;
    s[6] = x & 255; x >>= 8;
    s[5] = x & 255; x >>= 8;
    s[4] = x;
    x = ta->nano;
    s[3] = x & 255; x >>= 8;
    s[2] = x & 255; x >>= 8;
    s[1] = x & 255; x >>= 8;
    s[0] = x;
}
Beispiel #7
0
main()
{
  struct tai t;
  struct tai t2;
  struct caltime ct;
  struct caltime ct2;
  int weekday;
  int yearday;
  int i;
  double packerr;

  if (leapsecs_init() == -1)
    printf("unable to init leapsecs\n");

  while (fgets(line,sizeof line,stdin))
    if (!caltime_scan(line,&ct))
      printf("unable to parse\n");
    else {
      caltime_tai(&ct,&t);
      caltime_utc(&ct2,&t,&weekday,&yearday);
      tai_pack(x,&t);
      tai_unpack(x,&t2);
      tai_sub(&t2,&t2,&t);
      packerr = tai_approx(&t2);
      for (i = 0;i < TAI_PACK;++i)
        printf("%2.2x",(unsigned long) (unsigned char) x[i]);
      if (packerr)
        printf(" packerr=%f",packerr);
      printf(" %03d  %s",yearday,dayname[weekday]);
      if (caltime_fmt((char *) 0,&ct2) + 1 < sizeof out) {
        out[caltime_fmt(out,&ct2)] = 0;
        printf(" %s",out);
      }
      printf("\n");
    }
  return(0);
}
Beispiel #8
0
void tain_pack (char *s, struct taia const *t)
{
  tai_pack(s, &t->sec) ;
  uint32_pack_big(s+8, (uint32)t->nano) ;
}