Instruction Manual
ISI Programmer’s Guide 76
deleted devices, monitor the time of the last update for each entry in the table
and detect devices that have not recently sent a DRUM.
E
XAMPLE 1
The following example maintains a device table, adding new devices when
discovered, updating subnet and node IDs when they change, and deleting
stale devices.
#include <isi.h>
#include <mem.h>
#define MAX_DEVICES 16
#define MAX_CREDITS 5
#pragma num_alias_table_entries 6
unsigned deviceCount;
// Struct to hold device information
typedef struct {
unsigned credits;
unsigned subnetId;
unsigned nodeId;
unsigned neuronId[NEURON_ID_LEN];
} Device;
Device devices[MAX_DEVICES];
when (reset) {
deviceCount = 0; // Not required since global RAM is zeroed
scaled_delay(31745UL); // 800ms delay
IsiStartS(isiFlagNone);
}
void MaintainDevices(const IsiDrum* pDrum) {
unsigned i;
// Iterate through the device list and see if the Neuron ID
// of the stored device matches that of the new device; if it
// does, then update the related details
for (i = 0; i < deviceCount; i++) {
if (memcmp(Devices[i].neuronId, pDrum->NeuronId,
NEURON_ID_LEN) == 0) {
devices[i].credits = MAX_CREDITS;
devices[i].subnetId = pDrum->SubnetId;
devices[i].nodeId = pDrum->NodeId;
break;
}
}
// If i is equal to the device count, then the device was not
// found, so add it to the device table if possible
if (i == deviceCount && deviceCount < MAX_DEVICES) {
memcpy(devices[i].neuronId, pDrum->NeuronId,
NEURON_ID_LEN);
deviceCount++;
devices[i].credits = MAX_CREDITS;
devices[i].subnetId = pDrum->SubnetId;
devices[i].nodeId = pDrum->NodeId;
}
}










