Example #1
0
//--------------------------------------------------------------
//  Receive a message
//--------------------------------------------------------------
void CEngineStatus::GetEngineState()
{ state  = 0;
  CEngineData *data = (CEngineData *)emsg.voidData;
  if (0 == data)
  { Send_Message(&emsg);
    data = (CEngineData *)emsg.voidData;
    if (0 == data)  return;
  }
  //---Update internal state ----------------
  char est = data->EngState();
  state    = (est == mode);
  active   = (state != 0);
  return;
}
//-----------------------------------------------------------------------
//  Time Slice
//  when all dependents are OK, check the engine RPM
//-----------------------------------------------------------------------
void CGenerator::TimeSlice(float dT,U_INT FrNo)
{   CDependent::TimeSlice(dT, FrNo);
    if (!active)    return;
    //---Get engine RPM --------------------
    CEngineData *data = (CEngineData*)emsg.voidData;
    if (0 == data)
    {   Send_Message(&emsg);             // Querry engine
        data = (CEngineData*)emsg.voidData;
    }
    if (0 == data)
    {   active = false;
        state = 0;
        return;
    }
    //---Check enough RPM ----------------------
    bool rpm  = ((data->EngRPM() > loRG) && (data->EngRPM() < hiRG));
    active   &= rpm;
    return;
}
//-----------------------------------------------------------------------
//  Time Slice
//  when all dependents are OK, check the engine RPM
//-----------------------------------------------------------------------
void CAlternator::TimeSlice(float dT,U_INT FrNo)
{ CDependent::TimeSlice(dT, FrNo);
  //---Get engine RPM --------------------
  CEngineData *data = (CEngineData*)emsg.voidData;
  if (0 == data)
  { Send_Message(&emsg);             // Querry engine
    data = (CEngineData*)emsg.voidData;
  }
  if (0 == data)
  { active = false;
    state = 0;
    return;
  }
  //---Check enough RPM ----------------------
  bool rpm  = ((data->EngRPM() > loRg) && (data->EngRPM() < hiRg));
  active   &= rpm;
  //---Compute voltage ----------------------
  volt      = (data->EngRPM() - loRg) * vFac * state;
  if (volt > mvlt)  volt = mvlt;
  return;
}