Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_net.h
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
5 /* This program is free software: you can redistribute it and/or modify                           */
6 /* it under the terms of the GNU General Public License as published by                           */
7 /* the Free Software Foundation, either version 2 of the License, or                              */
8 /* (at your option) any later version.                                                            */
9 /*                                                                                                */
10 /* This program is distributed in the hope that it will be useful,                                */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
13 /* GNU General Public License for more details.                                                   */
14 /*                                                                                                */
15 /* You should have received a copy of the GNU General Public License                              */
16 /* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Internal header file of the Network Management.
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup G_NET
28  * @{
29  */
30
31 #ifndef UCS_NET_H
32 #define UCS_NET_H
33
34 /*------------------------------------------------------------------------------------------------*/
35 /* Includes                                                                                       */
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_base.h"
38 #include "ucs_inic.h"
39 #include "ucs_ret_pb.h"
40 #include "ucs_obs.h"
41 #include "ucs_fsm.h"
42
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47
48 /*------------------------------------------------------------------------------------------------*/
49 /* Enumerations                                                                                   */
50 /*------------------------------------------------------------------------------------------------*/
51 /*! \brief  Result codes of function Net_IsOwnAddress() */
52 typedef enum Net_IsOwnAddrResult_
53 {
54     NET_IS_OWN_ADDR_NODE,   /*!< \brief Is own node position address or own logical node address */
55     NET_IS_OWN_ADDR_GROUP,  /*!< \brief Is own group address */
56     NET_IS_OWN_ADDR_NONE    /*!< \brief Is foreign address */
57
58 } Net_IsOwnAddrResult_t;
59
60 /*------------------------------------------------------------------------------------------------*/
61 /* Structures                                                                                     */
62 /*------------------------------------------------------------------------------------------------*/
63 /*! \brief  Initialization structure of the attach service. */
64 typedef struct Net_InitData_
65 {
66     CBase *base_ptr;                /*!< \brief Reference to base instance */
67     CInic *inic_ptr;                /*!< \brief Reference to INIC instance */
68
69 } Net_InitData_t;
70
71 /*! \brief Parameter structure for MOST Network Status */
72 typedef struct Net_NetworkStatusParam_
73 {
74     /*! \brief Indicates if parameters have been changed since last update */
75     uint16_t change_mask;
76     /*! \brief Indicates if the MOST network is available and ready for control/packet
77                data transmission */
78     Ucs_Network_Availability_t availability;
79     /*! \brief Indicates the sub state to parameter Availability */
80     Ucs_Network_AvailInfo_t avail_info;
81     /*! \brief Indicates the transition cause of the MOST network going from Available to 
82                NotAvailable or vice versa */
83     Ucs_Network_AvailTransCause_t avail_trans_cause;
84     /*! \brief Contains events relating to the functionality for the MOST Network Interface */
85     uint16_t events;
86     /*! \brief Current size of packet bandwidth */
87     uint16_t packet_bw;
88     /*! \brief Current node address of the device */
89     uint16_t node_address;
90     /*! \brief Node position of the device */
91     uint8_t node_position;
92     /*! \brief Node position of last device in the ring */
93     uint8_t max_position;
94
95 } Net_NetworkStatusParam_t;
96
97 /*! \brief Structure holds the parameters of property INIC.MOSTNetworkStatus */
98 typedef struct Net_NetworkStatus_
99 {
100     /*! \brief Parameters of MOST Network Status */
101     Net_NetworkStatusParam_t param;
102     /*! \brief Observe MOST Network status in INIC module */
103     CObserver observer;
104     /*! \brief Subject to notify MOST Network Status the first time a observer has been added */
105     CSubject pre_subject;
106     /*! \brief Subject to notify MOST Network Status */
107     CSubject subject;
108
109 } Net_NetworkStatus_t;
110
111 /*! \brief Parameter structure for MOST Network Configuration */
112 typedef struct Net_NetworkConfigParam_
113 {
114     /*! \brief Indicates if parameters have been changed since last update */
115     uint16_t change_mask;
116     /*! \brief Current node address of the device */
117     uint16_t node_address;
118     /*! \brief Current group address of the device */
119     uint16_t group_address;
120     /*! \brief Low-level retry block count */
121     uint8_t llrbc;
122
123 } Net_NetworkConfigParam_t;
124
125 /*! \brief Structure holds the parameters of property INIC.MOSTNetworkConfiguration */
126 typedef struct Net_NetworkConfiguration_
127 {
128     /*! \brief Parameters of MOST Network Configuration */
129     Net_NetworkConfigParam_t param;
130     /*! \brief Observe MOST Network Configuration in INIC module */
131     CObserver observer;
132     /*! \brief Subject to notify MOST Network Configuration the first time a observer has been added */
133     CSubject pre_subject;
134     /*! \brief Subject to notify MOST Network Configuration */
135     CSubject subject;
136
137 } Net_NetworkConfiguration_t;
138
139 /*! \brief  Class structure of the Network Management. */
140 typedef struct CNetworkManagement_
141 {
142     /*! \brief Parameters of property INIC.MOSTNetworkStatus */
143     Net_NetworkStatus_t network_status;
144     /*! \brief Parameters of property INIC.MOSTNetworkConfig. */
145     Net_NetworkConfiguration_t network_configuration;
146     /*! \brief Reference to INIC instance */
147     CInic *inic_ptr;
148     /*! \brief Reference to base instance */
149     CBase *base_ptr;
150     /*! \brief Service instance for the scheduler */
151     CService net_srv;
152
153 } CNetworkManagement;
154
155 /*------------------------------------------------------------------------------------------------*/
156 /* Prototypes of class CNetworkManagement                                                         */
157 /*------------------------------------------------------------------------------------------------*/
158 extern void Net_Ctor(CNetworkManagement *self, Net_InitData_t *init_ptr);
159 extern void Net_AddObserverNetworkStatus(CNetworkManagement *self, CMaskedObserver *obs_ptr);
160 extern void Net_DelObserverNetworkStatus(CNetworkManagement *self, CMaskedObserver *obs_ptr);
161 extern void Net_AddObserverNetworkConfig(CNetworkManagement *self, CMaskedObserver *obs_ptr);
162 extern void Net_DelObserverNetworkConfig(CNetworkManagement *self, CMaskedObserver *obs_ptr);
163 extern Net_IsOwnAddrResult_t Net_IsOwnAddress(CNetworkManagement *self, uint16_t address);
164
165 #ifdef __cplusplus
166 }   /* extern "C" */
167 #endif
168
169 #endif  /* #ifndef UCS_NET_H */
170
171 /*!
172  * @}
173  * \endcond
174  */
175
176 /*------------------------------------------------------------------------------------------------*/
177 /* End of file                                                                                    */
178 /*------------------------------------------------------------------------------------------------*/
179