00001 #ifndef FVTX_CONNECTION_H
00002 #define FVTX_CONNECTION_H
00003
00004
00005
00006 #include <stdio.h>
00007 #include <vector>
00008 #include <ftplib.h>
00009
00011 typedef unsigned char byte;
00012
00014 typedef struct fvtx_element
00015 {
00016 byte wedge_add;
00017 byte fem_add;
00018 byte chipid;
00019 byte regid;
00020 }fvtx_el;
00021
00023 typedef std::vector<byte> Packet;
00024
00025 const byte wild_chipId = 21;
00026 const byte wild_reg = 21;
00027 const byte fem_default = 15;
00028
00030 class fvtx_connection
00031 {
00032 public:
00036 fvtx_connection(std::string server, std::string thiscrate="SW");
00037
00039 ~fvtx_connection();
00040
00042 bool get_is_connected()
00043 {
00044 #ifndef NOCONNECTION
00045 return is_connected;
00046 #endif
00047 #ifdef NOCONNECTION
00048 return true;
00049 #endif
00050 }
00051
00055 void set_verbose(size_t a) {FPHXTB_VERBOSE = a;}
00056
00063 bool write_enable_ro(fvtx_el element, byte initialval);
00064
00071 bool write_disable_ro(fvtx_el element, byte initialval);
00072
00078 bool write_pulse_amp(int amp, fvtx_el element);
00079
00085 bool write_pulse_module(int module, fvtx_el element);
00086
00093 bool write_pulse_config(int num, int deltabco, fvtx_el element);
00094
00099 bool write_pulse(fvtx_el element);
00100
00108 bool write_pulse_train(int num, int deltabco, byte amp, fvtx_el element);
00109
00114 bool write_latch(fvtx_el element);
00115
00120 bool write_fo_sync(fvtx_el element);
00121
00126 bool write_fpga_reset(fvtx_el element);
00127
00133 bool write_fem_lvl1_delay(byte delay, fvtx_el element);
00134
00139 bool write_bco_start(fvtx_el element);
00140
00145 bool write_batch_download(fvtx_el element);
00146
00151 bool write_eeprom_write(fvtx_el element);
00152
00157 bool write_page(fvtx_el element, byte row, byte col, byte side);
00158
00164 bool write_page_version(int version, fvtx_el element, byte row, byte col, byte side);
00165
00171 bool write_page_run(int runnumber, fvtx_el element, byte row, byte col, byte side);
00172
00178 bool write_page_time(std::string time, fvtx_el element, byte row, byte col, byte side);
00179
00181 bool test_write();
00182
00184 bool write_initpages_eeprom();
00185
00187 bool read_page(fvtx_el element, byte row, byte col, byte side);
00188
00190 bool read_page2(fvtx_el element, byte row, byte col, byte side);
00191
00193 bool we_eeprom(byte femaddr);
00194
00196 bool wd_eeprom(byte femaddr);
00197
00199 bool erase_eeprom(byte femaddr);
00200
00206 bool unmask_chan_fphx(byte chan, fvtx_el element);
00207
00212 bool unmask_all_fphx( fvtx_el element);
00213
00219 bool mask_chan_fphx(byte chan, fvtx_el element);
00220
00225 bool mask_all_fphx(fvtx_el element);
00226
00227
00236 bool set_threshold(size_t fem, size_t wedge, size_t chipid, size_t dac, size_t threshold);
00237
00245 bool set_threshold_all_chips(size_t fem, size_t wedge, size_t dac, size_t threshold);
00246
00251 bool reset_fphx(fvtx_el element, byte cmd=TESTBENCH_RESET);
00252
00257 bool clear_hits_fphx(fvtx_el element);
00258
00263 bool clear_bco_fphx(fvtx_el element);
00264
00269 bool calib_fphx(fvtx_el element);
00270
00271 bool send_pulse(byte amp, byte wedge, byte fem);
00272 bool send_enable_ro(byte val, byte chipid, byte wedge, byte fem);
00273 bool send_disable_ro(byte val, byte chipid, byte wedge, byte fem);
00274 bool send_core_reset(byte chipid, byte wedge, byte fem);
00275 bool send_bco_reset(byte chipid, byte wedge, byte fem);
00276
00277 bool send_lvl1_delay(byte delay);
00278
00279 bool send_fpga_reset();
00280
00281 bool send_fo_sync();
00282
00283 bool send_reset_fphx();
00284
00285 bool send_latch();
00286
00287 bool send_bco_start();
00288
00293 int start_run();
00294
00296 bool send_calib();
00297
00299 bool download();
00300
00304 int is_busy();
00305
00311 bool test_command(byte command, int data);
00312
00314 int last_fphx_command() {return (int)last_fphx_cmd;}
00315
00317 int last_fem() {return (int)last_element.fem_add;}
00318
00320 int last_wedge() {return (int)last_element.wedge_add;}
00321
00323 int last_chipid() {return (int)last_element.chipid;}
00324
00325 protected:
00326 size_t FPHXTB_VERBOSE;
00327 std::string ThisName;
00328 #ifndef NOCONNECTION
00329 ftplib *ftp;
00330 bool is_connected;
00331 #endif
00332
00339 void create_packet(Packet& packet, byte command, fvtx_el element, int pkt_data);
00340
00347 void create_packet(Packet& packet, byte command, fvtx_el element, Packet pkt_data);
00348
00355 int make_fphx_cmd(fvtx_el element, byte cmd, int data);
00356
00363 void create_packet_fphx(Packet& packet, fvtx_el element, int fphx_data);
00364
00370 byte checksum(byte* data, size_t data_length);
00371
00376 bool write_bytes_to_target(Packet packet);
00377
00383 bool prog_reset_fphx(byte cmd, fvtx_el element);
00384
00391 bool write_packet(int packet_data, byte cmd, fvtx_el element);
00392
00399 bool write_packet(Packet packet_data, byte cmd, fvtx_el element);
00400
00406 bool write_fphx(byte fphx_data, byte fphx_cmd, fvtx_el element);
00407
00408 bool write_ro(fvtx_el element, byte initialval);
00409
00414 void push_int_packet(int val, Packet& packet);
00415
00416 std::string ThisCrate;
00417 byte last_packet_cmd;
00418 byte last_fphx_cmd;
00419 fvtx_el last_element;
00420
00421 };
00422
00423 #endif