@@ -622,6 +622,40 @@ void WiFiInterface::Stop() noexcept
622622 }
623623}
624624
625+ bool WiFiInterface::GetFirmwareVersion (int &major, int &minor, int &patch)
626+ {
627+ // Simple parser for WiFi module firmware version string.
628+ // Parse the format (x=major, y=minor, and z=patch):
629+ // - x.y.z (from 2.1.0)
630+ // - x.y (prior to 2.1.0), returns -1 for z
631+ // Should be able to handle appended string after the version string.
632+ major = minor = patch = -1 ;
633+ auto numbers = {&major, &minor, &patch};
634+
635+ const char *curr = wiFiServerVersion.c_str ();
636+ const char *end = nullptr ;
637+
638+ for (auto num : numbers)
639+ {
640+ int temp = StrToI32 (curr, &end);
641+
642+ if (curr == end)
643+ {
644+ if (num != &patch)
645+ {
646+ return false ;
647+ }
648+ break ;
649+ }
650+
651+ *num = temp;
652+ curr = end + 1 ;
653+ end = nullptr ;
654+ }
655+
656+ return true ;
657+ }
658+
625659void WiFiInterface::Spin () noexcept
626660{
627661 // Main state machine.
@@ -685,9 +719,10 @@ void WiFiInterface::Spin() noexcept
685719 reprap.GetPlatform ().MessageF (NetworkErrorMessage, " failed to set WiFi hostname: %s\n " , TranslateWiFiResponse (rc));
686720 }
687721#if SAME5x
722+ int majorVer = 0 , dummy = -1 ;
688723 // If running the RTOS-based WiFi module code, tell the module to increase SPI clock speed to 40MHz.
689724 // This is safe on SAME5x processors but not on SAM4 processors.
690- if (isdigit (wiFiServerVersion[ 0 ] ) && wiFiServerVersion[ 0 ] >= ' 2 ' )
725+ if (GetFirmwareVersion (majorVer, dummy, dummy ) && (majorVer >= 2 ) )
691726 {
692727 rc = SendCommand (NetworkCommand::networkSetClockControl, 0 , 0 , 0x2001 , nullptr , 0 , nullptr , 0 );
693728 if (rc != ResponseEmpty)
0 commit comments