• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2024, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef OT_NEXUS_CORE_HPP_
30 #define OT_NEXUS_CORE_HPP_
31 
32 #include "common/owning_list.hpp"
33 #include "instance/instance.hpp"
34 
35 #include "nexus_alarm.hpp"
36 #include "nexus_radio.hpp"
37 #include "nexus_utils.hpp"
38 
39 namespace ot {
40 namespace Nexus {
41 
42 class Node;
43 
44 class Core
45 {
46 public:
47     Core(void);
48     ~Core(void);
49 
Get(void)50     static Core &Get(void) { return *sCore; }
51 
52     Node             &CreateNode(void);
GetNodes(void)53     LinkedList<Node> &GetNodes(void) { return mNodes; }
54 
GetNow(void)55     TimeMilli GetNow(void) { return mNow; }
56     void      AdvanceTime(uint32_t aDuration);
57 
58     //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59     // Used by platform implementation
60 
SetActiveNode(Node * aNode)61     void  SetActiveNode(Node *aNode) { mActiveNode = aNode; }
GetActiveNode(void)62     Node *GetActiveNode(void) { return mActiveNode; }
63 
64     void UpdateNextAlarmTime(const Alarm &aAlarm);
MarkPendingAction(void)65     void MarkPendingAction(void) { mPendingAction = true; }
66 
67 private:
68     static constexpr int8_t kDefaultRxRssi = -20;
69 
70     enum AckMode : uint8_t
71     {
72         kNoAck,
73         kSendAckNoFramePending,
74         kSendAckFramePending,
75     };
76 
77     void Process(Node &aNode);
78     void ProcessRadio(Node &aNode);
79 
80     static Core *sCore;
81 
82     OwningList<Node> mNodes;
83     uint16_t         mCurNodeId;
84     bool             mPendingAction;
85     TimeMilli        mNow;
86     TimeMilli        mNextAlarmTime;
87     Node            *mActiveNode;
88 };
89 
90 void Log(const char *aFormat, ...);
91 
92 } // namespace Nexus
93 } // namespace ot
94 
95 #endif // OT_NEXUS_CORE_HPP_
96