@@ -719,8 +719,24 @@ void WiFiInterface::Spin() noexcept
719719 int32_t rc = SendCommand (NetworkCommand::networkGetStatus, 0 , 0 , nullptr , 0 , status);
720720 if (rc > 0 )
721721 {
722+ memset (wiFiServerVersion, 0 , sizeof (wiFiServerVersion));
722723 SafeStrncpy (wiFiServerVersion, status.Value ().versionText , ARRAY_SIZE (wiFiServerVersion));
723724
725+ // Parse the version string to obtain major and minor versions. Expecting a string of the format
726+ // x.yn where x is the major version, y the minor version and n a development stage descriptor string.
727+ const char *verStr = wiFiServerVersion;
728+ majorVersion = minorVersion = 0 ;
729+ majorVersion = StrToI32 (verStr, &verStr);
730+
731+ if (majorVersion >= 1 && majorVersion <= 2 ) // The server versions valid for this RRF version
732+ {
733+ minorVersion = StrToI32 (verStr + 1 );
734+ }
735+ else
736+ {
737+ reprap.GetPlatform ().MessageF (NetworkErrorMessage, " unable to parse wifi server version string" );
738+ }
739+
724740 // Set the hostname before anything else is done
725741 rc = SendCommand (NetworkCommand::networkSetHostName, 0 , 0 , 0 , reprap.GetNetwork ().GetHostname (), HostNameLength, nullptr , 0 );
726742 if (rc != ResponseEmpty)
@@ -730,7 +746,7 @@ void WiFiInterface::Spin() noexcept
730746#if SAME5x
731747 // If running the RTOS-based WiFi module code, tell the module to increase SPI clock speed to 40MHz.
732748 // This is safe on SAME5x processors but not on SAM4 processors.
733- if (isdigit (wiFiServerVersion[ 0 ]) && wiFiServerVersion[ 0 ] >= ' 2 ' )
749+ if (majorVersion >= 2 )
734750 {
735751 rc = SendCommand (NetworkCommand::networkSetClockControl, 0 , 0 , 0x2001 , nullptr , 0 , nullptr , 0 );
736752 if (rc != ResponseEmpty)
@@ -857,7 +873,7 @@ void WiFiInterface::Spin() noexcept
857873 if (rc > 0 )
858874 {
859875 rssi = status.Value ().rssi ;
860- if (rc >= offsetof (NetworkStatusResponse, netmask) )
876+ if (majorVersion >= 2 )
861877 {
862878 reconnectCount = status.Value ().numReconnects ;
863879 }
@@ -892,7 +908,7 @@ void WiFiInterface::Spin() noexcept
892908 macAddress.SetFromBytes (status.Value ().macAddress ); // MAC address for AP and STA are separate and different
893909 SafeStrncpy (actualSsid, status.Value ().ssid , SsidLength);
894910
895- if (rc > offsetof (NetworkStatusResponse, netmask) )
911+ if (majorVersion >= 2 )
896912 {
897913 netmask.SetV4LittleEndian (status.Value ().netmask );
898914 gateway.SetV4LittleEndian (status.Value ().gateway );
@@ -1022,7 +1038,7 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
10221038
10231039 if (currentMode == WiFiState::connected || currentMode == WiFiState::runningAsAccessPoint)
10241040 {
1025- if (rc > offsetof (NetworkStatusResponse, netmask) )
1041+ if (majorVersion >= 2 )
10261042 {
10271043 platform.MessageF (mtype, " WiFi IP address %s, netmask %s, gateway %s%s\n " ,
10281044 IP4String (r.ipAddress ).c_str (), IP4String (r.netmask ).c_str (), IP4String (r.gateway ).c_str (),
@@ -1039,7 +1055,7 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
10391055
10401056 if (currentMode == WiFiState::connected)
10411057 {
1042- if (rc > offsetof (NetworkStatusResponse, netmask) )
1058+ if (majorVersion >= 2 )
10431059 {
10441060 platform.MessageF (mtype, " WiFi signal strength %ddBm, mode %s, reconnections %u, sleep mode %s, channel %u (%s), auth %s\n " ,
10451061 (int )r.rssi , ConnectionModes[r.phyMode ], reconnectCount, SleepModes[r.sleepMode ],
@@ -1052,7 +1068,7 @@ void WiFiInterface::Diagnostics(MessageType mtype) noexcept
10521068 }
10531069 else if (currentMode == WiFiState::runningAsAccessPoint)
10541070 {
1055- if (rc > offsetof (NetworkStatusResponse, netmask) )
1071+ if (majorVersion >= 2 )
10561072 {
10571073 platform.MessageF (mtype, " WiFi mode %s, sleep mode %s, channel %u (%s), auth %s\n " ,
10581074 ConnectionModes[r.phyMode ], SleepModes[r.sleepMode ], r.channel ,
0 commit comments