summaryrefslogtreecommitdiffstats
path: root/Src/Network/NetworkDevice.h
blob: 8f5b627d986878e8a0cbe95cb757edea454e55bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
/*
 * Video On Demand Samples
 *
 * Copyright (C) 2015 Microchip Technology Germany II GmbH & Co. KG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You may also obtain this software under a propriety license from Microchip.
 * Please contact Microchip for further information.
 *
 */

/*----------------------------------------------------------*/
/*! \file
 *  \brief  This file contains the CNetworkDevice class.
 */
/*----------------------------------------------------------*/
#ifndef _NETWORKDEVICE_H_
#define _NETWORKDEVICE_H_

#include <stdint.h>
#include <stdbool.h>
#include <semaphore.h>
#include "SafeVector.h"
#include "ScriptXml.h"
#include "Types.h"
#include "Thread.h"
#include "NetworkDeviceListener.h"
#include "IndustrialStack.h"
#include "IndustrialStack_Types.h"

typedef enum
{
    NetworkState_Unknown,
    NetworkState_Unavailable,
    NetworkState_Available,
    NetworkState_ShutdownInProgress
} NetworkState_t;

/*----------------------------------------------------------*/
/*! \brief This class represents an INIC instance.
 *         It will be multiple instanced, for each connected OS81118.
 *         It generates INIC requests and parses INIC responses.
 */
/*----------------------------------------------------------*/
class CNetworkDevice : public CThread, public CSInternalEvent
{
private:
    CIndustrialStack *iStack;
    CV1_OnMostRx *v1Events;
    CV3_OnMostRx *v3Events;
    bool promiscuous;
    NetworkState_t netState;
    void *pInic;
    void *pScriptMemoryArea;
    bool isRunning;
    bool isActionPending;
    uint8_t deviceIndex;
    uint8_t deviceApi;
    bool isTimingMaster;
    uint32_t asyncBandwidth;
    sem_t methodMutex;
    int controlEndpointRxHandle;
    int controlEndpointTxHandle;
    char *responseToWaitFor[64];
    char deviceNameControlRx[64];
    char deviceNameControlTx[64];
    CSafeVector<CNetworkDeviceListener *> allListeners;

    uint16_t startV3autoForced;
    uint16_t startV3packetBW;

    bool OpenDevice( const char *systemNameControlRx, const char *systemNameControlTx, const char *linkNameControlRx,
        const char *linkNameControlTx );
    bool OpenMostControlChannel( void );
    void CloseMostControlChannel( void );
    void WaitForIpcResponse( const char *responseMessage );
    void ExecuteMcmScript( uint16_t nodeAddress, CSciptXml *scriptXml );
public:
    /*----------------------------------------------------------*/
    /*! \brief Constructor of CNetworkDevice.
     *  \param deviceIndex - The index of the physical device instance of the server device.
     *                      Starting at 0 for the first device instance.
     *  \param deviceApi - 1: OS81092, OS81110; 2: OS81118-C-Rev; 3:OS81118-D-Rev 
     *  \param isTimingMaster - true, if this device shall act as timing master, otherwise it is timing slave
     *  \param asyncBandwidth - if set as timing master, how many bytes shall be reserved for the asynchronous channel
     *  \param promiscuousMode - true, promiscuous mode. false, perfect match filter with multicast and broadcast enabled. If enabled, tools like Wireshark will capture every packet.
     */
    /*----------------------------------------------------------*/
    CNetworkDevice( uint8_t deviceIndex, uint8_t deviceApi, bool isTimingMaster, uint32_t asyncBandwidth,
        bool promiscuousMode );


    /*----------------------------------------------------------*/
    /*! \brief Destructor of CNetworkDevice.
     */
    /*----------------------------------------------------------*/
    virtual ~CNetworkDevice();


    /*----------------------------------------------------------*/
    /*! \brief Function of background thread.
     *  \note Do never call this method. It is used by internal threads.
     */
    /*----------------------------------------------------------*/
    void Run();


