libnjb  2.2.7
Functions | Variables
protocol3.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include "libnjb.h"
#include "protocol.h"
#include "protocol3.h"
#include "unicode.h"
#include "byteorder.h"
#include "njb_error.h"
#include "usb_io.h"
#include "ioutil.h"
#include "defs.h"
#include "base.h"
#include "eax.h"
#include "datafile.h"
#include "njbtime.h"

Functions

int njb3_init_state (njb_t *njb)
 
int njb3_capture (njb_t *njb)
 
int njb3_release (njb_t *njb)
 
int njb3_get_codecs (njb_t *njb)
 
int njb3_ping (njb_t *njb, int type)
 
int njb3_power_status (njb_t *njb, int *battery_level, int *charging, int *ac_power)
 
int njb3_readid (njb_t *njb, u_int8_t *sdmiid)
 
int njb3_get_disk_usage (njb_t *njb, u_int64_t *totalbytes, u_int64_t *freebytes)
 
int njb3_turnoff_flashing (njb_t *njb)
 
int njb3_get_owner_string (njb_t *njb, char *name)
 
int njb3_set_owner_string (njb_t *njb, const char *name)
 
njb_time_tnjb3_get_time (njb_t *njb)
 
int njb3_set_bitmap (njb_t *njb, u_int16_t x_size, u_int16_t y_size, const unsigned char *bitmap)
 
int njb3_current_track (njb_t *njb, u_int16_t *position)
 
int njb3_elapsed_time (njb_t *njb, u_int16_t *elapsed, int *change)
 
int njb3_queue_track (njb_t *njb, u_int32_t trackid)
 
int njb3_play_track (njb_t *njb, u_int32_t trackid)
 
int njb3_seek_track (njb_t *njb, u_int32_t pos)
 
int njb3_clear_play_queue (njb_t *njb)
 
int njb3_ctrl_playing (njb_t *njb, int cmd)
 
int njb3_set_time (njb_t *njb, njb_time_t *time)
 
int njb3_reset_get_track_tag (njb_t *njb)
 
njb_songid_tnjb3_get_next_track_tag (njb_t *njb)
 
int njb3_reset_get_playlist_tag (njb_t *njb)
 
njb_playlist_tnjb3_get_next_playlist_tag (njb_t *njb)
 
int njb3_reset_get_datafile_tag (njb_t *njb)
 
njb_datafile_tnjb3_get_next_datafile_tag (njb_t *njb)
 
njb_keyval_tnjb3_get_keys (njb_t *njb)
 
int njb3_read_keys (njb_t *njb)
 
int njb3_request_file_chunk (njb_t *njb, u_int32_t fileid, u_int32_t offset)
 
int njb3_get_file_block (njb_t *njb, unsigned char *data, u_int32_t maxsize)
 
u_int32_t njb3_create_file (njb_t *njb, unsigned char *ptag, u_int32_t tagsize, u_int16_t database)
 
u_int32_t njb3_send_file_chunk (njb_t *njb, unsigned char *chunk, u_int32_t chunksize, u_int32_t fileid)
 
int njb3_send_file_complete (njb_t *njb, u_int32_t fileid)
 
int njb3_create_folder (njb_t *njb, const char *name, u_int32_t *folderid)
 
int njb3_delete_item (njb_t *njb, u_int32_t itemid)
 
int njb3_update_16bit_frame (njb_t *njb, u_int32_t itemid, u_int16_t frameid, u_int16_t value)
 
int njb3_update_string_frame (njb_t *njb, u_int32_t itemid, u_int16_t frameid, unsigned char *str)
 
int njb3_update_tag (njb_t *njb, u_int32_t itemid, unsigned char *ptag, u_int32_t ptagsize)
 
int njb3_create_playlist (njb_t *njb, char *name, u_int32_t *plid)
 
int njb3_add_multiple_tracks_to_playlist (njb_t *njb, u_int32_t *plid, u_int32_t *trids, u_int16_t ntracks)
 
int njb3_control_eax_processor (njb_t *njb, u_int16_t state)
 
int njb3_adjust_eax (njb_t *njb, u_int16_t eaxid, u_int16_t patchindex, u_int16_t active, u_int16_t scalevalue)
 
void njb3_read_eaxtypes (njb_t *njb)
 
njb_eax_tnjb3_get_nexteax (njb_t *njb)
 
