OpenAMIP Standard Revision C
OpenAMIP Standard Revision C
OpenAMIP™ Standard
Version 1.12
VT iDirect® is a global leader in IP-based satellite communications providing technology and solutions that enable
our partners worldwide to optimize their networks, differentiate their services and profitably expand their
businesses. Our product portfolio, branded under the name iDirect, sets standards in performance and efficiency to
deliver voice, video and data connectivity anywhere in the world. VT iDirect is the world’s largest TDMA enterprise
VSAT manufacturer and is the leader in key industries including mobility, military/government and cellular
backhaul.
VT iDirect®
Company Web site: http://www.idirect.net ~ Main Phone: 703.648.8000
TAC Contact Information: Phone: 703.648.8151 ~ Email: [email protected] ~ Web site: http://tac.idirect.net
iDirect Government™, created in 2007, is a wholly owned subsidiary of iDirect and was formed to better serve the
U.S. government and defense communities.
iDirect Government™
Company Web site: http://www.idirectgov.com ~ Main Phone: 703.648.8118
TAC Contact Information: Phone: 703.648.8111 ~ Email: [email protected] ~ Web site: http://tac.idirectgov.com
Revision History
The following table shows all revisions for this document. To determine if this is the latest
revision, check the Technical Assistance Center (TAC) Web site. Refer to Getting Help on
page ix for TAC access information.
Contents
About . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Certification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .viii
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .viii
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .viii
Document Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Chapter 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 3 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 Version Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1.1 Version Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Modified OpenAMIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.3 Hardware Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
About
Purpose
This document describes the Open Antenna Modem Interface Protocol (OpenAMIP™) for
satellite terminals. OpenAMIP is an ASCII message-based protocol for the interchange of
information between an antenna controller and a satellite modem. OpenAMIP allows the
modem to command the controller to seek a particular satellite. OpenAMIP also allows the
modem and controller to exchange information necessary to initiate and maintain
communications through the satellite.
OpenAMIP is designed to be extensible for vendor-specific enhancements.
Disclaimer
This protocol specification is Copyright© 2006-2013 iDirect. All rights reserved.
The Protocol was developed by iDirect.
The name "OpenAMIP" is a trademark™ of iDirect.
Permission to copy and distribute this document in unmodified form is hereby granted to all
without restriction. Modified forms of this document may be distributed, but only if this "legal
matters" section is retained intact and provided that any document that describes a modified
form of the protocol clearly states that the protocol is modified.
To the extent that iDirect has rights to control the protocol itself, iDirect grants rights to
implement the protocol to all, without restriction.
Use of the trademark "OpenAMIP" to describe an unmodified implementation of this protocol
is unrestricted. Use the term "modified OpenAMIP" to describe a variant of this protocol, is
also unrestricted; however the document containing the term "modified OpenAMIP" refers to
this document.
While iDirect, Inc. strives to make the information in this document as accurate as possible,
iDirect makes no claims, promises, or guarantees about the accuracy, completeness, or
adequacy of the contents, and expressly disclaims liability for errors and omissions. No
warranty of any kind, whether implied, expressed, or statutory, including but not limited to
the warranties of non-infringement of third party rights, title, merchantability, or fitness for a
particular purpose, is given with respect to the contents of this document.
iDirect, Inc. reserves the right to change or update this document at any time.
Certification
You may certify your compliance with the test suite yourself. If you do, you are free to use the
trademark "OpenAMIP™" freely for any product that you have certified.
Your use of the OpenAMIP™ trademark authorizes any OpenAMIP™ implementer to validate
your implementation and publish the results, referring to your product by company and
product name, if the implementer finds your implementation to be non-compliant. A finding
of non-compliance will not be published until thirty days after the OpenAMIP™ member
notifies you of the finding. At your option, the implementer's published finding of non-
compliance will include a reference to a statement in rebuttal by you.
Audience
The intended audience for this document is an engineering team responsible for integrating a
satellite terminal.
Contents
This document contains the following major sections:
• Introduction
This chapter gives an introduction about OpenAMIP.
• Protocol Specification
This chapter describes the protocol specifications, message types, and syntax.…
• Compatibility
This chapter describes the hardware and version compatibility.
• Test Suite
This chapter displays the sample protocols.
• Acronyms and Abbreviations
This list is meant to be generic within this document and may contain acronyms and
abbreviations not found in this manual and some terms may not be defined based on
industry standards.
• Glossary
This list is meant to be generic within this document and may contain entries not found
in this manual and some terms may not be defined based on industry standards.
Document Conventions
This section illustrates and describes the conventions used throughout this document.
Getting Help
The iDirect Technical Assistance Center (TAC) and the iDirect Government Technical
Assistance Center (TAC) are available to provide assistance 24 hours a day, 365 days a year.
Software user guides, installation procedures, FAQs, and other documents that support iDirect
and iDirect Government products are available on the respective TAC Web site:
• Access the iDirect TAC Web site at http://tac.idirect.net
• Access the iDirect Government TAC Web site at http://tac.idirectgov.com
The iDirect TAC may be contacted by telephone or email:
• Telephone: 703.648.8151
• E-mail: [email protected]
The iDirect Government TAC may be contacted by telephone or email:
• Telephone: 703.648.8111
• Email: [email protected]
iDirect and iDirect Government produce documentation that are technically accurate, easy to
use, and helpful to our customers. Please assist us in improving this document by providing
feedback. Send comments to:
• iDirect: [email protected]
• iDirect Government: [email protected]
For sales or product purchasing information contact iDirect Corporate Sales at the following
telephone number or e-mail address:
• Telephone: 703.648.8000
• E-mail: [email protected]
This document describes the Open Antenna Modem Interface Protocol (OpenAMIP™) for
satellite terminals. OpenAMIP is an ASCII message-based protocol to exchange information
between an antenna controller and a satellite modem. OpenAMIP allows the modem to
command the controller to seek a particular satellite. OpenAMIP also allows the modem and
controller to exchange information necessary to initiate and maintain communications
through the satellite.
OpenAMIP is not intended for any purpose except to permit a modem and a controller to
perform synchronized automatic beam selection. It is not a status logging system or a
diagnostic system. There is no explicit provision in OpenAMIP for security or validation. The
controller and the modem may choose to use any of several security measures at lower
protocol layers.
2 Protocol Specification
2.1 Introduction
OpenAMIP is intended to be simple and flexible. Communications are in the form of messages
that are readable ASCII characters. A message consists of one or more space-separated
variable-length fields. The command is terminated by a new line <lf> character or by the
<cr><lf> sequence.
The first field is a message type, a single alphabetic character in the standard command set.
Each type of message requires a specific number of parameters. The last parameter may
optionally be separated from the new line by a comment that begins with a #. The # can be
followed by a string containing any characters other than a new line.
The OpenAMIP protocol is a peer protocol: neither side is the master. The messages are sent
through any of the several lower-level protocols, such as HTTP, TCP/IP over a LAN, UDP over a
LAN, or using a high-speed serial connection.
2.2 Syntax
The OpenAMIP format specified here is in Backus-Naur form (BNF).
<msg>::=<msg_body><optional whitespace>'\n'
| <msg_body><optional whitespace>'#'<comment_body>'\n'
<comment_body>::=<non-newline>
|<non-newline><comment_body>
<non_newline>::= {any printable character except '\n'}
<msg_body>::=<msg_type>
| <msg_type> <param_list>
<param_list>::= <whitespace> <param>
| <param><param_list>
<param>::= <binary>
|<float>
|<int>
|<string>
<binary>::= '1'
|'0'
<int>::= '-' <natural>
| <natural>
<float::=<int>'.'<natural>
| <int>
<natural>::= <digit>
| <digit><natural>
<digit>::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
<string> ::=<string_char>
|<string_char><string>
<string_char>::={any printable character except ' ' and '\n'}
<optional whitespace>::=NULL|<whitespace>
<whitespace>::=<whitespace_char>|<whitespace><whitespace_char>
<whitespace_char>::= ' '|'\t'|'\r'
No. of
Type Description Name of the Parameters Sender
Parameter(s)
A Alive interval. Antenna should send a status message at 1 int interval, seconds M
least this often. 0 means never repeat.
B Beat frequency oscillator (local oscillator) frequencies; 2 float Rx LO frequency, MHz M
effective amount of down-conversion (Rx) or up- float Tx LO frequency, MHz
conversion (Tx).
C Carrier to Noise Ratio for Conical Scan. 5 float CNR (SNR) in dB, measured M
Reporting rate is configured by "c" message. Default on headers and pilots
"C" message rate is zero (if "c" message reporting rate
parameter is not present, the "C" message is disabled).
It is recommended to provide this message by UDP as a
separate stream.
float CNR (SNR) in dB, measured
on data
float time in seconds. This free-
running counter may wrap
around through zero
periodically; it is recommended
to use enough resolution for at
least an hour between wrap
events
int received carrier lock state.
Values are in the range 0..7,
where 0 means invalid, 1
means not locked, 7 means
fully locked, and values in
between are intermediate
states of lock (intermediate
state details are product-
specific).
float composite power, dBm,
measured at the IF input to the
modem.
E Expected power. Maximum L-band Tx power to be 1 float max power M
expected at the antenna, in dBm.
F Find the satellite. Antenna should now begin using the 0 M
satellite specified by S, P, B, X, and H. This command
overrides the N command.
No. of
Type Description Name of the Parameters Sender
Parameter(s)
H Hunt frequency in MHz. Modem expects antenna to use 2 float frequency, float bandwidth M
this L-band hunt center frequency when commanded.
Receive RF frequency can be determined through
combination of RX LO (LNB) frequency in the "B"
message and the center frequency in the "H"
message.
I ID of the modem type (optional) 2 string: modem manufacturer and M
string: modem model
K Maximum and minimum sKew of the beam short axis to 2 float max skew and float min M
the geosynchronous arc, in degrees. Transmitter should skew
be disabled when these limits are exceeded. Minimum
skew defaults to zero if absent.
L Lock status of receiver. The modem should send this 2 RX Lock State: binary 1 (locked) M
message immediately when the status changes. The or 0 (unlocked)
modem should send this message periodically at
intervals specified by the antenna in the "a" message.
Antenna is free to transmit, or not. This command may binary TX Enable: 1 (Tx on) or 0
be used by the antenna to remove power from the Tx (Tx off)
amplifiers.
NOTE: The Tx Enable parameter can be used to
support a power calibration mode, in which
the final power amplifier is disabled or
terminated, but the preamplifier is still
enabled and capable of measuring RF power
at the preamp.
N Non-geosynchronous mode. The antenna should be 0 M
aimed away from the geosynchronous arc. This is
intended to support installation tests such as power
measurements.
NOTE: The N command is intentionally redundant
with the L command; it is not intended to
be the sole means of preventing
interference during tests.
This command overrides the F command, but should
not cause the antenna to lose the parameters
previously specified by S, P, B, X and H.
P Polarization. Modem commands antenna to use these 2 char Rx Polarization: L, R, V, or M
polarizations. H and char Tx polarization: L, R,
V, or H
No. of
Type Description Name of the Parameters Sender
Parameter(s)
S Satellite longitude. Modem expects antenna to use this 3 float longitude (degrees) M
satellite when commanded.
Maximum excursion in satellite's latitude (for inclined- float latitude variance (degrees)
orbit satellites)
Satellite's nominal polarization offset in degrees (for float polarization skew (degrees)
skewed satellites) From behind the dish, facing
towards the satellite; clockwise
is positive.
T Transmit frequency. Modem intends to transmit at this 2 float Tx frequency, MHz and M
L-Band frequency and bandwidth float Tx bandwidth, MHz
W Where (location) Interval. Antenna should send w 1 int repeat interval, seconds. M
message immediately, and then repeat at least this Should be float, if the modem
often. 0 means "never repeat" requests antenna to transmit
NOTE: integer is a valid subset of the float type. "w" at rates higher than 1 Hz
Non-integer time is used only for specialized highly
dynamic terminals, by agreement between modem
and antenna vendor. The modem shall not request
non-integer time unless the antenna is known to
support it. Decimal point and digits after decimal
may be omitted, unless modem and antenna both
support high-rate reporting for highly dynamic
terminals, and modem has requested rate > 1Hz.
X eXtra hunt parameters. This is a fixed string to be 1 string M
configured by the operator and sent as part of the
lookup. The antenna vendor specifies the string. If the
controller does not need this command, the modem
does not need to send it, but the modem may send it
anyway, in which case the controller will ignore it.
a alive interval. Antenna requests to see an L message 1 int repeat interval, seconds A
from the modem at least this often. 0 means "never
repeat".
No. of
Type Description Name of the Parameters Sender
Parameter(s)
c conical scan setup (optional) 5 float1 -AZ: see drawing, A
Sent when conical scan performed. The four floating float2 +EL: see drawing,
point values represent the times (UTC or GPS epochal) float3 +AZ: see drawing,
of beam steering excursions from the previously
float4 -EL: see drawing, and
steered coordinates.
int reporting rate in Hertz for
Azimuth and elevation delta scan excursions are pre-
“c” message
determined by the antenna manufacturer and would
be on the order of ±0.25°.
The antenna may request periodic carrier-to-noise
estimates ("C" message) by setting the fifth parameter.
Default "C" message rate is zero (if "c" message
reporting rate parameter is not present, the "C"
message is disabled).
NOTE: Some terminal implementations will use only
the fifth parameter of this message; in that case, the
first four parameters may be set to zero, or may
optionally be set to describe the intended scan
timing.
No. of
Type Description Name of the Parameters Sender
Parameter(s)
s Status of the antenna. Antenna sends this immediately 4 binary Antenna Functional: A
in response to the F command from the modem, or 1 - antenna functional
immediately whenever either of the two statuses
0 - antenna not functional
changes, or periodically. The period is set by the A
command from the modem.
"Not functional" means that the antenna cannot
currently operate and will never operate with this
configuration. This can be temporary (for example, an
illegal configuration) or permanent (for example,
motor frozen).
"Modem must not transmit" means that the antenna has Binary Modem May Transmit:
detected a condition (loss of lock, blockage, cable 1 - Modem may transmit
unwrap, max skew exceeded) that does not require a
0 - Modem must not transmit
reconfiguration, but that does require the modem to
cease transmission.
The third parameter is the number of full sweeps the int Search Count
antenna has performed while searching for the
satellite. It should be set to 0 upon receipt of an F
command, and incremented when the antenna has
performed a full sweep for the satellite. If omitted,
this parameter is assumed to be 0. This parameter
should be zero if an N command is more recent than an
F command.
The fourth parameter should be set to 0 if an F binary Tx Disabled: antenna
command was sent more recently than an N command. (1 - has, 0 - has not) successfully
If omitted, this parameter is assumed to be 0. disabled transmission toward the
NOTE: If the antenna cannot ensure it is ready for a geosynchronous arc (response to
transmitter test without regulatory N command). If this parameter
violation, the third parameter should be set is "1" antenna is in a state to
to 0. support installation tests such as
power measurements; any power
from the transmitter test is
either terminated in a dummy
load or otherwise prevented
from interfering with satellites.
No. of
Type Description Name of the Parameters Sender
Parameter(s)
w where the platform is located. Antenna sends this to 11 binary Location Valid: A
modem periodically. The period is set by the W 1 - valid
command from the modem. If the location is not valid,
0 - invalid
the antenna may put 0 in the remaining parameters.
No. of
Type Description Name of the Parameters Sender
Parameter(s)
float skew angle (degrees).
Positive is CW when facing
satellite from ground. Negative
is CCW when facing satellite.
In Version 1.9, the modem may create a UDP stream for the "C" message, alongside the
primary TCP connection for all other OpenAMIP messages. Because the "C" message will be
sent at a relatively high rate (tens of Hertz), the UDP stream is more practical; it avoids TCP
handshaking overhead. It is recommended that the modem and antenna use the same IP
address and port for both TCP and UDP connections. Because TCP and UDP use separate
address spaces, this does not cause any conflict.
2.5 Semantics
The protocol is primarily intended to convey state change information based on external
events. The following notes are intended to provide functional guidance for various common
events and message sequences. It is not intended to be a comprehensive list of messages nor
a syntax dictionary.
To comply with regulatory constraints, the modem must disable its transmitter within 100ms
when the antenna loses lock on a satellite, and must also disable the transmitter immediately
when a blockage occurs. The antenna must minimize the interval between detecting a change
in condition and sending the status message to the modem. Similarly, the antenna may choose
to use the modem lock signal as part of its satellite search. The modem must also minimize
the interval between detecting the condition and sending the message to the controller.
Status changes should be reported within 10ms. However, since this will not be practical on a
slow serial link, the links are deprecated.
Prior to any communication between the modem and the controller, the OpenAMIP state is
unspecified. The timers are all set to infinite. The modem initiates communications by
sending the commands needed to deliver the satellite parameters to the controller. It then
sends an "F" message.
When the controller receives an "F" message, it must respond within 10 milliseconds with an
"s" message. This is necessary to ensure regulatory compliance in the case when the modem
needs to mute. The controller must also send a status every "keepalive" interval, and every
time the status changes. When the controller responds to an "F" message, the "may transmit"
status must reflect the status with respect to the newly-selected satellite parameters. This
means that if the modem has just commanded the antenna to "Find" the satellite that it is
already tracking and is already locked on, then the immediate status can be "may transmit".
However, if the antenna is already tracking a satellite and is successfully locked to it, and the
modem then sends new parameters and issues a new "Find" command, the controller must
immediately send a status of "must not transmit" because it is not locked to the new satellite
(it is locked to the old satellite). After the antenna locks to the new satellite, it will send a
new status message indicating that the modem may transmit.
The modem should send an "L" message whenever the modem lock changes. It should also
send the "locked" status every time its keepalive timer expires. Whenever the modem sends
the "L" message for any reason, it restarts its keepalive timer.
When the modem issues a "W", the controller immediately responds with a "w". The controller
responds thereafter every w seconds (zero seconds means never). If the controller sends a "w"
to the modem which indicates that the location information is invalid, the controller should
send a new "w" message immediately as soon as valid location information becomes available.
Latitude and longitude are reported in floating point decimal degrees. The range for latitude
is -90.0 to 90.0, where -90.0 is the South Pole. The range for longitude is 360.0 to 360.0,
where negative is west from the prime meridian and positive is east from the prime meridian.
The overlap is intentional: the sender is free to use zero to 360 or -180 to 180 (or even -360 to
0 or a mixed system). The receiver must be able to handle the full -360 to 360. Leading zeros
are optional for the sender, except that the number must have at least one digit before the
decimal point. Trailing zeros are optional for the sender, except that the number must have at
least one digit after the decimal. The receiver must be able to handle leading and trailing
zeros correctly. If the fractional part is zero, the number may be specified as an integer (that
is, without a decimal point). Note that the syntax does not permit the use of the "+"
character.
The precision of the latitude and longitude is not specified by the OpenAMIP syntax; the
number of digits after the decimal point is arbitrary. However, the sender should provide as
much precision as is actually available. As a practical matter, OpenAMIP contemplates the
ability to use this information for logging and transmission restrictions as mandated by
regulatory authorities, so accuracy to about one kilometer is needed: this implies that
latitudes and longitudes to a precision of one thousandth of a degree are needed.
If the modem issues a "P", "B", or "F" command that is incompatible with the antenna
hardware, the antenna may either ignore the incompatible parts of the command or may set
the "functional" status to "not functional".
The "K" message conveys the maximum skew of the short axis of a non-circular beam to the
geosynchronous arc. If the antenna has a beam shape that is radially symmetric about the
bore sight, this parameter may be ignored. Otherwise, the antenna must use the current skew
as a factor in computing the "must not transmit" or "may transmit" status. When all other
factors permit transmission, the antenna will immediately send a status message with a status
of "must not transmit" when the angle transitions from below to above the maximum skew,
and will immediately send a status message with a status of "may transmit" when the angle
transitions from above to below the maximum skew. In contrast to some other messages, the
"K" message takes effect immediately and the modem may send a new "K" message with a new
max skew angle at any time. The "K" message also includes a minimum skew parameter, to
support protection of non-geostationary satellites. The minimum skew parameter operates
analogously to the maximum skew parameter; the antenna controller should send a status of
"must not transmit" when the skew is less than this value.
When the antenna reports with an "s" message that the antenna is functional, it indicates that
the antenna should currently be working. "Non-functional" means that the antenna is not
currently in service. This does not include blockage, loss of lock, system initialization, loss of
heading information, cable unwrap, or any condition that can correct itself without
intervention. It does include detection of a fatal mechanical failure, or an operator command
to the antenna controller from its front panel or other source, or an illegal configuration.
When the modem detects this status, it will not attempt to recover by, for example, switching
to a different satellite or clearing and re-establishing the OpenAMIP connection. The modem
waits until the antenna sends a "functional" message. The antenna provides a "may transmit"
when it is locked on the satellite and ready to transmit. The antenna signals "must not
transmit" if there is any reason the modem should not transmit: blockage, loss of lock, cable
unwrap, sea too rough, etc.
2.6 Examples
This section is intended to describe the purpose of each message. The formal syntax and
semantics are described in later sections. Note that the messages here make use of the
"comment" syntax. It is unlikely that operational implementations of the protocol will ever
transmit messages with comments, but they are useful in descriptive documents such as this
one and in test scripts. Typically, implementations of the receive side of the protocol will
properly detect and ignore comments.
The modem must be able to convey all of the information needed by the controller to
describe a satellite. This must be sufficient for the controller to identify the satellite and to
command the controller to find the satellite.
3 Compatibility
messages are optional for operation of the equipment, then the protocol still qualifies as
"unmodified" OpenAMIP. If the messages must be used for a particular antenna or modem,
then the resulting implementation must be called "modified OpenAMIP".
Examples:
Yoyodyne:NID 1132 # additional search parameter
iDirect:stow 1 # command specified by iDirect
4 Test Suite
4.2 OpenAMIP_sim.c
/*
"Reference implementation" of the Antenna controller's
OpenAMIP(tm) protocol processing code.
---- begin notice----
Copyright (c) 2007, 2008 iDirect technologies iDirect hereby
licences anyone to use this code, modified or unmodified, for any
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define FALSE 0
#define TRUE 1
//commandline parameters:
static int verbose=TRUE;
static int tcp_port=5005;
static int my_ip=INADDR_ANY;
static double lat,lon;
int len;
int i,np;
double tmpfla,tmpflb,tmpflc;
char tmpchra, tmpchrb;
if((tmpfla!=sat_lon)||(tmpflb!=sat_io_lat)||(tmpflc!=sat_skew))
We get the current time and check against each timer. If any
timer has expired, we process that timer, which may set another
timer. After expired timers are processed, we find the next timer
that will expire and compute and return the interval from now
until then.
*/
static time_t process_timers(int sock,time_t now)
{
int i;
time_t next=now+3600; //preload a long sleep interval.
int avail=1;
char buff[100];
if(timers[GPS]<now)
{ sprintf(buff,"w %d %3.3f %3.3f %d\n",avail,lat,lon,(unsigned
int)now);
send_msg(buff,sock);
timers[GPS]=now+intervals[GPS];
}
if(timers[STAT]<now)
{ sprintf(buff,"s %d %d\n",functional,locked&!blocked);
send_msg(buff,sock);
timers[STAT]=now+intervals[STAT];
}
if(timers[SWING]<now)
{ locked=1;
timers[STAT]=now;
timers[SWING]=FAR_FUTURE;
}
for (i=0;i<MAXTIMER;i++)
if(timers[i]<next)
next=timers[i];
return (next-now);
}
gettimeofday(&now,0);
for(i=0;i<MAXTIMER;i++)
{ intervals[i]=3600;
timers[i]=FAR_FUTURE;
}
while(TRUE)
{ FD_ZERO(&read_fds);
FD_SET(sock,&read_fds);
tv.tv_sec=process_timers(sock,now.tv_sec);
tv.tv_usec=0;
retval=select(sock+1,&read_fds,NULL,NULL,&tv); //sleep here
if(retval==-1)
{ perror("select()");
exit (1);
}
gettimeofday(&now,0);
if(retval==1)
{ if(0>=(len = read(sock,read_pt, readbuf+999-read_pt)))
return; //connection is closed
read_pt+=len;
*read_pt=0;
*(argv++);
while (--argc)
{ parm= *(argv++);
if (parm[0]=='-')
{ while( (c=*++parm) )
switch(c)
{ case 'p':
tcp_port=atoi(*(argv++));
if(parm[1]!='\0')
{ err("\'p\' must be last");
return(FALSE);
}
if(!argc--)
{ err("missing port number after \'p\'");
return(FALSE);
}
break;
case 'i':
if(!argc--)
{ err("missing ip address after \'i\'");
return(FALSE);
}
if(-1==(my_ip=inet_addr(*(argv++))))
{ err("ip address is invalid");
return(FALSE);
}
break;
case 'v':
verbose=TRUE;
break;
case 'l':
argc-=2;
if(argc<=0)
{ err("\'l\' must be followed by two parameters");
return(FALSE);
}
lat=atof(*(argv++));
lon=atof(*(argv++));
break;
default:
err("unknown flag");
//fall through
case 'h':
printf("OpenAMIP(TM) Antenna controller simulator
version %s\n"
"Usage: OpenAMIP_sim [options...] \n"
" [options...] are any combination of:\n"
" -i <my_ip> --ip address on which to
listen.\n"
" -p <port> --listen on this port\n"
" -l <lat> <lon> --antenna's lat and
lon\n"
" -v --verbose\n"
process_args(argc,argv);
printf("Starting TCP server\n");
server_sock = socket(AF_INET, SOCK_STREAM, 0); // make a socket
if(server_sock == SOCKET_ERROR)
{ printf("ERROR: Could not make a socket\n");
return 1;
}
// fill address struct
address.sin_addr.s_addr = my_ip;
address.sin_port = htons(tcp_port);
address.sin_family = AF_INET;
}
getsockname(server_sock, (struct sockaddr *) &address,
&addr_size);
// establish listen queue
if(SOCKET_ERROR==listen(server_sock, QUEUE_SIZE))
{ printf("ERROR: Could not listen\n");
return 1;
}
// we are now a TCP server. listen for a connection. If it
closes,
// listen for a connection...
for(;;)
{ while(SOCKET_ERROR==(sock = accept(server_sock, (struct
sockaddr*)&address, &addr_size)))
printf(" Accept failed with %s\n",strerror(errno));
if (verbose)
printf("---- Opened socket\n");
// now go handle all the events. The routine will not return
here until the call is disconnected
handle_events(sock);
// close socket
if(verbose)
printf("==== Closing Socket\n");
if(SOCKET_ERROR==close(sock))
{ printf("ERROR: Could not close socket\n");
return 1;
}
}
return 0;
}
?
4.3 OpenAMIP_modem.c
/*
"Reference implementation" of the modem's OpenAMIP(tm) protocol
processing code.
---- begin notice----
Copyright (c) 2007, 2008 iDirect technologies
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#define FALSE 0
#define TRUE 1
//commandline parameters:
static int verbose=TRUE; //if set, print more
stuff
static int antenna_tcp_port=5005; //tcp port for the
antenna
static char *antenna_ip="127.0.0.1"; //antenna's IP address
static int antenna_alive_interval = 30; //keepalive timer
static int loc_interval=600;
int len;
int i,np;
case LOC:
timers[GPS]=now+intervals[GPS]; //reset the timeout for
"expected GPS"
break;
case LOCK_TIME:
np=sscanf(buff+len,"%d",&intervals[LOCK]);
timers[LOCK]=now;
break;
case MAX: //ignore unknown
messages
break;
}
}
We get the current time and check against each timer. If any
timer has
expired, we process that timer, which may set another timer.
After expired
timers are processed, we find the next timer that will expire
and compute
and return the interval from now until then.
*/
static time_t process_timers(int sock,time_t now)
{
int i;
time_t next=FAR_FUTURE; //preload a long sleep interval.
char buff[100];
if(timers[GPS]<now)
{ printf("Location timeout!\n");
timers[GPS]=now+intervals[GPS];
}
if(timers[STAT]<now)
{ printf("Keepalive timeout!\n");
timers[STAT]=now+intervals[STAT];
}
if(timers[LOCK]<now)
{ sprintf(buff,"L %d\n",modem_state);
timers[LOCK]=now+intervals[LOCK];
}
for (i=0;i<MAXTIMER;i++)
if(timers[i]<next)
next=timers[i];
return (next-now);
}
gettimeofday(&now_st,0);
now=now_st.tv_sec;
for(i=0;i<MAXTIMER;i++)
{ intervals[i]=3600;
timers[i]=FAR_FUTURE;
}
sprintf(buff,"S %3.2f %1.2f %1.2f\n"
"H %5.3f %5.3f\n"
"P %c %c\n"
"B %5.3f %2.3f\n"
"F\n"
"A 10\n"
"W 300\n",
sat_lon, sat_io_lat,sat_pol_skew,
freq_center,freq_bandwidth,
pol_rx,pol_tx,
rx_lo,tx_lo
);
send_msg(buff,sock);
timers[GPS]=now+600+1;
intervals[GPS]=601;
timers[STAT]=now+21;
intervals[STAT]=20;
while(TRUE)
{ FD_ZERO(&read_fds);
FD_SET(sock,&read_fds);
tv.tv_sec=process_timers(sock,now);
tv.tv_usec=0;
retval=select(sock+1,&read_fds,NULL,NULL,&tv); //sleep here
if(retval==-1)
{ perror("select()");
exit (1);
}
gettimeofday(&now_st,0);
now=now_st.tv_sec;
if(retval==1)
{ if(0>=(len = read(sock,read_pt, buff+999-read_pt)))
return; //connection is closed
read_pt+=len;
*read_pt=0;
while(0!=(eol=index(scan_pt,'\n'))) //is there a line in
the buffer?
{ *eol=0;
if(verbose)
printf("<-- %s\n",scan_pt);
*eol='\n';
process_message(scan_pt,now);
scan_pt=eol+1;
if(scan_pt>=read_pt)
{ read_pt=scan_pt=buff;
*buff=0;
}
}
}
}
}
*(argv++);
while (--argc)
{
parm= *(argv++);
if (parm[0]=='-')
{ while( (c=*++parm) )
switch(c)
{
case 'p':
antenna_tcp_port=atoi(*(argv++));
if(parm[1]!='\0')
{ err("\'p\' must be last");
return(FALSE);
}
if(!argc--)
{ err("missing port number after \'p\'");
return(FALSE);
}
break;
case 'i':
if(!argc--)
{ err("missing ip address after \'i\'");
return(FALSE);
}
antenna_ip= *argv++;
break;
case 'v':
verbose=TRUE;
break;
default:
err("unknown flag");
//fall through
case 'h':
printf("OpenAMIP(TM) modem simulator version %s\n"
"Usage: OpenAMIP_modem [options...] \n"
" [options...] are any combination of:\n"
" -i <antenns_ip> --ip address of antenna
controller.\n"
" -p <port> --tcp port nbr of antenna
controller\n"
" -v --verbose\n"
" -h --print this message\n",
version
);
return(FALSE);
}
}
}
return(TRUE);
}
/*
Main loop. get commandline params, open a TCP connection to the
antenna controller,
issue a satellite location sequence, ask for periodic status and
locations, and wait.
If the controller asks for periodic keepalive, then issue them.
After one minute,
shift to the next satellite and continue.
*/
process_args(argc,argv);
memset(&hostaddr_in,0,sizeof(struct sockaddr_in));
hp = gethostbyname (antenna_ip);
hostaddr_in.sin_family=AF_INET;
hostaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))-
>s_addr;
hostaddr_in.sin_port= htons(antenna_tcp_port);
while(TRUE)
{ if( connect(s,(struct sockaddr *) &hostaddr_in,
sizeof(hostaddr_in)))
{ perror("TCP connect failed");
exit(1);
}
handle_events(s);
// close socket
if(verbose)
printf("==== Closing Socket\n");
if(0!=close(s))
{ perror("Could not close socket\n");
return 1;
}
}
return(0);
}