Kaynağa Gözat

added function for setting the serial number during device setup allowing to set the serial number more easily per device; changed main to prompt for command line parameters, updated TODO and README

Alois Zoitl 16 yıl önce
ebeveyn
işleme
8cbe361dad

+ 2 - 2
README

@@ -30,8 +30,8 @@ Compile for PCs:
      1.1 Go into the bin/pc directory
      1.2 Invoke make
      1.3 For invoking opener type:
-          ./opener.exe ipaddress subnetmask gateway domainname hostaddress macaddress
-         e.g. ./opener.exe 192.168.0.2 255.255.255.0 192.168.0.1 test.com testdevice 00 15 C5 BF D0 87 
+          ./opener ipaddress subnetmask gateway domainname hostaddress macaddress
+         e.g. ./opener 192.168.0.2 255.255.255.0 192.168.0.1 test.com testdevice 00 15 C5 BF D0 87 
   2. Within Eclipse 
      2.1 Import the project
      2.2 Go to the bin/pc folder in the make targets view

+ 1 - 2
TODO

@@ -8,9 +8,8 @@ This file serves as brainstorming buffer for ideas to improve and enhance OpENer
 
 
 * Improvements and Optimizations
-  - pc/main.c remove my ip address
+  - test exclusive owner connections (inputs/outputs)
   - Handle errno == EINTR do continue else 
-  - add setSerialNumber in CIP_API
   - Rework logging and tracing facility
   - Remove the need for the response buffer in the explicit message handling (zero copy stack)
   - Rework I/O message handling:

+ 2 - 0
src/cip/cipconnectionmanager.c

@@ -254,6 +254,8 @@ EIP_STATUS handleReceivedConnectedData(EIP_UINT8 * pa_pnData, int pa_nDataLength
                     = getConnectedObject(g_stCPFDataItem.stAddr_Item.Data.ConnectionIdentifier);
                 if (pstConnectionObject == 0)
                   return EIP_ERROR;
+                
+                printf("Sequence nummer: %ld, %ld\n", g_stCPFDataItem.stAddr_Item.Data.SequenceNumber, pstConnectionObject->EIPSequenceCountConsuming);
 
                 if (SEQ_GEQ32(g_stCPFDataItem.stAddr_Item.Data.SequenceNumber, pstConnectionObject->EIPSequenceCountConsuming))
                   {

+ 7 - 1
src/cip/cipidentity.c

@@ -22,10 +22,16 @@ EIP_UINT16 ProductCode = OPENER_DEVICE_PRODUCT_CODE; /* #3 */
 S_CIP_Revision Revison =
   { OPENER_DEVICE_MAJOR_REVISION, OPENER_DEVICE_MINOR_REVISION }; /* #4 */
 EIP_UINT16 ID_Status = 0; /* #5 TODO find out what this is and how it gets set */
-EIP_UINT32 SerialNumber = OPENER_DEVICE_SERIAL; /* #6  TODO made this variable per device */
+EIP_UINT32 SerialNumber = 0; /* #6  Has to be set prior to OpENer initialization */
 S_CIP_Short_String ProductName =
   { sizeof(OPENER_DEVICE_NAME) - 1, OPENER_DEVICE_NAME }; /* #7 */
 
+
+void setDeviceSerialNumber(EIP_UINT32 pa_nSerialNumber)
+  {
+    SerialNumber = pa_nSerialNumber;
+  }
+
 static EIP_STATUS Reset(S_CIP_Instance *pa_pstInstance, /* pointer to instance*/
     S_CIP_MR_Request *pa_stMRRequest, /* pointer to message router request*/
     S_CIP_MR_Response *pa_stMRResponse, /* pointer to message router response*/

+ 7 - 0
src/opener_api.h

@@ -50,6 +50,13 @@ void configureDomainName(const char *pa_acDomainName);
  */
 void configureHostName(const char *pa_acHostName);
 
+/*! \ingroup CIP_API
+ * Set the serial number of the device's identy object.
+ * 
+ * @param pa_nSerialNumber unique 32 bit number identifying the device
+ */ 
+void setDeviceSerialNumber(EIP_UINT32 pa_nSerialNumber);
+
 /** \ingroup CIP_API 
  * \brief Initialize and setup the CIP-stack
  * 

+ 8 - 13
src/ports/platform-pc/main.c

@@ -30,19 +30,11 @@ int main(int argc, char *arg[])
     EIP_UINT8 acMyMACAddress[6];
 
     if (argc != 12)
-      { /*! use default values
-            configureNetworkInterface("192.168.1.1", "255.255.252.0", "192.168.1.1"); */
-        configureNetworkInterface("128.131.86.182", "255.255.255.128", "128.131.86.129");
-        configureDomainName("azrael.acin.tuwien.ac.at");
-
-        acMyMACAddress[0] = 0x00;
-        acMyMACAddress[1] = 0x15;
-        acMyMACAddress[2] = 0xC5;
-        acMyMACAddress[3] = 0xBF;
-        acMyMACAddress[4] = 0xD0;
-        acMyMACAddress[5] = 0x87;
-        configureMACAddress(acMyMACAddress);
-        configureHostName("OpenEIP");
+      { printf("Wrong number of commandline parameters!\n");
+        printf("The correct commandline parameters are:\n"); 
+        printf("./opener ipaddress subnetmask gateway domainname hostaddress macaddress\n");
+        printf("    e.g. ./opener 192.168.0.2 255.255.255.0 192.168.0.1 test.com testdevice 00 15 C5 BF D0 87\n");      
+        exit(0);
       }
     else
       {
@@ -59,6 +51,9 @@ int main(int argc, char *arg[])
         acMyMACAddress[5] = (EIP_UINT8)strtoul(arg[11], NULL, 16);
         configureMACAddress(acMyMACAddress);
       }
+    
+    /*for a real device the serial number should be unique per device */
+    setDeviceSerialNumber(123456789);
 
     /* Setup the CIP Layer */
     CIP_Init();

+ 0 - 1
src/ports/platform-pc/opener_user_conf.h

@@ -34,7 +34,6 @@
 #define OPENER_DEVICE_PRODUCT_CODE      200
 #define OPENER_DEVICE_MAJOR_REVISION      1
 #define OPENER_DEVICE_MINOR_REVISION      2
-#define OPENER_DEVICE_SERIAL       12345678      /*TODO -- this must made settable per device instance*/
 #define OPENER_DEVICE_NAME      "ENetIP EC"