Beispiel #1
0
/* open communication with mainframe under logical number 'id',
   do all necessary initialization and start thread */
int
sy1527Start(unsigned id_nowused, char *ip_address)
{
    int id; ///my:
    char arg[30], userName[20], passwd[30], name[MAX_CAEN_NAME];
    int link, ret;

    pthread_mutex_lock(&global_mutex);

    /* do global initialization on first call */
    if(nmainframes == -1) sy1527Init();

    nmainframes++;///my:
    ///id=nmainframes-1;///my:

    ///if((id+1)>nmainframes)nmainframes=id+1;
    id=id_nowused;///nmainframes-1;///my:

    printf("++++++++++++++++++++++++++++++++++++++++++++++++ nmainframes=%d id=%d\n", nmainframes, id);

    /* lock global mutex to prevent other mainframes to be started
       until we are done with this one */
    /// my: move upward - pthread_mutex_lock(&global_mutex); otherwise many sy1527Init() are possible

    if(nmainframes >= MAX_HVPS)
    {
        printf("ERROR: no more empty slots\n");
        pthread_mutex_unlock(&global_mutex);
        return(CAENHV_SYSERR);
    }

    CHECK_ID(id);
    CHECK_FREE(id);

/// my:  sprintf(name,"sy1527_%03d",id);
    sprintf(name, CRATE_LABEL, id); /// my:
    printf("System Name set as >%s<\n",name);

    strcpy(arg,ip_address);
    printf("TCP/IP address set as >%s<\n",arg);
    link = LINKTYPE_TCPIP;

    /*
    strcpy(userName, "user");
    strcpy(passwd, "user");
    */
    strcpy(userName, "admin");
    strcpy(passwd, "admin");

    ret = CAENHVInitSystem(name, link, arg, userName, passwd);

    printf("my: id_index=%d id=%d name=%s", id, ret, name );
    printf("\nCAENHVInitSystem error: %s (num. %d)\n\n", CAENHVGetError(name),ret);

    if(ret == CAENHV_OK)
    {
        if(strlen(ip_address)>=MAX_CAEN_NAME) {
            printf("too long mainfraime IP: exits now\n");    /// my:
            exit(1);
        }
        strcpy(Measure[id].IPADDR,ip_address); /// my:
        Measure[id].id = ret;
        strcpy(Measure[id].name, name);
        Demand[id].id = ret;
        strcpy(Demand[id].name, name);
    }
    else
    {
        printf("\n CAENHVInitSystem returned %d\n\n",ret);
        pthread_mutex_unlock(&global_mutex);
        return(CAENHV_SYSERR);
    }

    /* init mainframe mutex */
    pthread_mutex_init(&mainframe_mutex[id], &mattr);

    /* start thread */
    stat[id].threadid = id;
    force_exit[id] = 0;
    if(pthread_create(&idth[id],NULL,sy1527MainframeThread,(void *)&stat[id])!=0)
    {
        printf("ERROR: pthread_create(0x%08lx[%d],...) failure\n",idth[id],id);
        pthread_mutex_unlock(&global_mutex);
        return(CAENHV_SYSERR);
    }
    else
    {
        printf("INFO: pthread_create(0x%08lx[%d],...) done\n",idth[id],id);
    }

    /* register mainframe */
    mainframes[nmainframes-1] = id; /// my: removed nmainframes++
    ///mainframes[id] = id;

    printf("====================== 111111111111\n");
    /* get mainframe map */
    sy1527GetMap(id);
    printf("====================== 222222222222\n");

    pthread_mutex_unlock(&global_mutex);

    return(CAENHV_OK);
}
Beispiel #2
0
/* open communication with mainframe under logical number 'id',
   do all necessary initialization and start thread */
int
sy527Start(unsigned id, char *ip_address)
{
  char arg[30], userName[20], passwd[30], name[MAX_NAME];
  int link, ret;

  printf("123\n");fflush(stdout);

  /* do global initialization on first call */
  if(nmainframes == -1) sy527Init();

  printf("456\n");fflush(stdout);

  /* lock global mutex to prevent other mainframes to be started
     until we are done with this one */
  LOCK_GLOBAL;

  if(nmainframes >= MAX_HVPS)
  {
    printf("ERROR: no more empty slots\n");
    UNLOCK_GLOBAL;

    return(CAENHV_SYSERR);
  }

  CHECK_ID(id);
  CHECK_FREE(id);

  sprintf(name,"sy527_%03d",id);
  printf("System Name set as >%s<\n",name);

  /*strcpy(arg,ip_address); for sy1527*/
  /*printf("TCP/IP address set as >%s<\n",arg);*/

  strcpy(arg,"sy527_0x100000_9");

  /*link = LINKTYPE_TCPIP; for sy1527*/
  link = LINKTYPE_CAENET;

  strcpy(userName, "user");
  strcpy(passwd, "user");

  ret = CAENHVInitSystem(name, link, arg, userName, passwd);

  printf("\nCAENHVInitSystem: %s (num. %d)\n\n", CAENHVGetError(name),ret);

  if(ret == CAENHV_OK)
  {
    Measure[id]->id = ret;
    strcpy(Measure[id]->name, name); 
    Demand[id]->id = ret;
    strcpy(Demand[id]->name, name); 
  }
  else
  {
    printf("\n CAENHVInitSystem returned %d\n\n",ret);    
    UNLOCK_GLOBAL;

    return(CAENHV_SYSERR);
  }


#ifndef vxWorks
  /* init mainframe mutex */
  pthread_mutex_init(&mainframe_mutex[id], &mattr);
#else
  mainframe_mutex[id] = semBCreate(SEM_Q_FIFO, SEM_FULL);
  if(mainframe_mutex[id] == NULL)
  {
    printf("ERROR: could not allocate 'mainframe_mutex' semaphore\n");
    return(0);
  }
#endif


  /* start thread */
  stat[id].threadid = id;
  force_exit[id] = 0;

#ifdef vxWorks
  {
    int iTaskStat;
    iTaskStat = taskSpawn("SY527THRD", 150, 0, 800000, sy527Thread,
                          &stat[id], 0, 0,0,0,0,0,0,0,0);
    printf("taskSpawn(\"SY527THRD\") returns %d\n",iTaskStat);
    if(iTaskStat == ERROR)
    {
	  perror("taskSpawn"); 
      UNLOCK_GLOBAL;
    }
  }
#else
  if(pthread_create(&idth[id],NULL,sy527Thread,(void *)&stat[id])!=0)
  {
    printf("ERROR: pthread_create(0x%08lx[%d],...) failure\n",idth[id],id);
    UNLOCK_GLOBAL;
    return(CAENHV_SYSERR);
  }
  else
  {
    printf("INFO: pthread_create(0x%08lx[%d],...) done\n",idth[id],id);
  }
#endif

  /* register mainframe */
  mainframes[nmainframes++] = id;

  /* get mainframe map */
  sy527GetMap(id);

  UNLOCK_GLOBAL;

  return(CAENHV_OK);
}