.TH "ifp.h" 3 "20 Feb 2005" "Version 0.1.0.11" "libifp" \" -*- nroff -*- .ad l .nh .SH NAME ifp.h \- .SH "Detailed Description" .PP An interface for iRiver's flash-based portable music players. \fBAuthor:\fP .RS 4 Copyright (C) Geoff Oakham, 2004; .RE .PP Calling Conventions (unless otherwise stated): .IP "\(bu" 2 integer return value 0 indicates success, error otherwise .IP "\(bu" 2 argument 'dev' is a device handle .IP "\(bu" 2 argument 'f' is the full path to a remote file or directory. (eg. '\\foo\\bar.mp3') .IP "\(bu" 2 argument 'b' is a buffer for returning data .IP "\(bu" 2 remote pathnames use '\\' instead of '/' for separating directories (eg '\\classical\\mozart\\magicflute.ogg') .IP "\(bu" 2 functions that return numerical values (eg. \fBifp_freespace\fP) return negative values on error .PP .SH SYNOPSIS .br .PP .SS "Setup and initialization" .in +1c .ti -1c .RI "int \fBifp_init\fP (struct \fBifp_device\fP *dev, void *dev_handle)" .br .RI "\fIInitializes device. \fP" .ti -1c .RI "int \fBifp_finalize\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReleases device. Releases any resources aquired by \fBifp_init\fP. Basically, when \fBifp_init\fP returns 0 (success), \fBifp_finalize\fP must be called after you're finished with dev. \fP" .ti -1c .RI "void * \fBifp_find_device\fP (void)" .br .RI "\fIScans the system and returns the first compatible iFP device. \fP" .ti -1c .RI "int \fBifp_release_device\fP (void *)" .br .RI "\fIReleases device handle allocated by \fBifp_find_device\fP. \fP" .ti -1c .RI "int \fBifp_selftest\fP (struct \fBifp_device\fP *dev)" .br .RI "\fITests communications with the device. \fP" .ti -1c .RI "int \fBifp_format\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReformats the device's storage media. \fP" .ti -1c .RI "int \fBifp_update_firmware\fP (struct \fBifp_device\fP *dev, const char *localfile, \fBifp_progress\fP fn, void *context)" .br .RI "\fIUpgrades the firmware. \fP" .in -1c .SS "Device status" .in +1c .ti -1c .RI "int \fBifp_device_info\fP (struct \fBifp_device\fP *dev, char *b, int n)" .br .RI "\fICreates a human readable status string. \fP" .ti -1c .RI "int \fBifp_battery\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReports the battery's status on the scale from 0 to 4. \fP" .ti -1c .RI "int \fBifp_capacity\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReports the device's capacity in bytes. \fP" .ti -1c .RI "int \fBifp_freespace\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReports the device's available free space in bytes. \fP" .ti -1c .RI "int \fBifp_model\fP (struct \fBifp_device\fP *dev, char *b, int n)" .br .RI "\fIReads in the device's model number into 's'. \fP" .ti -1c .RI "int \fBifp_delta\fP (struct \fBifp_device\fP *dev, int *values)" .br .RI "\fI(experimental) retrieves a mystery value. \fP" .ti -1c .RI "int \fBifp_firmware_version\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReads the device's firmware version. The firmware version is returned in raw BCD. For human consumption, I suggest:. \fP" .ti -1c .RI "const char * \fBifp_error_message\fP (int n)" .br .RI "\fIReturn an English string describing an error number. \fP" .in -1c .SS "Metadata" .in +1c .ti -1c .RI "int \fBifp_rename\fP (struct \fBifp_device\fP *dev, const char *old_path, const char *new_path)" .br .RI "\fIRenames a file or directory. \fP" .ti -1c .RI "int \fBifp_delete\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fIDelete the file f. \fP" .ti -1c .RI "int \fBifp_mkdir\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fICreates a new directory, f. \fP" .ti -1c .RI "int \fBifp_rmdir\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fIDeletes the directory f. \fP" .ti -1c .RI "int \fBifp_list_dirs\fP (struct \fBifp_device\fP *dev, const char *dirname, int(*callbk)(void *, int, const char *, int), void *context)" .br .RI "\fIReads directory contents. \fP" .ti -1c .RI "int \fBifp_treewalk_open\fP (struct \fBifp_device\fP *dev, const char *directory, void **handle)" .br .RI "\fIRecursively walk a remote directory. (Interface similar to 'fts.h'.). \fP" .ti -1c .RI "int \fBifp_treewalk_close\fP (void *tws_p)" .br .RI "\fIReleases the resources used in a treewalk. \fP" .ti -1c .RI "\fBifp_treewalk_entry\fP * \fBifp_treewalk_next\fP (void *tws_p)" .br .RI "\fIReturns the next file or directory in a treewalk. \fP" .in -1c .SS "Reading files" .in +1c .ti -1c .RI "int \fBifp_read_open\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fIOpens the file f for reading. \fP" .ti -1c .RI "int \fBifp_read_close\fP (struct \fBifp_device\fP *dev)" .br .RI "\fICloses a file open for reading. \fP" .ti -1c .RI "int \fBifp_read_seek\fP (struct \fBifp_device\fP *dev, int abs_position)" .br .RI "\fIFast-forward within the current file. \fP" .ti -1c .RI "int \fBifp_read_data\fP (struct \fBifp_device\fP *dev, void *b, int bytes)" .br .RI "\fIReads from an open file. Reads the next 'bytes' of data into 'buff'. \fP" .ti -1c .RI "int \fBifp_read_eof\fP (struct \fBifp_device\fP *dev)" .br .RI "\fICheck if we've reached the end of the file. (EOF). \fP" .ti -1c .RI "int \fBifp_read_size\fP (struct \fBifp_device\fP *dev)" .br .RI "\fIReturns the size of the current file in bytes. \fP" .in -1c .SS "Creating files" .in +1c .ti -1c .RI "int \fBifp_write_open\fP (struct \fBifp_device\fP *dev, const char *f, int fsize)" .br .RI "\fIOpens the file f for writing. \fP" .ti -1c .RI "int \fBifp_write_close\fP (struct \fBifp_device\fP *dev)" .br .RI "\fICloses a file open for writing. \fP" .ti -1c .RI "int \fBifp_write_data\fP (struct \fBifp_device\fP *dev, void *b, int bytes)" .br .RI "\fIWrites 'bytes' of data from buff to the file. \fP" .in -1c .SS "Bulk file transfers (userland only)" .in +1c .ti -1c .RI "int \fBifp_read_file_progress\fP (struct \fBifp_device\fP *dev, FILE *dst, const char *f, int(*progress)(void *, int), void *context)" .br .RI "\fIDownloads a file; includes a hook for a progress metre. \fP" .ti -1c .RI "int \fBifp_write_file_progress\fP (struct \fBifp_device\fP *dev, FILE *src, int filesize, const char *f, int(*progress)(void *, int), void *context)" .br .RI "\fIUploads a file; includes a hook for a progress metre. Creates a new file 'f' on the device and populates it with data from 'src'. Filesize is the number of bytes to be uploaded from 'src'. \fP" .ti -1c .RI "static int \fBifp_read_file\fP (struct \fBifp_device\fP *dev, FILE *dst, const char *f)" .br .RI "\fIReads the file 'f' into dst. \fP" .ti -1c .RI "static int \fBifp_write_file\fP (struct \fBifp_device\fP *dev, FILE *src, int filesize, const char *f)" .br .RI "\fICreates a new file 'f' from src. \fP" .ti -1c .RI "int \fBifp_download_file\fP (struct \fBifp_device\fP *dev, const char *remotefile, const char *localfile, \fBifp_progress\fP fn, void *fn_context)" .br .RI "\fIDownloads 'remotefile' and saves it directly on the filesystem as 'localfile'. \fP" .ti -1c .RI "int \fBifp_upload_file\fP (struct \fBifp_device\fP *dev, const char *localfile, const char *remotefile, \fBifp_progress\fP fn, void *fn_context)" .br .RI "\fIUploads 'localfile' from the filesystem onto the device as 'remotefile'. \fP" .ti -1c .RI "int \fBifp_delete_dir_recursive\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fIDeletes the directory 'f', its files and subdirectories. (Think of 'rm -Rf'.). \fP" .ti -1c .RI "int \fBifp_download_dir\fP (struct \fBifp_device\fP *dev, const char *remotedir, const char *localdir, \fBifp_progress\fP fn, void *fn_context)" .br .RI "\fIDownloads the contents of 'remotedir' (including all subdirectories) and saves it as 'localdir'. \fP" .ti -1c .RI "int \fBifp_upload_dir\fP (struct \fBifp_device\fP *dev, const char *localdir, const char *remotedir, \fBifp_progress\fP fn, void *fn_context)" .br .RI "\fIUploads the contents of 'localdir' (including all subdirectories) to the device as 'remotedir'. \fP" .in -1c .SS "Boolean tests" .in +1c .ti -1c .RI "int \fBifp_is_file\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fITests if f is a file. \fP" .ti -1c .RI "int \fBifp_is_dir\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fITests if f is a directory. \fP" .ti -1c .RI "int \fBifp_exists\fP (struct \fBifp_device\fP *dev, const char *f)" .br .RI "\fITests for the existance of f. \fP" .in -1c .SS "FM Tuner preset station manipulation" .in +1c .ti -1c .RI "int \fBifp_get_tuner_presets\fP (struct \fBifp_device\fP *dev, void *data, int n)" .br .RI "\fIRetrieves the tuner preset file into 'data'. \fP" .ti -1c .RI "int \fBifp_set_tuner_presets\fP (struct \fBifp_device\fP *dev, void *data, int n)" .br .RI "\fIStores the tuner preset file 'data' on the device. \fP" .ti -1c .RI "int \fBifp_get_station\fP (int n, void *b, char *callsign, int *freq)" .br .RI "\fIReads station #n from the binary datablock into more useful forms. \fP" .ti -1c .RI "int \fBifp_set_station\fP (int n, void *data, const char *callsign, int freq)" .br .RI "\fISets station #n to 'freq' and 'callsign'. \fP" .in -1c .SS "Defines" .in +1c .ti -1c .RI "#define \fBIFP_1XX\fP 0x1001" .br .ti -1c .RI "#define \fBIFP_3XX\fP 0x1003" .br .ti -1c .RI "#define \fBIFP_5XX\fP 0x1005" .br .ti -1c .RI "#define \fBIFP_7XX\fP 0x1007" .br .ti -1c .RI "#define \fBIFP_8XX\fP 0x1008" .br .ti -1c .RI "#define \fBIFP_9XX\fP 0x1008" .br .ti -1c .RI "#define \fBIFP_N10\fP 0x1011" .br .ti -1c .RI "#define \fBIFP_FILE\fP 1" .br .ti -1c .RI "#define \fBIFP_DIR\fP 2" .br .ti -1c .RI "#define \fBIFP_ERR_DEV_FUBAR\fP 8" .br .ti -1c .RI "#define \fBIFP_ERR_BAD_FREQUENCY\fP 9" .br .ti -1c .RI "#define \fBIFP_ERR_BAD_FILENAME\fP 10" .br .ti -1c .RI "#define \fBIFP_ERR_USER_CANCEL\fP 11" .br .ti -1c .RI "#define \fBIFP_TUNER_PRESET_DATA\fP 240" .br .ti -1c .RI "#define \fBIFP_FREQ_MIN\fP 8750" .br .ti -1c .RI "#define \fBIFP_FREQ_MAX\fP 10800" .br .ti -1c .RI "#define \fBIFP_PRESET_TOTAL\fP 20" .br .ti -1c .RI "#define \fBIFP_TUNER_LABEL\fP 6" .br .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef int(* \fBifp_progress\fP )(void *, struct \fBifp_transfer_status\fP *)" .br .RI "\fICallback for implementing a progress metre. \fP" .in -1c .SS "Enumerations" .in +1c .ti -1c .RI "enum { \fBIFP_WALK_FILE\fP = IFP_FILE, \fBIFP_WALK_DIR_PRE\fP = IFP_DIR, \fBIFP_WALK_DIR_POST\fP, \fBIFP_WALK_NONE\fP }" .br .RI "\fIFile types for treewalking. \fP" .in -1c .SH "Define Documentation" .PP .SS "#define IFP_1XX 0x1001" .PP Model number for iFP-100 series .SS "#define IFP_3XX 0x1003" .PP Model number for iFP-300 series .SS "#define IFP_5XX 0x1005" .PP Model number for iFP-500 series .SS "#define IFP_7XX 0x1007" .PP Model number for iFP-700 series .SS "#define IFP_8XX 0x1008" .PP Model number for iFP-800 series .SS "#define IFP_9XX 0x1008" .PP Model number for iFP-900 series .SS "#define IFP_N10 0x1011" .PP Model number for N10 .SS "#define IFP_FILE 1" .PP File 'type'. .SS "#define IFP_DIR 2" .PP Dir 'type'. .SS "#define IFP_ERR_DEV_FUBAR 8" .PP device not responding; try jiggling handle .SS "#define IFP_ERR_BAD_FREQUENCY 9" .PP tuner frequency out of range .SS "#define IFP_ERR_BAD_FILENAME 10" .PP filename is invalid. Likely causes are unsupported characters, or a filename that's too long (more than ::IFP_MAXFILENAMELEN chars). .PP note: linux's fatfs returns EINVAL instead. Should we switch? .SS "#define IFP_ERR_USER_CANCEL 11" .PP A user callback requested the transfer be cancelled. .SS "#define IFP_TUNER_PRESET_DATA 240" .PP Tuner preset buffer size. .SS "#define IFP_FREQ_MIN 8750" .PP lowist valid frequency (87.5kHz) .SS "#define IFP_FREQ_MAX 10800" .PP highist valid frequency (108.0kHz) .SS "#define IFP_PRESET_TOTAL 20" .PP number of preset stations. .SS "#define IFP_TUNER_LABEL 6" .PP max size of label string. .SH "Typedef Documentation" .PP .SS "typedef int(* \fBifp_progress\fP)(void *, struct \fBifp_transfer_status\fP *)" .PP Callback for implementing a progress metre. .PP If provided, this function is typically called several times during a file transfer to give GUI applications a chance provide user feedback. .PP This function should return 0 for 'success' or 1 to request the transfer be cancelled when possible. (The request might be ignored.) Other values are considered 'error values'. .PP The first parameter is whatever if you passed to the main function as 'context'. You may use this for anything you like or leave it NULL. .PP The second parameter is a pointer to information about the transfer in progress. The only value guaranteed to be valid for _all_ transfers is file_bytes. Which values *are* valid should be obvious from context. To be on the safe side, please guard against NULL pointers and divide-by -zero errors. (The structure itself won't be NULL. I promise.) .SH "Enumeration Type Documentation" .PP .SS "anonymous enum" .PP File types for treewalking. .PP \fBEnumeration values: \fP .in +1c .TP \fB\fIIFP_WALK_FILE \fP\fP file .TP \fB\fIIFP_WALK_DIR_PRE \fP\fP directory, before visiting its children .TP \fB\fIIFP_WALK_DIR_POST \fP\fP directory, after visiting its children .TP \fB\fIIFP_WALK_NONE \fP\fP none of the above .SH "Function Documentation" .PP .SS "int ifp_init (struct \fBifp_device\fP * dev, void * device_handle)" .PP Initializes device. .PP Initialzies and tests the device for use with device_handle. (\fBifp_finalize\fP should be called when you're finished with 'dev'.) .PP \fBParameters:\fP .RS 4 \fIdev\fP Unitialized memory ready for use as an \fBifp_device\fP. .br \fIdevice_handle\fP The iFP USB hardware device handle. .RE .PP \fBReturns:\fP .RS 4 \fBIFP_ERR_DEV_FUBAR\fP if the self-test failed. (Ask the user to jiggle the handle.) .PP 0 on success. .RE .PP .PP \fBExamples: \fP .in +1c \fBsimple.c\fP. .SS "void* ifp_find_device (void)" .PP Scans the system and returns the first compatible iFP device. .PP If no device is found, NULL is returned. The handle must be released with \fBifp_release_device\fP. .PP \fBExamples: \fP .in +1c \fBsimple.c\fP. .SS "int ifp_selftest (struct \fBifp_device\fP * dev)" .PP Tests communications with the device. .PP This is done automatically on startup by \fBifp_init\fP, so normal shouldn't need to call this.. unless they really want to. .SS "int ifp_format (struct \fBifp_device\fP * dev)" .PP Reformats the device's storage media. .PP (Deletes all your stuff.) Returns 0 on success, 1 on error. This function hasn't been tested--please report if you've successfully used it. .SS "int ifp_update_firmware (struct \fBifp_device\fP * dev, const char * localfile, \fBifp_progress\fP fn, void * fn_context)" .PP Upgrades the firmware. .PP This is much like a file upload, except: the filename on the local disk must be in the format 'IFP-?XXT.HEX', 'IFP-1XXTC.HEX' or 'N10.HEX'. The progress meter only tracks the firmware upload. The flash-upgrading itself and reboot take extra time we can't predict. .PP Immediately after calling ifp_update_firmware, the caller should release 'dev', and wait a healthy ammount of time (10 or more seconds) before trying to reconnect. During this time, you'll see the message 'upgrading firmware please don't touch' on the device, after which the device will shutdown: user will likely have to turn it back on themselves. .PP I welcome suggestions and/or code on how to help monitor the device status during a firmware upgrade. .SS "int ifp_device_info (struct \fBifp_device\fP * dev, char * s, int n)" .PP Creates a human readable status string. .PP Creates a human readable status string similar to 'model IFP-007T, firmware 1.14, battery =[####], delta 1.8.4.42'. .PP \fBExamples: \fP .in +1c \fBsimple.c\fP. .SS "int ifp_battery (struct \fBifp_device\fP * dev)" .PP Reports the battery's status on the scale from 0 to 4. .PP Typical values are 4, 0 and occasionally 2. .SS "int ifp_model (struct \fBifp_device\fP * dev, char * s, int size)" .PP Reads in the device's model number into 's'. .PP ('size' is the size of the buffer s points to.) Typical results look like 'IFP-590T'. .SS "int ifp_delta (struct \fBifp_device\fP * dev, int * values)" .PP (experimental) retrieves a mystery value. .PP I've coined this mystery value 'Delta' until a better name is chosen. .PP \fBParameters:\fP .RS 4 \fIvalues\fP an empty int[4] for the output values. .RE .PP Integers returned in 'values' are my interpretation of the data. The actual raw data has been varried widely: .PP .PP .nf 0108 0312 ffff ffff 0108 0415 ffff ffff 0108 0616 ffff ffff 0108 0417 0000 0000 0108 0418 ffff ffff .fi .PP .PP Two devices returned 4 bytes instead of 8. .SS "int ifp_firmware_version (struct \fBifp_device\fP * dev)" .PP Reads the device's firmware version. The firmware version is returned in raw BCD. For human consumption, I suggest:. .PP .PP .nf sprintf(s, '%x.%02x', r/0x0100, r%0x100) .fi .PP .SS "const char* ifp_error_message (int n)" .PP Return an English string describing an error number. .PP (Available only in userland.) .SS "int ifp_rename (struct \fBifp_device\fP * dev, const char * old_path, const char * new_path)" .PP Renames a file or directory. .PP Renames or moves the object 'old_path' to 'new_path'. .PP \fBParameters:\fP .RS 4 \fIold_path\fP an existing file or directory. .br \fInew_path\fP an available path for a new file or directory. (Ie, the path's parent directory exists and the path isn't in use by another object in that directory.) .RE .PP Returns 0 on success and -ENOENT, -EEXIST, -EACCES, IFP_ERR_BAD_FILENAME on failure, as appropriate. .SS "int ifp_delete (struct \fBifp_device\fP * dev, const char * f)" .PP Delete the file f. .PP Returns -ENOENT if f doesn't exist. .SS "int ifp_mkdir (struct \fBifp_device\fP * dev, const char * f)" .PP Creates a new directory, f. .PP Returns -ENOENT if f's parent doesn't exist, -EEXISTS the dirname 'f' is allready in use, and IFP_ERR_BAD_FILENAME if 'f' contains unsupported characters. .SS "int ifp_rmdir (struct \fBifp_device\fP * dev, const char * d)" .PP Deletes the directory f. .PP Returns 0 on success or: -ENOENT -ENOTEMPTY -EACCES .SS "int ifp_list_dirs (struct \fBifp_device\fP * dev, const char * filename, int(*)(void *, int, const char *, int) callbk, void * context)" .PP Reads directory contents. .PP Passes the contents of 'dirname' to a callback function, one entry at a time. The parameters given to the callback function are: .IP "\(bu" 2 void * context is the same context passed to list_dirs .IP "\(bu" 2 int type is either \fBIFP_FILE\fP or \fBIFP_DIR\fP .IP "\(bu" 2 char * name is the entry name without a full path. (Ie, no '\\' chars) .IP "\(bu" 2 int filesize is the number of bytes in a file (undefied for directories) .PP The callback can return '0' on success, '1' to 'break' (leave early without error) or <0 on error. .PP Returns 0 on success or -ENOENT if the directory doesn't exist. .PP \fBExamples: \fP .in +1c \fBsimple.c\fP. .SS "struct int ifp_treewalk_open (struct \fBifp_device\fP * dev, const char * directory, void ** handle)" .PP Recursively walk a remote directory. (Interface similar to 'fts.h'.). .PP Start a treewalk for the 'directory' on the device. The handle for this session is placed at *handle; this handle is freed by calling \fBifp_treewalk_close\fP. .PP 'dev' won't be left in a 'special state' after calling treewalk-family functions. Likewise, please don't leave dev in a 'special state' before calling \fBifp_treewalk_open\fP or \fBifp_treewalk_next\fP. .PP Returns -ENOENT if the directory doesn't exist. .SS "int ifp_treewalk_close (void * tws_p)" .PP Releases the resources used in a treewalk. .PP Must be called after each successful call of \fBifp_treewalk_open\fP. .SS "struct \fBifp_treewalk_entry\fP* ifp_treewalk_next (void * tws_p)" .PP Returns the next file or directory in a treewalk. .PP The structure returned is valid until the next \fBifp_treewalk_next\fP or \fBifp_treewalk_close\fP function call. See \fBifp_treewalk_entry\fP for details about the fields. .PP Likewise, please don't leave 'dev' in a 'special state' before calling \fBifp_treewalk_next\fP. .PP NULL is returned after the last entry. .SS "int ifp_read_open (struct \fBifp_device\fP * dev, const char * f)" .PP Opens the file f for reading. .PP Returns -ENOENT if 'f' doesn't exist and -EACCES if 'f' is read-protected by the device. .SS "int ifp_read_seek (struct \fBifp_device\fP * dev, int bytes)" .PP Fast-forward within the current file. .PP In the current open file, skip forward to 'bytes' (ignoring the data). Caution: the implementation isn't particularily fast, and can only seek forward. Avoid it if you can. .SS "int ifp_read_data (struct \fBifp_device\fP * dev, void * buff, int bytes)" .PP Reads from an open file. Reads the next 'bytes' of data into 'buff'. .PP \fBReturns:\fP .RS 4 the number of bytes read, or <0 on error. .RE .PP .SS "int ifp_write_open (struct \fBifp_device\fP * dev, const char * f, int filesize)" .PP Opens the file f for writing. .PP Creates and opens a new file of 'filesize' bytes with the name 'f'. Returns -EEXIST if the name 'f' isn't available. (Ie, if there allready exists a file or directory with the same name.) Returns -ENOENT, -ENOSPC, or IFP_ERR_BAD_FILENAME .SS "int ifp_write_data (struct \fBifp_device\fP * dev, void * buff, int bytes)" .PP Writes 'bytes' of data from buff to the file. .PP Returns 0 on success. (Does not return the number of bytes written--it's all or nothing.) .SS "int ifp_read_file_progress (struct \fBifp_device\fP * dev, FILE * dst, const char * f, int(*)(void *, int) fn, void * fn_context)" .PP Downloads a file; includes a hook for a progress metre. .PP Reads the file 'f' from the device and saves it in 'dst'. .PP \fBParameters:\fP .RS 4 \fIf\fP name of the remote file we're downloading .br \fIdst\fP where the data will be saved .br \fIprogress\fP Optional. If given, this function will be called occationally so an application can update a progress metre. (For example.) .br \fIcontext\fP Context for the progress metre. (Safe to leave NULL.) .RE .PP (Available only in userland.) .PP Returns -ENOENT if 'f' doesn't exist; -EACCES if 'f' is read-protected by the device; -ENOSPC; and \fBIFP_ERR_USER_CANCEL\fP if the callback requested the transfer cancelled. .PP (Available only in userland.) .SS "int ifp_write_file_progress (struct \fBifp_device\fP * dev, FILE * src, int filesize, const char * f, int(*)(void *, int) fn, void * fn_context)" .PP Uploads a file; includes a hook for a progress metre. Creates a new file 'f' on the device and populates it with data from 'src'. Filesize is the number of bytes to be uploaded from 'src'. .PP (Note: it appears the device might not need to know the number of bytes in a file ahead time. The current implementation doesn't support this, but if you don't have access to the filesize ahead of time, you might be able to hack libifp to let you do it anyways.) .PP \fBParameters:\fP .RS 4 \fIsrc\fP data to be uploaded .br \fIfilesize\fP number of bytes to copy from src .br \fIf\fP name of the file to be created .br \fIprogress\fP Optional. If given, this function will be called occationally so an application can update its progress metre. .br \fIcontext\fP Context for the progress metre. (Safe to leave NULL.) .RE .PP Returns -EEXIST, -ENOENT, -ENOSPC, \fBIFP_ERR_BAD_FILENAME\fP, \fBIFP_ERR_USER_CANCEL\fP .PP (Available only in userland.) .SS "struct int ifp_download_file (struct \fBifp_device\fP * dev, const char * remotefile, const char * localfile, \fBifp_progress\fP fn, void * fn_context)" .PP Downloads 'remotefile' and saves it directly on the filesystem as 'localfile'. .PP The progress callback function 'fn' and its context pointer are optional. See \fBifp_progress\fP and \fBifp_transfer_status\fP for more information. .PP Returns -ENOENT, -EACCES, -ENOSPC and \fBIFP_ERR_USER_CANCEL\fP (Available only in userland.) .PP Note: There is currently a 'EPIPE' bug in the wild that is relatively rare but causes file corruption during download. ifp_download_file and ifp_download_dir detect and recover from it automatically, but you might see the progress numbers 'jump backwards' occasionally. .SS "int ifp_upload_file (struct \fBifp_device\fP * dev, const char * localfile, const char * remotefile, \fBifp_progress\fP fn, void * fn_context)" .PP Uploads 'localfile' from the filesystem onto the device as 'remotefile'. .PP The progress callback function 'fn' and its context pointer are optional. See \fBifp_progress\fP and \fBifp_transfer_status\fP for more information. .PP Returns -EEXIST, -ENOENT, -ENOSPC, \fBIFP_ERR_BAD_FILENAME\fP, \fBIFP_ERR_USER_CANCEL\fP (Available only in userland.) .SS "int ifp_delete_dir_recursive (struct \fBifp_device\fP * dev, const char * f)" .PP Deletes the directory 'f', its files and subdirectories. (Think of 'rm -Rf'.). .PP Will return -ENOENT if 'f' doesn't exist or isn't a directory. .PP (Available only in userland, at this time.) .SS "int ifp_download_dir (struct \fBifp_device\fP * dev, const char * remotedir, const char * localdir, \fBifp_progress\fP fn, void * fn_context)" .PP Downloads the contents of 'remotedir' (including all subdirectories) and saves it as 'localdir'. .PP Note that 'localdir' must not allready exist. Example: suppose localdir was '/tmp/tunes/tame' and remotedir was '\\classical\\junk'. The directory '/tmp/tunes/tame' will be created and the file '\\classical\\junk\\buz\\fud.ogg' will be copied as '/tmp/tunes/tame/buz/fud.ogg' .PP The progress callback function 'fn' and its context pointer are optional. See \fBifp_progress\fP and \fBifp_transfer_status\fP for more information. .PP Returns -ENOENT, -EACCES, -ENOSPC \fBIFP_ERR_USER_CANCEL\fP .PP (Available only in userland.) .PP Note: There is currently a 'EPIPE' bug in the wild that is relatively rare but causes file corruption during download. ifp_download_file and ifp_download_dir detect and recover from it automatically, but you might see the progress numbers 'jump backwards' occasionally. .SS "int ifp_upload_dir (struct \fBifp_device\fP * dev, const char * localdir, const char * remotedir, \fBifp_progress\fP fn, void * fn_context)" .PP Uploads the contents of 'localdir' (including all subdirectories) to the device as 'remotedir'. .PP Note that 'remotedir' must not exist on the remote device. Example: suppose localdir was '/tmp/tunes/tame' and remotedir was '\\classical\\junk'. The directory '\\classical\\junk' will be created and the file '/tmp/tunes/tame/buz/fud.ogg' will be copied as '\\classical\\junk\\buz\\fud.ogg'. .PP The progress callback function 'fn' and its context pointer are optional. See \fBifp_progress\fP and \fBifp_transfer_status\fP for more information. .PP Returns -EEXIST, -ENOENT, -ENOSPC, \fBIFP_ERR_BAD_FILENAME\fP, or \fBIFP_ERR_USER_CANCEL\fP. FIXME: handle invalid filenames from local filesystem with more grace .PP (Available only in userland.) .SS "int ifp_is_file (struct \fBifp_device\fP * dev, const char * f)" .PP Tests if f is a file. .PP Returns 1 if it is, and 0 if it doesn't exist or isn't a file. .SS "int ifp_is_dir (struct \fBifp_device\fP * dev, const char * f)" .PP Tests if f is a directory. .PP Returns 1 if it is, and 0 if it doesn't exist or isn't a dir. .SS "int ifp_exists (struct \fBifp_device\fP * dev, const char * f)" .PP Tests for the existance of f. .PP \fBReturns:\fP .RS 4 \fBIFP_FILE\fP if f is a file .PP \fBIFP_DIR\fP if f is a directory .PP 0 if f doesn't exist .PP <0 error. .RE .PP .SS "int ifp_get_tuner_presets (struct \fBifp_device\fP * dev, void * data, int n)" .PP Retrieves the tuner preset file into 'data'. .PP 'data' is a buffer of 'n' bytes.. n must be at least \fBIFP_TUNER_PRESET_DATA\fP bytes. .SS "int ifp_set_tuner_presets (struct \fBifp_device\fP * dev, void * data, int n)" .PP Stores the tuner preset file 'data' on the device. .PP 'data' is tuner preset file to be stored.. it is extactly \fBIFP_TUNER_PRESET_DATA\fP bytes. 'n' must be exactly \fBIFP_TUNER_PRESET_DATA\fP .SS "int ifp_get_station (int n, void * b, char * callsign, int * freq)" .PP Reads station #n from the binary datablock into more useful forms. .PP b is the block of data loaded using \fBifp_get_tuner_presets\fP, n is a number between 0 and \fBIFP_PRESET_TOTAL\fP-1, callsign is a pointer to a buffer of at least \fBIFP_TUNER_LABEL\fP+1 bytes, freq is a pointer to an integer, where the station's frequency will be saved. The frequency units are 10*kHz (0.01MHz) and should range from \fBIFP_FREQ_MIN\fP to \fBIFP_FREQ_MAX\fP. .PP Apon successful return, 'callsign' will be loaded the station's label as a zero-terminated string, and 'freq' will be the station's frequency in units of 10*kHz (0.01MHz). .SS "int ifp_set_station (int n, void * b, const char * callsign, int freq)" .PP Sets station #n to 'freq' and 'callsign'. .PP b is the block of data loaded using \fBifp_get_tuner_presets\fP, n is a number between 0 and \fBIFP_PRESET_TOTAL\fP-1, callsign is a zero-terminated string (but only the first 6 characters will be used), freq is the FM frequency in units of Hz*10^4 (or 0.01 MHz); freq should range from \fBIFP_FREQ_MIN\fP to \fBIFP_FREQ_MAX\fP. .PP eg: //sets station #4 to 94.9MHz and labeled 'bbc1' i = \fBifp_set_station\fP(3, p, 'bbc1', 9490); .PP Notes: -\fBifp_set_tuner_presets\fP must be called before any changes to take affect. .PP -Although this interface suggests frequency accuracy of 0.01MHz is possible, I've found some players only support increments 0.05MHz. Setting a frequency to a more accurate value is *not* an error: the hardware will silently truncate to a nearby acceptable value. .PP -User interfaces can provide feedback to the user of the above 'effect' by saving and reloading the preset data after every change. Any trunction by the hardware will be immediately obvious. .PP Returns \fBIFP_ERR_BAD_FREQUENCY\fP if the frequency is out of range. .SH "Author" .PP Generated automatically by Doxygen for libifp from the source code.