File tree Expand file tree Collapse file tree 5 files changed +34
-44
lines changed Expand file tree Collapse file tree 5 files changed +34
-44
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,27 @@ void Arduino_Portenta_OTA::reset()
71
71
NVIC_SystemReset ();
72
72
}
73
73
74
+ /* *****************************************************************************
75
+ * PROTECTED MEMBER FUNCTIONS
76
+ ******************************************************************************/
77
+
78
+ bool Arduino_Portenta_OTA::findProgramLength (DIR * dir, uint32_t & program_length)
79
+ {
80
+ struct dirent * entry = NULL ;
81
+ while ((entry = readdir (dir)) != NULL )
82
+ {
83
+ if (String (entry->d_name ) == " UPDATE.BIN" )
84
+ {
85
+ struct stat stat_buf;
86
+ stat (" /fs/UPDATE.BIN" , &stat_buf);
87
+ program_length = stat_buf.st_size ;
88
+ return true ;
89
+ }
90
+ }
91
+
92
+ return false ;
93
+ }
94
+
74
95
/* *****************************************************************************
75
96
* PRIVATE MEMBER FUNCTIONS
76
97
******************************************************************************/
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ class Arduino_Portenta_OTA
103
103
virtual bool init () = 0;
104
104
virtual bool open () = 0;
105
105
106
+ static bool findProgramLength (DIR * dir, uint32_t & program_length);
106
107
107
108
private:
108
109
Original file line number Diff line number Diff line change @@ -77,23 +77,15 @@ bool Arduino_Portenta_OTA_InternalFlash::init()
77
77
bool Arduino_Portenta_OTA_InternalFlash::open ()
78
78
{
79
79
DIR * dir = NULL ;
80
- struct dirent *entry = NULL ;
81
80
82
81
if (_storage_type == INTERNAL_FLASH_FATFS)
83
82
{
84
83
if ((dir = opendir (" /fs" )) != NULL )
85
84
{
86
- /* print all the files and directories within directory */
87
- while ((entry = readdir (dir)) != NULL )
85
+ if (Arduino_Portenta_OTA::findProgramLength (dir, _program_length))
88
86
{
89
- if (String (entry->d_name ) == " UPDATE.BIN" )
90
- {
91
- struct stat stat_buf;
92
- stat (" /fs/UPDATE.BIN" , &stat_buf);
93
- _program_length = stat_buf.st_size ;
94
- closedir (dir);
95
- return true ;
96
- }
87
+ closedir (dir);
88
+ return true ;
97
89
}
98
90
closedir (dir);
99
91
}
@@ -104,17 +96,10 @@ bool Arduino_Portenta_OTA_InternalFlash::open()
104
96
{
105
97
if ((dir = opendir (" /little_fs" )) != NULL )
106
98
{
107
- /* print all the files and directories within directory */
108
- while ((entry = readdir (dir)) != NULL )
99
+ if (Arduino_Portenta_OTA::findProgramLength (dir, _program_length))
109
100
{
110
- if (String (entry->d_name ) == " UPDATE.BIN" )
111
- {
112
- struct stat stat_buf;
113
- stat (" /little_fs/UPDATE.BIN" , &stat_buf);
114
- _program_length = stat_buf.st_size ;
115
- closedir (dir);
116
- return true ;
117
- }
101
+ closedir (dir);
102
+ return true ;
118
103
}
119
104
closedir (dir);
120
105
}
Original file line number Diff line number Diff line change @@ -86,18 +86,10 @@ bool Arduino_Portenta_OTA_QSPI::open()
86
86
DIR * dir = NULL ;
87
87
if ((dir = opendir (" /fs" )) != NULL )
88
88
{
89
- /* print all the files and directories within directory */
90
- struct dirent * entry = NULL ;
91
- while ((entry = readdir (dir)) != NULL )
89
+ if (Arduino_Portenta_OTA::findProgramLength (dir, _program_length))
92
90
{
93
- if (String (entry->d_name ) == " UPDATE.BIN" )
94
- {
95
- struct stat stat_buf;
96
- stat (" /fs/UPDATE.BIN" , &stat_buf);
97
- _program_length = stat_buf.st_size ;
98
- closedir (dir);
99
- return true ;
100
- }
91
+ closedir (dir);
92
+ return true ;
101
93
}
102
94
closedir (dir);
103
95
}
Original file line number Diff line number Diff line change @@ -95,22 +95,13 @@ bool Arduino_Portenta_OTA_SD::open()
95
95
DIR * dir = NULL ;
96
96
if ((dir = opendir (" /fs" )) != NULL )
97
97
{
98
- /* print all the files and directories within directory */
99
- struct dirent * entry = NULL ;
100
- while ((entry = readdir (dir)) != NULL )
98
+ if (Arduino_Portenta_OTA::findProgramLength (dir, _program_length))
101
99
{
102
- if (String (entry->d_name ) == " UPDATE.BIN" )
103
- {
104
- struct stat stat_buf;
105
- stat (" /fs/UPDATE.BIN" , &stat_buf);
106
- _program_length = stat_buf.st_size ;
107
- closedir (dir);
108
- return true ;
109
- }
100
+ closedir (dir);
101
+ return true ;
110
102
}
111
103
closedir (dir);
112
104
}
113
- return false ;
114
105
}
115
106
116
107
return false ;
You can’t perform that action at this time.
0 commit comments