| 905 | #endif |
| 906 | |
| 907 | void AP_Logger_File::io_timer(void) |
| 908 | { |
| 909 | uint32_t tnow = AP_HAL::millis(); |
| 910 | _io_timer_heartbeat = tnow; |
| 911 | |
| 912 | if (start_new_log_pending) { |
| 913 | start_new_log(); |
| 914 | start_new_log_pending = false; |
| 915 | } |
| 916 | |
| 917 | if (erase.log_num != 0) { |
| 918 | // continue erase |
| 919 | erase_next(); |
| 920 | return; |
| 921 | } |
| 922 | |
| 923 | if (_write_fd == -1 || !_initialised || recent_open_error()) { |
| 924 | return; |
| 925 | } |
| 926 | |
| 927 | if (last_log_is_marked_discard && hal.util->get_soft_armed()) { |
| 928 | // time to make the log permanent |
| 929 | const auto log_num = find_last_log(); |
| 930 | last_log_is_marked_discard = false; |
| 931 | write_lastlog_file(log_num); |
| 932 | } |
| 933 | |
| 934 | uint32_t nbytes = _writebuf.available(); |
| 935 | if (nbytes == 0) { |
| 936 | return; |
| 937 | } |
| 938 | if (nbytes < _writebuf_chunk && |
| 939 | tnow - _last_write_time < 2000UL) { |
| 940 | // write in _writebuf_chunk-sized chunks, but always write at |
| 941 | // least once per 2 seconds if data is available |
| 942 | return; |
| 943 | } |
| 944 | if (tnow - _free_space_last_check_time > _free_space_check_interval) { |
| 945 | _free_space_last_check_time = tnow; |
| 946 | last_io_operation = "disk_space_avail"; |
| 947 | if (disk_space_avail() < _free_space_min_avail && disk_space() > 0) { |
| 948 | DEV_PRINTF("Out of space for logging\n"); |
| 949 | stop_logging(); |
| 950 | _open_error_ms = AP_HAL::millis(); // prevent logging starting again for 5s |
| 951 | last_io_operation = ""; |
| 952 | return; |
| 953 | } |
| 954 | last_io_operation = ""; |
| 955 | } |
| 956 | |
| 957 | _last_write_time = tnow; |
| 958 | if (nbytes > _writebuf_chunk) { |
| 959 | // be kind to the filesystem layer |
| 960 | nbytes = _writebuf_chunk; |
| 961 | } |
| 962 | |
| 963 | uint32_t size; |
| 964 | const uint8_t *head = _writebuf.readptr(size); |
nothing calls this directly
no test coverage detected