    /*----------------------------------------------------------*/
    /*! \brief Opens the USB connection to the INIC.
     *  \param controlRxEndpointAddress - The USB endpoint address of the RX direction.
     *  \param controlTxEndpointAddress - The USB endpoint address of the TX direction.
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool OpenUsb( uint8_t controlRxEndpointAddress, uint8_t controlTxEndpointAddress );




    /*----------------------------------------------------------*/
    /*! \brief Opens the MLB connection to the INIC.
     *  \param controlRxChannelAddress - The MLB channel address of the RX direction.
     *  \param controlTxChannelAddress - The MLB channel address of the TX direction.
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool OpenMlb( uint8_t controlRxChannelAddress, uint8_t controlTxChannelAddress );


    /*----------------------------------------------------------*/
    /*! \brief Opens the I2C connection to the INIC.
     *  \param inicApi - INIC API Version
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool OpenI2C();


    /*----------------------------------------------------------*/
    /*! \brief Closes the USB connection to the INIC.
     */
    /*----------------------------------------------------------*/
    void Close();

    /*----------------------------------------------------------*/
    /*! \brief Returns the used API of the INIC.
     *  \return INIC API Version 1: OS81092, OS81110; 2: OS81118-C-Rev; 3:OS81118-D-Rev 
     */
    /*----------------------------------------------------------*/
    uint8_t GetDeviceApi();

    NetworkState_t GetNetState();
    void SetNetstate( NetworkState_t newState );
    void SetTimingMaster(bool tm);
    bool IsTimingMaster();
    void SetAsyncBandwidth(uint32_t bw);
    uint32_t GetAsyncBandwidth();

    /*----------------------------------------------------------*/
    /*! \brief Determines if there are jobs currently in the working queue.
     *  \note This method will block until the result is queried from the worker process.
     *  \return true, if there are pending actions enqueued.
     */
    /*----------------------------------------------------------*/
    bool ActionsPending();



    /*----------------------------------------------------------*/
    /*! \brief Remove all pending actions from the working queue.
     */
    /*----------------------------------------------------------*/
    void ClearAllPendingActions();



    /*----------------------------------------------------------*/
    /*! \brief Configure the Linux character device driver to handle an USB connection.
     *  \note This overloaded function is used to configure synchronous channels.
     *  \param aimType - Specifies the type of used Linux Driver Application Interface Module.
     *  \param endpointAddress - The USB endpoint address.
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param deviceName - On successful configuration, this method stores the name of the character device into the given buffer.
     *  \param deviceNameBufLen - The length of the given buffer.
     *  \param amountOfBuffers - The amount of buffers used in the driver.
     *  \param bufferSize - The amount of bytes used in a single buffer.
     *  \param subbufferSize - The amount of bytes used for a single subbuffer. For isoc channel this maybe 188 or 196 byte.
     *  \param packetsPerTransaction - The amount of packets per transaction.
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool ConfigureUsbEndpoint( AimType_t aimType, uint8_t endpointAddress, EPDataType_t epType, EPDirection_t epDir,
        char *deviceName, uint32_t deviceNameBufLen, uint32_t amountOfBuffers, uint32_t bufferSize,
        uint32_t subbufferSize, uint32_t packetsPerTransaction );



    /*----------------------------------------------------------*/
    /*! \brief Configure the Linux character device driver to handle an USB connection.
     *  \param endpointAddress - The USB endpoint address.
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param deviceName - On successful configuration, this method stores the name of the character device into the given buffer.
     *  \param deviceNameBufLen - The length of the given buffer.
     *  \param amountOfBuffers - The amount of buffers used in the driver.
     *  \param bufferSize - The amount of bytes used in a single buffer.
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool ConfigureUsbEndpoint( uint8_t endpointAddress, EPDataType_t epType, EPDirection_t epDir, char *deviceName,
        uint32_t deviceNameBufLen, uint32_t amountOfBuffers, uint32_t bufferSize );


    /*----------------------------------------------------------*/
    /*! \brief Configure the Linux character device driver to handle an MLB connection.
     *  \note This overloaded function is used to configure synchronous channels.
     *  \param aimType - Specifies the type of used Linux Driver Application Interface Module.
     *  \param mlbChannelAddress - The MLB channel address
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param deviceName - On successful configuration, this method stores the name of the character device into the given buffer.
     *  \param deviceNameBufLen - The length of the given buffer.
     *  \param amountOfBuffers - The amount of buffers used in the driver.
     *  \param bufferSize - The amount of bytes used in a single buffer.
     *  \param subbufferSize - The amount of bytes used for a single subbuffer. For isoc channel this maybe 188 or 196 byte.
     *  \param packetsPerTransaction - The amount of packets per transaction.
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool ConfigureMlbChannel( AimType_t aimType, uint8_t mlbChannelAddress, EPDataType_t epType, EPDirection_t epDir,
        char *deviceName, uint32_t deviceNameBufLen, uint32_t amountOfBuffers, uint32_t bufferSize,
        uint32_t subbufferSize, uint32_t packetsPerTransaction );


    /*----------------------------------------------------------*/
    /*! \brief Configure the Linux character device driver to handle an MLB connection.
     *  \param mlbChannelAddress - The MLB channel address
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param deviceName - On successful configuration, this method stores the name of the character device into the given buffer.
     *  \param deviceNameBufLen - The length of the given buffer.
     *  \param amountOfBuffers - The amount of buffers used in the driver.
     *  \param bufferSize - The amount of bytes used in a single buffer.
     *  \return true, if successful. false, otherwise.
     */
    /*----------------------------------------------------------*/
    bool ConfigureMlbChannel( uint8_t mlbChannelAddress, EPDataType_t epType, EPDirection_t epDir, char *deviceName,
        uint32_t deviceNameBufLen, uint32_t amountOfBuffers, uint32_t bufferSize );