int njb3_announce_firmware (njb_t *njb, u_int32_t size)
 
u_int32_t njb3_send_firmware_chunk (njb_t *njb, u_int32_t chunksize, unsigned char *chunk)
 
int njb3_get_firmware_confirmation (njb_t *njb)
 
void njb3_destroy_state (njb_t *njb)
 

Variables

int __sub_depth
 

Detailed Description

This file contains the protocol code for the series 3 devices. This protocol is believed to have the internal name "PDE" at Creative.

Function Documentation

◆ njb3_add_multiple_tracks_to_playlist()

int njb3_add_multiple_tracks_to_playlist ( njb_t njb,
u_int32_t *  plid,
u_int32_t *  trids,
u_int16_t  ntracks 
)

This takes an array of 32-bit track ID:s and adds it to a certain playlist.

Parameters
plida pointer to the ID of the playlist to add tracks to. The ID will change during this operation, so it is important to pass in a pointer.
tridsan array of tracks to add
ntracksabsolute number of tracks in the array.

References EO_NOMEM, from_16bit_to_njb3_bytes(), and from_32bit_to_njb3_bytes().

◆ njb3_announce_firmware()

int njb3_announce_firmware ( njb_t njb,
u_int32_t  size 
)

This announces a firmware image which will then be sent in several chunks.

Parameters
njba pointer to the njb device object to use
sizethe total size of the firmware image
Returns
0 on success, -1 on failure

References from_32bit_to_njb3_bytes().

Referenced by NJB_Send_Firmware().

◆ njb3_control_eax_processor()

int njb3_control_eax_processor ( njb_t njb,
u_int16_t  state 
)

This command turns the EAX DSP processor on or off. You will also have to adjust the currently used EAX effect with njb3_adjust_eax() below.

References from_16bit_to_njb3_bytes().

◆ njb3_create_playlist()

int njb3_create_playlist ( njb_t njb,
char *  name,
u_int32_t *  plid 
)

This function creates a new playlist on the device.

Parameters
namethe name of the playlist to create, as a string.
plida pointer to a 32-bit numer that will contain the new playlist ID after this routine has been called.
Returns
0 on success, -1 on failure.

References EO_NOMEM, from_16bit_to_njb3_bytes(), and ucs2strlen().

◆ njb3_destroy_state()

void njb3_destroy_state ( njb_t njb)

Cleans up any dangling lists in the njb_t state holder struct, and other stuff related to the state.

References njb_keyval_struct::next, and njb_struct::protocol_state.

◆ njb3_get_codecs()

int njb3_get_codecs ( njb_t njb)

Reads the supported audio file types.

◆ njb3_get_file_block()

int njb3_get_file_block ( njb_t njb,
unsigned char *  data,
u_int32_t  maxsize 
)

This function retrieves a part of the requested chunk. Short reads are allowed, so the caller must make sure that it is called as many times as is needed to retrieve the entire file chunk.

Parameters
dataan allocated byte array to store the retrieved chunk in.
maxsizethe maximum number of bytes to retrieve from this chunk at a time.

References EO_USBBLK, and usb_pipe_read().

◆ njb3_get_firmware_confirmation()

int njb3_get_firmware_confirmation ( njb_t njb)

This simply reads back the device status after a firmware upgrade.

◆ njb3_init_state()

int njb3_init_state ( njb_t njb)

◆ njb3_power_status()

int njb3_power_status ( njb_t njb,
int *  battery_level,
int *  charging,
int *  ac_power 
)

This function reads out the current battery level and charging status from a series 3 device.

Parameters
battery_levela variable that will hold the current level after the call.
chargingif the battery is charging, this variable will hold 1 after the call, else 0.
ac_powerif the charger is connected, this variable will hold 1 after the call, else 0.
Returns
0 on success, -1 on failure. If the call fails, all other return values are invalid.

Referenced by NJB_Get_Auxpower(), NJB_Get_Battery_Charging(), and NJB_Get_Battery_Level().

◆ njb3_request_file_chunk()

int njb3_request_file_chunk ( njb_t njb,
u_int32_t  fileid,
u_int32_t  offset 
)

This function requests a chunk from a certain file. The offset may index into the file. The chunk transfer size is 1MB by default (as used by creative) but may actually exceed that.

Returns actual chunk size or -1 if failed.

References from_32bit_to_njb3_bytes().

◆ njb3_reset_get_datafile_tag()

