1 /**
2  *   (c) 2001-2006 Nathan Hjelm <hjelmn@users.sourceforge.net>
3  *   v1.5.0 rio.h
4  *
5  *   header file for librioutil
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU Library Public License as published by
9  *   the Free Software Foundation; either version 2 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU Library Public License
18  *   along with this program; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  **/
21 
22 #ifndef _RIO_H
23 #define _RIO_H
24 
25 #include <sys/types.h>
26 
27 /* errors */
28 #define URIO_SUCCESS 0
29 
30 enum rios { RIO600, RIO800, PSAPLAY, RIO900, RIOS10, RIOS50,
31 	    RIOS35, RIOS30, RIOFUSE, RIOCHIBA, RIOCALI,
32 	    RIORIOT, RIOS11, RIONITRUS, UNKNOWN };
33 
34 /* other defines */
35 #define MAX_MEM_UNITS   2   /* there are never more than 2 memory units */
36 #define MAX_RIO_FILES   3000 /* arbitrary */
37 
38 
39 /*
40   Playlist structure:
41 
42   first entry is always blank.
43   name is copied from rio_file->name
44   title is 32 characters from rio_file->title
45   unk[3] is an integer whose value is the entry number
46       (stored in little endian format)
47 
48   Note:librioutil does not handle creation of playlists.
49 */
50 typedef struct _rio_plst {
51     struct song_list {
52 	u_int8_t  name[64];
53 	u_int32_t unk[8];
54 	u_int8_t  title[32];
55     } playlist[128];
56 } rio_plst_t;
57 
58 /*
59   Use these for list_flags in function return_list_rio
60 */
61 #define RMP3 0x01
62 #define RWMA 0x02
63 #define RWAV 0x04
64 #define RDOW 0x08
65 #define RSYS 0x10
66 #define RLST 0x20
67 #define RALL 0x3f
68 
69 typedef struct _file_list {
70   char artist[64];
71   char title[64];
72   char album[64];
73   char name[64];
74 
75   int bitrate;
76   int samplerate;
77   int mod_date;
78   int size;
79   int time;
80 
81   /* pointer to start of file in rio's memory */
82   int start;
83 
84   enum file_type {MP3 = 0, WMA, WAV, WAVE, OTHER} type;
85 
86   int num;
87   int inum;
88 
89   struct _file_list *prev;
90   struct _file_list *next;
91 
92   u_int8_t sflags[3];
93   u_int32_t rio_num;
94 
95   char year[5];
96   char genre[17];
97 
98   int track_number;
99 } file_list;
100 
101 typedef file_list flist_rio_t;
102 
103 typedef struct _mem_list {
104     u_int32_t size;
105     u_int32_t free;
106     char name[32];
107 
108     flist_rio_t *files;
109 
110     u_int32_t total_time;
111     u_int32_t num_files;
112 } mem_list;
113 
114 typedef mem_list mlist_rio_t;
115 
116 typedef struct _rio_info {
117   mem_list memory[MAX_MEM_UNITS];
118 
119   /* these values can be changed an sent to the rio */
120   char name[16];
121 
122   u_int8_t  light_state;
123   u_int8_t  repeat_state;
124   u_int8_t  eq_state;
125   u_int8_t  bass;
126   u_int8_t  treble;
127   u_int8_t  sleep_time;
128   u_int8_t  contrast;
129   u_int8_t  playlist;
130   u_int8_t  volume;
131   u_int8_t  random_state;
132   u_int8_t  the_filter_state;
133 
134   /* these values can not be manipulated */
135   u_int8_t  total_memory_units; /* 1 or 2 */
136 
137   float firmware_version;
138   u_int8_t serial_number[16];
139 } rio_info_t;
140 
141 typedef struct _rios {
142   /* void here to avoid the user needing to define WITH_USBDEVFS and such */
143   void *dev;
144 
145   rio_info_t info;
146 
147   int debug;
148   void *log;
149   int abort;
150 
151   unsigned char cmd_buffer[16];
152   unsigned char buffer    [64];
153 
154   void (*progress)(int x, int X, void *ptr);
155   void *progress_ptr;
156 
157   /* make rioutil thread-safe */
158   int lock;
159 } rios_t;
160 
161 typedef rios_t rio_instance_t;
162 
163 /*
164   rio funtions:
165 */
166 int open_rio (rios_t *rio, int number, int debug, int fill_structures);
167 void close_rio (rios_t *rio);
168 
169 int set_info_rio (rios_t *rio, rio_info_t *info);
170 int add_song_rio (rios_t *rio, u_int8_t memory_unit, char *file_name, char *artist, char *title, char *album);
171 int download_file_rio (rios_t *rio, u_int8_t memory_unit, u_int32_t fileno, char *fileName);
172 int upload_from_pipe_rio (rios_t *rio, u_int8_t memory_unit, int addpipe, char *name, char *artist,
173 			  char *album, char *title, int mp3, int bitrate, int samplerate);
174 int delete_file_rio (rios_t *rio, u_int8_t memory_unit, u_int32_t fileno);
175 int format_mem_rio (rios_t *rio, u_int8_t memory_unit);
176 
177 /* upgrade the rio's firmware from a file */
178 int firmware_upgrade_rio (rios_t *rio, char *file_name);
179 
180 /* update the rio structure's internal info structure */
181 int update_info_rio (rios_t *rio);
182 /* store a copy of the rio's internal info structure in info */
183 int get_info_rio (rios_t *rio, rio_info_t **info);
184 
185 /* sets the progress callback function */
186 void set_progress_rio  (rios_t *rio, void (*f)(int x, int X, void *ptr), void *ptr);
187 
188 /* These only work with S-Series or newer Rios */
189 int create_playlist_rio (rios_t *rio, char *name, int songs[], int memory_units[], int nsongs);
190 int overwrite_file_rio (rios_t *rio, u_int8_t memory_unit, u_int32_t fileno, char *filename);
191 int return_serial_number_rio (rios_t *rio, u_int8_t serial_number[16]);
192 
193 
194 /* Added to API 02-02-2005 */
195 /* Returns the file number that will be assigned to the next file uploaded. */
196 int first_free_file_rio (rios_t *rio, u_int8_t memory_unit);
197 
198 /* library info */
199 char          *return_conn_method_rio(void);
200 
201 /*
202   retrieve information on the rio's memory units
203 
204   memory_unit is an integer between 0 and MAX_MEM_UNITS - 1
205 */
206 int return_mem_units_rio (rios_t *rio);
207 int return_free_mem_rio (rios_t *rio, u_int8_t memory_unit);
208 int return_used_mem_rio (rios_t *rio, u_int8_t memory_unit);
209 int return_total_mem_rio (rios_t *rio, u_int8_t memory_unit);
210 int return_num_files_rio (rios_t *rio, u_int8_t memory_unit);
211 int return_time_rio (rios_t *rio, u_int8_t memory_unit);
212 
213 /* store a copy of the rio's file list in flist */
214 int return_flist_rio (rios_t *rio, u_int8_t memory_unit, u_int8_t list_flags, flist_rio_t **flist);
215 
216 void free_flist_rio (flist_rio_t *flist);
217 
218 char *return_file_name_rio (rios_t *rio, u_int32_t song_id, u_int8_t memory_unit);
219 int return_file_size_rio (rios_t *rio, u_int32_t song_id, u_int8_t memory_unit);
220 int return_type_rio (rios_t *rio);
221 
222 #endif /* _RIO_H */
223