# protocol.h

    00001 #ifndef __NJB__PROTO__H
    00002 #define __NJB__PROTO__H
    00003
    00004 #include "libnjb.h"
    00005
    00006 typedef struct {
    00007         unsigned char id[16];
    00008         u_int64_t count;
    00009 } njblibctr_t;
    00010
    00011 typedef struct {
    00012         u_int32_t trackid;
    00013         u_int32_t size;
    00014 } njbttaghdr_t;
    00015
    00016 typedef struct {
    00017         u_int32_t plid;
    00018         u_int32_t size;
    00019 } njbplhdr_t;
    00020
    00021 typedef struct {
    00022         u_int32_t dfid;
    00023         u_int32_t size;
    00024 } njbdfhdr_t;
    00025
    00026
    00027 /* Structure to hold protocol states */
    00028 typedef struct {
    00029   int session_updated;
    00030   u_int64_t libcount;
    00031   njb_eax_t *first_eax;
    00032   njb_eax_t *next_eax;
    00033   int reset_get_track_tag;
    00034   int reset_get_playlist;
    00035   int reset_get_datafile_tag;
    00037   u_int8_t power;
    00039   u_int8_t sdmiid[16];
    00041   char productName[33];
    00042   u_int8_t fwMajor;
    00043   u_int8_t fwMinor;
    00044 } njb_state_t;
    00045
    00046 /*
    00047  * These defines are only applicable to the NJB1.
    00048  */
    00049 #define NJB_POWER_BATTERY       0x00
    00050 #define NJB_POWER_AC_CHARGED    0x01
    00052 #define NJB_POWER_AC_CHARGING   0x03
    00055 #define NJB_XFER_BLOCK_SIZE             0x0000FE00
    00056 #define NJB_XFER_BLOCK_HEADER_SIZE      68
    00057
    00058 #define NJB_RELEASE     0x00
    00059 #define NJB_CAPTURE     0x01
    00060
    00061 #define NJB_CMD_PING                            0x01
    00062 #define NJB_CMD_GET_DISK_USAGE                  0x04
    00063 #define NJB_CMD_GET_FIRST_TRACK_TAG_HEADER      0x06
    00064 #define NJB_CMD_GET_NEXT_TRACK_TAG_HEADER       0x07
    00065 #define NJB_CMD_GET_TRACK_TAG                   0x09
    00066 #define NJB_CMD_SEND_TRACK_TAG                  0x0a
    00067 #define NJB_CMD_DELETE_TRACK                    0x0b
    00068 #define NJB_CMD_REPLACE_TRACK_TAG               0x0c
    00069 #define NJB_CMD_REQUEST_TRACK                   0x0d
    00070 #define NJB_CMD_TRANSFER_COMPLETE               0x0e
    00071 #define NJB_CMD_SEND_FILE_BLOCK                 0x0f
    00072 #define NJB_CMD_RECEIVE_FILE_BLOCK              0x10
    00073 #define NJB_CMD_GET_FIRST_PLAYLIST_HEADER       0x11
    00074 #define NJB_CMD_GET_NEXT_PLAYLIST_HEADER        0x12
    00075 #define NJB_CMD_GET_PLAYLIST                    0x14
    00076 #define NJB_CMD_CREATE_PLAYLIST                 0x15
    00077 #define NJB_CMD_DELETE_PLAYLIST                 0x16
    00078 #define NJB_CMD_ADD_TRACK_TO_PLAYLIST           0x17
    00079 #define NJB_CMD_QUEUE_TRACK                     0x1b
    00080 #define NJB_CMD_PLAY_TRACK                      0x1d
    00081 #define NJB_CMD_STOP_PLAY                       0x1e
    00082 #define NJB_CMD_ELAPSED_TIME                    0x22
    00083 #define NJB_CMD_ADJUST_SOUND                    0x23
    00084 #define NJB_CMD_GET_TIME                        0x29
    00085 #define NJB_CMD_SET_TIME                        0x2a
    00086 #define NJB_CMD_CAPTURE_NJB                     0x2b
    00087 #define NJB_CMD_RELEASE_NJB                     0x2c
    00088 #define NJB_CMD_GET_EAX_SIZE                    0x3a
    00089 #define NJB_CMD_GET_EAX                         0x24
    00090 #define NJB_CMD_RENAME_PLAYLIST                 0x40
    00091 #define NJB_CMD_SET_OWNER_STRING                0x41
    00092 #define NJB_CMD_GET_OWNER_STRING                0x42
    00093 #define NJB_CMD_GET_LIBRARY_COUNTER             0x43
    00094 #define NJB_CMD_SET_LIBRARY_COUNTER             0x44
    00095 #define NJB_CMD_ADD_MULTIPLE_TRACKS_TO_PLAYLIST 0x46
    00096 #define NJB_CMD_SEND_DATAFILE_TAG               0x48
    00097 #define NJB_CMD_DELETE_DATAFILE                 0x49
    00098 #define NJB_CMD_GET_FIRST_DATAFILE_HEADER       0x4a
    00099 #define NJB_CMD_GET_NEXT_DATAFILE_HEADER        0x4b
    00100 #define NJB_CMD_GET_DATAFILE_TAG                0x4d
    00101 #define NJB_CMD_VERIFY_LAST_CMD                 0xf0
    00102 #define NJB_CMD_CAPTURE_NJB3                    0xfd
    00103 #define NJB_CMD_RELEASE_NJB3                    0xfe
    00104 #define NJB_CMD_UNKNOWN_NJB3                    0xff
    00105
    00106 #define NJB_VAL_GET_EAX                         0x00
    00107 #define NJB_VAL_GET_EAX_UNKNOWN                 0x01
    00108
    00109 #define NJB_SOUND_SET_VOLUME                    0x01
    00110 #define NJB_SOUND_SET_BASS                      0x02
    00111 #define NJB_SOUND_SET_TREBLE                    0x03
    00112 #define NJB_SOUND_SET_MUTING                    0x04
    00113 #define NJB_SOUND_SET_MIDRANGE                  0x05
    00114 #define NJB_SOUND_SET_MIDFREQ                   0x06
    00115 #define NJB_SOUND_SET_EAX                       0x07
    00116 #define NJB_SOUND_SET_EAXAMT                    0x08
    00117 #define NJB_SOUND_SET_HEADPHONE                 0x09
    00118 #define NJB_SOUND_SET_REAR                      0x0A
    00119 #define NJB_SOUND_SET_EQSTATUS                  0x0D
    00120
    00121 #define NJB_MSG_OKAY                            0x00
    00122 #define NJB_ERR_FAILED                          0x01
    00123 #define NJB_ERR_DEVICE_BUSY                     0x02
    00124 #define NJB_ERR_STORAGE_FULL                    0x03
    00125 #define NJB_ERR_HD_GENERAL_ERROR                0x04
    00126 #define NJB_ERR_SETTIME_REJECTED                0x05
    00127
    00128 #define NJB_ERR_TRACK_NOT_FOUND                 0x10
    00129 #define NJB_ERR_TRACK_EXISTS                    0x11
    00130 #define NJB_ERR_TITLE_MISSING                   0x12
    00131 #define NJB_ERR_CODEC_MISSING                   0x13
    00132 #define NJB_ERR_SIZE_MISSING                    0x14
    00133 #define NJB_ERR_IO_OPERATION_ABORTED            0x15
    00134 #define NJB_ERR_READ_WRITE_ERROR                0x16
    00135 #define NJB_ERR_NOT_OPENED                      0x17
    00136 #define NJB_ERR_UPLOAD_DENIED                   0x18
    00137
    00138 #define NJB_ERR_PLAYLIST_NOT_FOUND              0x20
    00139 #define NJB_ERR_PLAYLIST_EXISTS                 0x21
    00140 #define NJB_ERR_PLAYLIST_ITEM_NOT_FOUND         0x22
    00141 #define NJB_ERR_PLAYLIST_ITEM_EXISTS            0x23
    00142
    00143 #define NJB_MSG_QUEUED_AUDIO_STARTED            0x30
    00144 #define NJB_MSG_PLAYER_FINISHED                 0x31
    00145
    00146 #define NJB_ERR_QUEUE_ALREADY_EMPTY             0x40
    00147 #define NJB_ERR_VOLUME_CONTROL_UNAVAILABLE      0x42
    00148
    00149 #define NJB_ERR_DATA_NOT_FOUND                  0x60
    00150 #define NJB_ERR_DATA_NOT_OPENED                 0x67
    00151
    00152 #define NJB_ERR_PLAYER_NOT_CONNECTED            0x80
    00153 #define NJB_ERR_CANCELLED                       0x81
    00154 #define NJB_ERR_PORT_NOT_AVAILABLE              0x82
    00155 #define NJB_ERR_OUT_OF_MEMORY                   0x83
    00156 #define NJB_ERR_FILEOPEN_ERR                    0x84
    00157 #define NJB_ERR_ITEM_NOT_FOUND                  0x85
    00158 #define NJB_ERR_LOAD_COMPONENTS_FAILED          0x86
    00159 #define NJB_ERR_ID_INVALID                      0x87
    00160 #define NJB_ERR_FILETYPE_ILLEGAL                0x88
    00161 #define NJB_ERR_LOADRES_FAIL                    0x89
    00162 #define NJB_ERR_FORMAT_NOT_FOUND                0x8a
    00163 #define NJB_ERR_FILE_ALREADY_EXISTS             0x8b
    00164 #define NJB_ERR_LIB_CORRUPTED                   0x8c
    00165 #define NJB_ERR_LIB_BUSY                        0x8d
    00166 #define NJB_ERR_FILE_READ_WRITE_FAILED          0x8e
    00167 #define NJB_ERR_INVALID_FILEPATH                0x8f
    00168 #define NJB_ERR_DISKFULL_FOR_DOWNLOAD           0x90
    00169 #define NJB_ERR_FILE_PLAYONLY                   0x91
    00170
    00171 #define NJB_ERR_UNDEFINED_ERR                   0xff
    00172 #define NJB_ERR_NOT_IMPLEMENTED                 0x100
    00173
    00174 /* NJB1 functions */
    00175
    00176 int njb_init_state (njb_t *njb);
    00177
    00178 int njb_get_library_counter (njb_t *njb, njblibctr_t *njbctr);
    00179 int njb_set_library_counter (njb_t *njb, u_int64_t count);
    00180 int njb_ping (njb_t *njb);
    00181 int njb_verify_last_command (njb_t *njb);
    00182 int njb_capture (njb_t *njb, int which);
    00183 int njb_reset_get_songlist (njb_t *njb);
    00184 int njb_get_disk_usage (njb_t *njb, u_int64_t *total, u_int64_t *free);
    00185 int njb_get_owner_string (njb_t *njb, owner_string name);
    00186 int njb_set_owner_string (njb_t *njb, owner_string name);
    00187 int njb_request_file (njb_t *njb, u_int32_t fileid);
    00188 int njb_transfer_complete (njb_t *njb);
    00189 int njb_send_track_tag (njb_t *njb, njbttaghdr_t *tagh, void *tag);
    00190 int njb_send_datafile_tag (njb_t *njb, njbdfhdr_t *dfh, void *tag);
    00191 int njb_replace_track_tag (njb_t *njb, njbttaghdr_t *tagh, void *tag);
    00192 int njb_add_track_to_playlist (njb_t *njb, u_int32_t plid, u_int32_t trid);
    00193 int njb_add_multiple_tracks_to_playlist (njb_t *njb, u_int32_t plid,
    00194         u_int32_t *trids, u_int16_t ntracks);
    00195 int njb_delete_track (njb_t *njb, u_int32_t trackid);
    00196 int njb_delete_datafile (njb_t *njb, u_int32_t fileid);
    00197
    00198 int njb_create_playlist (njb_t *njb, char *name, u_int32_t *plid);
    00199 int njb_delete_playlist (njb_t *njb, u_int32_t plid);
    00200 int njb_rename_playlist (njb_t *njb, u_int32_t plid, char *name);
    00201
    00202 int njb_get_eax_size (njb_t *njb, u_int32_t *size);
    00203 void njb_read_eaxtypes (njb_t *njb, u_int32_t size);
    00204 njb_eax_t *njb_get_nexteax(njb_t *njb);
    00205
    00206 njb_time_t *njb_get_time(njb_t *njb);
    00207 int njb_set_time(njb_t *njb, njb_time_t *time);
    00208
    00209 u_int32_t njb_send_file_block (njb_t *njb, void *data, u_int32_t blocksize);
    00210 u_int32_t njb_receive_file_block (njb_t *njb, u_int32_t offset, u_int32_t blocksize,
    00211                                   void *block);
    00212 int njb_get_track_tag_header (njb_t *njb, njbttaghdr_t *tagh, int cmd);
    00213 #define njb_get_first_track_tag_header(a,b) njb_get_track_tag_header(a,b,NJB_CMD_GET_FIRST_TRACK_TAG_HEADER)
    00214 #define njb_get_next_track_tag_header(a,b) njb_get_track_tag_header(a,b,NJB_CMD_GET_NEXT_TRACK_TAG_HEADER)
    00215 njb_songid_t *njb_get_track_tag (njb_t *njb, njbttaghdr_t *tagh);
    00216
    00217 int njb_get_playlist_header(njb_t *njb, njbplhdr_t *plh, int cmd);
    00218 #define njb_get_first_playlist_header(a,b) njb_get_playlist_header(a,b,NJB_CMD_GET_FIRST_PLAYLIST_HEADER)
    00219 #define njb_get_next_playlist_header(a,b) njb_get_playlist_header(a,b,NJB_CMD_GET_NEXT_PLAYLIST_HEADER)
    00220 njb_playlist_t *njb_get_playlist (njb_t *njb, njbplhdr_t *plh);
    00221
    00222 int njb_get_datafile_header (njb_t *njb, njbdfhdr_t *dfh, int cmd);
    00223 #define njb_get_first_datafile_header(a,b) njb_get_datafile_header(a,b,NJB_CMD_GET_FIRST_DATAFILE_HEADER);
    00224 #define njb_get_next_datafile_header(a,b) njb_get_datafile_header(a,b,NJB_CMD_GET_NEXT_DATAFILE_HEADER);
    00225 njb_datafile_t *njb_get_datafile_tag (njb_t *njb, njbdfhdr_t *dfh);
    00226
    00227 #define njb_play_track(a,b) njb_play_or_queue(a,b,NJB_CMD_PLAY_TRACK)
    00228 #define njb_queue_track(a,b) njb_play_or_queue(a,b,NJB_CMD_QUEUE_TRACK)
    00229 int njb_play_or_queue (njb_t *njb, u_int32_t trackid, int cmd);
    00230 int njb_stop_play (njb_t *njb);
    00231 int njb_elapsed_time (njb_t *njb, u_int16_t *elapsed, int *change);
    00232 int njb_adjust_sound(njb_t *njb, u_int8_t effect, int16_t value);
    00233
    00234 #endif
    00235