-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgomxio.c
78 lines (69 loc) · 1.57 KB
/
gomxio.c
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
#include "stdlib.h"
#include "stdio.h"
#include "mxio.h"
#include "gomxio.h"
// Init the system so that we can get driver.
int initIF(WORD *wIFCount) {
int err = MXEIO_Init();
if ( err != MXIO_OK ){
return err;
}
return MXIO_ListIF( wIFCount );
}
// Init and GetIF info.
char *getIFInfo(WORD *wIFCount, int *err){
char *IFInfo = NULL;
*err = initIF( wIFCount );
if( wIFCount == 0 ){
return NULL;
}
if( *err != MXIO_OK ){
return NULL;
}
IFInfo = malloc( *wIFCount * MX_IF_ONE_IF_SIZE );
*err = MXIO_GetIFInfo( *wIFCount, IFInfo );
if( err != MXIO_OK ){
free(IFInfo);
IFInfo = NULL;
return NULL;
}
return IFInfo;
}
// Select IF will select the interface that we need.
char *selectIF(DWORD index, int* err){
WORD wIFCount = 0;
*err = initIF( &wIFCount );
if( wIFCount == 0 ){
return NULL;
}
char *IFInfo = malloc( wIFCount * MX_IF_ONE_IF_SIZE );
*err = MXIO_GetIFInfo( wIFCount, IFInfo );
if( *err != MXIO_OK ){
free(IFInfo);
IFInfo = NULL;
return NULL;
}
*err = MXIO_SelectIF( wIFCount, IFInfo, index );
if( *err != MXIO_OK ){
free(IFInfo);
IFInfo = NULL;
return NULL;
}
return IFInfo;
}
// Auto Search
MODULE_LIST *autoSearch(int retry, int timeout, int deviceType,int IFidx, char *IFInfo, int *deviceCount, int *err ) {
// char *IFInfo = NULL;
MODULE_LIST *ml = (MODULE_LIST*) malloc(sizeof(MODULE_LIST) * 256);
IFInfo = selectIF(IFidx,err);
if( *err != MXIO_OK ){
free(ml);
return NULL;
}
*err = MXIO_AutoSearch(deviceType, retry, timeout, deviceCount, (char *)ml);
if( *err != MXIO_OK){
free(ml);
return NULL;
}
return ml;
}