merge 64-bit fixes from Fernando Lucas Rodriguez <fernando_lr@terra.es>
[debian/gcpegg] / egg.c
diff --git a/egg.c b/egg.c
index 84786c586c4e0bcf819e19caa12e34edfa91a11f..47bef4a36614a43ae6042b8122fef892a8680590 100644 (file)
--- a/egg.c
+++ b/egg.c
@@ -49,6 +49,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <time.h>
 
 #include "global.h"
 #include "genlib.h"
@@ -94,7 +95,7 @@ static EggCarton savebuffer;
 char   *pgmname;                     /* Program name from argv[0] */
 char   *myaddr;                      /* Interface to bind */
 int16  myport;                       /* Service port to bind */
-int32 lastDataSent = 0;              /* Time last packet sent to basket */
+uint32 lastDataSent = 0;             /* Time last packet sent to basket */
 
 /* If no priority increment has been specified at compile time, set to
    our default of ±10. [+/- 10, for folks without 8bit editors] */
@@ -106,7 +107,7 @@ static int niceness = NICE;       /* Priority increment/decrement for collection
 
 /* Status exported to user interface. */
 
-int32 time_latency = 0, time_housekeeping = 0;
+uint32 time_latency = 0, time_housekeeping = 0;
 
 #ifdef ALT_UI
 static double mean_Packet = 0.0, mean_Grand = 0.0;
@@ -292,7 +293,7 @@ int main(int argc, char *argv[]) {
   }
 #ifdef DEBUG
     else {
-    printf("REG configured: %s = %d, %d, %ld\n", configuredREG ->reg_name,
+    printf("REG configured: %s = %d, %d, %d\n", configuredREG ->reg_name,
        devopts.type, devopts.port, devopts.baud);
   }
 #endif
@@ -463,7 +464,7 @@ int main(int argc, char *argv[]) {
        totalTrials += ptrials;
        mean_Grand = totalGrand / totalTrials;
        total_Packets++;
-       printf("Packets sent: %ld  Packet mean: %6.2f  Grand mean: %6.2f\n",
+       printf("Packets sent: %d  Packet mean: %6.2f  Grand mean: %6.2f\n",
                total_Packets, mean_Packet, mean_Grand);
 #endif
       }
@@ -489,7 +490,7 @@ int main(int argc, char *argv[]) {
     /* But let's be sure it really *is* in the interval. */
     if (t.tv_sec < savebuffer.records[0].timestamp ||
        t.tv_sec >= (savebuffer.records[0].timestamp + savebuffer.hdr.sec_rec * savebuffer.hdr.rec_pkt)) {
-      fprintf(stderr, "***Sample, collected at %ld, is not within packet starting at %ld.\n",
+      fprintf(stderr, "***Sample, collected at %ld, is not within packet starting at %u.\n",
              t.tv_sec, savebuffer.records[0].timestamp);
       exit(-1);
     }
@@ -605,11 +606,12 @@ int main(int argc, char *argv[]) {
              uint32 stime;
              char *pktP = pktbuf + (2 * sizeof(uint16));
              
-             unpackShort(reggid);
-             unpackLong(stime);
+             unpack16(reggid);
+             unpack32(stime);
 #ifdef PACKETDUMP
-             fprintf(stderr, "Request: eggid = %d, starttm = %ld: %s",
-                     reggid, stime, asctime(gmtime((time_t *) &stime)));
+        time_t stime_val = stime;
+             fprintf(stderr, "Request: eggid = %d, starttm = %u: %s\n",
+                     reggid, stime, asctime(gmtime(&stime_val)));
 #endif
              res = LoadPacket(stime, reggid, &retrcart);
            }
@@ -639,10 +641,10 @@ int main(int argc, char *argv[]) {
            
            { char *pktP = pktbuf + (3 * sizeof(uint16)) + sizeof(uint32);
            
-           unpackShort(protocol.samp_rec);
-           unpackShort(protocol.sec_rec);
-           unpackShort(protocol.rec_pkt);
-           unpackByte(protocol.trialsz);
+           unpack16(protocol.samp_rec);
+           unpack16(protocol.sec_rec);
+           unpack16(protocol.rec_pkt);
+           unpack8(protocol.trialsz);
            }
 #ifdef PACKETDUMP
            fprintf(stderr, "Settings: samp_rec = %d, sec_rec = %d, rec_pkt = %d, trialsz = %d\n",
@@ -672,12 +674,12 @@ int main(int argc, char *argv[]) {
     usec = time_latency;
     msec = usec / 1000;
     usec %= 1000;
-    printf("Sampling latency: %ld.%03ld msec", msec, usec);
+    printf("Sampling latency: %d.%03d msec", msec, usec);
 
     usec = time_housekeeping;
     msec = usec / 1000;
     usec %= 1000;
-    printf("  Housekeeping time: %ld.%03ld msec\n", msec, usec);
+    printf("  Housekeeping time: %d.%03d msec\n", msec, usec);
 #endif
     lt = ct;
     sleeptime = ((1000000 - SLACK) - ct.tv_usec);
@@ -845,10 +847,10 @@ static void LoadRCFile(char *filename) {
 static void MakeAwake(AwakePacket *pkt) {
   char *pktP = (char *) pkt;
 
-  packShort(AWAKE_PACKET);
-  packShort((4 * sizeof(uint16)) + sizeof(uint32));
-  packShort(eggtable[0].id);
-  packLong(getzulutime(NULL));
+  pack16(AWAKE_PACKET);
+  pack16((4 * sizeof(uint16)) + sizeof(uint32));
+  pack16(eggtable[0].id);
+  pack32(getzulutime(NULL));
 }
 
 /*  MakeDataPkt  --  Build a canonical network byte order data packet
@@ -866,20 +868,20 @@ static void MakeDataPkt(char **pkt, EggCarton *src) {
 
   /* Assemble header fields into data packet. */
 
-  packShort(src->hdr.type = DATA_PACKET);
-  packShort(src->hdr.pktsize = pktsize);
-  packShort(src->hdr.eggid);
-  packShort(src->hdr.samp_rec);
-  packShort(src->hdr.sec_rec);
-  packShort(src->hdr.rec_pkt);
-  packByte(src->hdr.trialsz);
-  packShort(src->hdr.numrec);
+  pack16(src->hdr.type = DATA_PACKET);
+  pack16(src->hdr.pktsize = pktsize);
+  pack16(src->hdr.eggid);
+  pack16(src->hdr.samp_rec);
+  pack16(src->hdr.sec_rec);
+  pack16(src->hdr.rec_pkt);
+  pack8(src->hdr.trialsz);
+  pack16(src->hdr.numrec);
 
   /* Append data records to packet. */
 
   for (rec = 0; rec < src->hdr.numrec; rec++) {
-    packLong(src->records[rec].timestamp);
-    packBytes(&(src->records[rec].trials), src->hdr.samp_rec);
+    pack32(src->records[rec].timestamp);
+    pack8s(&(src->records[rec].trials), src->hdr.samp_rec);
   }
 
   /* No need to calculate CRC -- NetTalk does that for us.