#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
+#include <time.h>
#include "global.h"
#include "genlib.h"
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] */
/* 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;
}
#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
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
}
/* 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);
}
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);
}
{ 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",
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);
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
/* 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.