    /*----------------------------------------------------------*/
    /*! \brief Adds a callback class, which derives CNetworkDeviceListener.
     *         This class will then be informed about any results and changes of MOST transactions.
     *  \note It is possible to register multiple listeners.
     *  \param listener - The class, which wants to be registered for MOST events.
     */
    /*----------------------------------------------------------*/
    void AddListener( CNetworkDeviceListener *listener );



    /*----------------------------------------------------------*/
    /*! \brief Retrieves the amount of registered listeners.
     *  \note Use this method in combination of GetListener()
     *  \return The amount of registered listeners.
     */
    /*----------------------------------------------------------*/
    uint32_t GetAmountOfListners();


    /*----------------------------------------------------------*/
    /*! \brief Gets a pointer to the class implementing the CNetworkDeviceListener interface.
     *  \note Use this method in combination of GetAmountOfListners()
     *  \return The pointer to the given instance of Listener.
     */
    /*----------------------------------------------------------*/
    CNetworkDeviceListener *GetListener( uint32_t instance );


    /*----------------------------------------------------------*/
    /*! \brief Gets the MOST instance index of the server device.
     *  \return The MOST instance index, starting at 0 for the first instance.
     */
    /*----------------------------------------------------------*/
    uint8_t GetDeviceIndex();



    /*----------------------------------------------------------*/
    /*! \brief Wait let the scripting engine wait for the given amount of time.
     *  \param timeInMillis - Time value in milliseconds.
     */
    /*----------------------------------------------------------*/
    void ScriptPause( uint32_t timeInMillis );



    /*----------------------------------------------------------*/
    /*! \brief Execute a bunch of MCM send and receive actions, as descibed in the XML file.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param pPathToScriptXml - Path to the XML file.
     */
    /*----------------------------------------------------------*/
    void ExecuteMcmScript( uint16_t nodeAddress, const char *pPathToScriptXml );



    /*----------------------------------------------------------*/
    /*! \brief Execute a bunch of MCM send and receive actions, as descibed in the XML zero terminated string.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param pPathToScriptXml - Path to the XML file.
     */
    /*----------------------------------------------------------*/
    void ExecuteMcmScript( uint16_t nodeAddress, const char *pStringBuffer, uint32_t bufferLength );


    /*----------------------------------------------------------*/
    /*! \brief Sends a NetworkMaster.NOT_OK and NetworkMaster.OK, in order resolve address conflicts.
     */
    /*----------------------------------------------------------*/
    void ToggleNotOk();



    /*----------------------------------------------------------*/
    /*! \brief Retrieves the GroupAddresses of all available MOST devices in this MOST instance.
     *  \note The result of this request is reported in the callback method OnMostDeviceType of the CNetworkDeviceListener class.
     *        Use AddListener to get the result.
     */
    /*----------------------------------------------------------*/
    void GetGroupAddresses( uint8_t maxNodePos );




