FastScan review
authorgroke6
Fri, 12 Sep 2008 10:54:54 +0200
changeset 517 003679edc437
parent 516 19085e93ad21
child 518 0dc0750327c0
FastScan review
doc/manual/en/manual.tex
examples/TestMasterSlaveLSS/Master.c
examples/TestMasterSlaveLSS/SlaveA.c
examples/TestMasterSlaveLSS/SlaveA.h
examples/TestMasterSlaveLSS/SlaveB.c
examples/TestMasterSlaveLSS/SlaveB.h
examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c
include/data.h
include/lss.h
src/lss.c
src/nmtSlave.c
src/states.c
--- a/doc/manual/en/manual.tex	Sun Sep 07 17:58:37 2008 +0200
+++ b/doc/manual/en/manual.tex	Fri Sep 12 10:54:54 2008 +0200
@@ -122,6 +122,10 @@
 
 Only concise DFC is supported.
 
+\subsubsection{DS-305}
+
+LSS services are fully supported although they have to be enabled at compile time. Additionally, FastScan LSS service is also optionally enabled. 
+
 \section{How to start}
 
 \subsection{Host requirements}
@@ -203,6 +207,7 @@
 ./drivers/hcs12 HCS12 full target interface
 ./examples Examples
 ./examples/TestMasterSlave 2 nodes, NMT SYNC SDO PDO, win32+unix
+./examples/TestMasterSlaveLSS 3 nodes, NMT SYNC SDO PDO LSS, win32+unix
 ./examples/TestMasterMicroMod 1 node, control Peak I/O Module, unix
 ./examples/gene_SYNC_HCS12 Just send periodic SYNC on HCS12
 ./examples/win32test Ask some DS301 infos to a node (win32)
