Skip to content

Commit 237492b

Browse files
author
Don Goodman-Wilson
committed
Fixed a bug where vnodes with duplicate NodeIDs—perfectly legal here-were having a problem with an infinite loop of alias al
location, as alias collisions inevitably resulted from an attemp to allocate aliases for two identical NodeIDs. git-svn-id: svn+ssh://svn.code.sf.net/p/openlcb/svn/trunk/prototypes/C@2782 87536cb5-86f1-4cdc-8fc6-3f0f71bcd267
1 parent ee44177 commit 237492b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

libraries/OpenLCB/OLCB_CAN_Alias_Helper.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -271,27 +271,27 @@ void OLCB_CAN_Alias_Helper::preAllocateAliases(void)
271271

272272
void OLCB_CAN_Alias_Helper::allocateAlias(OLCB_NodeID* nodeID)
273273
{
274-
//Serial.println("Allocating Alias for:");
275-
//nodeID->print();
274+
Serial.println("Allocating Alias for:");
275+
nodeID->print();
276276
private_nodeID_t *slot = 0;
277277
//first, see if this NodeID is already in our list, and if so, don't worry about it.TODO
278278
uint8_t i;
279279
for(i = 0; i < CAN_ALIAS_BUFFER_SIZE; ++i)
280280
{
281-
if(nodeID == _nodes[i].node) //should point to same thing if same NID
281+
if(_nodes[i].node->sameNID(nodeID)) //should point to same thing if same NID
282282
{
283-
//Serial.println("No need to add duplicate NodeID to alias list");
283+
Serial.println("No need to add duplicate NodeID to alias list");
284284
return;
285285
}
286286
}
287-
//Serial.println("setting initialized to false");
287+
Serial.println("setting initialized to false");
288288
nodeID->initialized = false;
289289
//find a location for this nodeID in our list
290290
for(i = 0; i < CAN_ALIAS_BUFFER_SIZE; ++i)
291291
{
292292
if(_nodes[i].state == ALIAS_HOLDING_STATE)
293293
{
294-
//Serial.println("allocate: found a slot w/alias!");
294+
Serial.println("allocate: found a slot w/alias!");
295295
slot = &(_nodes[i]);
296296
break;
297297
}
@@ -300,12 +300,12 @@ void OLCB_CAN_Alias_Helper::allocateAlias(OLCB_NodeID* nodeID)
300300
{
301301
for(uint8_t i = 0; i < CAN_ALIAS_BUFFER_SIZE; ++i)
302302
{
303-
//Serial.print("Checking slot ");
304-
//Serial.println(i, DEC);
305-
//Serial.println(_nodes[i].state, DEC);
303+
Serial.print("Checking slot ");
304+
Serial.println(i, DEC);
305+
Serial.println(_nodes[i].state, DEC);
306306
if(_nodes[i].state == ALIAS_EMPTY_STATE)
307307
{
308-
//Serial.println("allocate: found a slot w/o alias!");
308+
Serial.println("allocate: found a slot w/o alias!");
309309
slot = &(_nodes[i]);
310310
break;
311311
}
@@ -314,25 +314,25 @@ void OLCB_CAN_Alias_Helper::allocateAlias(OLCB_NodeID* nodeID)
314314
if(!slot)
315315
//SERIUS ERROR CONDITION! NO SPACE TO CACHE NODEID!!
316316
{
317-
//Serial.println("allocate: NO MORE SLOTS FOR NODEIDS!");
318-
//Serial.println(CAN_ALIAS_BUFFER_SIZE, DEC);
317+
Serial.println("allocate: NO MORE SLOTS FOR NODEIDS!");
318+
Serial.println(CAN_ALIAS_BUFFER_SIZE, DEC);
319319
while(1);
320320
}
321321

322322

323-
//Serial.println("Assigning nodeid to cache slot");
323+
Serial.println("Assigning nodeid to cache slot");
324324
slot->node = nodeID;
325325
//does the slot already have an alias we can reuse?
326326
if(slot->alias)
327327
{
328-
//Serial.print("allocate: no need to allocate alias: ");
329-
//Serial.println(slot->alias, DEC);
328+
Serial.print("allocate: no need to allocate alias: ");
329+
Serial.println(slot->alias, DEC);
330330
slot->node->alias = slot->alias; //copy it into the nodeID
331331
slot->state = ALIAS_AMD_STATE; //ready to go! Just send an AMD
332332
}
333333
else //we'll need to generate and allocate an alias
334334
{
335-
//Serial.println("allocate: moving to CID1!");
335+
Serial.println("allocate: moving to CID1!");
336336
uint32_t lfsr1 = (((uint32_t)nodeID->val[0]) << 16) | (((uint32_t)nodeID->val[1]) << 8) | ((uint32_t)nodeID->val[2]);
337337
uint32_t lfsr2 = (((uint32_t)nodeID->val[3]) << 16) | (((uint32_t)nodeID->val[4]) << 8) | ((uint32_t)nodeID->val[5]);
338338
slot->alias = (lfsr1 ^ lfsr2 ^ (lfsr1>>12) ^ (lfsr2>>12) )&0xFFF;
@@ -341,9 +341,9 @@ void OLCB_CAN_Alias_Helper::allocateAlias(OLCB_NodeID* nodeID)
341341
slot->alias = 1; //a hack just to avoid a 0 alias.
342342
slot->state = ALIAS_CID1_STATE;
343343
}
344-
//Serial.print("New alias = ");
345-
//Serial.println(slot->alias);
346-
//Serial.println("Allocate alias done!");
344+
Serial.print("New alias = ");
345+
Serial.println(slot->alias);
346+
Serial.println("Allocate alias done!");
347347
}
348348

349349
void OLCB_CAN_Alias_Helper::reAllocateAlias(private_nodeID_t* nodeID)

0 commit comments

Comments
 (0)