    /*----------------------------------------------------------*/
    /*! \brief Retrieves the MOST MAC address for the given node address in this MOST instance.
     *  \note The result of this request is reported in the callback method OnMostMacAddress of the CNetworkDeviceListener class.
     *        Use AddListener to get the result.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     */
    /*----------------------------------------------------------*/
    void GetMacAddress( uint16_t nodeAddress );


    /*----------------------------------------------------------*/
    /*! \brief Starts up the MOST on the local INIC of the server device.
     *  \param isTimingMaster - true, if the INIC shall act as a timing master. false, if the device shall act as a timing slave.
     *  \param packetBandWidth - The amount of Bytes, which are reserved for asynchronous data (MEP, MHP).
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void StartMostV1( bool isTimingMaster, uint16_t packetBandWidth );



    /*----------------------------------------------------------*/
    /*! \brief Performs a network shutdown sequence on the local INIC attached to the server device.
     *  \note This method will cause a chain reaction on the MOST network. All devices will switch of their output signal on MOST.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void MostNetworkShutdownV1();


    /*----------------------------------------------------------*/
    /*! \brief Enables the usage of the MLB bus for the device on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param mlbSpeed - The used MLB speed.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void OpenMlbV1( uint16_t nodeAddress, MlbPortSpeed_t mlbSpeed );




    /*----------------------------------------------------------*/
    /*! \brief Sets the MOST MAC address for the device on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param macAddress1 - The 1st byte of the MAC address.
     *  \param macAddress2 - The 2nd byte of the MAC address.
     *  \param macAddress3 - The 3rd byte of the MAC address.
     *  \param macAddress4 - The 4th byte of the MAC address.
     *  \param macAddress5 - The 5th byte of the MAC address.
     *  \param macAddress6 - The 6th byte of the MAC address.
     *  \param persistent - true, if the given MAC address shall be stored persistent into the INIC flash memory.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void SetMostMacAddressV1( uint16_t nodeAddress, uint8_t macAddress1, uint8_t macAddress2, uint8_t macAddress3,
        uint8_t macAddress4, uint8_t macAddress5, uint8_t macAddress6, bool persistent );

     
    /*----------------------------------------------------------*/
    /*! \brief Enables the usage of the MLB bus for the device on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param tsiPortId - The instance id of the used TSI port.
     *  \param tsiPortMode - The used mode for this TSI port.
     *  \note This is an INIC API Version 1 command. Use it for OS81110 only.
     */
    /*----------------------------------------------------------*/
    void OpenTsiV1( uint16_t nodeAddress, V1TsiPortInstance_t tsiPortId, V1TsiPortMode tsiPortMode );

    
    /*----------------------------------------------------------*/
    /*! \brief Creates a TSI socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param portInst - The port instance id of the TSI port.
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param blockWidthTsi -The block width in bytes to be allocated on the MLB bus.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void CreateTsiSocketV1( uint16_t nodeAddress, V1TsiPortInstance_t portInst, 
        EPDataType_t epType, EPDirection_t epDir,uint16_t blockWidthTsi, uint32_t tag );

    /*----------------------------------------------------------*/
    /*! \brief Creates a MLB socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param mlbChannelAddress - The MLB channel address (even value).
     *  \param blockWidthMlb -The block width in bytes to be allocated on the MLB bus.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void CreateMlbSocketV1( uint16_t nodeAddress, EPDataType_t epType, EPDirection_t epDir, uint16_t mlbChannelAddress,
        uint16_t blockWidthMlb, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Creates a MLB socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param mlbChannelAddress - The MLB channel address (even value).
     *  \param blockWidthMlb -The block width in bytes of this singular splitted socked.
     *  \param splittedOffset - Offset in between the splitted socket.
     *  \param blockWidthCombined - The block width in bytes of all splitted sockets combined.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void CreateSplittedMlbSocketV1( uint16_t nodeAddress, EPDataType_t epType, EPDirection_t epDir,
        uint16_t mlbChannelAddress, uint16_t blockWidthMlb, uint16_t splittedOffset, uint16_t blockWidthCombined,
        uint32_t tag );


    /*----------------------------------------------------------*/
    /*! \brief Creates a MOST socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param connectionLabel - Only in case of if epDir is "EPDIR_IN": The connection label, which this socket will be bound.
     *                           Otherwise, the value will be ignored.
     *  \param blockwidthMost - The block width in bytes to be allocated on the MOST bus.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void CreateMostSocketV1( uint16_t nodeAddress, EPDataType_t epType, EPDirection_t epDir, uint16_t connectionLabel,
        uint16_t blockwidthMost, uint32_t tag );




    /*----------------------------------------------------------*/
    /*! \brief  on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param handle - The handle of socket (will be reported by the callback callback methods of the create socket methods).
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void DestroySocketV1( uint16_t nodeAddress, uint8_t handle, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief  on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param handle - The handle of socket (will be reported by the callback callback methods of the connect socket method).
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void DisconnectSocketsV1( uint16_t nodeAddress, uint8_t handle, uint32_t tag );




    /*----------------------------------------------------------*/
    /*! \brief Connects two different sockets, which then is called a connection, on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param inHandle - The handle of the in-socket (will be reported by the callback callback methods of the create socket methods).
     *  \param outHandle - * The handle of out-socket (will be reported by the callback callback methods of the create socket methods).
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 1 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void ConnectSocketsV1( uint16_t nodeAddress, uint8_t inHandle, uint8_t outHandle, uint32_t tag );

    /*----------------------------------------------------------*/
    /*! \brief Configures an I2S port on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void OpenStreamPortV1( uint16_t nodeAddress, V1I2SPortClkDriveMode_t portMode,
        V1I2SStreamingPortMode_t streamPortMode, V1I2SStreamingDataFormat_t format, uint32_t tag );


    /*----------------------------------------------------------*/
    /*! \brief Creates an I2S socket on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param portInstance - The I2S port instance. 0 = Port A, 1 = Port B.
     *  \param epDir - he Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param blockWidthI2S - The block width in bytes allocated on the I2S bus.
     *  \param pin - The physical I2S data pin of the INIC.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void CreateStreamSocketV1( uint16_t nodeAddress, EPDirection_t epDir, uint16_t blockWidthI2S, V1I2SPin_t pin,
        uint32_t tag );

    /*----------------------------------------------------------*/
    /*! \brief Creates an I2S socket on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param portInstance - The I2S port instance. 0 = Port A, 1 = Port B.
     *  \param epDir - he Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param blockWidthI2S - The block width in bytes allocated on the I2S bus.
     *  \param splittedOffset - Offset in between the splitted socket.
     *  \param blockWidthCombined - The block width in bytes of all splitted sockets combined.
     *  \param pin - The physical I2S data pin of the INIC.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81110
     */
    /*----------------------------------------------------------*/
    void CreateSplittedStreamSocketV1( uint16_t nodeAddress, EPDirection_t epDir, uint16_t blockWidthI2S,
        uint16_t splittedOffset, uint16_t blockWidthCombined, V1I2SPin_t pin, uint32_t tag );