@@ -409,9 +414,21 @@
 	./configure --can=vscom
 \end{verbatim}
 The VSCAN API archive will be automatically downloaded and decompressed (unzip required). See \href{http://www.vscom.de/1_1_05.htm}{www.vscom.de} for available adapters.
+
+\subsubsection{LSS services}
+Canfestival optionally supports LSS services but they must be enabled.
+\begin{verbatim}
+	./configure --enable-lss
+\end{verbatim}
+
+Additionally, the FastScan LSS service can also be enabled.
+\begin{verbatim}
+	./configure --enable-lss --enable-lss-fs
+\end{verbatim}
+
 \subsection{Testing your CanFestival installation}
 
-\subsection{User space}
+\subsubsection{User space}
 
 Sample provided in /example/TestMasterSlave is installed into your
 system during installation.
@@ -435,8 +452,9 @@
 	TestMasterSlave -l libcanfestival_can_peak.so -s 40 -m 41
 \end{verbatim}
 
-
-\subsection{Kernel space}
+If the LSS services are enabled the sample provided in /example/TestMasterSlaveLSS will be also installed. It behaves the same as TestMasterSlave except that there are 2 slave nodes without a valid nodeID so the the initializations is done via  the LSS services. If FastScan optional service is enabled the example will use it. 
+
+\subsubsection{Kernel space}
 
 
 \begin{verbatim}
@@ -985,6 +1003,63 @@
   **************************************************************
 \end{verbatim}
 
+\subsection{TestMasterSlaveLSS}
+
+
+\begin{verbatim}
+**************************************************************
+*  TestMasterSlaveLSS                                        *
+*                                                            *
+*  A LSS example for PC. It does implement 3 CanOpen         *
+*  nodes in the same process. A master and 2 slaves. All     *
+*  communicate together, exchanging periodically NMT, SYNC,  *
+*  SDO and PDO. Master configure heartbeat producer time     *
+*  at 1000 ms for the slaves by concise DCF.                 *
+*                                                            *
+*   Usage:                                                   *
+*   ./TestMasterSlaveLSS  [OPTIONS]                          *
+*                                                            *
+*   OPTIONS:                                                 *
+*     -l : Can library ["libcanfestival_can_virtual.so"]     *
+*                                                            *
+*    SlaveA:                                                 *
+*     -a : bus name ["0"]                                    *
+*     -A : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *
+*                                                            *
+*    SlaveB:                                                 *
+*     -b : bus name ["1"]                                    *
+*     -B : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *
+*                                                            *
+*    Master:                                                 *
+*     -m : bus name ["2"]                                    *
+*     -M : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *
+*                                                            *
+**************************************************************
+\end{verbatim}
+
+The function used to request LSS services is \textit{configNetworkNode}. It works similar to \textit{writeNetworkDict} and its model is the following:
+\begin{verbatim}
+UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, 
+LSSCallback_t Callback)
+\end{verbatim}
+
+\subsection{FastScan}
+FastScan is a special LSS service that allow the dynamically identification of the slave nodes even if they do not have a valid nodeID. This identification is based on the LSS address, composed by vendor ID, product code, revision number and serial number (refer to the DS305 for more information). The LSS address can be partially known or fully unknown. To represent this fact in Canfestival, we use the structure \textit{lss\_fs\_transfer\_t}. The parameter \textit{FS\_LSS\_ID} is an array of four elements which represents the four elements of the LSS address. The other parameter, \textit{FS\_BitChecked}, is also an array and it represents how many bits of each LSS address element are UNKNOWN. The next example is taken from \textit{TestMasterSlaveLSS}, where only the last two digits (8 bits) of vendor ID and product code are unknown and revision number and serial number are totally unknown. 
+
+\begin{verbatim}
+lss_fs_transfer_t lss_fs;
+/* The VendorID and ProductCode are partialy known, */
+/* except the last two digits (8 bits). */
+lss_fs.FS_LSS_ID[0]=Vendor_ID;
+lss_fs.FS_BitChecked[0]=8;
+lss_fs.FS_LSS_ID[1]=Product_Code;
+lss_fs.FS_BitChecked[1]=8;
+/* serialNumber and RevisionNumber are unknown, */
+/* i.e. the 8 digits (32bits) are unknown. */
+lss_fs.FS_BitChecked[2]=32;
+lss_fs.FS_BitChecked[3]=32;
+res=configNetworkNode(&d,LSS_IDENT_FASTSCAN,&lss_fs,0,CheckLSSAndContinue);
+\end{verbatim}
 
 \section{Developing a new node}
 
--- a/examples/TestMasterSlaveLSS/Master.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/examples/TestMasterSlaveLSS/Master.c	Fri Sep 12 10:54:54 2008 +0200
@@ -216,13 +216,16 @@
 	
 				/* The slaves are now configured (nodeId and Baudrate) via the LSS services.
    			 	* Switch the LSS state to WAITING and restart the slaves. */
+				
+				/*TODO: change the baud rate of the master!!*/
    			 	MasterBoard.baudrate="250K";
-   	
+   			 	
+   			 	
 	   			printf("Master : Switch Delay period finished. Switching to LSS WAITING state\n");
    				configNetworkNode(d,LSS_SM_GLOBAL,&LSS_mode,0,NULL);
 	   			
    				printf("Master : Restarting all the slaves\n");
