Gocator API
GoAcceleratorMgr.h
Go to the documentation of this file.
1 /**
2  * @file GoAcceleratorMgr.h
3  * @brief Declares the GoAcceleratorMgr class public interfaces.
4  *
5  * @internal
6  * Copyright (C) 2018-2025 by LMI Technologies Inc.
7  * Licensed under the MIT License.
8  * Redistributed files must retain the above copyright notice.
9  *
10  * The SDK Accelerator Manager object allows SDK clients to accelerate more than
11  * one sensor within a single platform. SDK client can build its own accelerator
12  * application using the SDK Accelerator Manager. The SDK Accelerator Manager
13  * provides a mechanism for the SDK client to receive event updates from the
14  * Accelerator Manager.
15  *
16  * A brief description of how to use the SDK Accelerator Manager follows.
17  * Note the description omits error checking and parameters to focus on the
18  * call sequences.
19  *
20  * A. Initializing the Accelerator Manager.
21  * Here is sample code showing how to initialize the Accelerator Manager and how
22  * to start it running.
23  *
24  * kStatus kCall MyApp_UpdateHandler(MyAppClass MyApp, kPointer caller, GoAcceleratorMgrAccelUpdate* update)
25  * {
26  * printf(
27  * "Sensor %u event - %d\n",
28  * update->sensorId,
29  * update->accelEvent);
30  * }
31  *
32  * // Construct the Accelerator Manager.
33  * GoAcceleratorMgr_Construct();
34  *
35  * // Accelerator logging is disabled by default.
36  * // Enable default GoXProcess logger.
37  * // If a sensor is currently accelerated, this will have no effect for that sensor.
38  * GoAcceleratorMgr_EnableLogging(kTRUE);
39  *
40  * // Set up the update handler so the SDK client can receive events
41  * // from the Accelerator Manager. This step is optional.
42  * GoAcceleratorMgr_SetAccelUpdateHandler(MyApp_UpdateHandler, MyApp);
43  *
44  * // Must give the Accelerator Manager the system object before starting it.
45  * GoSystem system = kNULL;
46  *
47  * GoSystem_Construct(&system, ...);
48  * GoAcceleratorMgr_SetSystem(system);
49  *
50  * // Now start the Accelerator Manager.
51  * GoAcceleratorMgr_Start();
52  *
53  * // Set the range of port numbers any time as long as no sensor is configured
54  * // for acceleration. This is an optional step to change the default
55  * // range. See the section on changing the port range for more details.
56  * GoAcceleratorMgr_SetPortRange(startPort, endPort);
57  *
58  * B. Accelerating a Sensor.
59  *
60  * // Set up the parameters in a GoAcceleratorMgrSensorParam structure and
61  * // call the accelerate interface.
62  * GoAcceleratorMgrSensorParam param;
63  * k32u sensorId = 12345;
64  *
65  * if (useAutomaticAllocation)
66  * {
67  * param.ports.controlPort = 0;
68  * param.ports.upgradePort = 0;
69  * param.ports.healthPort = 0;
70  * param.ports.privateDataPort = 0;
71  * param.ports.publicDataPort = 0;
72  * param.ports.webPort = 0;
73  * }
74  * else
75  * {
76  * // Manually specify ports that the SDK client is allowed to set up
77  * // TCP/IP connections through a network to the accelerated sensor.
78  * // This example assumes ports 4000 and up are available for use.
79  * param.ports.controlPort = 4000;
80  * param.ports.upgradePort = 4001;
81  * param.ports.healthPort = 4002;
82  * param.ports.privateDataPort = 4003;
83  * param.ports.publicDataPort = 4004;
84  * param.ports.webPort = 4005;
85  * }
86  * // Assume okay to use any IPv4 address (ie. 0.0.0.0).
87  * // Otherwise choose one of the accelerator platform's network interface
88  * // IP address.
89  * param.platforIpAddress = kIpAddress_AnyV4();
90  *
91  * GoAcceleratorMgr_Accelerate(sensorId, &param);
92  *
93  * C. Decelerating (Unaccelerating) a Sensor.
94  *
95  * k32u sensorId = 12345;
96  *
97  * GoAcceleratorMgr_Decelerate(sensorId);
98  *
99  * D. Get the List of Sensors Managed by the Accelerator Manager.
100  *
101  * kArrayList sensorList = kNULL;
102  *
103  * kArrayList_Construct(&sensorList, kTypeOf(GoAcceleratorMgrSensorInfo), 0, kObject_Alloc(myApp));
104  * GoAcceleratorMgr_ListSensors(sensorList);
105  *
106  * E. Get the port range limits and change the port range.
107  *
108  * k16u startLimit;
109  * k16u endLimit;
110  * k16u minNumPorts;
111  * k16u userStartPort;
112  * k16u userEndPort;
113  *
114  * // Some code initializes userStartPort and userEndPort.
115  * userStartPort = 4000;
116  * userEndPort = 4010;
117  *
118  * // Get the min and max values of the port range and the minimum number
119  * // of ports within the port range to help with user configuration
120  * // validation.
121  * GoAcceleratorMgr_GetPortRangeLimits(startLimit, endLimit, minNumPorts);
122  *
123  * if ((userStartPort >= startLimit) && (userEndPort <= endLimit) &&
124  * ((userEndPort - userStartPort + 1) >= minNumPorts)
125  * {
126  * GoAcceleratorMgr_SetPortRange(userStartPort, userEndPort);
127  * }
128  * else
129  * {
130  * printf("Invalid user port range\n");
131  * }
132  *
133  * F. Get current port range.
134  *
135  * k16u startPort;
136  * k16u endPort;
137  *
138  * GoAcceleratorMgr_GetPortRange(&startPort, &endPort);
139  *
140  * G. Get the number of sensors managed by the Accelerator Manager.
141  *
142  * if (GoAcceleratorMgr_AccelSensorCount() > 0)
143  * {
144  * printf("Sensors configured for acceleration\n");
145  * }
146  * else
147  * {
148  * printf("No sensors configured for acceleration\n");
149  * }
150  *
151  */
152 #ifndef GO_ACCELERATOR_MGR_H
153 #define GO_ACCELERATOR_MGR_H
154 
155 #include <GoSdk/GoSdk.h>
156 // Don't know why need to explicitly include GoSystem header file again
157 // here when GoSdk.h already includes it. If this is not done, compile fails
158 // to find GoSystem declaration!?
159 #include <GoSdk/GoSystem.h>
161 
162 /**
163  * @class GoAcceleratorMgr
164  * @extends kObject
165  * @ingroup GoSdk
166  * @brief Represents an GoAcceleratorMgr instance.
167  */
168 typedef kObject GoAcceleratorMgr;
169 
170 /**
171 * @class GoAcceleratorMgr
172 * @extends kValue
173 * @ingroup GoSdk
174 * @brief Represents an GoAcceleratorMgr events passed into the acceleration
175 * update callback handler bound in by SDK client.
176 * Meaning of the events are:
177 * - GO_ACCELERATOR_MGR_EVENT_ACCELERATING - Sensor acceleration is in progress.
178 * - GO_ACCELERATOR_MGR_EVENT_ACCELERATED: - Sensor is accelerated successfully.
179 * - GO_ACCELERATOR_MGR_EVENT_DECELERATING: - Sensor deceleration is in progress.
180 * - GO_ACCELERATOR_MGR_EVENT_DECELERATED: - Sensor is no longer accelerated.
181 * - GO_ACCELERATOR_MGR_EVENT_STOPPED: - Sensor acceleration stopped or failed to start.
182 * - GO_ACCELERATOR_MGR_EVENT_DISCONNECTED: - Accelerated sensor is disconnected from network.
183 * - GO_ACCELERATOR_MGR_EVENT_PROCESS_STOPPED: - Special case for the STOPPED event to indicate acceleration
184 * was in progress but terminated unexpectedly.
185 * This stop reason differs from other stop reasons,
186 * such as firmware mismatch etc.
187 */
188 typedef enum GoAcceleratorMgrAccelEvents
189 {
190  GO_ACCELERATOR_MGR_EVENT_ACCELERATING = 0,
191  GO_ACCELERATOR_MGR_EVENT_ACCELERATED,
192  GO_ACCELERATOR_MGR_EVENT_DECELERATING,
193  GO_ACCELERATOR_MGR_EVENT_DECELERATED,
194  GO_ACCELERATOR_MGR_EVENT_STOPPED,
195  GO_ACCELERATOR_MGR_EVENT_DISCONNECTED,
196  GO_ACCELERATOR_MGR_EVENT_PROCESS_STOPPED,
197  GO_ACCELERATOR_MGR_EVENT_TIME_DATE,
198 } GoAcceleratorMgrAccelEvents;
199 
200 /**
201 * @struct GoAcceleratorMgrAccelUpdate
202 * @extends kValue
203 * @ingroup GoSdk
204 * @brief Structure to hold data for the acceleration update handler.
205 */
207 {
208  k32u sensorId;
209  GoAcceleratorMgrAccelEvents accelEvent;
211 
212 /**
213 * @struct GoAcceleratorMgrSensorParam
214 * @extends kValue
215 * @ingroup GoSdk
216 * @brief Structure to hold user configuration parameters from SDK client
217 * for a sensor that is to be accelerated.
218 */
220 {
221  GoAccelSensorPortAllocPorts ports;
222  kIpAddress platformIpAddress; // Bind an accelerated sensor to this accelerator host interface IP address.
224 
225 /**
226 * @struct GoAcceleratorMgrSensorBackup
227 * @extends kValue
228 * @ingroup GoSdk
229 * @brief Structure to provide the original unaccelerated sensor information to the SDK client.
230 * This is useful for reaching the sensor object while it is being accelerated, or
231 * if there are errors during acceleration, or after stopping acceleration.
232 */
233 typedef struct GoAcceleratorMgSensorBackup
234 {
235  GoAccelSensorPortAllocPorts ports;
236  GoAddressInfo sensorAddressInfo;
238 
239 /**
240 * @struct GoAcceleratorMgrSensorInfo
241 * @extends kValue
242 * @ingroup GoSdk
243 * @brief Structure to return accelerated sensor information to SDK client.
244 * The param field contains information received from the SDK client, except if
245 * SDK client requested automatic port selection. In this case, the ports in the
246 * param field are the ports selected by the SDK for the SDK client.
247 */
249 {
250  k32u sensorId;
251  GoSensorAccelStatus status;
255 
256 /**
257 * Constructs the accelerator manager object
258 *
259 * @public @memberof GoAcceleratorMgr
260 * @version Introduced in firmware 5.2.18.3
261 * @param manager Address of uninitialized manager object.
262 * @param allocator Allocator object (kNULL for fallback allocator).
263 * @return Operation status.
264 */
265 GoFx(kStatus) GoAcceleratorMgr_Construct(GoAcceleratorMgr* manager, kAlloc allocator);
266 
267 /**
268 * Assigns the SDK GoSystem object to the accelerator manager object. This must be
269 * done before starting the accelerator manager.
270 *
271 * @public @memberof GoAcceleratorMgr
272 * @version Introduced in firmware 5.2.18.3
273 * @param manager GoAcceleratorMgr object.
274 * @param system Instance of GoSystem
275 * @return Operation status.
276 */
278 
279 /**
280 * Starts the accelerator manager object after it has been configured.
281 *
282 * @public @memberof GoAcceleratorMgr
283 * @version Introduced in firmware 5.2.18.3
284 * @param manager GoAcceleratorMgr object.
285 * @return Operation status.
286 */
288 
289 /**
290 * Accelerate the specified sensor with the given set of parameters.
291 * The parameter structure contains the accelerator host IP address to
292 * associate with the accelerated sensor, and the ports the accelerated
293 * sensor should use to communicate with the SDK client.
294 * If the SDK client wishes to have the GoAcceleratorMgr dynamically/automatically
295 * allocate the port numbers from within the configured port range,
296 * the SDK client must set all the ports in the parameter structure to
297 * zero (0).
298 * Any non-zero value for a port in the port parameter list is treated
299 * as if the client is providing ALL the port numbers to use. If the
300 * client provided port numbers are valid, then they will be used by
301 * the accelerated sensor.
302 * The "param" structure is modified to store actual ports selected if
303 * SDK client chose dynamic/automatic port allocation.
304 *
305 * @public @memberof GoAcceleratorMgr
306 * @version Introduced in firmware 5.2.18.3
307 * @param manager GoAcceleratorMgr object.
308 * @param sensorId Identifier of the sensor.
309 * @param param Pointer to parameter structure for accelerating the sensor.
310 * @return Operation status.
311 */
313 
314 /**
315 * Decelerate (unaccelerate) a sensor.
316 *
317 * @public @memberof GoAcceleratorMgr
318 * @version Introduced in firmware 5.2.18.3
319 * @param manager GoAcceleratorMgr object.
320 * @param sensorId Identifier of the sensor.
321 * @return Operation status.
322 */
324 
325 /**
326 * Get a list of accelerated sensors. The list is returned in an array list
327 * of GoAcceleratorMgrSensorInfo. Caller must construct the kArrayList and
328 * pass the it as an argument to this API. The API will fill this list.
329 *
330 * Each entry includes the set of ports used by the accelerated sensor.
331 * If the client had specified the ports to use, then the list entry's
332 * set of ports should be the same as the client specified ports.
333 * If the client had specified the Accelerator Manager dynamically
334 * allocate ports from the configured port range, then the list entry's
335 * set of ports contains the ports allocated to the sensor.
336 * The current acceleration status of the sensor is returned in the
337 * list entry for each sensor.
338 *
339 * @public @memberof GoAcceleratorMgr
340 * @version Introduced in firmware 5.2.18.3
341 * @param manager GoAcceleratorMgr object.
342 * @param sensorList Array list of GoAcceleratorMgrSensorInfo for each
343 * accelerated sensor.
344 * @return Operation status.
345 */
347 
348 /**
349 * Set up the update handler so that the SDK client can receive events
350 * from the Accelerator Manager about a sensor. This step is optional. If update handler
351 * is not bound in, then client will not receive any event notifications.
352 * Update handler is called with a pointer to GoAcceleratorMgrAccelUpdate which
353 * contains event information about a sensor.
354 * The update handler does not free the memory for the GoAcceleratorMgrAccelUpdate
355 * structure.
356 *
357 * @public @memberof GoAcceleratorMgr
358 * @version Introduced in firmware 5.2.18.3
359 * @param manager GoAcceleratorMgr object.
360 * @param function Update callback handler function.
361 * @param context SDK client context for the callback handler.
362 * It is a pointer to GoAcceleratorMgrAccelUpdate.
363 * @return Operation status.
364 */
365 GoFx(kStatus) GoAcceleratorMgr_SetAccelUpdateHandler(GoAcceleratorMgr manager, kCallbackFx function, kPointer context);
366 
367 /**
368 * Set the range of port numbers used to communicate with the accelerated
369 * sensors. Changes to the port range is allowed only if no sensor is
370 * configured for acceleration.
371 * Changing the port range is optional if the client application can use
372 * the default port range.
373 * The port numbers range must be within the port range limits (see
374 * GoAcceleratorMgr_GetPortRangeLimits()).
375 * Configure the port range if your network places limits on what ports are
376 * permitted for communication use or if some range of ports is known to be used
377 * by another application.
378 *
379 * @public @memberof GoAcceleratorMgr
380 * @version Introduced in firmware 5.2.18.3
381 * @param manager GoAcceleratorMgr object.
382 * @param startPort Starting port number in the range
383 * @param endPort Last port number in the range.
384 * @return Operation status.
385 */
386 GoFx(kStatus) GoAcceleratorMgr_SetPortRange(GoAcceleratorMgr manager, k16u startPort, k16u endPort);
387 
388 /**
389 * Get the range of port numbers to assign to accelerated sensors.
390 * The ports within the port range are used by the Accelerator Manager
391 * to allocate ports for the accelerated sensors.
392 *
393 * @public @memberof GoAcceleratorMgr
394 * @version Introduced in firmware 5.2.18.3
395 * @param manager GoAcceleratorMgr object.
396 * @param startPort Returns the starting port number in the range
397 * @param endPort Returns the last port number in the range.
398 * @return Operation status.
399 */
400 GoFx(kStatus) GoAcceleratorMgr_GetPortRange(GoAcceleratorMgr manager, k16u* startPort, k16u* endPort);
401 
402 /**
403 * Get the min and max values of the port range and the minimum number
404 * of ports within the port range. These limits are the default port range.
405 * The upper limit is set to just below the start of the ephemeral port
406 * range that are available for use by any network application.
407 *
408 * @public @memberof GoAcceleratorMgr
409 * @version Introduced in firmware 5.2.18.3
410 * @param manager GoAcceleratorMgr object.
411 * @param startLimit Returns the limit for the starting port number in the range
412 * @param endLimit Returns the limit for the last port number in the range.
413 * @param minNumPorts Returns the minimum number of ports that the range must support.
414 * @return Operation status.
415 */
416 GoFx(kStatus) GoAcceleratorMgr_GetPortRangeLimits(GoAcceleratorMgr manager, k16u* startLimit, k16u* endLimit, k16u* minNumPorts);
417 
418 /**
419 * Get the number of sensors which the accelerator manager has been configured
420 * to accelerate. The count includes sensors whose acceleration may have failed
421 * for whatever reason.
422 * This is a convenient interface to find out how many sensors have
423 * been configured without having to get the list of sensors. This count
424 * should match the number of successful calls to GoAcceleratorMgr_Accelerate()
425 * less successful calls to GoAcceleratorMgr_Decelerate().
426 *
427 * @public @memberof GoAcceleratorMgr
428 * @version Introduced in firmware 5.2.18.3
429 * @param manager GoAcceleratorMgr object.
430 * @return Number of sensors configured for acceleration.
431 */
433 
434 /**
435 * Checks whether default Gocator accelerator logger is enabled.
436 * Default logger will write data to file.
437 * Log filename: sensorId_GoXProcess.log
438 *
439 * @public @memberof GoAcceleratorMgr
440 * @version Introduced in firmware x.x.x.x
441 * @param manager GoAcceleratorMgr object.
442 * @return True, if default logging is enabled, false otherwise.
443 */
445 
446 /**
447 * Enables default Gocator accelerator logger.
448 * Log location: ./data/GoXProcess/
449 * Log filename: sensorId_GoXProcess.log
450 * Max size of single log file: 2 MB
451 * Max number of log files: 2
452 * Only 2 latest log files are kept. Older log files will be removed.
453 *
454 * @public @memberof GoAcceleratorMgr
455 * @version Introduced in firmware x.x.x.x
456 * @param manager GoAcceleratorMgr object.
457 * @param enabled Whether logger should be enabled or disabled.
458 * @return Operation status.
459 */
461 
462 #include <GoSdk/GoAcceleratorMgr.x.h>
463 
464 #endif // GO_ACCELERATOR_MGR_H
kStatus GoAcceleratorMgr_SetAccelUpdateHandler(GoAcceleratorMgr manager, kCallbackFx function, kPointer context)
Set up the update handler so that the SDK client can receive events from the Accelerator Manager abou...
Represents a system of Gocator devices.
kStatus GoAcceleratorMgr_EnableLogging(GoAcceleratorMgr manager, kBool enabled)
Enables default Gocator accelerator logger.
kStatus GoAcceleratorMgr_SetSystem(GoAcceleratorMgr manager, GoSystem system)
Assigns the SDK GoSystem object to the accelerator manager object.
Includes all Gocator SDK headers.
kStatus GoAcceleratorMgr_Construct(GoAcceleratorMgr *manager, kAlloc allocator)
Constructs the accelerator manager object.
kStatus GoAcceleratorMgr_Accelerate(GoAcceleratorMgr manager, k32u sensorId, GoAcceleratorMgrSensorParam *param)
Accelerate the specified sensor with the given set of parameters.
Structure to provide the original unaccelerated sensor information to the SDK client. This is useful for reaching the sensor object while it is being accelerated, or if there are errors during acceleration, or after stopping acceleration.
Definition: GoAcceleratorMgr.h:233
Declares the GoAccelSensorPortAlloc class.
kSize GoAcceleratorMgr_AccelSensorCount(GoAcceleratorMgr manager)
Get the number of sensors which the accelerator manager has been configured to accelerate.
kStatus GoAcceleratorMgr_ListSensors(GoAcceleratorMgr manager, kArrayList sensorList)
Get a list of accelerated sensors.
Structure to hold user configuration parameters from SDK client for a sensor that is to be accelerate...
Definition: GoAcceleratorMgr.h:219
kStatus GoAcceleratorMgr_Decelerate(GoAcceleratorMgr manager, k32u sensorId)
Decelerate (unaccelerate) a sensor.
Represents the acceleration status of a sensor that is available or being accelerated by the local ho...
kStatus GoAcceleratorMgr_GetPortRangeLimits(GoAcceleratorMgr manager, k16u *startLimit, k16u *endLimit, k16u *minNumPorts)
Get the min and max values of the port range and the minimum number of ports within the port range...
kStatus GoAcceleratorMgr_SetPortRange(GoAcceleratorMgr manager, k16u startPort, k16u endPort)
Set the range of port numbers used to communicate with the accelerated sensors.
Structure to return accelerated sensor information to SDK client. The param field contains informatio...
Definition: GoAcceleratorMgr.h:248
Structure to hold data for the acceleration update handler.
Definition: GoAcceleratorMgr.h:206
Declares the GoSystem class.
kStatus GoAcceleratorMgr_Start(GoAcceleratorMgr manager)
Starts the accelerator manager object after it has been configured.
kStatus GoAcceleratorMgr_GetPortRange(GoAcceleratorMgr manager, k16u *startPort, k16u *endPort)
Get the range of port numbers to assign to accelerated sensors.
kBool GoAcceleratorMgr_IsLoggingEnabled(GoAcceleratorMgr manager)
Checks whether default Gocator accelerator logger is enabled.
Represents an GoAcceleratorMgr instance.
Sensor network address settings.
Definition: GoSdkDef.h:845