F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
TlmChanImplRecv.cpp
Go to the documentation of this file.
1 /*
2  * TelemChanImpl.cpp
3  *
4  * Created on: Mar 28, 2014
5  * Author: tcanham
6  */
7 
9 #include <cstring>
10 #include <Fw/Types/BasicTypes.hpp>
11 #include <Fw/Types/Assert.hpp>
12 
13 #include <stdio.h>
14 
15 namespace Svc {
16 
17  void TlmChanImpl::TlmRecv_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) {
18 
19  // Compute index for entry
20 
21  NATIVE_UINT_TYPE index = this->doHash(id);
22  TlmEntry* entryToUse = 0;
23  TlmEntry* prevEntry = 0;
24 
25  // Search to see if channel has already been stored or a bucket needs to be added
26  if (this->m_tlmEntries[this->m_activeBuffer].slots[index]) {
27  entryToUse = this->m_tlmEntries[this->m_activeBuffer].slots[index];
28  for (NATIVE_UINT_TYPE bucket = 0; bucket < TLMCHAN_HASH_BUCKETS; bucket++) {
29  if (entryToUse) {
30  if (entryToUse->id == id) { // found the matching entry
31  break;
32  } else { // try next entry
33  prevEntry = entryToUse;
34  entryToUse = entryToUse->next;
35  }
36  } else {
37  // Make sure that we haven't run out of buckets
38  FW_ASSERT(this->m_tlmEntries[this->m_activeBuffer].free < TLMCHAN_HASH_BUCKETS);
39  // add new bucket from free list
40  entryToUse = &this->m_tlmEntries[this->m_activeBuffer].buckets[this->m_tlmEntries[this->m_activeBuffer].free++];
41  prevEntry->next = entryToUse;
42  // clear next pointer
43  entryToUse->next = 0;
44  break;
45  }
46  }
47  } else {
48  // Make sure that we haven't run out of buckets
49  FW_ASSERT(this->m_tlmEntries[this->m_activeBuffer].free < TLMCHAN_HASH_BUCKETS);
50  // create new entry at slot head
51  this->m_tlmEntries[this->m_activeBuffer].slots[index] = &this->m_tlmEntries[this->m_activeBuffer].buckets[this->m_tlmEntries[this->m_activeBuffer].free++];
52  entryToUse = this->m_tlmEntries[this->m_activeBuffer].slots[index];
53  entryToUse->next = 0;
54  }
55 
56  // copy into entry
57  FW_ASSERT(entryToUse);
58  entryToUse->used = true;
59  entryToUse->id = id;
60  entryToUse->updated = true;
61  entryToUse->lastUpdate = timeTag;
62  entryToUse->buffer = val;
63 
64  }
65 }
Fw::Time
Definition: Time.hpp:10
TlmChanImpl.hpp
Component that stores telemetry channel values.
Svc::TlmChanImpl::TlmEntry
struct Svc::TlmChanImpl::tlmEntry TlmEntry
Fw::TlmBuffer
Definition: TlmBuffer.hpp:21
FwChanIdType
#define FwChanIdType
Type representation for a channel id.
Definition: FpConfig.hpp:66
Svc::TlmChanImpl::TlmSet::free
NATIVE_INT_TYPE free
next free bucket
Definition: TlmChanImpl.hpp:63
Svc::TlmChanImpl::id
PRIVATE FwChanIdType id
Definition: TlmChanImpl.hpp:40
Svc::TlmChanImpl::m_activeBuffer
U32 m_activeBuffer
Definition: TlmChanImpl.hpp:66
Svc::TlmChanImpl::TlmSet::slots
TlmEntry * slots[TLMCHAN_NUM_TLM_HASH_SLOTS]
set of hash slots in hash table
Definition: TlmChanImpl.hpp:61
Assert.hpp
Svc::TlmChanImpl::val
PRIVATE FwChanIdType Fw::Time Fw::TlmBuffer & val
Definition: TlmChanImpl.hpp:40
NATIVE_UINT_TYPE
unsigned int NATIVE_UINT_TYPE
native unsigned integer type declaration
Definition: BasicTypes.hpp:30
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Svc
Definition: ActiveLoggerComponentAc.cpp:22
Svc::TlmChanImpl::tlmEntry::next
tlmEntry * next
pointer to next bucket in table
Definition: TlmChanImpl.hpp:55
BasicTypes.hpp
Declares ISF basic types.
Svc::TlmChanImpl::TlmSet::buckets
TlmEntry buckets[TLMCHAN_HASH_BUCKETS]
set of buckets used in hash table
Definition: TlmChanImpl.hpp:62
Svc::TlmChanImpl::m_tlmEntries
struct Svc::TlmChanImpl::TlmSet m_tlmEntries[2]
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Svc::TlmChanImpl::timeTag
PRIVATE FwChanIdType Fw::Time & timeTag
Definition: TlmChanImpl.hpp:40