-   				masterSendNMTstateChange (d, 0x00, NMT_Reset_Node);
+   				masterSendNMTstateChange (d, 0x00, NMT_Reset_Comunication);
 	   			
    				printf("Master : Starting the SYNC producer\n");
    				writeLocalDict( d, /*CO_Data* d*/
@@ -342,9 +345,20 @@
 			break;
 #ifdef CO_ENABLE_LSS_FS
 		case 2:	/* LSS=>FastScan */
+		{
+			lss_fs_transfer_t lss_fs;
 			eprintf("LSS=>FastScan\n");
-			res=configNetworkNode(&TestMaster_Data,LSS_IDENT_FASTSCAN,0,0,CheckLSSAndContinue);
-			break;
+			/* The VendorID and ProductCode are partialy known, except the last two digits (8 bits). */
+			lss_fs.FS_LSS_ID[0]=Vendor_ID;
+			lss_fs.FS_BitChecked[0]=8;
+			lss_fs.FS_LSS_ID[1]=Product_Code;
+			lss_fs.FS_BitChecked[1]=8;
+			/* serialNumber and RevisionNumber are unknown, i.e. the 8 digits (32bits) are unknown. */
+			lss_fs.FS_BitChecked[2]=32;
+			lss_fs.FS_BitChecked[3]=32;
+			res=configNetworkNode(&TestMaster_Data,LSS_IDENT_FASTSCAN,&lss_fs,0,CheckLSSAndContinue);
+		}
+		break;
 #else
 		case 2:	/* LSS=>identify node */
 			eprintf("LSS=>identify node\n");
--- a/examples/TestMasterSlaveLSS/SlaveA.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/examples/TestMasterSlaveLSS/SlaveA.c	Fri Sep 12 10:54:54 2008 +0200
@@ -81,8 +81,13 @@
 	eprintf("SlaveA received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
 }
 
+void TestSlaveA_NMT_Slave_Communications_Reset_Callback(CO_Data* d)
+{
+	eprintf("TestSlaveA_NMT_Slave_Communications_Reset_Callback\n");
+}
+
 void TestSlaveA_StoreConfiguration(CO_Data* d, UNS8 *error, UNS8 *spec_error)
 {
-	printf("TestSlaveA_StoreConfiguration\n");
+	eprintf("TestSlaveA_StoreConfiguration\n");
 }
 
--- a/examples/TestMasterSlaveLSS/SlaveA.h	Sun Sep 07 17:58:37 2008 +0200
+++ b/examples/TestMasterSlaveLSS/SlaveA.h	Fri Sep 12 10:54:54 2008 +0200
@@ -13,4 +13,5 @@
 void TestSlaveA_post_TPDO(CO_Data* d);
 void TestSlaveA_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
 void TestSlaveA_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg);
+void TestSlaveA_NMT_Slave_Communications_Reset_Callback(CO_Data* d);
 void TestSlaveA_StoreConfiguration(CO_Data* d, UNS8 *error, UNS8 *spec_error);
--- a/examples/TestMasterSlaveLSS/SlaveB.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/examples/TestMasterSlaveLSS/SlaveB.c	Fri Sep 12 10:54:54 2008 +0200
@@ -80,8 +80,13 @@
 	eprintf("SlaveB received EMCY message. Node: %2.2x  ErrorCode: %4.4x  ErrorRegister: %2.2x\n", nodeID, errCode, errReg);
 }
 
+void TestSlaveB_NMT_Slave_Communications_Reset_Callback(CO_Data* d)
+{
+	eprintf("TestSlaveB_NMT_Slave_Communications_Reset_Callback\n");
+}
+
 void TestSlaveB_StoreConfiguration(CO_Data* d, UNS8 *error, UNS8 *spec_error)
 {
-	printf("TestSlaveB_StoreConfiguration\n");
+	eprintf("TestSlaveB_StoreConfiguration\n");
 }
 
--- a/examples/TestMasterSlaveLSS/SlaveB.h	Sun Sep 07 17:58:37 2008 +0200
+++ b/examples/TestMasterSlaveLSS/SlaveB.h	Fri Sep 12 10:54:54 2008 +0200
@@ -13,4 +13,5 @@
 void TestSlaveB_post_TPDO(CO_Data* d);
 void TestSlaveB_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
 void TestSlaveB_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg);
+void TestSlaveB_NMT_Slave_Communications_Reset_Callback(CO_Data* d);
 void TestSlaveB_StoreConfiguration(CO_Data* d, UNS8 *error, UNS8 *spec_error);
--- a/examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c	Fri Sep 12 10:54:54 2008 +0200
@@ -66,24 +66,24 @@
   printf("*  nodes in the same process. A master and 2 slaves. All     *\n");
   printf("*  communicate together, exchanging periodically NMT, SYNC,  *\n");
   printf("*  SDO and PDO. Master configure heartbeat producer time     *\n");
