Innovate Motorsports OT-2 SDK User Manual

Page 67

Advertising
background image

67


So no host network configuration should normally be necessary, aside from connecting to the ad
hoc network above


OK, now that the down and dirty basics are out of the way, it is time to make a pitch for a
little added complexity. Instead of hard coding for the above IP address/port, we
recommend using a ‘Discovery Method’ to find the unit and connect to it.

Discovery basically consists of:

1. Create a UDP (user datagram) socket
2. Set it with broadcast options
3. Broadcast a discovery packet
4. Listen for a response
5. Open a TCP connection using the IP address and port provided in the discovery

response


There are two advantages to this. First, it allows us to change the IP address and port used
without breaking your software. Second, although the unit will only accept one TCP
connection for MTS data at a time, it will always respond to discovery inquiries. If it is
currently being used, it reports that in the response. This lets you distinguish between
failures because of usage conflict and literal ‘device not there’ problems.

For discovery, we use port 0x1936, which is the ‘well known port’ for a protocol called
ArtNet. The discovery packet and response is structured so as not to confuse any actual
ArtNet devices which might be present:

typedef

unsigned

char

U8;

typedef

unsigned

short

U16;

typedef

unsigned

long

U32;

// Protocol ID

#define

IMSNET_PROTO_ID

"IMS Net"

// Interface Version

#define

IMSNET_VERSION (1)

// UDP Discovery Port

#define

IMSNET_DISCOVERY (0x1936)

// OpCodes

#define

IMSNET_OPCODE_POLL (0x4000)

#define

IMSNET_OPCODE_POLLREPLY (0x4100)

// Flags

#define

IMSNET_FLAG_INUSE (0x1)

// Poll Structures

#pragma

pack

(

push

)

#pragma

pack

(1)

// must be byte aligned

Advertising