Exemplo n.º 1
0
void    SafeTransitExecute3(void)
{
uint    i;
uchar   j;

  if (bInBuff5 >= bPORTS)
    Result(bRES_BADADDRESS);
  else if (IsSlave(bInBuff5))
    Result(bRES_BADPORT);
  else if (IndexInBuff() <= 10)
    Result(bRES_BADDATA);
  else
  {
    SaveInBuff();
    iwInBuffSave = IndexInBuff();

    j = ibPort;

    ibPort = bInBuff5;

    cbHeaderBcc = bInBuff8;
    cwInBuffBcc = 0;

    InitPush(0);
    for (i=0; i<iwInBuffSave-11; i++) PushChar(mpbInBuffSave[i+9]);
    Query(bInBuff6+bInBuff7*0x100, iwInBuffSave-11, 1);

    InitWaitAnswer();

    while (1)
    {
      if (fKey == true) { mpSerial[ibPort] = SER_BADLINK; break; }

      ResetWatchdog();
      ShowWaitAnswer(1);
      if (GetWaitAnswer()) { mpSerial[ibPort] = SER_BADLINK; break; }

      if (mpSerial[ibPort] == SER_INPUT_MASTER)
        DecompressK(0);

      if (mpSerial[ibPort] == SER_POSTINPUT_MASTER)
        break;
      else if ((mpSerial[ibPort] == SER_OVERFLOW) ||
               (mpSerial[ibPort] == SER_BADLINK)) break;
    }

    MonitorIn();

    SaveInBuff();
    iwInBuffSave = IndexInBuff();

    mpSerial[ibPort] = SER_BEGIN;
    ibPort = j;

    InitPushCRC();
    if (iwInBuffSave > 0)
      for (i=0; i<iwInBuffSave; i++) PushChar(mpbInBuffSave[i]);
    Output(iwInBuffSave);
  }
}
Exemplo n.º 2
0
void    SafeTransitExecute2(void)
{
uint    i;
uchar   j;

  if (bInBuff5 >= bPORTS)
    Result(bRES_BADADDRESS);
  else if (IsSlave(bInBuff5))
    Result(bRES_BADPORT);
  else if (IndexInBuff() <= 10)
    Result(bRES_BADDATA);
  else
  {
    SaveInBuff();
    iwInBuffSave = IndexInBuff();

    j = ibPort;

    ibPort = bInBuff5;

    InitPush(0);
    for (i=0; i<iwInBuffSave-10; i++) PushChar(mpbInBuffSave[i+8]);
    Query(bInBuff6+bInBuff7*0x100, iwInBuffSave-10, 1);

    InitWaitAnswer();

    while (1)
    {
      if (fKey == true) { mpSerial[ibPort] = SER_BADLINK; break; }

      ResetWatchdog();
      ShowWaitAnswer(1);
      if (GetWaitAnswer()) { mpSerial[ibPort] = SER_BADLINK; break; }

      if (mpSerial[ibPort] == SER_POSTINPUT_MASTER)
        break;
      else if ((mpSerial[ibPort] == SER_OVERFLOW) ||
               (mpSerial[ibPort] == SER_BADLINK)) break;
    }

    if (mpSerial[ibPort] != SER_POSTINPUT_MASTER)
    {
      ibPort = j;
      Result(bRES_BADMODE);
    }
    else
    {
      mpSerial[ibPort] = SER_BADLINK;   // !!!
      SaveInBuff();
      iwInBuffSave = IndexInBuff();

      ibPort = j;

      InitPushCRC();
      for (i=0; i<iwInBuffSave; i++) PushChar(mpbInBuffSave[i]);
      Output(iwInBuffSave);
    }
  }
}
int TeleTaskProducer::PushTaskBatch() {
  int i;
  int n = 0;
  pthread_mutex_lock(&task_lock_); 
  if (fetch_time_str_.length() != 12) {
    LOG(INFO) << "please wait for the fetch time str";
    pthread_mutex_unlock(&task_lock_);
    return 0;
  }
  char buf[4];
  strcpy(buf, fetch_time_str_.c_str() + 10);
  int minute = atoi(buf);
  memset(buf, 0, sizeof(buf));
  strncpy(buf, fetch_time_str_.c_str() + 8, 2);
  int hour = atoi(buf);
   
  for (i = index_; i < index_ + BATCHNUMS && i < MAX_FETCH_INDEX; i++) {
    int minute_index = hour * 60 + minute;
    if (!IsSlave()) {
      CLEAR_SET(tele::GetShareMem(), minute_index, i);
    } else if (IS_SET(tele::GetShareMem(), minute_index, i)) {
      n++;
      continue;
    }
    TeleTask * task = TeleTaskFactory::BuildTask(i, token_str_, fetch_time_str_, TASK_NORMAL);
    if (!task) {
      n++;
      continue;
    }
      
    task->minute_index = minute_index;
    if (PushTask(task) < 0) {
      delete task;
      break;
    } else {
      n++;
    }
  }
  index_ += n;
  pthread_mutex_unlock(&task_lock_);
  if (n > 0) {
    pthread_cond_broadcast(&not_empty_);
  }
  return n;
}