//! //! This function returns the opened file size. //! //! @param fd file descriptor. //! //! @return size_t : size of the file pointed to by the descriptor //! size_t fsaccess_file_get_size(int fd) { size_t size; if (fd < 0) { return (0); } // take the mutex for nav access fsaccess_take_mutex(); // select the navigator nav_select( fd ); // get the file size size = nav_file_lgt(); // give the mutex for nav access fsaccess_give_mutex(); return (size); }
//! @brief This function manages the ls command //! //! @param b_more enable the '|more' management when true otherwise no '|more' management //! void ushell_cmd_ls( bool b_more ) { uint8_t str_char[MAX_FILE_PATH_LENGTH]; uint16_t u16_i,u16_nb_file,u16_nb_dir,last_i; uint8_t ext_filter=false; //** Print drive name printf("%c: volume is %s\r\n", 'a'+nav_drive_get(), mem_name(nav_drive_get()) ); printf("Drive uses "); switch (nav_partition_type()) { case FS_TYPE_FAT_12: printf("FAT12\n\r"); break; case FS_TYPE_FAT_16: printf("FAT16\n\r"); break; case FS_TYPE_FAT_32: printf("FAT32\n\r"); break; default: printf("an unknown partition type\r\n"); return; } //** Print directory name if( !nav_dir_name( (FS_STRING)str_char, MAX_FILE_PATH_LENGTH ) ) return; printf("Dir name is %s\n\r",str_char); //** Check extension filter in extra parameters if(g_s_arg[0][0]!=0) { if(g_s_arg[0][0] == '*' && g_s_arg[0][1]=='.') { ext_filter=true; for(u16_i=2; u16_i<USHELL_SIZE_CMD_LINE; u16_i++) { g_s_arg[0][u16_i-2]=g_s_arg[0][u16_i]; } } } //** Print files list printf(" Size Name\n\r"); // Init loop at the beginning of directory nav_filelist_reset(); u16_nb_file=0; u16_nb_dir=0; last_i=0; // For each file in list while( nav_filelist_set(0,FS_FIND_NEXT) ) { if(!ext_filter) { // No extension filter if( nav_file_isdir() ) { printf("Dir "); u16_nb_dir++; // count the number of directory }else{ printf(" "); } } else { // If extension filter then ignore directories if(nav_file_isdir()) continue; // Check extension if(!nav_file_checkext((FS_STRING)g_s_arg[0])) continue; } u16_nb_file++; // count the total of files (directories and files) // Check 'more' step if( b_more && ((u16_nb_file%USHELL_NB_LINE)==0) && (u16_nb_file!=0) && (last_i != u16_nb_file) ) { last_i=u16_nb_file; if( !ushell_more_wait() ) return; // Exit LS command } // Display file nav_file_name((FS_STRING)str_char, MAX_FILE_PATH_LENGTH, FS_NAME_GET, true); printf("%10lu %s\n\r", nav_file_lgt(), str_char); } // Display total number printf(" %4i Files\r\n", u16_nb_file-u16_nb_dir ); printf(" %4i Dir\r\n", u16_nb_dir ); }
//! This function adds files in play list //! //! @param sz_filterext add file only corresponding to the extension filter //! @param u8_mode PL_ADD_FILE, PL_ADD_DIR, PL_ADD_SUBDIR //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! //! @verbatim //! It is possible to select a file or all files in a directory //! @endverbatim //! bool pl_add( const FS_STRING sz_filterext , uint8_t u8_mode ) { uint8_t nav_id_save; uint8_t u8_folder_level; if( !pl_main_modify() ) return false; nav_id_save = nav_get(); // Check last character of file nav_select( FS_NAV_ID_PLAYLIST ); if( 0!=nav_file_lgt() ) { #if( PL_UNICODE == true) file_string_unicode(); file_seek( 2, FS_SEEK_END); if( '\n' != file_getc()) { file_seek( 2, FS_SEEK_END); file_putc('\n'); } file_string_ascii(); #else file_seek( 1, FS_SEEK_END); if( '\n' != file_getc()) { file_seek( 1, FS_SEEK_END); file_putc('\n'); } #endif } nav_select( nav_id_save ); // Get path of play list file and check with current to create a relative path if( PL_ADD_FILE == u8_mode ) goto pl_add_file; // Add all files valid in current dir u8_folder_level = 0; nav_filelist_reset(); while(1) { while(1) { if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) break; // a next file and directory is found // No other dir or file in current dir then go to parent dir if( 0 == u8_folder_level ) goto pl_add_end; // end of ADD // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list u8_folder_level--; if( !nav_dir_gotoparent() ) return false; } if( nav_file_isdir()) { if( PL_ADD_SUBDIR == u8_mode ) { // Enter in sub dir if( !nav_dir_cd()) return false; u8_folder_level++; } } else { pl_add_file: if( nav_file_checkext( sz_filterext ) ) { // It is a valid file // Get name of current file #if( (FS_ASCII == true) && (FS_UNICODE == true) && (PL_UNICODE == false) ) nav_string_ascii(); #endif nav_getcwd( (FS_STRING)pl_cache_path, PL_CACHE_PATH_MAX_SIZE, true ); #if( (FS_ASCII == true) && (FS_UNICODE == true) && (PL_UNICODE == false) ) nav_string_unicode(); #endif // Write path in file list nav_select( FS_NAV_ID_PLAYLIST ); #if( PL_UNICODE == true) file_string_unicode(); #endif if( file_puts(pl_cache_path)) file_putc('\n'); #if( PL_UNICODE == true) file_string_ascii(); #endif nav_select( nav_id_save ); pl_g_u16_list_size++; } if( PL_ADD_FILE == u8_mode ) goto pl_add_end; } // if dir OR file } // end of first while(1) pl_add_end: // Go to beginning of file AND no file selected nav_select( FS_NAV_ID_PLAYLIST ); file_seek( 0 , FS_SEEK_SET ); pl_g_u16_list_sel = 0; nav_select( nav_id_save ); return true; }
///---------------------------------------------------------------------------- /// Function Break ///---------------------------------------------------------------------------- void MoveManualCalToFile(void) { uint16 i; uint16 sample; uint16 normalizedData; uint16 hiA = 0, hiR = 0, hiV = 0, hiT = 0; uint16 lowA = 0xFFFF, lowR = 0xFFFF, lowV = 0xFFFF, lowT = 0xFFFF; uint16* startOfEventPtr; uint16* endOfEventDataPtr; uint32 compressSize; int manualCalFileHandle = -1; uint16* aManualCalPeakPtr; uint16* rManualCalPeakPtr; uint16* vManualCalPeakPtr; uint16* tManualCalPeakPtr; debug("Processing Manual Cal to be saved\r\n"); if (g_freeEventBuffers < g_maxEventBuffers) { g_pendingEventRecord.summary.captured.eventTime = GetCurrentTime(); // Clear out A, R, V, T channel calculated data (in case the pending event record is reused) memset(&g_pendingEventRecord.summary.calculated.a, 0, (NUMBER_OF_CHANNELS_DEFAULT * sizeof(CHANNEL_CALCULATED_DATA_STRUCT))); startOfEventPtr = g_currentEventStartPtr; endOfEventDataPtr = g_currentEventStartPtr + g_wordSizeInCal; for (i = (uint16)g_samplesInCal; i != 0; i--) { if (g_bitShiftForAccuracy) AdjustSampleForBitAccuracy(); //========================================================= // First channel - A sample = *(g_currentEventSamplePtr + A_CHAN_OFFSET); if (sample > hiA) hiA = sample; if (sample < lowA) lowA = sample; normalizedData = FixDataToZero(sample); if (normalizedData > g_pendingEventRecord.summary.calculated.a.peak) { g_pendingEventRecord.summary.calculated.a.peak = normalizedData; aManualCalPeakPtr = (g_currentEventSamplePtr + A_CHAN_OFFSET); } //========================================================= // Second channel - R sample = *(g_currentEventSamplePtr + R_CHAN_OFFSET); if (sample > hiR) hiR = sample; if (sample < lowR) lowR = sample; normalizedData = FixDataToZero(sample); if (normalizedData > g_pendingEventRecord.summary.calculated.r.peak) { g_pendingEventRecord.summary.calculated.r.peak = normalizedData; rManualCalPeakPtr = (g_currentEventSamplePtr + R_CHAN_OFFSET); } //========================================================= // Third channel - V sample = *(g_currentEventSamplePtr + V_CHAN_OFFSET); if (sample > hiV) hiV = sample; if (sample < lowV) lowV = sample; normalizedData = FixDataToZero(sample); if (normalizedData > g_pendingEventRecord.summary.calculated.v.peak) { g_pendingEventRecord.summary.calculated.v.peak = normalizedData; vManualCalPeakPtr = (g_currentEventSamplePtr + V_CHAN_OFFSET); } //========================================================= // Fourth channel - T sample = *(g_currentEventSamplePtr + T_CHAN_OFFSET); if (sample > hiT) hiT = sample; if (sample < lowT) lowT = sample; normalizedData = FixDataToZero(sample); if (normalizedData > g_pendingEventRecord.summary.calculated.t.peak) { g_pendingEventRecord.summary.calculated.t.peak = normalizedData; tManualCalPeakPtr = (g_currentEventSamplePtr + T_CHAN_OFFSET); } g_currentEventSamplePtr += NUMBER_OF_CHANNELS_DEFAULT; } g_pendingEventRecord.summary.calculated.a.peak = (uint16)(hiA - lowA + 1); g_pendingEventRecord.summary.calculated.r.peak = (uint16)(hiR - lowR + 1); g_pendingEventRecord.summary.calculated.v.peak = (uint16)(hiV - lowV + 1); g_pendingEventRecord.summary.calculated.t.peak = (uint16)(hiT - lowT + 1); g_pendingEventRecord.summary.calculated.a.frequency = CalcSumFreq(aManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr); g_pendingEventRecord.summary.calculated.r.frequency = CalcSumFreq(rManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr); g_pendingEventRecord.summary.calculated.v.frequency = CalcSumFreq(vManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr); g_pendingEventRecord.summary.calculated.t.frequency = CalcSumFreq(tManualCalPeakPtr, SAMPLE_RATE_1K, startOfEventPtr, endOfEventDataPtr); CompleteRamEventSummary(); CacheResultsEventInfo((EVT_RECORD*)&g_pendingEventRecord); if (g_fileAccessLock != AVAILABLE) { ReportFileSystemAccessProblem("Save Manual Cal"); } else // (g_fileAccessLock == AVAILABLE) { GetSpi1MutexLock(SDMMC_LOCK); nav_select(FS_NAV_ID_DEFAULT); // Get new event file handle manualCalFileHandle = GetEventFileHandle(g_pendingEventRecord.summary.eventNumber, CREATE_EVENT_FILE); if (manualCalFileHandle == -1) { ReleaseSpi1MutexLock(); debugErr("Failed to get a new file handle for the Manual Cal event\r\n"); } else // Write the file event to the SD card { sprintf((char*)g_spareBuffer, "%s %s #%d %s...", getLangText(CALIBRATION_TEXT), getLangText(EVENT_TEXT), g_pendingEventRecord.summary.eventNumber, getLangText(BEING_SAVED_TEXT)); OverlayMessage(getLangText(EVENT_COMPLETE_TEXT), (char*)g_spareBuffer, 0); // Write the event record header and summary write(manualCalFileHandle, &g_pendingEventRecord, sizeof(EVT_RECORD)); // Write the event data, containing the Pretrigger, event and cal write(manualCalFileHandle, g_currentEventStartPtr, (g_wordSizeInCal * 2)); SetFileDateTimestamp(FS_DATE_LAST_WRITE); // Update the remaining space left UpdateSDCardUsageStats(nav_file_lgt()); // Done writing the event file, close the file handle g_testTimeSinceLastFSWrite = g_lifetimeHalfSecondTickCount; close(manualCalFileHandle); //========================================================================================================== // Save compressed data file //---------------------------------------------------------------------------------------------------------- if (g_unitConfig.saveCompressedData != DO_NOT_SAVE_EXTRA_FILE_COMPRESSED_DATA) { // Get new event file handle g_globalFileHandle = GetERDataFileHandle(g_pendingEventRecord.summary.eventNumber, CREATE_EVENT_FILE); g_spareBufferIndex = 0; compressSize = lzo1x_1_compress((void*)g_currentEventStartPtr, (g_wordSizeInCal * 2), OUT_FILE); // Check if any remaining compressed data is queued if (g_spareBufferIndex) { // Finish writing the remaining compressed data write(g_globalFileHandle, g_spareBuffer, g_spareBufferIndex); g_spareBufferIndex = 0; } debug("Manual Cal Compressed Data length: %d (Matches file: %s)\r\n", compressSize, (compressSize == nav_file_lgt()) ? "Yes" : "No"); SetFileDateTimestamp(FS_DATE_LAST_WRITE); // Update the remaining space left UpdateSDCardUsageStats(nav_file_lgt()); // Done writing the event file, close the file handle g_testTimeSinceLastFSWrite = g_lifetimeHalfSecondTickCount; close(g_globalFileHandle); } //========================================================================================================== ReleaseSpi1MutexLock(); debug("Manual Cal Event file closed\r\n"); AddEventToSummaryList(&g_pendingEventRecord); // Don't log a monitor entry for Manual Cal //UpdateMonitorLogEntry(); // After event numbers have been saved, store current event number in persistent storage. StoreCurrentEventNumber(); // Now store the updated event number in the universal ram storage. g_pendingEventRecord.summary.eventNumber = g_nextEventNumberToUse; } if (++g_eventBufferReadIndex == g_maxEventBuffers) { g_eventBufferReadIndex = 0; g_currentEventSamplePtr = g_startOfEventBufferPtr; } else { g_currentEventSamplePtr = g_startOfEventBufferPtr + (g_eventBufferReadIndex * g_wordSizeInEvent); } clearSystemEventFlag(MANUAL_CAL_EVENT); // Set flag to display calibration results if not monitoring or monitoring in waveform if ((g_sampleProcessing == IDLE_STATE) || ((g_sampleProcessing == ACTIVE_STATE) && (g_triggerRecord.opMode == WAVEFORM_MODE))) { // Set printout mode to allow the results menu processing to know this is a manual cal pulse raiseMenuEventFlag(RESULTS_MENU_EVENT); } g_freeEventBuffers++; } } else { debugWarn("Manual Cal: No free buffers\r\n"); clearSystemEventFlag(MANUAL_CAL_EVENT); } }