Exemplo n.º 1
0
FileHandle *FATFileSystem::open(const char* name, int flags) {
    debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%s]\n", name, _name, _fsid);
    char n[64];
    sprintf(n, "%s:/%s", _fsid, name);

    /* POSIX flags -> FatFS open mode */
    BYTE openmode;
    if (flags & O_RDWR) {
        openmode = FA_READ|FA_WRITE;
    } else if(flags & O_WRONLY) {
        openmode = FA_WRITE;
    } else {
        openmode = FA_READ;
    }
    if(flags & O_CREAT) {
        if(flags & O_TRUNC) {
            openmode |= FA_CREATE_ALWAYS;
        } else {
            openmode |= FA_OPEN_ALWAYS;
        }
    }

    FIL fh;
    FRESULT res = f_open(&fh, n, openmode);
    if (res) {
        debug_if(FFS_DBG, "f_open('w') failed: %d\n", res);
        return NULL;
    }
    if (flags & O_APPEND) {
        f_lseek(&fh, fh.fsize);
    }
    return new FATFileHandle(fh);
}
Exemplo n.º 2
0
FATFileSystem::FATFileSystem(const char* n) : FileSystemLike(n) {
    debug_if(FFS_DBG, "FATFileSystem(%s)\n", n);
    for(int i=0; i<_VOLUMES; i++) {
        if(_ffs[i] == 0) {
            _ffs[i] = this;
            _fsid = i;
            debug_if(FFS_DBG, "Mounting [%s] on ffs drive [%d]\n", _name, _fsid);
            f_mount(i, &_fs);
            return;
        }
    }
    error("Couldn't create %s in FATFileSystem::FATFileSystem\n", n);
}
Exemplo n.º 3
0
void OnRxTimeout(void)
{
	Radio.Sleep();
	Buffer[BufferSize] = 0;
	State = RX_TIMEOUT;
	debug_if(DEBUG_MESSAGE, "> OnRxTimeout\r\n");
}
Exemplo n.º 4
0
void OnRxError(void)
{
	Radio.Sleep();
	SkipRx = 1;
	State = RX_ERROR;
	debug_if(DEBUG_MESSAGE, "> OnRxError\r\n");
}
Exemplo n.º 5
0
DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
{
    debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
    DWORD ssize = disk_get_sector_size(pdrv);
    int err = _ffs[pdrv]->read(buff, sector*ssize, count*ssize);
    return err ? RES_PARERR : RES_OK;
}
Exemplo n.º 6
0
int FATFileSystem::mount(BlockDevice *bd, bool mount)
{
    lock();
    if (_id != -1) {
        unlock();
        return -EINVAL;
    }

    for (int i = 0; i < FF_VOLUMES; i++) {
        if (!_ffs[i]) {
            _id = i;
            _ffs[_id] = bd;
            _fsid[0] = '0' + _id;
            _fsid[1] = ':';
            _fsid[2] = '\0';
            debug_if(FFS_DBG, "Mounting [%s] on ffs drive [%s]\n", getName(), _fsid);
            FRESULT res = f_mount(&_fs, _fsid, mount);
            unlock();
            return fat_error_remap(res);
        }
    }

    unlock();
    return -ENOMEM;
}
Exemplo n.º 7
0
int FATFileSystem::remove(const char *filename) {
    FRESULT res = f_unlink(filename);
    if (res) {
        debug_if(FFS_DBG, "f_unlink() failed: %d\n", res);
        return -1;
    }
    return 0;
}
Exemplo n.º 8
0
int FATFileSystem::rename(const char *oldname, const char *newname) {
    FRESULT res = f_rename(oldname, newname);
    if (res) {
        debug_if(FFS_DBG, "f_rename() failed: %d\n", res);
        return -1;
    }
    return 0;
}
Exemplo n.º 9
0
int FATFileSystem::format() {
    FRESULT res = f_mkfs(_fsid, 0, 512); // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
    if (res) {
        debug_if(FFS_DBG, "f_mkfs() failed: %d\n", res);
        return -1;
    }
    return 0;
}
Exemplo n.º 10
0
int FATFileSystem::mkdir(const char *name, mode_t mode) {
    // Added by Embedded Artists to fix implementation when using more than one volume
    debug_if(FFS_DBG, "mkdir(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
    char n[64];
    snprintf(n, 64, "%d:/%s", _fsid, name);
    
    FRESULT res = f_mkdir(n);
    return res == 0 ? 0 : -1;
}
Exemplo n.º 11
0
static void SendTISReq()
{
	debug_if(DEBUG_MESSAGE || CurCount == 0, "TIS_REQ %d %03d %03d\r\n",
		 SID, CurCount+1, EndCount);
	Buffer[0] = 'c';
	Buffer[1] = SID;
	sprintf(&Buffer[2], "%03d%03d", CurCount++, EndCount);
	Radio.Send((uint8_t*)Buffer, 2 + 6);
}
Exemplo n.º 12
0
////// File operations //////
int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags)
{
    debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%s]\n", path, getName(), _id);

    FIL *fh = new FIL;
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    /* POSIX flags -> FatFS open mode */
    BYTE openmode;
    if (flags & O_RDWR) {
        openmode = FA_READ | FA_WRITE;
    } else if (flags & O_WRONLY) {
        openmode = FA_WRITE;
    } else {
        openmode = FA_READ;
    }

    if (flags & O_CREAT) {
        if (flags & O_TRUNC) {
            openmode |= FA_CREATE_ALWAYS;
        } else {
            openmode |= FA_OPEN_ALWAYS;
        }
    }

    if (flags & O_APPEND) {
        openmode |= FA_OPEN_APPEND;
    }

    lock();
    FRESULT res = f_open(fh, fpath, openmode);

    if (res != FR_OK) {
        unlock();
        debug_if(FFS_DBG, "f_open('w') failed: %d\n", res);
        delete fh;
        return fat_error_remap(res);
    }

    unlock();

    *file = fh;
    return 0;
}
Exemplo n.º 13
0
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
{
	Radio.Sleep();
	BufferSize = size;
	memcpy(Buffer, payload, BufferSize);
	RssiValue = rssi;
	SnrValue = snr;
	State = RX;
	debug_if(DEBUG_MESSAGE, "> OnRxDone\r\n");
}
Exemplo n.º 14
0
static void SendTRPResp()
{
	debug_if(DEBUG_MESSAGE || CurCount+1 == EndCount, "TRP_RESP %d %03d (%03d)\r\n",
		 SID, CurCount, EndCount);
	Buffer[0] = 'b';
	Buffer[1] = SID;
	sprintf(&Buffer[2], "%03d", CurCount++);
	sprintf(&Buffer[5], "%03d", AccRssi * -1);
	Radio.Send((uint8_t*)Buffer, 2 + 6);
}
Exemplo n.º 15
0
int FATFileSystem::file_sync(fs_file_t file) {
    FIL *fh = static_cast<FIL*>(file);

    lock();
    FRESULT res = f_sync(fh);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_sync() failed: %d\n", res);
    }
    return fat_error_remap(res);
}
Exemplo n.º 16
0
int FATFileSystem::mkdir(const char *path, mode_t mode) {
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FRESULT res = f_mkdir(fpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_mkdir() failed: %d\n", res);
    }
    return fat_error_remap(res);
}
Exemplo n.º 17
0
int FATFileSystem::rename(const char *oldpath, const char *newpath) {
    Deferred<const char*> oldfpath = fat_path_prefix(_id, oldpath);
    Deferred<const char*> newfpath = fat_path_prefix(_id, newpath);

    lock();
    FRESULT res = f_rename(oldfpath, newfpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_rename() failed: %d\n", res);
    }
    return fat_error_remap(res);
}
Exemplo n.º 18
0
DirHandle *FATFileSystem::opendir(const char *name) {
    // Added by Embedded Artists to fix implementation when using more than one volume
    debug_if(FFS_DBG, "opendir(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
    char n[64];
    snprintf(n, 64, "%d:/%s", _fsid, name);
    
    FATFS_DIR dir;
    FRESULT res = f_opendir(&dir, n);
    if (res != 0) {
        return NULL;
    }
    return new FATDirHandle(dir);
}
Exemplo n.º 19
0
bool ATCmdParser::process_oob()
{
    if (!_fh->readable()) {
        return false;
    }

    int i = 0;
    while (true) {
        // Receive next character
        int c = getc();
        if (c < 0) {
            return false;
        }
        _buffer[i++] = c;
        _buffer[i] = 0;

        // Check for oob data
        struct oob *oob = _oobs;
        while (oob) {
            if (i == (int)oob->len && memcmp(
                    oob->prefix, _buffer, oob->len) == 0) {
                debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
                oob->cb();
                return true;
            }
            oob = oob->next;
        }
        
        // Clear the buffer when we hit a newline or ran out of space
        // running out of space usually means we ran into binary data
        if (i+1 >= _buffer_size ||
            strcmp(&_buffer[i-_output_delim_size], _output_delimiter) == 0) {

            debug_if(_dbg_on, "AT< %s", _buffer);
            i = 0;
        }
    }
}
Exemplo n.º 20
0
ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len) {
    FIL *fh = static_cast<FIL*>(file);

    lock();
    UINT n;
    FRESULT res = f_write(fh, buffer, len, &n);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_write() failed: %d", res);
        return fat_error_remap(res);
    } else {
        return n;
    }
}
Exemplo n.º 21
0
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
{
    debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
    DWORD ssize = disk_get_sector_size(pdrv);
    int err = _ffs[pdrv]->erase(sector*ssize, count*ssize);
    if (err) {
        return RES_PARERR;
    }

    err = _ffs[pdrv]->program(buff, sector*ssize, count*ssize);
    if (err) {
        return RES_PARERR;
    }

    return RES_OK;
}
Exemplo n.º 22
0
int FATFileSystem::remove(const char *path)
{
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FRESULT res = f_unlink(fpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_unlink() failed: %d\n", res);
        if (res == FR_DENIED) {
            return -ENOTEMPTY;
        }
    }
    return fat_error_remap(res);
}
Exemplo n.º 23
0
////// Dir operations //////
int FATFileSystem::dir_open(fs_dir_t *dir, const char *path) {
    FATFS_DIR *dh = new FATFS_DIR;
    Deferred<const char*> fpath = fat_path_prefix(_id, path);

    lock();
    FRESULT res = f_opendir(dh, fpath);
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "f_opendir() failed: %d\n", res);
        delete dh;
        return fat_error_remap(res);
    }

    *dir = dh;
    return 0;
}
Exemplo n.º 24
0
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
{
    debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
    switch (cmd) {
        case CTRL_SYNC:
            if (_ffs[pdrv] == NULL) {
                return RES_NOTRDY;
            } else {
                return RES_OK;
            }
        case GET_SECTOR_COUNT:
            if (_ffs[pdrv] == NULL) {
                return RES_NOTRDY;
            } else {
                *((DWORD*)buff) = disk_get_sector_count(pdrv);
                return RES_OK;
            }
        case GET_SECTOR_SIZE:
            if (_ffs[pdrv] == NULL) {
                return RES_NOTRDY;
            } else {
                *((WORD*)buff) = disk_get_sector_size(pdrv);
                return RES_OK;
            }
        case GET_BLOCK_SIZE:
            *((DWORD*)buff) = 1; // default when not known
            return RES_OK;
        case CTRL_TRIM:
            if (_ffs[pdrv] == NULL) {
                return RES_NOTRDY;
            } else {
                DWORD *sectors = (DWORD*)buff;
                DWORD ssize = disk_get_sector_size(pdrv);
                bd_addr_t addr = (bd_addr_t)sectors[0]*ssize;
                bd_size_t size = (bd_size_t)(sectors[1]-sectors[0]+1)*ssize;
                int err = _ffs[pdrv]->trim(addr, size);
                return err ? RES_PARERR : RES_OK;
            }
    }

    return RES_PARERR;
}
Exemplo n.º 25
0
off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence) {
    FIL *fh = static_cast<FIL*>(file);

    lock();
    if (whence == SEEK_END) {
        offset += fh->fsize;
    } else if(whence==SEEK_CUR) {
        offset += fh->fptr;
    }

    FRESULT res = f_lseek(fh, offset);
    off_t noffset = fh->fptr;
    unlock();

    if (res != FR_OK) {
        debug_if(FFS_DBG, "lseek failed: %d\n", res);
        return fat_error_remap(res);
    } else {
        return noffset;
    }
}
Exemplo n.º 26
0
// Command parsing with line handling
bool ATCmdParser::vsend(const char *command, va_list args)
{
    // Create and send command
    if (vsprintf(_buffer, command, args) < 0) {
        return false;
    }

    for (int i = 0; _buffer[i]; i++) {
        if (putc(_buffer[i]) < 0) {
            return false;
        }
    }

    // Finish with newline
    for (size_t i = 0; _output_delimiter[i]; i++) {
        if (putc(_output_delimiter[i]) < 0) {
            return false;
        }
    }

    debug_if(_dbg_on, "AT> %s\n", _buffer);
    return true;
}
Exemplo n.º 27
0
DSTATUS disk_initialize(BYTE pdrv)
{
    debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
    return (DSTATUS)_ffs[pdrv]->init();
}
Exemplo n.º 28
0
DSTATUS disk_status(BYTE pdrv)
{
    debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
    return RES_OK;
}
Exemplo n.º 29
0
static void mp4sys_adts_cleanup( importer_t *importer )
{
    debug_if( importer && importer->info )
        remove_mp4sys_adts_importer( importer->info );
}
Exemplo n.º 30
0
static void vc1_importer_cleanup( importer_t *importer )
{
    debug_if( importer && importer->info )
        remove_vc1_importer( importer->info );
}