-  printf("*  at 0 ms for slave node-id 0x02 and 0x03 by concise DCF.   *\n");                                  
+  printf("*  at 1000 ms for the slaves by concise DCF.                 *\n");                                  
   printf("*                                                            *\n");
   printf("*   Usage:                                                   *\n");
   printf("*   ./TestMasterSlaveLSS  [OPTIONS]                          *\n");
   printf("*                                                            *\n");
   printf("*   OPTIONS:                                                 *\n");
-  printf("*     -l : Can library [\"libcanfestival_can_virtual.so\"]   *\n");
+  printf("*     -l : Can library [\"libcanfestival_can_virtual.so\"]     *\n");
   printf("*                                                            *\n");
   printf("*    SlaveA:                                                 *\n");
-  printf("*     -a : bus name [\"0\"]                                  *\n");
+  printf("*     -a : bus name [\"0\"]                                    *\n");
   printf("*     -A : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
   printf("*                                                            *\n");
-   printf("*    SlaveB:                                                *\n");
-  printf("*     -b : bus name [\"1\"]                                  *\n");
+  printf("*    SlaveB:                                                 *\n");
+  printf("*     -b : bus name [\"1\"]                                    *\n");
   printf("*     -B : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
   printf("*                                                            *\n");
   printf("*    Master:                                                 *\n");
-  printf("*     -m : bus name [\"2\"]                                  *\n");
+  printf("*     -m : bus name [\"2\"]                                    *\n");
   printf("*     -M : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
   printf("*                                                            *\n");
   printf("**************************************************************\n");
@@ -236,7 +236,8 @@
 		TestSlaveA_Data.post_TPDO = TestSlaveA_post_TPDO;
 		TestSlaveA_Data.storeODSubIndex = TestSlaveA_storeODSubIndex;
 		TestSlaveA_Data.post_emcy = TestSlaveA_post_emcy;
-		/* in this example the slave doesn't support Store configuration*/
+		/* in this example the slave doesn't implement NMT_Slave_Communications_Reset_Callback */
+		//TestSlaveA_Data.NMT_Slave_Communications_Reset_Callback = TestSlaveA_NMT_Slave_Communications_Reset_Callback;
 		TestSlaveA_Data.lss_StoreConfiguration = TestSlaveA_StoreConfiguration;
 
 		if(!canOpen(&SlaveBoardA,&TestSlaveA_Data)){
@@ -256,6 +257,7 @@
 		TestSlaveB_Data.post_TPDO = TestSlaveB_post_TPDO;
 		TestSlaveB_Data.storeODSubIndex = TestSlaveB_storeODSubIndex;
 		TestSlaveB_Data.post_emcy = TestSlaveB_post_emcy;
+		TestSlaveB_Data.NMT_Slave_Communications_Reset_Callback = TestSlaveB_NMT_Slave_Communications_Reset_Callback;
 		TestSlaveB_Data.lss_StoreConfiguration = TestSlaveB_StoreConfiguration;
 
 		if(!canOpen(&SlaveBoardB,&TestSlaveB_Data)){
--- a/include/data.h	Sun Sep 07 17:58:37 2008 +0200
+++ b/include/data.h	Fri Sep 12 10:54:54 2008 +0200
@@ -157,7 +157,8 @@
   		0, 						/* LSSNext */\
   		0, 						/* LSSPos */\
   		LSS_FS_RESET,			/* FastScan_SM */\
-  		-1						/* timerFS */
+  		-1,						/* timerFS */\
+  		{{0,0,0,0},{0,0,0,0}}   /* lss_fs_transfer */
 #else
 #define lss_fs_Initializer
 #endif		
--- a/include/lss.h	Sun Sep 07 17:58:37 2008 +0200
+++ b/include/lss.h	Fri Sep 12 10:54:54 2008 +0200
@@ -82,6 +82,15 @@
 
 //#include "timer.h"
 
+#ifdef CO_ENABLE_LSS_FS
+struct struct_lss_fs_transfer {
+	UNS32 FS_LSS_ID[4];
+	UNS8 FS_BitChecked[4];
+};
+
+typedef struct struct_lss_fs_transfer lss_fs_transfer_t;
+#endif
+
 /* The Transfer structure
 * Used to store the different fields of the internal state of the LSS  
 */
@@ -130,6 +139,10 @@
   TIMER_HANDLE timerFS;		/* timerFS is automatically incremented when the FastScan service
   							 * has been requested and reseted to 0 when the protocol ends.
                               */
+#ifdef CO_ENABLE_LSS_FS
+  lss_fs_transfer_t lss_fs_transfer;
+#endif
+  
 #endif                           
 };
 
@@ -139,7 +152,8 @@
 typedef UNS8 lss_transfer_t;
 #endif
   
-  
+
+
 void startLSS(CO_Data* d);
 void stopLSS(CO_Data* d);
 
--- a/src/lss.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/src/lss.c	Fri Sep 12 10:54:54 2008 +0200
@@ -108,10 +108,13 @@
 		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
    			/* if at least one node had answered before the timer expired, start the FastScan protocol*/
    			if(d->lss_transfer.LSSanswer!=0){
+   				UNS32 Mask=0xFFFFFFFF;
    				d->lss_transfer.LSSanswer=0;
-   				d->lss_transfer.BitChecked=31;
-   				d->lss_transfer.IDNumber=0;
+   				d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[0];
+   				Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
+   				d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[0] & Mask;
    				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
+   				//printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
    				StartLSS_FS_TIMER();
    				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
    				return;
@@ -126,6 +129,8 @@
    		else{
 			/* This should not happen, an error ocurred*/
 			MSG_ERR(0x1D07, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
+			d->lss_transfer.state = LSS_ABORTED_INTERNAL;
+			d->lss_transfer.FastScan_SM=LSS_FS_RESET;
    		}
 	}
 	else
@@ -140,6 +145,9 @@
     	MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
     	/* Set aborted state */
     	d->lss_transfer.state = LSS_ABORTED_INTERNAL;
+#ifdef CO_ENABLE_LSS_FS
+    	d->lss_transfer.FastScan_SM = LSS_FS_RESET;
+#endif
     }
     	
     /* Call the user function to inform of the problem.*/
@@ -220,7 +228,7 @@
 		else{
 			d->lss_transfer.BitChecked--;
 		}
-   			
+		//printf("BitChecked=%d, IDNumber=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber);
    		d->lss_transfer.LSSanswer=0;
   		StartLSS_FS_TIMER();
    		sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
@@ -245,11 +253,14 @@
 				d->lss_transfer.dat1=0;
 			}
 			else{
+				UNS32 Mask=0xFFFFFFFF;
 				/* Start with the next LSS-ID[sub] */
 				d->lss_transfer.LSSSub++;
-				d->lss_transfer.BitChecked=31;
-   				d->lss_transfer.IDNumber=0;
+				d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[d->lss_transfer.LSSSub];
+				Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
+   				d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[d->lss_transfer.LSSSub] & Mask;
    				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
+   				//printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
    				StartLSS_FS_TIMER();
    				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
    				return;
@@ -258,8 +269,11 @@
 		else{
 			/* This should not happen, an error ocurred*/
 			MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
+			MSG_ERR(0x1D0E, "There is not any node with LSS_ID# =>", d->lss_transfer.LSSSub);
+			MSG_ERR(0x1D0E, "with the value =>", d->lss_transfer.IDNumber);
 			/* Set aborted state */
     		d->lss_transfer.state = LSS_ABORTED_INTERNAL;
+    		d->lss_transfer.FastScan_SM = LSS_FS_RESET;
 		}
 	}
 	break;
@@ -469,6 +483,24 @@
   	break;
 #ifdef CO_ENABLE_LSS_FS
   case LSS_IDENT_FASTSCAN:
+	  	if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
+	  		UNS8 i;
+	  		 /* Initialize the lss_fs_transfer FastScan parameters */
+	  		for(i=0;i<4;i++){
+	  			d->lss_transfer.lss_fs_transfer.FS_LSS_ID[i]=(*(lss_fs_transfer_t*)dat1).FS_LSS_ID[i];
+	  			d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]=(*(lss_fs_transfer_t*)dat1).FS_BitChecked[i];
+	  			/* Adjust BitChecked from 32-1 to 31-0 */
+	  			if(d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]>0)d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]--;
+	  		}
+	  		
+	  		d->lss_transfer.IDNumber=0;
+	  		d->lss_transfer.BitChecked=128;
+	  		d->lss_transfer.LSSSub=0;
+	  		d->lss_transfer.LSSNext=0;
+	  				
+	  		/* it will generate a response only if it is the start of the FastScan protocol*/
+	  		hasResponse=1;
+	  	}
 		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
 		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
 		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
