30 lines
1.2 KiB
C
30 lines
1.2 KiB
C
#define _POSIX_C_SOURCE 200809L
|
|
#include "atom_bridge.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
static uint64_t now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return (uint64_t)t.tv_sec*1000+(uint64_t)t.tv_nsec/1000000; }
|
|
int main(int argc,char **argv) {
|
|
uint32_t s[24],h=0; uint16_t data[2]={42,43}; unsigned ok=0,err=0;
|
|
int uncertain=0,last=0; uint64_t start=now(); struct timespec pause={0,1000000};
|
|
if(argc!=4) return 2;
|
|
uint16_t port=(uint16_t)atoi(argv[1]); uint8_t f=(uint8_t)atoi(argv[2]);
|
|
#define CALL(cmd) ab_call(cmd,h,0x7f000001u,port,1,f,0,2,data,2,s,24,now(),100,80,20)
|
|
if(CALL(AB_OPEN)) return 2;
|
|
h=s[0]; if(CALL(AB_CONFIGURE) || CALL(AB_ENABLE)) return 2;
|
|
while(now()-start<1500 && ok<(unsigned)atoi(argv[3])) {
|
|
if(CALL(AB_TICK)) return 2;
|
|
if(s[3]) {
|
|
if(f<=4 && CALL(AB_COPY_READ)) return 2;
|
|
ok++; if(CALL(AB_ACK)) return 2;
|
|
}
|
|
if(s[4]) { err++; last=(int)s[5]; uncertain|=(int)s[9]; if(CALL(AB_ACK)) return 2; }
|
|
if(s[1]==3 && ok<(unsigned)atoi(argv[3])) {
|
|
if(CALL(AB_REQUEST_TIMEOUT) || CALL(AB_SUBMIT)) return 2;
|
|
}
|
|
nanosleep(&pause,0);
|
|
}
|
|
printf("%u %u %u %d %d %u %u\n",ok,err,s[11],uncertain,last,data[0],data[1]);
|
|
CALL(AB_CLOSE); return ok==(unsigned)atoi(argv[3])?0:1;
|
|
}
|