Stack applications – Echelon LonTal Stack User Manual
Page 228
216
Appendix G: Appendix G
Example LonTalk
Stack Applications
5. Runs a simple command console:
• When the S command is pressed, sends a service pin messages from both
router halves by calling the sendServicePinMsg() method of the
LtIp852Router object.
• When the E or Q command is pressed, breaks out of the console loop
6. On exit, does the following:
• Shuts down the router by calling the Shutdown() method of the
LtIp852Router object.
• Closes the native LonWorks network interface by deleting the
LtLogicalChannel object.
The main() function is shown below.
/* The main function just initializes the router and then runs a simple
command line interface. */
int
main(
int
argc,
char
* argv[])
{
const
char
*pNiName = NULL;
int
ipAddress;
int
ipPort;
LtIp852Router router;
LtLtLogicalChannel *pLtChannel = NULL;
LtErrorType sts;
if
(argc < 4 || sscanf(argv[3],
"%d"
, &ipPort) != 1)
{
printf(
"Run an IP-852 to native LonTalk Router\n\n"
"Syntax:\n"
" Ip852Router
"\n"
"
interface\n"
"
for the IP-852\n"
" interface\n"
"
IP-852 interface\n"
"\n"
);
return
1;
}
else
{
pNiName = argv[1];
ipAddress = htonl(inet_addr(argv[2]));
}
pLtChannel =
new
LtLtLogicalChannel(pNiName);
sts = pLtChannel->getStartError();
if
(sts == LT_NO_ERROR && !pLtChannel->getLonLink()->isOpen())
{
sts = LT_CANT_OPEN_PORT;
}
if
(sts == LT_NO_ERROR)
{
#pragma
message
(
"Warning: TBD - Must set a valid unique ID for IP-852
interface!!!"
)
const
byte data[6] = { 0xBA, 0xDB, 0xAD, 0xBA, 0xD0, 0x00 };
LtUniqueId ltUid;
LtUniqueId ipUid(data);
pLtChannel->getLonLink()->getUniqueId(ltUid);