@@ -476,8 +508,6 @@
 		m.data[5]=d->lss_transfer.BitChecked;
 		m.data[6]=d->lss_transfer.LSSSub;
 		m.data[7]=d->lss_transfer.LSSNext;
-		/* it will generate a response only if it is the start of the FastScan protocol*/
-		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET)hasResponse=1;
 	break;
 #endif
   default:
@@ -645,7 +675,7 @@
 					setNodeId(d, d->lss_transfer.nodeID);
 					setState(d, Initialisation);
 				}
-				else{/* The nodeID will be changed on NMT_Reset Request*/
+				else{/* The nodeID will be changed on NMT_Reset_Comunication Request*/
 				}
 			}
 			d->lss_transfer.mode=LSS_WAITING_MODE;
--- a/src/nmtSlave.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/src/nmtSlave.c	Fri Sep 12 10:54:54 2008 +0200
@@ -80,22 +80,22 @@
 
       case NMT_Reset_Comunication:
          {
-         UNS8 newNodeId = getNodeId(d);
+         UNS8 currentNodeId = getNodeId(d);
          
             if(d->NMT_Slave_Communications_Reset_Callback != NULL)
                d->NMT_Slave_Communications_Reset_Callback(d);
 #ifdef CO_ENABLE_LSS
             // LSS changes NodeId here in case lss_transfer.nodeID doesn't 
             // match current getNodeId()
-            if(newNodeId!=d->lss_transfer.nodeID && newNodeId>0 && newNodeId<=127 )
-               newNodeId = d->lss_transfer.nodeID;
+            if(currentNodeId!=d->lss_transfer.nodeID)
+               currentNodeId = d->lss_transfer.nodeID;
 #endif
 
             // clear old NodeId to make SetNodeId reinitializing
             // SDO, EMCY and other COB Ids
             *d->bDeviceNodeId = 0xFF; 
          
-            setNodeId(d, newNodeId);
+            setNodeId(d, currentNodeId);
          }
          setState(d,Initialisation);
          break;
--- a/src/states.c	Sun Sep 07 17:58:37 2008 +0200
+++ b/src/states.c	Fri Sep 12 10:54:54 2008 +0200
@@ -244,12 +244,16 @@
   
 #ifdef CO_ENABLE_LSS
   d->lss_transfer.nodeID=nodeId;
-  if(nodeId==0xFF)
-  {
+  if(nodeId==0xFF){
   	*d->bDeviceNodeId = nodeId;
   	return;
   }
+  else
 #endif
+  if(!(nodeId>0 && nodeId<=127)){
+	  MSG_WAR(0x2D01, "Invalid NodeID",nodeId);
+	  return;
+  }
 
   if(offset){
     /* Adjust COB-ID Client->Server (rx) only id already set to default value or id not valid (id==0xFF)*/