@@ -142,78 +142,6 @@ int ml_getOutputLength() {
142142 return output_length ;
143143}
144144
145- // TODO: Remove this function and use ml_getLabels instead
146- ml_labels_t * ml_getLabels () {
147- static ml_labels_t labels = {
148- .num_labels = 0 ,
149- .labels = NULL
150- };
151-
152- const ml_model_header_t * const model_header = (ml_model_header_t * )MODEL_ADDRESS ;
153- if (model_header == NULL ) {
154- labels .num_labels = 0 ;
155- if (labels .labels != NULL ) {
156- free (labels .labels );
157- labels .labels = NULL ;
158- }
159- return NULL ;
160- }
161-
162- // Workout the addresses in flash from each label, there are as many strings
163- // as indicated by model_header->number_of_actions
164- const char * flash_labels [model_header -> number_of_actions ];
165- ml_header_action_t * action = (ml_header_action_t * )& model_header -> actions [0 ];
166- for (int i = 0 ; i < model_header -> number_of_actions ; i ++ ) {
167- flash_labels [i ] = & action -> label [0 ];
168- // Check the label has a single null terminator at the end
169- for (int j = 0 ; j < action -> label_length - 1 ; j ++ ) {
170- if (flash_labels [i ][j ] == '\0' ) {
171- return NULL ;
172- }
173- }
174- // And check the last character is a null terminator
175- if (flash_labels [i ][action -> label_length - 1 ] != '\0' ) {
176- return NULL ;
177- }
178- action = (ml_header_action_t * )((uint32_t )action + ml_action_size_without_label + action -> label_length );
179- // Next action address is 4 byte aligned
180- action = (ml_header_action_t * )(((uint32_t )action + 3 ) & ~3 );
181- }
182-
183- // First check if the labels are the same, if not we need to set them again
184- bool set_labels = false;
185- if (labels .num_labels == 0 || labels .labels == NULL ) {
186- set_labels = true;
187- } else if (labels .num_labels != model_header -> number_of_actions ) {
188- set_labels = true;
189- } else {
190- for (size_t i = 0 ; i < labels .num_labels ; i ++ ) {
191- if (labels .labels [i ] != flash_labels [i ]) {
192- set_labels = true;
193- break ;
194- }
195- }
196- }
197- if (set_labels ) {
198- // First clear them out if needed
199- labels .num_labels = 0 ;
200- if (labels .labels != NULL ) {
201- free (labels .labels );
202- }
203- // Then set them to point to the strings in flash
204- labels .labels = (const char * * )malloc (model_header -> number_of_actions * sizeof (char * ));
205- if (labels .labels == NULL ) {
206- return NULL ;
207- }
208- labels .num_labels = model_header -> number_of_actions ;
209- for (size_t i = 0 ; i < labels .num_labels ; i ++ ) {
210- labels .labels [i ] = flash_labels [i ];
211- }
212- }
213-
214- return & labels ;
215- }
216-
217145ml_actions_t * ml_allocateActions () {
218146 const ml_model_header_t * const model_header = (ml_model_header_t * )MODEL_ADDRESS ;
219147 if (model_header == NULL ) {
0 commit comments