    /*----------------------------------------------------------*/
    /*! \brief Attach to a local INIC on the server device.
     *  \note This command has to be called before any other commands to the local INIC.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void AttachV3();



    /*----------------------------------------------------------*/
    /*! \brief Destroyes any resource on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param sync - true, if the device shall be used afterwise. false, if the device is going to suspend (shutdown).
     *  \note In any case (regardless if sync is true or false), all ports, sockets and connects are going to be destroyed).
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void DeviceSyncV3( uint16_t nodeAddress, bool sync );



    /*----------------------------------------------------------*/
    /*! \brief Performs a network startup sequence on the local INIC attached to the server device.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118-D Revision
     */
    /*----------------------------------------------------------*/
    void MostNetworkStartupV3( uint16_t autoForcedNotAvailable, uint16_t packetBW );



    /*----------------------------------------------------------*/
    /*! \brief Performs a network startup sequence on the local INIC attached to the server device, after MostNetworkStartupV3 with parameters had failed.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118-D Revision
     *  \note Call this method only if the MostNetworkStartupV3( uint16_t autoForcedNotAvailable, uint16_t packetBW ) had failed. This will be treated as retry.
     */
    /*----------------------------------------------------------*/
    void MostNetworkStartupV3();


    /*----------------------------------------------------------*/
    /*! \brief Performs a network shutdown sequence on the local INIC attached to the server device.
     *  \note This method will cause a chain reaction on the MOST network. All devices will switch of their output signal on MOST.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void MostNetworkShutdownV3();


    
    /*----------------------------------------------------------*/
    /*! \brief Closes the IPC connection to local attached INIC.
     *  \note This will also cleanup any used resource in the INIC.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void InicUnsychronizeV3();




    /*----------------------------------------------------------*/
    /*! \brief Sets the MOST MAC address for the device on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param macAddress1 - The 1st byte of the MAC address.
     *  \param macAddress2 - The 2nd byte of the MAC address.
     *  \param macAddress3 - The 3rd byte of the MAC address.
     *  \param macAddress4 - The 4th byte of the MAC address.
     *  \param macAddress5 - The 5th byte of the MAC address.
     *  \param macAddress6 - The 6th byte of the MAC address.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118-D Rev
     */
    /*----------------------------------------------------------*/
    void SetMostMacAddressV3( uint16_t nodeAddress, uint8_t macAddress1, uint8_t macAddress2, uint8_t macAddress3,
        uint8_t macAddress4, uint8_t macAddress5, uint8_t macAddress6 );


