Exemple #1
0
int main(int argc, char *argv[])
{
  remtrans_item *remtrans;
  unsigned char id[32];
  unsigned char pname[32];

  pwr_tStatus sts;
  struct timeval tv;
  int i;
  
  /* Read arg number 2, should be id for this instance */

  if (argc >= 2)
    strcpy((char *)id, argv[1]);
  else
    strcpy((char *)id, "0");

  /* Build process name with id */

  sprintf((char *) pname, "rs_remudp_%s", id);

  /* Init of errh */

  errh_Init((char *) pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);
  
  /* Init of gdh */

  sts = gdh_Init((char *) pname);
  if ( EVEN(sts)) {
    errh_Error("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Arg number 3 should be my remnodes objid in string representation,
     read it, convert to real objid and store in remnode_item */

  sts = 0;
  if (argc >= 3) sts = cdh_StringToObjid(argv[2], &rn.objid);
  if ( EVEN(sts)) {
    errh_Error("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Get pointer to RemnodeUDP object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_udp);
  if ( EVEN(sts)) {
    errh_Error("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Initialize some internal data and make standard remtrans init */

  rn.next = NULL;
  rn.local = NULL;		// We dont use local structure since we only have one remnode
  rn.retransmit_time = rn_udp->RetransmitTime;
  rn_udp->ErrCount = 0;

  sts = RemTrans_Init(&rn);

  /* Log that we will multicast */
    
  if (rn.multicast) {
    errh_Info("Will send to dual address: %d.%d.%d.%d",
      rn.multicast->Address[0],
      rn.multicast->Address[1],
      rn.multicast->Address[2],
      rn.multicast->Address[3]);
  }

  if ( EVEN(sts)) {
    errh_Error("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Store remtrans objects objid in remnode_udp object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_udp->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_udp->RemTransObjects)/sizeof(rn_udp->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }

  /* Initialize no timeout value (poll) for select call */

  tv.tv_sec = 0;
  tv.tv_usec = 0;

  /* Create UDP socket and init adress structures */

  CreateSocket();

  /* Wait for one cycle */
  
  RemoteSleep(rn_udp->ScanTime);

  /* Set running status */
  
  errh_SetStatus(PWR__SRUN);
  
  /* Set (re)start time in remnode object */
  
  time_GetTime(&rn_udp->RestartTime);
  
  /* Loop forever */

  while (!doomsday)
  {
    /* Check disable flag */
    
    if (rn_udp->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    
    /* Timestamp */
    
    aproc_TimeStamp(TIME_INCR, 5);

    RemoteSleep(TIME_INCR);

    /* Increase time counters in local remnode and prevent big counters */
    
    time_since_scan += TIME_INCR;
    time_since_keepalive += TIME_INCR;
    time_since_rcv += TIME_INCR;
    time_since_scan = min(time_since_scan, rn_udp->ScanTime + 1.0);
    time_since_keepalive = min(time_since_keepalive, rn_udp->KeepaliveTime + 1.0);
    time_since_rcv = min(time_since_rcv, rn_udp->LinkTimeout + 1.0);

    /* Update retransmit time, could have been changed */
    
    rn.retransmit_time = rn_udp->RetransmitTime;

    remtrans = rn.remtrans;
    while(remtrans) {
      remtrans->time_since_send += TIME_INCR;
      /* Prevent big counter */
      remtrans->time_since_send = min(remtrans->time_since_send, rn.retransmit_time + 1.0);
      remtrans = (remtrans_item *) remtrans->next;
    }

    tv.tv_sec = 0;
    tv.tv_usec = 0;

    FD_ZERO(&fds);
    FD_SET(my_socket, &fds);
    sts = select(32, &fds, NULL, NULL, &tv);

    if (sts > 0) Receive();

    if (sts < 0) {
      errh_Error("Select, %d", sts);
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }
    
    if (time_since_scan >= rn_udp->ScanTime) {
      if (!rn_udp->Disable) RemTrans_Cyclic(&rn, &RemnodeSend);
      time_since_scan = 0;
    }

    if (time_since_keepalive >= rn_udp->KeepaliveTime) {
      if (!rn_udp->Disable && rn_udp->UseKeepalive) SendKeepalive();
      time_since_keepalive = 0;
    }

    if (time_since_rcv >= rn_udp->LinkTimeout && rn_udp->LinkTimeout > 0) {
      if (rn_udp->LinkUp) {
        errh_Info("UDP link down %s", rn_udp->RemoteHostname);
        rn_udp->LinkUp = 0;
      }
    }
  }
}
Exemple #2
0
int main(int argc, char *argv[])
{
  unsigned int sts;			/* Status from function calls etc. */
  unsigned char id[32];
  unsigned char pname[32];
  remtrans_item *remtrans;
  int i;

  /* Read arg number 2, should be id for this instance */

  if (argc >= 2)
    strcpy((char *)id, argv[1]);
  else
    strcpy((char *)id, "0");
    
  /* Build process name with id */

  sprintf((char *) pname, "rs_remser_%s", id);

  /* Init of errh */

  errh_Init((char *) pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);

  /* Set debug mode if arg number 4 is "debug" (started manually) */

  debug = 0;
  if (argc >= 4) {
    if (!strncmp(argv[3],"debug",5)) debug = 1;
  }

  if (debug) printf("debugmode valt\n");

  /* Init of gdh */

  sts = gdh_Init((char *) pname);
  if ( EVEN(sts)) {
    errh_Error("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Arg number 3 should be my remnodes objid in string representation,
     read it, convert to real objid and store in remnode_item */

  sts = 0;
  if (argc >= 3) sts = cdh_StringToObjid(argv[2], &rn.objid);
  if ( EVEN(sts)) {
    errh_Error("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Get pointer to RemnodeSerial object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_serial);
  if ( EVEN(sts)) {
    errh_Error("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Initialize some internal data and make standard remtrans init */

  rn.next = NULL;
  rn.local = NULL;		// We dont use local structure since we only have one remnode
  rn.retransmit_time = 10.0;	// Not used, but initialize anyway
  rn_serial->ErrCount = 0;

  sts = RemTrans_Init(&rn);

  if ( EVEN(sts)) {
    errh_Error("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  time_since_scan = 0;
  time_since_rcv = 0;

  /* Store remtrans objects objid in remnode_serial object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_serial->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_serial->RemTransObjects)/sizeof(rn_serial->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }

  /* Initialize device */

  ser_fd = RemUtils_InitSerialDev(rn_serial->DevName, 
  				  rn_serial->Speed, 
				  rn_serial->DataBits,
				  rn_serial->StopBits,
				  rn_serial->Parity);
				  
  if (!ser_fd) {
    errh_Error("InitDev, %d", ser_fd);
    errh_SetStatus(PWR__SRVTERM);
    exit(0);
  }    

  /* Loop forever */

  while (1)
  {
    if (rn_serial->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    sts = Receive();
    sts = RemTrans_Cyclic(&rn, &remnode_send);
  }
}
Exemple #3
0
int main(int argc, char *argv[])
{
  remtrans_item *remtrans;
  unsigned char id[32];
  unsigned char pname[32];
  
  pwr_tStatus sts;
  int i;
  float time_since_scan = 0.0;
  
  
  
  /* Read arg number 2, should be id for this instance and id is our queue number */
  
  if (argc >= 2)
    strcpy((char *)id, argv[1]);
  else
    strcpy((char *)id, "0");
  
  /* Build process name with id */
  
  sprintf((char *) pname, "rs_remwmq_%s", id);
  
  /* Init of errh */
  
  errh_Init((char *) pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);
  
  /* Init of gdh */
  if (debug) printf("Before gdh_init\n");
  sts = gdh_Init((char *) pname);
  if ( EVEN(sts)) {
    errh_Fatal("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Arg number 3 should be my remnodes objid in string representation,
     read it, convert to real objid and store in remnode_item */
  
  sts = 0;
  if (argc >= 3) sts = cdh_StringToObjid(argv[2], &rn.objid);
  if ( EVEN(sts)) {
    errh_Fatal("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Get pointer to RemnodeWMQ object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_wmq);
  if ( EVEN(sts)) {
    errh_Fatal("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Initialize some internal data and make standard remtrans init */
  
  rn.next = NULL;
  rn.local = NULL;		// We dont use local structure since we only have one remnode
  rn_wmq->ErrCount = 0;
  
  if (debug) printf("Before remtrans_init\n");
  
  sts = RemTrans_Init(&rn);
  
  if ( EVEN(sts)) {
    errh_Fatal("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Store remtrans objects objid in remnode_mq object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_wmq->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_wmq->RemTransObjects) / sizeof(rn_wmq->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }
  
  /* Variables for MQ calls */
  
  strncpy(mgr_name, rn_wmq->QueueManager, MQ_Q_MGR_NAME_LENGTH);
  //  strncpy(mgr_name, "hejsanqqq", sizeof(MQ_Q_MGR_NAME_LENGTH));
  

  /* Open queue for receiving messages */
  
  strncpy(rcv_que_name, rn_wmq->RcvQueue, MQ_Q_NAME_LENGTH);
  //  strncpy(rcv_que_name, "hejsanqqq", sizeof(MQ_Q_NAME_LENGTH));

  /* Initialize object descriptor control block */

  strncpy(RcvObjDesc.ObjectName, rcv_que_name, MQ_Q_NAME_LENGTH);

  /* open queue for input but not if MQM stopping */

  RcvOpenOptions =  MQOO_INPUT_AS_Q_DEF | MQOO_FAIL_IF_QUIESCING;

  /* Open queue for sending messages */
  
  strncpy(snd_que_name, rn_wmq->SndQueue, MQ_Q_NAME_LENGTH);
  //  strncpy(snd_que_name, "hejsanqqq", sizeof(MQ_Q_NAME_LENGTH));

  /* Initialize object descriptor control block */

  strncpy(SndObjDesc.ObjectName, snd_que_name, MQ_Q_NAME_LENGTH);

  /* open queue for output but not if MQM stopping */

  SndOpenOptions =  MQOO_OUTPUT | MQOO_FAIL_IF_QUIESCING;
  
  errh_SetStatus(PWR__SRUN);
  
  /* Connect and open */

  sts = wmq_connectandopen();

  /* Set (re)start time in remnode object */
  
  time_GetTime(&rn_wmq->RestartTime);
  
  /* Loop forever */

  while (!doomsday) {
    if (rn_wmq->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    aproc_TimeStamp(TIME_INCR, 5);
    RemoteSleep(TIME_INCR);

    time_since_scan += TIME_INCR;

    if (!connected) 
      sts = wmq_connectandopen();

    if (connected) {
      sts = wmq_receive();

      if (time_since_scan >= rn_wmq->ScanTime) {
	sts = RemTrans_Cyclic(&rn, &wmq_send);
	time_since_scan = 0.0;
      }
    }
  }
}
int main(int argc, char *argv[]) /*argv[2]=remnode name*/
{
  unsigned int sts;			/* Status from function calls etc. */
  unsigned char id[32];
  unsigned char pname[32];
  remtrans_item *remtrans;
  int i;
  char first;
  pssupd_buffer_vnet buff;		/* Buffer for 'hello' */
  pssupd_order_header *header;		/* Header for 'hello' */
  char name[80];

  /* Read arg number 2, should be id for this instance */

  if (argc >= 2)
    strcpy((char *) id, argv[1]);
  else
    strcpy((char *) id, "0");
    
  /* Build process name with id */

  sprintf((char *) pname, "rs_rem3964r_%s", id);

  /* Init of errh */

  errh_Init((char *) pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);

  /* Init of gdh */

  sts = gdh_Init((char *) pname);
  if ( EVEN(sts)) {
    errh_Error("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Arg number 3 should be my remnodes objid in string representation,
     read it, convert to real objid and store in remnode_item */

  sts = 0;
  if (argc >= 3) sts = cdh_StringToObjid(argv[2], &rn.objid);
  if ( EVEN(sts)) {
    errh_Error("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Get pointer to Remnode3964R object and store locally */
  
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress *) &rn_3964R);
  if ( EVEN(sts)) {
    errh_Error("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  /* Get name of object to use in sending poll */
  
  sts = gdh_ObjidToName(rn.objid, name, sizeof(name), cdh_mName_object);
  name[3] = 'P';
  name[4] = 'S';
  name[5] = 'S';
  name[6] = 0;
  RemUtils_AsciiToR50((char *) &name, (short *) &poll_id);
  
  if (debug) printf("%s, %d %d\n", name, poll_id[0], poll_id[1]);  
      
  /* Initialize some internal data and make standard remtrans init */

  rn.next = NULL;
  rn.local = NULL;		// We dont use local structure since we only have one remnode
  rn.retransmit_time = 10.0;	// Not used, but initialize anyway
  rn_3964R->ErrCount = 0;

  sts = RemTrans_Init(&rn);
  
  if ( EVEN(sts)) {
    errh_Error("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  sts = RemIO_Init_3964R(&rn);

  if ( EVEN(sts)) {
    errh_Error("RemIO_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
  
  if (rn.remio_data == NULL) 
    use_remote_io = 0;
  else
    use_remote_io = 1;  

  time_since_poll = 0.0;
  time_since_io = 0.0;
  time_since_scan = 0.0;

  /* Store remtrans objects objid in remnode_3964R object */
  remtrans = rn.remtrans;
  i = 0;
  while(remtrans) {
    rn_3964R->RemTransObjects[i++] = remtrans->objid;
    if ( i >= (int)(sizeof(rn_3964R->RemTransObjects)/sizeof(rn_3964R->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item *) remtrans->next;
  }

  /* Initialize device */

  ser_fd = RemUtils_InitSerialDev(rn_3964R->DevName, 
  				  rn_3964R->Speed, 
				  rn_3964R->DataBits,
				  rn_3964R->StopBits,
				  rn_3964R->Parity);
				  
  if (!ser_fd) {
    errh_Error("InitDev, %d", ser_fd);
    errh_SetStatus(PWR__SRVTERM);
    exit(0);
  }    

  first = TRUE;
  rn_3964R->LinkUp = 1;
  
  /* Loop forever */

  while (1)
  {

    if (rn_3964R->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }   
    
    // Wait micro time  
    // Wait cycle time
//    timer = (int) (rn_3964R->ScanTime * 1000000.0);
    usleep(30000);
    
    Receive();
    
//    time_since_poll += rn_3964R->ScanTime;
//    time_since_io += rn_3964R->ScanTime;
    time_since_poll += 0.03;
    time_since_io += 0.03;
    time_since_scan += 0.03;

    if (first && use_remote_io) {
      /* Send Hello to subsystem if we have poll */
      header = (pssupd_order_header *) &buff.data;
      header->type = PSS_Switch_Done;
      header->size = 0;
      header->signal = 0;
      buff.no_of_updates = 1;
      buff.length = (sizeof(pssupd_buffer_vnet) -
      MAX_ORDER_BUFFERSIZE_VNET + sizeof(pssupd_order_header) + 1) / 2;
      send_pollbuff(&rn, &buff);
    }
        
//    if (debug) printf("Remtrans Cyclic\n");
    if (time_since_scan >= rn_3964R->ScanTime) {
      if (debug) printf("Remtrans Cyclic\n");
      RemTrans_Cyclic(&rn, &remnode_send);
      time_since_scan = 0.0;
    }

    if (use_remote_io) {
    
      if ((rn_3964R->LinkUp && time_since_poll >= rn_3964R->ScanTime*2.0) ||
          (!rn_3964R->LinkUp && time_since_poll >= rn_3964R->ScanTime*10.0))
      {
        if (debug) printf("RemIO Cyclic\n");
        sts = RemIO_Cyclic_3964R(&rn, &send_pollbuff);
        time_since_poll = 0.0;
      }

      if (time_since_io >= rn_3964R->LinkTimeout && rn_3964R->LinkTimeout > 0) {
        if (debug) printf("RemIO Stall\n");
        sts = RemIO_Stall_3964R(&rn, stall_action);
      }
    }

    first = FALSE;    
  }
}
Exemple #5
0
int main(int argc, char* argv[])
{
  remtrans_item* remtrans;
  unsigned char id[32];
  unsigned char pname[32];
  pwr_tStatus sts;
  int i;
  float time_since_scan = 0.0;

  /* Read arg number 2, should be id for this instance and id is our queue
   * number */

  if (argc >= 2)
    strcpy((char*)id, argv[1]);
  else
    strcpy((char*)id, "0");

  /* Build process name with id */

  sprintf((char*)pname, "rs_remrabbitmq_%s", id);

  /* Init of errh */

  errh_Init((char*)pname, errh_eAnix_remote);
  errh_SetStatus(PWR__SRVSTARTUP);

  /* Init of gdh */
  if (debug)
    printf("Before gdh_init\n");
  sts = gdh_Init((char*)pname);
  if (EVEN(sts)) {
    errh_Fatal("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Arg number 3 should be my remnodes objid in string representation,
     read it, convert to real objid and store in remnode_item */

  sts = 0;
  if (argc >= 3)
    sts = cdh_StringToObjid(argv[2], &rn.objid);
  if (EVEN(sts)) {
    errh_Fatal("cdh_StringToObjid, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Get pointer to RemnodeRabbitMQ object and store locally */
  sts = gdh_ObjidToPointer(rn.objid, (pwr_tAddress*)&rn_rmq);
  if (EVEN(sts)) {
    errh_Fatal("cdh_ObjidToPointer, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  if (streq(rn_rmq->ReceiveQueue, "")
      && streq(rn_rmq->SendQueue, "")) {
    errh_Fatal(
        "Process terminated, neither send or receive queue configured, %s", id);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Create context */
  ctx = calloc(1, sizeof(*ctx));
  ctx->op = rn_rmq;
  if (!streq(rn_rmq->ReceiveQueue, ""))
    ctx->is_consumer = 1;
  if (!streq(rn_rmq->SendQueue, ""))
    ctx->is_producer = 1;

  /* Initialize some internal data and make standard remtrans init */

  rn.next = NULL;
  rn.local = NULL; // We dont use local structure since we only have one remnode
  rn_rmq->ErrCount = 0;
  if (debug)
    printf("Before remtrans_init\n");

  sts = RemTrans_Init(&rn);

  if (EVEN(sts)) {
    errh_Fatal("RemTrans_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Store remtrans objects objid in remnode_qcom object */
  remtrans = rn.remtrans;
  i = 0;
  while (remtrans) {
    rn_rmq->RemTransObjects[i++] = remtrans->objid;
    if (i >= (int)(sizeof(rn_rmq->RemTransObjects)
                 / sizeof(rn_rmq->RemTransObjects[0])))
      break;
    remtrans = (remtrans_item*)remtrans->next;
  }

  /* Connect to rabbitmq broker */
  sts = rmq_connect();
  if (EVEN(sts)) {
    rmq_close(1);
    errh_Fatal("Process terminated, unable to connect to RabbitMQ, %s", id);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  /* Set running status */

  errh_SetStatus(PWR__SRUN);

  /* Set (re)start time in remnode object */

  time_GetTime(&rn_rmq->RestartTime);

  /* Loop forever */

  while (!doomsday) {
    if (rn_rmq->Disable == 1) {
      errh_Fatal("Disabled, exiting");
      errh_SetStatus(PWR__SRVTERM);
      exit(0);
    }
    aproc_TimeStamp(TIME_INCR, 5);

    if (ctx->is_consumer)
      sts = rmq_receive();
    else
      RemoteSleep(TIME_INCR);

    time_since_scan += TIME_INCR;
    if (time_since_scan >= rn_rmq->ScanTime) {
      if (ctx->is_producer)
        sts = RemTrans_Cyclic(&rn, &rmq_send);
      time_since_scan = 0.0;
    }
  }
}