Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Examples

protocol3.h

Go to the documentation of this file.
00001 
00009 #ifndef __NJB__PROTO3__H
00010 #define __NJB__PROTO3__H
00011 
00012 #include "libnjb.h"
00013 
00014 /* Buffer for short reads */
00015 #define NJB3_SHORTREAD_BUFSIZE 1024
00016 
00017 /* Transfer block size (adding and fetching tracks, files */
00018 #define NJB3_CHUNK_SIZE 0x100000U
00019 #define NJB3_FIRMWARE_CHUNK_SIZE 0x40000U
00020 #define NJB3_DEFAULT_GET_FILE_BLOCK_SIZE    0x2000U
00021 #define NJB3_DEFAULT_SEND_FILE_BLOCK_SIZE   0x2000U
00022 
00023 /*
00024  * Known commands (first 16 bits)
00025  * 0x0001 Update database entry metadata on files, tracks, playlists also
00026  *        used for adding smartvolume information to tracks
00027  * 0x0002 Get file chunk
00028  * 0x0003 Send file chunk
00029  * 0x0004 Create database item  files, tracks, playlists
00030  * 0x0005 Delete database item  files, tracks, playlists
00031  * 0x0006 Read database        tracks, datafiles, playlists..
00032  * 0x0007 Set device info      owner string, current track position,
00033  *                             play status (pause/stop), set time,
00034  *                             EAX processor mode (on/off)
00035  * 0x0008 Request device info  codecs, device info, ID, fw version, 
00036  *                             hw version, disk usage, owner string,
00037  *                             time, current track position, play status
00038  *                             (pause/stop)
00039  * 0x0009 Send file complete
00040  * 0x000a Create folder or playlist (empty, non-file entry in database)
00041  * 0x000b Set bitmap and firmware upgrade (load device software?)
00042  * 0x000c Get device keys
00043  * 0x0010 Verify file??
00044  * 0x0100 Play track
00045  * 0x0101 Get elapsed time for current track, just 4 bytes 0101 0001
00046  * 0x0104 Enqueue track
00047  * 0x0107 Add tracks to playlist
00048  * 0x0108 Get tracks for playlist
00049  * 0x0200 Get EAX effect settings
00050  * 0x0201 Adjust EAX setting
00051  */
00052 
00053 /* These are the metadata frame IDs used by NJB3 */
00054 #define NJB3_CODECS_FRAME_ID    0x0001U /* List of supported audio file types/codecs */
00055 #define NJB3_DISKUTIL_FRAME_ID  0x0002U /* 14 bytes disk utilization information */
00056 #define NJB3_PRODID_FRAME_ID    0x0003U /* 3 bytes FW rev 3 bytes HW rev, string product ID */
00057 /* 0x0004 and 0x0005 return NULL when read */
00058 #define NJB3_LOCKED_FRAME_ID    0x0006U /* 16 bit word */
00059 #define NJB3_FNAME_FRAME_ID     0x0007U /* String: Original filename on host */
00060 #define NJB3_UNKNOWN1_FRAME_ID  0x0008U /* 16 bit word, value 0x0004 on NJB Zen USB 2.0, not read by Win SW */
00061 /* 0x0009 return NULL when read */
00062 #define NJB3_KEY_FRAME_ID       0x000aU /* 4 bytes string "AR00", "PL00", "SG00", "LG00" known */
00063 #define NJB3_CODEC_FRAME_ID     0x000bU /* 16 bit word */
00064 #define NJB3_POSTID_FRAME_ID    0x000cU /* 16 bit word TrackID on tracks, PlaylistID on playlists */
00065 #define NJB3_DIR_FRAME_ID       0x000dU /* String: Original directory on host */
00066 #define NJB3_FILESIZE_FRAME_ID  0x000eU /* 32 bit word */
00067 #define NJB3_FILECOUNT_FRAME_ID 0x0013U /* 6 bytes: at least top 2 bytes are file & directory count */
00068 #define NJB3_VALUE_FRAME_ID     0x0014U /* 8 bytes, 2*32 bit words */
00069 #define NJB3_JUKEBOXID_FRAME_ID 0x0015U /* 16 bytes - unique device ID */
00070 #define NJB3_FILETIME_FRAME_ID  0x0016U /* 32 bit word timestamp (UNIX format) */
00071 #define NJB3_UNKNOWN6_FRAME_ID  0x0017U /* 32 bit word - could be FAT32 attributes */
00072 #define NJB3_FILEFLAGS_FRAME_ID 0x0018U /* 32 bit word set on files and folders - NTFS file attributes */
00073 #define NJB3_ALBUM_FRAME_ID     0x0101U /* String */
00074 #define NJB3_ARTIST_FRAME_ID    0x0102U /* String */
00075 #define NJB3_GENRE_FRAME_ID     0x0103U /* String */
00076 #define NJB3_TITLE_FRAME_ID     0x0104U /* String */
00077 #define NJB3_LENGTH_FRAME_ID    0x0105U /* String */
00078 #define NJB3_TRACKNO_FRAME_ID   0x0106U /* 16 bit word */
00079 #define NJB3_YEAR_FRAME_ID      0x0107U /* 16 bit word */
00080 #define NJB3_SMARTPAR_FRAME_ID  0x010aU /* 0x01b6 bytes, unknown format */
00081 /* Smartvolume parameters for a track is sent after a track with the command:
00082  * 0x0001 0x0001 update file with info
00083  * 0x0000 0x0000 4 bytes trackid
00084  * 0x01b6 (length)
00085  * 0x010a (smartvol)
00086  * 0x01b6 unknown bytes, appears to be an array of 109 32-bit words.
00087  * 0x0000 terminator
00088  */
00089 #define NJB3_TRACKINFO_FRAME_ID 0x010bU /* 16 bit word: Info about current track on the playlist */
00090 #define NJB3_SEEKTRACK_FRAME_ID 0x010cU /* 32 bit word: seek to position (in ms) in current track */
00091 #define NJB3_EAX_TYPENAME       0x010eU /* String with the name of an EAX type */
00092 #define NJB3_PLNAME_FRAME_ID    0x010fU /* String: playlist name */
00093 #define NJB3_TIME_FRAME_ID      0x0110U /* 10 bytes */
00094 #define NJB3_OWNER_FRAME_ID     0x0113U /* String: owner name */
00095 #define NJB3_BATTERY_FRAME_ID   0x0114U /* 4 bytes: 0x14 0x02 then two bytes of battery level */
00096 #define NJB3_UNKNOWN3_FRAME_ID  0x0115U /* 32bit word - unknown use,
00097                                            requested after reading tracks value on NJB3 0x0000 0x0003 */
00098 #define NJB3_PLAYTRACK_FRAME_ID 0x0119U /* 32 bit word track ID to play */
00099 #define NJB3_PLTRACKS_FRAME_ID  0x011cU /* Array of 16bit words */
00100 /* 
00101    0200 EAX read command?
00102    0201 EAX write command?
00103  */ 
00104 #define NJB3_MINMAX_ID          0x0201U /* 2x16 bit values, max and min */
00105 #define NJB3_EAX_ACTIVE_ID      0x0202U /* 16 bit word - this EAX type is active/to 
00106                                          * be activated (0x0000 = off, 0x0001 = on) */
00107 #define NJB3_VOLUME_FRAME_ID    0x0203U /* 16 bit word */
00108 #define NJB3_ENV_FRAME_ID       0x0204U /* 16 bit word - environment setting */
00109 #define NJB3_EQ_FRAME_ID        0x0205U /* 16 bit word - equalizer setting */
00110 #define NJB3_SPAT_FRAME_ID      0x0206U /* 16 bit word - spatialization 2 = full */
00111 #define NJB3_TSCALE_FRAME_ID    0x0207U /* 16 bit word - time scaling factor */
00112 #define NJB3_SMARTVOL_FRAME_ID  0x0208U /* 16 bit word - smart volume setting */
00113 #define NJB3_EAXACTIVE_FRAME_ID 0x020aU /* 16 bit word - 0x0000/0x0001 = activate/deactivate EAX processor */
00114 #define NJB3_EAXID_FRAME_ID     0x020bU /* 16 bit word with the numerical ID of a certain EAX type */
00115 #define NJB3_EAX_INDEX_ID       0x020cU /* 16 bit word - currently selected effect in a set of effects */
00116 #define NJB3_KEYVALUE_FRAME_ID  0x1400U /* Array of value-key-pairs, requested in a 
00117                                           subrequest parameter to this request */
00118 
00119 /* File type IDs, used for eg create_file */
00120 #define NJB3_FILETYPE_FILE     0x0000U
00121 #define NJB3_FILETYPE_TRACK    0x0002U
00122 
00123 /* Codec IDs */
00124 #define NJB3_CODEC_MP3_ID_OLD        0x0000U /* Used on NJB3/Zen FW? */
00125 #define NJB3_CODEC_WAV_ID            0x0001U
00126 #define NJB3_CODEC_MP3_ID            0x0002U
00127 #define NJB3_CODEC_WMA_ID            0x0003U
00128 /* 
00129  * 0x0004, 0x0005 and 0x0006 unknown, one of them is 
00130  * undoubtedly the Real Networks AAC + Helix DRM 
00131  * decoder. Only very certain firmwares will support
00132  * these I believe...
00133  */
00134 #define NJB3_CODEC_AA_ID             0x0007U /* Audible.com codec */
00135 #define NJB3_CODEC_PROTECTED_WMA_ID  0x0203U /* Is it two bytes actually? */
00136 
00137 /* Stop, pause and resume are very much alike. */
00138 #define NJB3_START_PLAY     0x00
00139 #define NJB3_STOP_PLAY      0x01
00140 #define NJB3_PAUSE_PLAY     0x02
00141 #define NJB3_RESUME_PLAY    0x03
00142 
00143 /* Status codes */
00144 #define NJB3_STATUS_OK                0x0000U
00145 #define NJB3_STATUS_EMPTY             0x0001U /* You tried to retrieve an empty item */
00146 #define NJB3_STATUS_TRANSFER_ERROR    0x0002U /* Error during read or write */
00147 #define NJB3_STATUS_BAD_FILESIZE      0x0003U /* Illegal file size (e.g. negative, too large) */
00148 #define NJB3_STATUS_NOTIMPLEMENTED    0x0004U /* For example if EAX is not supported on a device */
00149 #define NJB3_STATUS_NOTEXIST          0x0005U /* Tried to access nonexistant track */
00150 #define NJB3_STATUS_PROTECTED         0x000cU /* Tried to access protected object */
00151 #define NJB3_STATUS_EMPTY_CHUNK       0x000eU /* Appear when requesting empty metadata lists
00152                                                * or beyond the end of files. */
00153 
00154 /*
00155  * Status codes that must exist, find by trial-and-error:
00156  * - postid invalid (does not exist)
00157  * - disk full
00158  * - file path / track name etc too long 
00159  * - playing (cannot transfer when playing)
00160  * - tried to skip to position outside file in playback mode
00161  * - too many files/tracks etc - limit reached.
00162  * - filename or track+artist+(all metadata) is the same as
00163  *   one already present on the player
00164  * - transfer in progress (a track/file is transferring in
00165  *   either direction
00166  */
00167 
00168 #define njb3_start_play(njb) njb3_ctrl_playing(njb, NJB3_START_PLAY)
00169 #define njb3_stop_play(njb) njb3_ctrl_playing(njb, NJB3_STOP_PLAY)
00170 #define njb3_pause_play(njb) njb3_ctrl_playing(njb, NJB3_PAUSE_PLAY)
00171 #define njb3_resume_play(njb) njb3_ctrl_playing(njb, NJB3_RESUME_PLAY)
00172 
00173 /* Structure to hold protocol3 states */
00174 typedef struct {
00175   /* Get extended tags */
00176   int get_extended_tag_info;
00177   njb_songid_t *first_songid;
00178   njb_songid_t *next_songid;
00179   njb_playlist_t *first_plid;
00180   njb_playlist_t *next_plid;
00181   njb_datafile_t *first_dfid;
00182   njb_datafile_t *next_dfid;
00183   int current_playing_track;
00184   njb_keyval_t *first_key;
00185   njb_keyval_t *next_key;
00186   njb_eax_t *first_eax;
00187   njb_eax_t *next_eax;
00189   u_int8_t eax_processor_active;
00191   char *product_name;
00193   u_int8_t fwMajor;
00195   u_int8_t fwMinor;
00197   u_int8_t fwRel;
00199   u_int8_t hwMajor;
00201   u_int8_t hwMinor;
00203   u_int8_t hwRel;
00205   u_int16_t last_elapsed;
00207   u_int8_t turbo_mode;
00208 } njb3_state_t;
00209 
00210 
00211 /* NJB3 functions */
00212 int njb3_init_state (njb_t *njb);
00213 int njb3_set_bitmap(njb_t *njb, u_int16_t x_size, u_int16_t y_size, const unsigned char *bitmap);
00214 int njb3_current_track (njb_t *njb, u_int16_t * track);
00215 int njb3_elapsed_time (njb_t *njb, u_int16_t * elapsed, int * change);
00216 int njb3_play_track (njb_t *njb, u_int32_t trackid);
00217 int njb3_queue_track (njb_t *njb, u_int32_t trackid);
00218 int njb3_ctrl_playing (njb_t *njb, int cmd);
00219 int njb3_seek_track (njb_t *njb, u_int32_t position);
00220 int njb3_get_codecs(njb_t *njb);
00221 int njb3_ping (njb_t *njb, int type);
00222 int njb3_power_status (njb_t *njb, int *battery_level, int *charging, int *ac_power);
00223 int njb3_readid (njb_t *njb, u_int8_t *sdmiid);
00224 int njb3_capture (njb_t *njb);
00225 int njb3_release (njb_t *njb);
00226 int njb3_get_disk_usage (njb_t *njb, u_int64_t *totalbytes, u_int64_t *freebytes);
00227 int njb3_get_owner_string (njb_t *njb, char *name);
00228 int njb3_set_owner_string (njb_t *njb, const char *name);
00229 njb_time_t *njb3_get_time(njb_t *njb);
00230 int njb3_set_time(njb_t *njb, njb_time_t *time);
00231 int njb3_reset_get_track_tag (njb_t *njb);
00232 njb_songid_t *njb3_get_next_track_tag (njb_t *njb);
00233 int njb3_reset_get_playlist_tag (njb_t *njb);
00234 njb_playlist_t *njb3_get_next_playlist_tag (njb_t *njb);
00235 int njb3_reset_get_datafile_tag (njb_t *njb);
00236 njb_datafile_t *njb3_get_next_datafile_tag (njb_t *njb);
00237 int njb3_read_keys(njb_t *njb);
00238 njb_keyval_t *njb3_get_keys(njb_t *njb);
00239 int njb3_request_file_chunk(njb_t *njb, u_int32_t fileid, u_int32_t offset);
00240 int njb3_get_file_block(njb_t *njb, unsigned char *data, u_int32_t maxsize);
00241 u_int32_t njb3_create_file(njb_t *njb, unsigned char *ptag, u_int32_t tagsize, u_int16_t filetype);
00242 u_int32_t njb3_send_file_chunk(njb_t *njb, unsigned char *chunk, u_int32_t chunksize, u_int32_t fileid);
00243 int njb3_send_file_complete(njb_t *njb, u_int32_t fileid);
00244 int njb3_create_folder(njb_t *njb, const char *name, u_int32_t *folderid);
00245 int njb3_delete_item(njb_t *njb, u_int32_t itemid);
00246 int njb3_update_16bit_frame(njb_t *njb, u_int32_t itemid, u_int16_t frameid, u_int16_t value);
00247 int njb3_update_string_frame(njb_t *njb, u_int32_t itemid, u_int16_t frameid, unsigned char *str);
00248 int njb3_update_tag(njb_t *njb, u_int32_t trackid, unsigned char *ptag, u_int32_t ptagsize);
00249 int njb3_create_playlist(njb_t *njb, char *name, u_int32_t *plid);
00250 int njb3_add_multiple_tracks_to_playlist (njb_t *njb, u_int32_t *plid, u_int32_t *trids, u_int16_t ntracks);
00251 int njb3_adjust_volume(njb_t *njb, u_int16_t value);
00252 int njb3_control_eax_processor (njb_t * njb, u_int16_t state);
00253 int njb3_adjust_eax(njb_t *njb, u_int16_t eaxid, u_int16_t patchindex, u_int16_t active, u_int16_t scalevalue);
00254 void njb3_read_eaxtypes(njb_t *njb);
00255 njb_eax_t *njb3_get_nexteax(njb_t *njb);
00256 int njb3_announce_firmware(njb_t *njb, u_int32_t size);
00257 u_int32_t njb3_send_firmware_chunk(njb_t *njb, u_int32_t chunksize, unsigned char *chunk);
00258 int njb3_get_firmware_confirmation(njb_t *njb);
00259 void njb3_destroy_state(njb_t *njb);
00260 
00261 #endif

Generated on Thu Oct 20 20:35:58 2005 for libnjb by  doxygen 1.4.4