AssociationHandler
The AssociationHandler
interface handles all the per-association callbacks that are unrelated to measurement data. It contains a single method (get_current_time
)
to retrieve a UTC timestamp used to synchronize the time on the outstation.
Typically, you'd return the system time in get_current_time
which is kept synchronized via NTP. However, you can use a different clock if desired. For example, you might want a data concentrator to receive time from an upstream DNP3 master while maintaining an offset from an internal clock. The examples below demonstrate how to implement an AssociationHandler
that retrieves the system time.
- Rust
- C
- Java
- C#
note
Rust's 'AssociationHandler' trait has a default implementation of get_current_time
that retrieves the system time.
dnp3_timestamp_utc_t get_system_time(void *arg)
{
time_t timer = time(NULL);
return dnp3_timestamp_utc_valid(timer * 1000);
}
dnp3_association_handler_t get_association_handler()
{
return (dnp3_association_handler_t){
.get_current_time = get_system_time,
.on_destroy = NULL,
.ctx = NULL,
};
}
class TestAssociationHandler implements AssociationHandler {
@Override
public TimestampUtc getCurrentTime() {
return TimestampUtc.valid(ulong(System.currentTimeMillis()));
}
}
class TestAssocationHandler : IAssociationHandler
{
public TimestampUtc GetCurrentTime()
{
return TimestampUtc.Valid((ulong)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalMilliseconds);
}
}