int njb3_reset_get_datafile_tag ( njb_t njb)

This routine retrieves the list of datafiles, and returns the first item.

References njb_struct::protocol_state.

Referenced by NJB_Reset_Get_Datafile_Tag().

◆ njb3_reset_get_playlist_tag()

int njb3_reset_get_playlist_tag ( njb_t njb)

This routine retrieves the list of playlists, while also filling in each playlist post with it's respective track ID:s.

References njb_struct::protocol_state.

Referenced by NJB_Reset_Get_Playlist().

◆ njb3_send_firmware_chunk()

u_int32_t njb3_send_firmware_chunk ( njb_t njb,
u_int32_t  chunksize,
unsigned char *  chunk 
)

This sends a chunk of firmware. Typically the chunks are NJB3_FIRMWARE_CHUNK_SIZE each, except for the last chunk.

Parameters
njba pointer to the njb device object to use
chunksizethe size of this chunk
chunka pointer to the raw bytes representing this firmware chunk
Returns
0 on success, -1 on failure

◆ njb3_set_bitmap()

int njb3_set_bitmap ( njb_t njb,
u_int16_t  x_size,
u_int16_t  y_size,
const unsigned char *  bitmap 
)

NJB2 only (shall be expanded for all jukeboxes). Set up the black/white bitmap shown on shutdown.

The bitmap must be exactly 1088 bytes large, coded as a serial bitmap of 136x64 pixels. The final 4 bits per line are not shown, because the the display of the NJB2 has only 132x64 pixels.

A set pixel (1) means dark, an unset means white.

To create a compatible bitmap, take a 132x64 PBM file (of course not a ASCII-coded, but a binary "P4") and cut off the header.

Explaination of the JBM1 file format:

Byte offset:     Contents:
0x00 - 0x03      "JBM1"
0x04 - 0x05      width of bitmap in pixels 16bit
                 unsigned bigendian integer
0x06 - 0x07      height of bitmap in pixels 16bit
                 unsigned bigendian integer
0x08 - 0x0b      file format version? contains 0x00000001
                 as a 32bit unsigned bigendian integer
0x0c - fileend   actual bitmap data

The bitmap data is black-and-white and each bit represents a single pixel. A set pixel is 1 and a cleared pixel is 0. The bitmap is stored in 16bit unsigned integers which are little-endian, and each of these 16bit integers form a vertical, eight-pixel high and two-pixel wide "bar".

References EO_NOMEM, from_16bit_to_njb3_bytes(), and from_32bit_to_njb3_bytes().

Referenced by NJB_Set_Bitmap().

◆ njb3_update_16bit_frame()

int njb3_update_16bit_frame ( njb_t njb,
u_int32_t  itemid,
u_int16_t  frameid,
u_int16_t  value 
)

This function will update a single 16bit metadata frame associated with a certain item (track, playlist or datafile). Only call this function to modify 16-bit values!

Parameters
itemidthe item ID (track, playlist or datafile) to modify.
frameidthe frame ID of the frame to modyfy. Must be a 16-bit frame.
valudthe new 16-bit value.

References from_16bit_to_njb3_bytes(), and from_32bit_to_njb3_bytes().

◆ njb3_update_string_frame()

int njb3_update_string_frame ( njb_t njb,
u_int32_t  itemid,
u_int16_t  frameid,
unsigned char *  str 
)

This function updates a single string of metadata associated with a certain item (track, playlist or datafile). Only call this routine to modify string frames!

Parameters
itemidthe item ID (track, playlist or datafile) to be modified.
frameidthe frame ID of the frame to be updated.
strthe new string value.

References EO_NOMEM, from_16bit_to_njb3_bytes(), from_32bit_to_njb3_bytes(), and ucs2strlen().

◆ njb3_update_tag()

int njb3_update_tag ( njb_t njb,
u_int32_t  itemid,
unsigned char *  ptag,
u_int32_t  ptagsize 
)

A function to update a block of metadata on the series 3 devices.

Parameters
itemidthe track (or similar) whose metadata is to be updated.
ptaga packed metadata structure for series 3 devices.
Returns
0 on success, -1 on failure.

References EO_NOMEM, and from_32bit_to_njb3_bytes().

Referenced by NJB_Replace_Track_Tag().

Variable Documentation

◆ __sub_depth

int __sub_depth
extern

The current subroutine depth for all of libnjb (global)