Main Page | Namespace List | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

yepp.h

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * $Id: yepp.h,v 1.6 2005/05/25 18:58:46 cowo Exp $ 00003 ****************************************************************************/ 00004 /* 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00025 #ifndef _YEPP_H_ 00026 #define _YEPP_H_ 00027 00028 #ifdef _MSC_VER 00029 #if _MSC_VER <= 1300 00030 #error "Cannot compile with this version of M$C due to STL problems" 00031 #endif 00032 #endif //_MSC_VER 00033 00034 using namespace std; 00035 00036 #include <string> 00037 #include <vector> 00038 #include <list> 00039 #include <stack> 00040 #include <usb.h> 00041 00042 #include "exceptions.h" 00043 00045 #define USB_BLOCK_SIZE 0x40 00046 #define DEVICE_INFO_RESULT_SIZE (USB_BLOCK_SIZE + 80) 00047 00049 #define YEPP_FLASH 0x4D 00050 00051 #define YEPP_MEDIA 0x53 00052 00053 #define YEPP_BULKBUFFER 0x240 00054 00059 class yeppTitleFrame { 00060 private: 00062 char start_frame:4; 00064 char title_frame_no:4; 00066 vector<char> characters; 00067 public: 00069 yeppTitleFrame (const char *buffer); 00071 yeppTitleFrame (const yeppTitleFrame& source); 00073 yeppTitleFrame (); 00077 void getTitle (string& title); 00081 char *getTitle (void); 00083 friend ostream& operator<< (ostream& os, const yeppTitleFrame& f); 00084 }; 00085 00090 class yeppInfoFrame { 00091 private: 00093 char trackID[13]; 00095 int size; 00096 public: 00098 yeppInfoFrame (const char *buffer); 00100 yeppInfoFrame (const yeppInfoFrame& source); 00102 yeppInfoFrame (); 00104 int getSize (void) {return size;}; 00106 char* const getTrackID (void) {return trackID;}; 00108 friend ostream& operator<< (ostream& os, const yeppInfoFrame& f); 00109 }; 00110 00115 class yeppTrack { 00116 public: 00118 //~ vector<yeppTitleFrame> title_frames; 00119 list<yeppTitleFrame> title_frames; 00121 yeppInfoFrame info_frame; 00123 string title; 00124 00126 yeppTrack () {}; 00128 yeppTrack (const yeppTrack& source); 00136 int build (const char *buffer); 00137 int build_title (void); 00138 char* const getTrackID (void) {return info_frame.getTrackID();}; 00139 00141 friend ostream& operator<< (ostream& os, const yeppTrack& t); 00142 }; 00143 00148 class yeppPlaylist { 00149 public: 00151 vector<yeppTrack> tracks; 00153 yeppPlaylist () {}; 00155 yeppPlaylist (const yeppPlaylist& source); 00164 int build (char *buffer, int buflen); 00166 int build (char *filename); 00167 00180 int title_frame_no (char *buffer); 00182 friend ostream& operator<< (ostream& os, const yeppPlaylist& p); 00183 }; 00184 00188 class yepp { 00189 private: 00195 stack<string> error_stack; 00197 string device_info_string; 00199 int has_external_mem; 00201 int device_capacity; 00203 int device_space_available; 00205 int external_capacity; 00207 int external_space_available; 00209 char send_buffer[USB_BLOCK_SIZE*2]; 00211 char recv_buffer[USB_BLOCK_SIZE]; 00213 char bulk_buffer[YEPP_BULKBUFFER]; 00215 char control_buffer[USB_BLOCK_SIZE]; 00216 const unsigned int read_endpoint; 00217 const unsigned int write_endpoint; 00218 const unsigned char data_length; 00220 yeppPlaylist playlist; 00222 yeppPlaylist ext_playlist; 00223 00224 protected: 00226 struct usb_device *dev; 00228 struct usb_dev_handle *dev_handle; 00230 int usb_debug; 00232 int timeout; 00234 int retries; 00236 void last_error (string error); 00238 void last_error (const char *method, const char *format, ...); 00240 void clear_send_buffer (void); 00242 void clear_bulk_buffer (void); 00244 void clear_recv_buffer (void); 00246 void clear_control_buffer (void); 00248 void clear_buffers (void); 00250 void clear_halt (unsigned int endpoint) throw (YeppException, UsbException); 00255 void reset_ep (unsigned int endpoint) throw (YeppException, UsbException); 00264 int file_present (const char *filename, bool internal); 00270 void build_trackID (string& trackID, string filename); 00271 public: 00273 const int vendor; 00275 const int product; 00276 00278 yepp () : 00279 has_external_mem (-1), 00280 device_capacity (-1), 00281 device_space_available (-1), 00282 external_capacity (-1), 00283 external_space_available (-1), 00284 read_endpoint (0x82), 00285 write_endpoint (0x01), 00286 data_length (0x240), 00287 dev (NULL), 00288 dev_handle (NULL), 00289 #ifdef DEBUG 00290 usb_debug (4), 00291 #else 00292 usb_debug (0), 00293 #endif //DEBUG 00294 timeout (5000), 00295 retries (2), 00296 vendor (0x4E8), 00297 product (0x5A00) 00298 {}; 00302 ~yepp (); 00312 void init (struct usb_device *dev, int usb_debug = 0) throw(UsbException, YeppException); 00314 string last_error (); 00328 void control(int request, unsigned char lsb, unsigned char msb) throw (UsbException, YeppException); 00344 void recv(int request, unsigned char lsb, unsigned char msb, char *buffer, int size) throw (UsbException); 00361 void send(int request, unsigned char lsb, unsigned char msb, char *buffer, int size) throw (UsbException); 00362 00379 void move_track (bool internal, unsigned int from, unsigned int to) throw (YeppException, UsbException) ; 00388 void get_device_info (void) throw (UsbException, YeppException); 00393 void get_device_info (string& dev_info) throw (UsbException, YeppException); 00397 void get_playlist (void) throw (YeppException, UsbException); 00408 void get_playlist (bool internal) throw (YeppException, UsbException); 00412 void get_playlist (yeppPlaylist& internal, yeppPlaylist& external) throw (YeppException, UsbException); 00419 void get_external_mem_info (void) throw (YeppException, UsbException); 00427 void get_device_capacity (int& internal, int& int_avail, int& ext, int& ext_avail); 00438 void delete_track (unsigned int trackno, bool internal=true) throw (YeppException, UsbException); 00439 00456 void download (const char *filename, bool internal = true, void (*callback)(int, int) = NULL) throw (UsbException, YeppException); 00457 00463 void format (bool internal = true) throw (YeppException, UsbException); 00464 00479 void upload (unsigned int trackno, string filename = "", void (*callback)(int, int) = NULL) throw (YeppException, UsbException); 00480 00487 void reset_read_ep (void) throw(UsbException, YeppException); 00494 void reset_write_ep (void) throw(UsbException, YeppException); 00496 friend ostream& operator<< (ostream& os, yepp& u); 00497 }; 00498 00499 #endif // _YEPP_H_

Generated on Sun May 29 16:13:38 2005 for yex by doxygen 1.3.7