0
void
ProducerNew2::OnInterest(std::shared_ptr<const ndn::Interest> interest)
{
  ndn::App::OnInterest(interest);
  //  auto milliseconds = ndn::time::steady_clock::now();

  auto now = boost::chrono::steady_clock::now().time_since_epoch();
  auto timeSinceEpoch = boost::chrono::duration_cast<boost::chrono::seconds> 
  (now).count();
  auto current_round = int(double(timeSinceEpoch)/15); //change the freq
  here


 //auto since_epoch = milliseconds.time_since_epoch();
 //auto secs = boost::chrono::duration_cast<nanoseconds> 
 (since_epoch).count();
 //  auto nanos = std::chrono::duration_cast<nanoseconds> 
 (milliseconds.time_since_epoch()).count();
//  ndn::time::milliseconds milliseconds = 
::ndn::time::duration_cast<::ndn::time::milliseconds> (now.time_since_epoch()); 
NS_LOG_DEBUG("Current time"<< now);
NS_LOG_DEBUG("Current time"<< timeSinceEpoch);
NS_LOG_DEBUG("Current round"<< current_round);

//  static const std::string content("hello world");
std::string content = {0};
content = boost::lexical_cast<std::string>(current_round);
NS_LOG_DEBUG("Content"<< content << "length" << content.length());

auto data = std::make_shared<ndn::Data>(interest->getName());
data->setFreshnessPeriod(ndn::time::milliseconds(1000));
data->setContent(reinterpret_cast<const uint8_t*>(content.data()), 
content.length());
//  data->setContent(reinterpret_cast<const uint8_t*>(content.data()), 
content.size());
ndn::StackHelper::getKeyChain().sign(*data);

NS_LOG_DEBUG("Sending Data packet for " << data->getName());
m_transmittedDatas(data, this, m_face);
m_appLink->onReceiveData(*data);
}

Is there any way to print the sequence number for each round of frequency on line 9? Basically, when I run the block of code it is supposed to give me the round number as well as the sequence number, e.g. rounds 1-20 would be sequence 1, rounds 21-40 would be sequence 2 and so forth.

cigien
  • 57,834
  • 11
  • 73
  • 112
  • I don't think I understand what you are trying to do. Why can't you just divide current_round by 20, rounding up? – jtbandes Sep 16 '20 at 17:46
  • So basically at round 10, I am supposed to show end of seq 1 and then beginning of round 11 would be seq 2 up until round 20. Like that. – Abrar Alam Sep 16 '20 at 22:42
  • So basically I am trying to print out the sequence number for each set of rounds, e.g. for rounds 1-20 would be seq 1, rounds 21-40 would be seq 2. so at round 20, it would show that seq 1 has ended and then at round 21 seq 2 has started like that. – Abrar Alam Sep 17 '20 at 18:05
  • I'm not sure if your question is about math or programming. You already have `current_round`. Maybe you are looking for `(current_round - 1) / 20 + 1` ? – jtbandes Sep 17 '20 at 18:16
  • My question is about a simple arithmetic but I am not sure how to implement it in programming. what is (current_round - 1) / 20 + 1 – Abrar Alam Sep 17 '20 at 20:22
  • What's your topology? What are you trying to accomplish with rounds? Why are you calculating the sequence number in the producer and not in the consumer? Please edit your question to add more details and background info – thenewjames Sep 20 '20 at 14:54

0 Answers0