-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·174 lines (149 loc) · 4.79 KB
/
main.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
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
/****************************************************************************
**
** Copyright (C) 2009 D&R Electronica Weesp B.V. All rights reserved.
**
** This file is part of the Axum/MambaNet digital mixing system.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
/* #define USE_IF_UDP */
#define USE_IF_TCP
#define MBN_VARARG
#include "mbn.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include <stdlib.h>
/* sleep() */
#ifdef MBNP_mingw
# include <windows.h>
# define sleep(x) Sleep(x*1000)
#else
# include <unistd.h>
#endif
struct mbn_node_info this_node = {
0x00031337, 0x00, /* MambaNet Addr + Services */
"MambaNet Stack Test Application",
">> YorHel's Power Node! <<",
0xFFFF, 0x0001, 0x0001, /* UniqueMediaAccessId */
0, 0, /* Hardware revision */
0, 0, /* Firmware revision */
0, 0, /* FPGAFirmware revision */
2, /* NumberOfObjects */
0, /* DefaultEngineAddr */
{0,0,0}, /* Hardwareparent */
0 /* Service request */
};
struct mbn_object objects[2];
void AddressTableChange(struct mbn_handler *mbn, struct mbn_address_node *old, struct mbn_address_node *new) {
struct mbn_address_node *cur;
cur = new == NULL ? old : new;
/*printf("%s: %08lX -> %04X:%04X:%04X (%02X)\n",
old == NULL ? "New node" : new == NULL ? "Removed node" : "Node changed",
cur->MambaNetAddr, cur->ManufacturerID, cur->ProductID, cur->UniqueIDPerProduct, cur->Services);*/
mbn += 1;
}
void OnlineStatus(struct mbn_handler *mbn, unsigned long addr, char valid) {
printf("OnlineStatus: %08lX %s\n", addr, valid ? "validated" : "invalid");
/*if(valid)
mbnSendPingRequest(mbn, MBN_BROADCAST_ADDRESS);*/
mbn += 1;
}
void Error(struct mbn_handler *mbn, int code, char *msg) {
printf("Error(%d, \"%s\")\n", code, msg);
mbn += 1;
}
void mWriteLogMessage(struct mbn_handler *mbn, char *msg) {
printf("%s\n", msg);
mbn += 1;
}
int ReceiveMessage(struct mbn_handler *mbn, struct mbn_message *msg) {
/*printf("ReceiveMessage from %08lX to %08lX type %d\n", msg->AddressFrom, msg->AddressTo, msg->MessageType);*/
mbn += 1; msg += 1;
return 0;
}
int total = 0;
int ObjectInformationResponse(struct mbn_handler *mbn, struct mbn_message *msg, unsigned short object, struct mbn_object *nfo) {
if(nfo == NULL) {
printf("ERROR: nfo == NULL\n");
exit(1);
}
printf("%4d (%4d: %s)\n", ++total, object, nfo->Description);
msg++; mbn++;
return 0;
}
int main(void) {
struct mbn_handler *mbn;
struct mbn_interface *itf = NULL;
char err[MBN_ERRSIZE];
struct mbn_if_ethernet *ifl, *n;
char *ifname;
int i;
fprintf(stdout, "%s\n",mbnVersion());
#ifdef USE_IF_UDP
itf = mbnUDPOpen("192.168.0.200", "34848", NULL, err);
if(itf == NULL) {
printf("Error: %s\n", err);
return 1;
}
#elif defined(USE_IF_TCP)
itf = mbnTCPOpen("192.168.0.200", "34848", NULL, NULL, err);
if(itf == NULL) {
printf("Error: %s\n", err);
return 1;
}
#else
ifname = NULL;
ifl = mbnEthernetIFList(err);
if(ifl == NULL) {
printf("Error: %s\n", err);
return 1;
}
for(n=ifl; n!=NULL; n=n->next) {
if(!ifname)
ifname = n->name;
printf("ethernet interface \"%s\": %02X:%02X:%02X:%02X:%02X:%02X (%s)\n",
n->name, n->addr[0], n->addr[1], n->addr[2], n->addr[3], n->addr[4], n->addr[5],
n->desc ? n->desc : "no description");
}
itf = mbnEthernetOpen(ifname, err);
if(itf == NULL) {
printf("Error: %s\n", err);
return 1;
}
mbnEthernetIFFree(ifl);
if (mbnEthernetMIILinkStatus(itf, err))
fprintf(stdout, "Link up\n");
else
fprintf(stdout, "Link down\n");
#endif
objects[0] = MBN_OBJ("Object #1", MBN_DATATYPE_UINT, 0, 2, 0, 512, 256, MBN_DATATYPE_NODATA);
objects[1] = MBN_OBJ("Object #2", MBN_DATATYPE_NODATA, MBN_DATATYPE_UINT, 2, 0, 512, 0, 256);
mbn = mbnInit(&this_node, objects, itf, err);
if(mbn == NULL) {
printf("Error initializing mbn: %s\n", err);
return 1;
}
mbnSetAddressTableChangeCallback(mbn, AddressTableChange);
mbnSetOnlineStatusCallback(mbn, OnlineStatus);
mbnSetErrorCallback(mbn, Error);
mbnSetReceiveMessageCallback(mbn, ReceiveMessage);
mbnSetObjectInformationResponseCallback(mbn, ObjectInformationResponse);
mbnSetWriteLogMessageCallback(mbn, mWriteLogMessage);
mbnStartInterface(itf, err);
for (i=0; i<20; i++) {
sleep(1);
printf("sleep number %d\n", i);
}
/*pthread_exit(NULL);*/
mbnFree(mbn);
return 0;
}