    /*----------------------------------------------------------*/
    /*! \brief Enables the usage of the MLB bus for the device on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param mlbSpeed - The speed of the MLB bus.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void OpenMlbV3( uint16_t nodeAddress, MlbPortSpeed_t mlbSpeed );


    /*----------------------------------------------------------*/
    /*! \brief Creates an USB socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param endPointAddress - The USB endpoint address.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \param packetsPerFrame - The amount of packets stored in a single USB frame (512 byte).
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateUsbSocketV3( uint16_t nodeAddress, EPDataType_t epType, EPDirection_t epDir, uint8_t endPointAddress,
        uint16_t packetsPerFrame, uint32_t tag );


    /*----------------------------------------------------------*/
    /*! \brief Creates an splitted USB socket on the given node address to use with Combiner or Splitter.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param endPointAddress - The USB endpoint address.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \param packetsPerFrame - The amount of packets stored in a single USB frame (512 byte).
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateSplittedUsbSocketV3( uint16_t nodeAddress, EPDataType_t epType, EPDirection_t epDir,
        uint8_t endPointAddress, uint16_t packetsPerFrame, uint16_t bytesPerPacket, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Creates a MLB socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param mlbChannelAddress - The MLB channel address (even value).
     *  \param blockwidthMlb - The block width in bytes to be allocated on the MLB bus.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateMlbSocketV3( uint16_t nodeAddress, uint16_t mlbPortHandle, EPDataType_t epType, EPDirection_t epDir,
        uint16_t mlbChannelAddress, uint16_t blockwidthMlb, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Creates a splitted MLB socket on the given node address to use with Combiner or Splitter.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this endpoint.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param mlbChannelAddress - The MLB channel address (even value).
     *  \param blockwidthMlb - The block width in bytes to be allocated on the MLB bus.
     *  \param bytesPerPacket - The total number of data bytes to be transfered each MOST frame.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateSplittedMlbSocketV3( uint16_t nodeAddress, uint16_t mlbPortHandle, EPDataType_t epType,
        EPDirection_t epDir, uint16_t mlbChannelAddress, uint16_t blockwidthMlb, uint16_t bytesPerPacket,
        uint32_t tag );


    /*----------------------------------------------------------*/
    /*! \brief Creates a MOST socket on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this MOST channel.
     *  \param epDir - The Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param connectionLabel - Only in case of if epDir is "EPDIR_IN": The connection label, which this socket will be bound.
     *                          Otherwise, the value will be ignored.
     *  \param blockwidthMost - The block width in bytes to be allocated on the MOST bus.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateMostSocketV3( uint16_t nodeAddress, EPDataType_t epType, EPDirection_t epDir, uint16_t connectionLabel,
        uint16_t blockwidthMost, uint32_t tag );




    /*----------------------------------------------------------*/
    /*! \brief Connects two different sockets, which then is called a connection, on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param epType - The data type, which then will be transmitted on this connection.
     *  \param inHandle - The handle of the in-socket (will be reported by the callback callback methods of the create socket methods).
     *  \param outHandle - * The handle of out-socket (will be reported by the callback callback methods of the create socket methods).
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void ConnectSocketsV3( uint16_t nodeAddress, EPDataType_t epType, uint16_t inHandle, uint16_t outHandle,
        uint16_t offset, uint32_t tag );




    /*----------------------------------------------------------*/
    /*! \brief Destroyes up to three resources (Ports or connections) on the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \param amountOfHandles - The amount of resources to be destroyed. (value must be between 1 to 3).
     *  \param handle1 - The first resource to be destroyed.
     *  \param handle2 - The second resource to be destroyed.
     *  \param handle3 - The third resource to be destroyed.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void ResourceDestroyV3( uint16_t nodeAddress, uint8_t amountOfHandles, const uint16_t *pHandle, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Configures an I2S port on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param portInstance - The I2S port instance. 0 = Port A, 1 = Port B.
     *  \param option - The I2S port option.
     *  \param mode - The I2S clock mode.
     *  \param delay - The I2S delay mode.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void ConfigureStreamPortV3( uint16_t nodeAddress, uint8_t portInstance, V3I2SPortOption_t option,
        V3I2SClockMode_t mode, V3I2SDelayMode_t delay, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Creates an I2S port on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param portInstance - The I2S port instance. 0 = Port A, 1 = Port B.
     *  \param clock - The I2S port speed in multiple of MOST base clock.
     *  \param align - The I2S data format alignment.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateStreamPortV3( uint16_t nodeAddress, uint8_t portInstance, V3I2SPortSpeed_t clock,
        V3I2SAlignment_t align, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Creates an I2S socket on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param portInstance - The I2S port instance. 0 = Port A, 1 = Port B.
     *  \param epDir - he Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param blockWidthI2S - The block width in bytes allocated on the I2S bus.
     *  \param pin - The physical I2S data pin of the INIC.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateStreamSocketV3( uint16_t nodeAddress, uint8_t portInstance, EPDirection_t epDir, uint16_t blockWidthI2S,
        V3I2SPin_t pin, uint32_t tag );


    /*----------------------------------------------------------*/
    /*! \brief Creates an splitted I2S socket on the given node address  to use with Combiner or Splitter.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param portInstance - The I2S port instance. 0 = Port A, 1 = Port B.
     *  \param epDir - he Direction of the stream. (EPDIR_IN == Data from the INIC to the EHC, EPDIR_OUT == Data from the EHC to the INIC)
     *  \param blockWidthI2S - The block width in bytes allocated on the I2S bus.
     *  \param pin - The physical I2S data pin of the INIC.
     *  \param bytesPerPacket - The total number of data bytes to be transfered each MOST frame.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void CreateSplittedStreamSocketV3( uint16_t nodeAddress, uint8_t portInstance, EPDirection_t epDir,
        uint16_t blockWidthI2S, V3I2SPin_t pin, uint16_t bytesPerPacket, uint32_t tag );


    /*----------------------------------------------------------*/
    /*! \brief Creates an I2S socket on the given node address.
     *  \param nodeAddr -The device with this MOST node address raised this event.
     *  \param tag - Any 32 bit value. This value will be unmodified passed back in the corresponding callback method.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void GetRingBreakResultV3( uint16_t nodeAddress, uint32_t tag );



    /*----------------------------------------------------------*/
    /*! \brief Sends the given Control Message out to MOST ring.
     *  \param targetAddr - The MOST target address
     *  \param nFBlock - The MOST Function Block Identifier
     *  \param nInst - The MOST Function Block Instance Identifier
     *  \param nFunc - The MOST Function Block Function Identifier
     *  \param nPayloadLen - The amount of bytes stored in Payload
     *  \param Payload - The pointer to the payload byte array.
     */
    /*----------------------------------------------------------*/
    bool SendMostControlMessage( uint8_t devInst, uint32_t targetAddr, uint32_t nFBlock, uint32_t nInst,
        uint32_t nFunc, uint8_t nOpType, uint32_t nPayloadLen, const uint8_t *Payload );
    
    /*----------------------------------------------------------*/
    /*! \brief Gets the device information for the given node address.
     *  \param nodeAddress - The MOST node address (e.g. 0x101).
     *  \note The corresponding callback to this request is OnDeviceVersion.
     *  \note This is an INIC API Version 3 command. Use it for e.g. OS81118
     */
    /*----------------------------------------------------------*/
    void GetDeviceVersion( uint16_t nodeAddress );

    /* Callback from underlying layers */
    virtual ISReturn_t OnMostMessage(CIndustrialStack *iStack, CISMostMsg *r);
};

#endif //_NETWORKDEVICE_H_