Exemplo n.º 1
0
//-------------------------------------------------------------------------------------------------------
int main( int argc, char const **argv )
{
   if (!NetSystemInit()) {
      printf( "Failed to initialize net system.\n" );
      _getch();
      return false;
   }

   // List Addresses
   char const *hostname = AllocLocalHostName();
   ListAddressesForHost( hostname, gHostPort );
   FreeLocalHostName(hostname);

   // Host/Client Logic
   if ((argc <= 1) || (_strcmpi( argv[1], "sock" ) == 0)) {
      printf( "Hosting...\n" );
      NetworkHost( gHostPort ); 
   } else if (argc > 2) {
      char const *addr = argv[1];
      char const *msg = argv[2];
      printf( "Sending message \"%s\" to [%s]\n", msg, addr );
      NetworkClient( addr, gHostPort, msg );
   } else {
      char const *msg = argv[1];
      printf( "Broadcast message \"%s\".\n", msg );
      NetworkBroadcast( msg );
   }

   NetSystemDeinit();

   printf( "Press any key to continue...\n" );
   _getch();
   return 0;
}
Exemplo n.º 2
0
int main(int argc,char *argv[]) {
  DIO *dio;
  System *sys;
  Time *t;
  int socket;
  int i,j,n,m,RED_LED;
  char* name;
  unsigned t0,t1,tot=0;
  DIOState val;
  tsctl *conn;

  /*  
  if (argv < 3) {
    printf("usage: %s <host> <inst>\n",argv[0]);
    return 1;
  }
  */
  conn = TsctlClient("127.0.0.1",NetModeBlocking);
  if (!conn) {
    perror("socket:");
    return 1;
  }
  dio = NetDIOInit(conn,0);
  if (!dio) {
    printf("Error initializing DIO\n");
    return 1;
  }
  t = NetTimeInit(conn,0);
  if (!t) {
    printf("Error initializing Time\n");
    return 1;
  }
  sys = NetSystemInit(conn,0);
  if (!sys) {
    printf("Error initializing System\n");
    return 1;
  }
  if (!setjmp(conn->exception)) {
    t0 = t->Tick(t);
    for (i=0;i<1000;i++) {
      t1 = t->Tick(t);
      if (t1 > t0) {
	tot += (t1-t0);
      } else {
	tot += (0xFFFFFFFF - t0) + t1;
      }
      t0 = t1;
    }
    printf("%uus avg round trip time\n",tot/i);
    printf("Model ID=%02X\n",sys->ModelId(sys));
    printf("BaseBoard ID=%02X\n",sys->BaseBoardId(sys));
    RED_LED = sys->MapLookup(sys,ASCIIZ("RED_LED"));
    val = dio->GetAsync(dio,RED_LED);
    printf("RED_LED=%s\n",DIOValueString(val));
    for (i=0;i<100;i++) {
      dio->SetAsync(dio,RED_LED,HIGH);
      dio->SetAsync(dio,RED_LED,LOW);
    }
    j = sys->MapLength(sys);
    for (i=0;i<j;i++) {
      name=sys->MapGet(sys,i,&n);
      //printf("%d:%s=%d\n",i,name,n);
      /*
      m=sys->MapLookup(sys,name);
      if (m!=n) {
	printf("%s=%d/%d error\n",n,m);
      }
      */
    }
  } else {
    printf("exception\n");
  }
}