firmware for the SOLID Slow Control Module for SM1
Dependencies: S_SCTRL_SMlib adc_ad9249 mbed sscm_comm AD5384 SWSPI T_adt7320
main.cpp@12:54b96bf7b291, 2015-10-12 (annotated)
- Committer:
- wbeaumont
- Date:
- Mon Oct 12 08:37:18 2015 +0000
- Revision:
- 12:54b96bf7b291
- Parent:
- 11:b1e6d7c18790
- Child:
- 13:ac7235a87242
set haetbeat to false by default
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:dcd70d1b89b1 | 1 | #include "mbed.h" |
wbeaumont | 1:f792767b2223 | 2 | /* SOLID SM1 Slow Control firmware |
wbeaumont | 1:f792767b2223 | 3 | * |
wbeaumont | 1:f792767b2223 | 4 | |
wbeaumont | 1:f792767b2223 | 5 | * V 1.0? initial version release |
wbeaumont | 1:f792767b2223 | 6 | * v 1.11 version , added status field |
wbeaumont | 1:f792767b2223 | 7 | * v 1.13 corrected error in ADC register write |
wbeaumont | 2:d18b1a1643e8 | 8 | * v 1.14 added heartbeat off / in |
wbeaumont | 3:badf265a8898 | 9 | * v 1.20 added DAC |
wbeaumont | 3:badf265a8898 | 10 | * v 1.30 added Temperature probe support |
wbeaumont | 3:badf265a8898 | 11 | * v 1.31 bug correction ,for selecting the probe the devnr has to be used |
wbeaumont | 3:badf265a8898 | 12 | * v 1.35 added version read for software modules (comm, T , ADC , DAC SWSPI) |
wbeaumont | 3:badf265a8898 | 13 | * v 1.36 added ini1 ini2 srst commands for DAC |
wbeaumont | 3:badf265a8898 | 14 | * v 1.37 new get Version class |
wbeaumont | 4:009703f995c6 | 15 | * v 1.40 added init ( dac) for all connectors (2) |
wbeaumont | 4:009703f995c6 | 16 | * v 1.50 added broadcast for DAC channels ( 1.. 32 ) |
wbeaumont | 4:009703f995c6 | 17 | * v 1.51 added set bias (digital) commands |
wbeaumont | 4:009703f995c6 | 18 | * v 1.54 added hardware DAC reset in init , added hw reset call for DAC |
wbeaumont | 4:009703f995c6 | 19 | * v 1.55 removed decode message , messages on the ADC commands |
wbeaumont | 4:009703f995c6 | 20 | * v 1.60 added set cal values fire call , error codes corrected |
wbeaumont | 4:009703f995c6 | 21 | * v 1.61 corrected BIAS channel, introduced DEIMOS32.h |
wbeaumont | 5:4177f8012a25 | 22 | * v 1.65 added heartbeat on / off, added set cal level |
wbeaumont | 5:4177f8012a25 | 23 | * v 1.66 implemented real temperature readout |
wbeaumont | 5:4177f8012a25 | 24 | * v 1.70 implemented set_volt and get_volt commands |
wbeaumont | 8:03f20aed4214 | 25 | * v 1.72 implemented setbias , get bias volt dummy |
wbeaumont | 10:efd3f490648c | 26 | * v 1.73 implemented setbias , get bias volt via Deimos32 class |
wbeaumont | 10:efd3f490648c | 27 | * v 1.74 added check for empty deimos pointer |
wbeaumont | 10:efd3f490648c | 28 | * v 1.75 added check for devnr < 1 |
wbeaumont | 10:efd3f490648c | 29 | * v 1.76 added check for devnr per device type , added connector range ( only 1 or 2 are accepted) |
wbeaumont | 10:efd3f490648c | 30 | * v 1.78 canged the place of cmd read to the end of the mail loop was at the start |
wbeaumont | 10:efd3f490648c | 31 | * v 1.79 added hv stet /get string to replace bi(ias) old commands are still working |
wbeaumont | 10:efd3f490648c | 32 | * wait only if cmd is not ready |
wbeaumont | 11:b1e6d7c18790 | 33 | * v 1.86 corrected dac assignment in DEIMOS32 class , correced gain factor in dac AD5384 class |
wbeaumont | 12:54b96bf7b291 | 34 | * V 1.90 sthv returns |
wbeaumont | 1:f792767b2223 | 35 | */ |
wbeaumont | 0:dcd70d1b89b1 | 36 | |
wbeaumont | 12:54b96bf7b291 | 37 | #define VERSION "1.90" |
wbeaumont | 0:dcd70d1b89b1 | 38 | |
wbeaumont | 2:d18b1a1643e8 | 39 | |
wbeaumont | 3:badf265a8898 | 40 | #include "SWSPI_BI.h" |
wbeaumont | 0:dcd70d1b89b1 | 41 | #include "solid_sctrl_def.h" |
wbeaumont | 0:dcd70d1b89b1 | 42 | #include "S_SCTRL_SM1_PinDef.h" |
wbeaumont | 0:dcd70d1b89b1 | 43 | #include "S_SCTRL_SM1_hwfunct.h" |
wbeaumont | 4:009703f995c6 | 44 | #include "DEIMOS32.h" |
wbeaumont | 2:d18b1a1643e8 | 45 | #include "AD9249.h" |
wbeaumont | 2:d18b1a1643e8 | 46 | #include "AD5384.h" |
wbeaumont | 3:badf265a8898 | 47 | #include "adt7320.h" |
wbeaumont | 3:badf265a8898 | 48 | #include "getVersion.h" |
wbeaumont | 0:dcd70d1b89b1 | 49 | |
wbeaumont | 0:dcd70d1b89b1 | 50 | #define DEBUGPF(x) printf((x)); |
wbeaumont | 0:dcd70d1b89b1 | 51 | |
wbeaumont | 0:dcd70d1b89b1 | 52 | |
wbeaumont | 0:dcd70d1b89b1 | 53 | #define MAXCMDLLENGTH 256 |
wbeaumont | 0:dcd70d1b89b1 | 54 | |
wbeaumont | 0:dcd70d1b89b1 | 55 | #include "sscm_comm.h" |
wbeaumont | 0:dcd70d1b89b1 | 56 | using namespace sscm_comm ; |
wbeaumont | 0:dcd70d1b89b1 | 57 | |
wbeaumont | 0:dcd70d1b89b1 | 58 | |
wbeaumont | 0:dcd70d1b89b1 | 59 | |
wbeaumont | 0:dcd70d1b89b1 | 60 | Serial pc(USBTX,USBRX); |
wbeaumont | 0:dcd70d1b89b1 | 61 | |
wbeaumont | 0:dcd70d1b89b1 | 62 | |
wbeaumont | 0:dcd70d1b89b1 | 63 | char cmdin[MAXCMDLLENGTH]; |
wbeaumont | 0:dcd70d1b89b1 | 64 | u8 cmdready; |
wbeaumont | 0:dcd70d1b89b1 | 65 | bool cmdstart=false; |
wbeaumont | 0:dcd70d1b89b1 | 66 | |
wbeaumont | 0:dcd70d1b89b1 | 67 | |
wbeaumont | 0:dcd70d1b89b1 | 68 | void pc_callback() { |
wbeaumont | 0:dcd70d1b89b1 | 69 | // Note: you need to actually read from the serial to clear the RX interrupt |
wbeaumont | 0:dcd70d1b89b1 | 70 | static unsigned char cnt; |
wbeaumont | 0:dcd70d1b89b1 | 71 | |
wbeaumont | 0:dcd70d1b89b1 | 72 | char c; |
wbeaumont | 0:dcd70d1b89b1 | 73 | c=pc.getc(); |
wbeaumont | 0:dcd70d1b89b1 | 74 | if( c== CMDSTART && !cmdready ) { cnt=0; cmdstart=true; cmdready=false; } |
wbeaumont | 0:dcd70d1b89b1 | 75 | if ( cmdstart) { |
wbeaumont | 0:dcd70d1b89b1 | 76 | cmdin[cnt]=c; cnt++; |
wbeaumont | 0:dcd70d1b89b1 | 77 | if (c== CMDSTOP ) { cmdready=true;} |
wbeaumont | 0:dcd70d1b89b1 | 78 | } |
wbeaumont | 0:dcd70d1b89b1 | 79 | |
wbeaumont | 0:dcd70d1b89b1 | 80 | |
wbeaumont | 0:dcd70d1b89b1 | 81 | |
wbeaumont | 0:dcd70d1b89b1 | 82 | //printf("%c:",c ); |
wbeaumont | 0:dcd70d1b89b1 | 83 | } |
wbeaumont | 0:dcd70d1b89b1 | 84 | |
wbeaumont | 0:dcd70d1b89b1 | 85 | |
wbeaumont | 0:dcd70d1b89b1 | 86 | |
wbeaumont | 0:dcd70d1b89b1 | 87 | |
wbeaumont | 0:dcd70d1b89b1 | 88 | int main() { |
wbeaumont | 0:dcd70d1b89b1 | 89 | pc.attach(pc_callback); |
wbeaumont | 0:dcd70d1b89b1 | 90 | ssc_cmd cmd; |
wbeaumont | 12:54b96bf7b291 | 91 | bool heartbeat=false; |
wbeaumont | 0:dcd70d1b89b1 | 92 | int i = 0; |
wbeaumont | 0:dcd70d1b89b1 | 93 | HWlines hwl ; |
wbeaumont | 0:dcd70d1b89b1 | 94 | assignports( &hwl ); |
wbeaumont | 0:dcd70d1b89b1 | 95 | setdefault(hwl ); |
wbeaumont | 3:badf265a8898 | 96 | // reuse getVesion |
wbeaumont | 3:badf265a8898 | 97 | getVersion gv( VERSION, VERSION , __TIME__, __DATE__ ); |
wbeaumont | 3:badf265a8898 | 98 | getVersion gvc; |
wbeaumont | 3:badf265a8898 | 99 | getsscmVersion gvsscm; |
wbeaumont | 2:d18b1a1643e8 | 100 | SWSPI spi(hwl.mosi[0],hwl.miso[0],hwl.sclk[0]); // mosi, miso, sclk |
wbeaumont | 2:d18b1a1643e8 | 101 | SWSPI spi2(hwl.mosi[1],hwl.miso[1],hwl.sclk[1]); // mosi, miso, sclk |
wbeaumont | 0:dcd70d1b89b1 | 102 | |
wbeaumont | 0:dcd70d1b89b1 | 103 | SWSPI_BI spi_adc(hwl.msio[0],hwl.direction[0],hwl.stio_mo[0] ,hwl.sclk[0]); // msio, dir , sclk |
wbeaumont | 0:dcd70d1b89b1 | 104 | SWSPI_BI spi_adc2(hwl.msio[1],hwl.direction[1],hwl.stio_mo[1],hwl.sclk[1]); // msio, dir , sclk |
wbeaumont | 0:dcd70d1b89b1 | 105 | // initalize ADC classes |
wbeaumont | 0:dcd70d1b89b1 | 106 | AD9249 adc[2][2]={AD9249( &spi_adc,hwl.csb1[0]), AD9249( &spi_adc,hwl.csb2[0]), |
wbeaumont | 0:dcd70d1b89b1 | 107 | AD9249( &spi_adc2,hwl.csb1[1]), AD9249 ( &spi_adc2,hwl.csb2[1])}; |
wbeaumont | 4:009703f995c6 | 108 | AD5384 dac[2][1]={AD5384(&spi,hwl.dac_cs[0],hwl.dac_rst[0]), AD5384(&spi2,hwl.dac_cs[1],hwl.dac_rst[1]) }; |
wbeaumont | 3:badf265a8898 | 109 | adt7320 temp[2][3]= { adt7320(&spi, hwl.t_cs[0]),adt7320(&spi, hwl.tc_cs1[0]),adt7320(&spi, hwl.tc_cs2[0]), |
wbeaumont | 3:badf265a8898 | 110 | adt7320(&spi2, hwl.t_cs[1]),adt7320(&spi2, hwl.tc_cs1[1]),adt7320(&spi2, hwl.tc_cs2[1]) }; |
wbeaumont | 0:dcd70d1b89b1 | 111 | |
wbeaumont | 8:03f20aed4214 | 112 | Deimos32* deimos[2] = { 0,0}; |
wbeaumont | 0:dcd70d1b89b1 | 113 | |
wbeaumont | 0:dcd70d1b89b1 | 114 | pc.printf("\nSOLID SLOW CONTROL for SM1 version %s %s %s \n\r",VERSION,__DATE__,__TIME__ ); |
wbeaumont | 4:009703f995c6 | 115 | |
wbeaumont | 4:009703f995c6 | 116 | for (u8 cc= 1; cc < 3 ; cc++) { |
wbeaumont | 4:009703f995c6 | 117 | dac[cc-1][0].init1(); |
wbeaumont | 4:009703f995c6 | 118 | |
wbeaumont | 4:009703f995c6 | 119 | } |
wbeaumont | 4:009703f995c6 | 120 | |
wbeaumont | 0:dcd70d1b89b1 | 121 | cmdready=false; |
wbeaumont | 0:dcd70d1b89b1 | 122 | while (1) { |
wbeaumont | 3:badf265a8898 | 123 | char cmdoutstr[100]; |
wbeaumont | 0:dcd70d1b89b1 | 124 | if (cmdready) { |
wbeaumont | 10:efd3f490648c | 125 | //cmdready=false; |
wbeaumont | 0:dcd70d1b89b1 | 126 | int decresult=decode_cmd(cmdin,&cmd); |
wbeaumont | 4:009703f995c6 | 127 | //printf("decode result = %d \n\r" ,decresult); |
wbeaumont | 10:efd3f490648c | 128 | decresult=abs(decresult); |
wbeaumont | 10:efd3f490648c | 129 | if( cmd.con <1 || cmd.con > 2 ) { decresult= 0x04 +decresult; } |
wbeaumont | 10:efd3f490648c | 130 | if( decresult){ |
wbeaumont | 4:009703f995c6 | 131 | u8 errcode=(u8)decresult ; |
wbeaumont | 4:009703f995c6 | 132 | errcode = 0xE0 + errcode; |
wbeaumont | 4:009703f995c6 | 133 | cmd.status=errcode; |
wbeaumont | 10:efd3f490648c | 134 | encode_cmd ( cmdoutstr, &cmd); pc.printf( "%s", cmdoutstr); |
wbeaumont | 10:efd3f490648c | 135 | cmdready=false; |
wbeaumont | 4:009703f995c6 | 136 | continue; |
wbeaumont | 4:009703f995c6 | 137 | } |
wbeaumont | 4:009703f995c6 | 138 | |
wbeaumont | 4:009703f995c6 | 139 | |
wbeaumont | 3:badf265a8898 | 140 | |
wbeaumont | 0:dcd70d1b89b1 | 141 | |
wbeaumont | 0:dcd70d1b89b1 | 142 | u8 do8; // dataout |
wbeaumont | 0:dcd70d1b89b1 | 143 | u16 do16; |
wbeaumont | 4:009703f995c6 | 144 | int chc=0, stch=0 ,endch=0; |
wbeaumont | 1:f792767b2223 | 145 | cmd.status=1; // use it for the moment as error handling , |
wbeaumont | 1:f792767b2223 | 146 | switch ( cmd.dev) { |
wbeaumont | 2:d18b1a1643e8 | 147 | |
wbeaumont | 4:009703f995c6 | 148 | case ADC : { |
wbeaumont | 1:f792767b2223 | 149 | cmd.status=2; |
wbeaumont | 4:009703f995c6 | 150 | //pc.printf("ADC cmd = %s \n\r",cmd.cmd); |
wbeaumont | 4:009703f995c6 | 151 | //pc.printf("check now ranges %d %d \n\r",cmd.con, cmd.devnr); |
wbeaumont | 10:efd3f490648c | 152 | if( cmd.devnr < 1 || cmd.devnr > 2 ) { cmd.status =3; } |
wbeaumont | 10:efd3f490648c | 153 | else { |
wbeaumont | 1:f792767b2223 | 154 | if (!strcmp( cmd.cmd, "spa1")) { adc[cmd.con-1][cmd.devnr-1].setPattern1(cmd.datain);cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 1:f792767b2223 | 155 | if (!strcmp( cmd.cmd, "spa2")) { adc[cmd.con-1][cmd.devnr-1].setPattern2(cmd.datain);cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 2:d18b1a1643e8 | 156 | if (!strcmp( cmd.cmd, "rpa1")) { adc[cmd.con-1][cmd.devnr-1].readPattern1(do16 ); cmd.dataout=do16; cmd.status=0; } |
wbeaumont | 2:d18b1a1643e8 | 157 | if (!strcmp( cmd.cmd, "rpa2")) { adc[cmd.con-1][cmd.devnr-1].readPattern2(do16 ); cmd.dataout=do16; cmd.status=0; } |
wbeaumont | 2:d18b1a1643e8 | 158 | if (!strcmp( cmd.cmd, "rr08")) {adc[cmd.con-1][cmd.devnr-1].readReg8(cmd.ch,do8 ); cmd.dataout=(u16)do8; cmd.status=0; } |
wbeaumont | 1:f792767b2223 | 159 | if (!strcmp( cmd.cmd, "rr16")) {adc[cmd.con-1][cmd.devnr-1].readReg16(cmd.ch,do16 ); cmd.dataout=(u32)do16;cmd.status=0; } |
wbeaumont | 1:f792767b2223 | 160 | if (!strcmp( cmd.cmd, "sr08")) { adc[cmd.con-1][cmd.devnr-1].setReg8(cmd.ch, (u8)cmd.datain ); cmd.dataout=cmd.datain; cmd.status=0; } |
wbeaumont | 1:f792767b2223 | 161 | if (!strcmp( cmd.cmd, "sr16")) { adc[cmd.con-1][cmd.devnr-1].setReg16(cmd.ch, (u16)cmd.datain ); cmd.dataout=cmd.datain; cmd.status=0; } |
wbeaumont | 3:badf265a8898 | 162 | if (!strcmp( cmd.cmd, "ghrv")) {do16=adc[cmd.con-1][cmd.devnr-1].getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 163 | if (!strcmp( cmd.cmd, "gscv")) {do16=adc[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 164 | if (!strcmp( cmd.cmd, "ini1")) { adc[cmd.con-1][cmd.devnr-1].init1();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 165 | if (!strcmp( cmd.cmd, "ini2")) { adc[cmd.con-1][cmd.devnr-1].init2();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 10:efd3f490648c | 166 | } // end check dev nr. |
wbeaumont | 4:009703f995c6 | 167 | }break; |
wbeaumont | 4:009703f995c6 | 168 | case DAC :{ |
wbeaumont | 10:efd3f490648c | 169 | cmd.status=2; |
wbeaumont | 10:efd3f490648c | 170 | if( cmd.devnr != 1 ) { cmd.status =3;goto DACENDCMD; } |
wbeaumont | 4:009703f995c6 | 171 | if (!strcmp( cmd.cmd, "ini1")) { dac[cmd.con-1][cmd.devnr-1].init1();cmd.dataout=cmd.datain;cmd.status=0; goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 172 | if (!strcmp( cmd.cmd, "ini2")) { dac[cmd.con-1][cmd.devnr-1].init2();cmd.dataout=cmd.datain;cmd.status=0; goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 173 | if (!strcmp( cmd.cmd, "srst")) { dac[cmd.con-1][cmd.devnr-1].soft_rst();cmd.dataout=cmd.datain;cmd.status=0;goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 174 | if (!strcmp( cmd.cmd, "hrst")) { dac[cmd.con-1][cmd.devnr-1].hw_rst();cmd.dataout=cmd.datain;cmd.status=0;goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 175 | if (!strcmp( cmd.cmd, "gctr")) { do16=dac[cmd.con-1][cmd.devnr-1].get_ctrl();cmd.dataout=do16;cmd.status=0;goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 176 | if (!strcmp( cmd.cmd, "ghrv")) { do16=dac[cmd.con-1][cmd.devnr-1].getHdrVersion();cmd.dataout=do16; cmd.status=0;goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 177 | if (!strcmp( cmd.cmd, "gscv")) { do16=dac[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;goto DACENDCMD;} |
wbeaumont | 4:009703f995c6 | 178 | // set output register bias channel |
wbeaumont | 10:efd3f490648c | 179 | if ((!strcmp( cmd.cmd, "sbid")) || (!strcmp( cmd.cmd, "shvd")) ) |
wbeaumont | 10:efd3f490648c | 180 | { cmd.ch=DACBIASCH;dac[cmd.con-1][cmd.devnr-1].set_dac(cmd.ch-1,cmd.datain);cmd.dataout=cmd.datain;cmd.status=0;goto DACENDCMD;} |
wbeaumont | 10:efd3f490648c | 181 | if ((!strcmp( cmd.cmd, "gbid")) || (!strcmp( cmd.cmd, "ghvd")) ) |
wbeaumont | 10:efd3f490648c | 182 | {cmd.ch=DACBIASCH;do16=dac[cmd.con-1][cmd.devnr-1].get_dac(cmd.ch-1);cmd.dataout=do16;cmd.status=0;goto DACENDCMD;} |
wbeaumont | 8:03f20aed4214 | 183 | if (!strcmp( cmd.cmd, "inhv")) { |
wbeaumont | 8:03f20aed4214 | 184 | if(cmd.con== 0) {cmd.status=100;goto DACENDCMD;} // can not be broadcast ;} |
wbeaumont | 8:03f20aed4214 | 185 | if(cmd.con > 2) {cmd.status=101;goto DACENDCMD;} |
wbeaumont | 10:efd3f490648c | 186 | if( deimos[cmd.con-1] ) {cmd.status=102;goto DACENDCMD;} // if already init don't init again. |
wbeaumont | 8:03f20aed4214 | 187 | float hvnom=u162float( cmd.dataout , cmd.datain); |
wbeaumont | 11:b1e6d7c18790 | 188 | deimos[cmd.con-1]= new Deimos32(hvnom ,cmd.con,&dac[cmd.con-1][cmd.devnr-1]); |
wbeaumont | 8:03f20aed4214 | 189 | cmd.status=0;goto DACENDCMD; |
wbeaumont | 8:03f20aed4214 | 190 | } |
wbeaumont | 10:efd3f490648c | 191 | if ((!strcmp( cmd.cmd, "sbia")) || (!strcmp( cmd.cmd, "sthv")) ) { |
wbeaumont | 8:03f20aed4214 | 192 | float biasvolt= u162float( cmd.dataout , cmd.datain); |
wbeaumont | 8:03f20aed4214 | 193 | u8 strtcnt=0; u8 stpcnt=2; |
wbeaumont | 8:03f20aed4214 | 194 | if (cmd.con ==1) stpcnt=1; |
wbeaumont | 8:03f20aed4214 | 195 | if (cmd.con ==2) strtcnt=1; // else it is assumed to be 9 |
wbeaumont | 8:03f20aed4214 | 196 | float retvalue=0; |
wbeaumont | 9:20fc5a795ec4 | 197 | for ( u8 bcnt=strtcnt ; bcnt < stpcnt; bcnt++) { |
wbeaumont | 12:54b96bf7b291 | 198 | u16 dacvalue=0; |
wbeaumont | 11:b1e6d7c18790 | 199 | if ( ! deimos[bcnt]) retvalue=200; |
wbeaumont | 11:b1e6d7c18790 | 200 | else { |
wbeaumont | 11:b1e6d7c18790 | 201 | retvalue+=-deimos[bcnt]->setHV(biasvolt,dacvalue); |
wbeaumont | 11:b1e6d7c18790 | 202 | cmd.datain=0; cmd.dataout=dacvalue; |
wbeaumont | 11:b1e6d7c18790 | 203 | } |
wbeaumont | 9:20fc5a795ec4 | 204 | } |
wbeaumont | 8:03f20aed4214 | 205 | cmd.status=u8(retvalue);goto DACENDCMD; |
wbeaumont | 7:5f8abd383a7d | 206 | } |
wbeaumont | 11:b1e6d7c18790 | 207 | if ((!strcmp( cmd.cmd, "gbia")) || (!strcmp( cmd.cmd, "gthv")) || (!strcmp( cmd.cmd, "gthn")) ) { |
wbeaumont | 8:03f20aed4214 | 208 | if ( cmd.con ==0 ) cmd.con=1; |
wbeaumont | 9:20fc5a795ec4 | 209 | if (deimos[cmd.con-1]) { |
wbeaumont | 11:b1e6d7c18790 | 210 | float volt; |
wbeaumont | 11:b1e6d7c18790 | 211 | if (!strcmp( cmd.cmd, "gthn")) volt=deimos[cmd.con-1]->getHvNom(); |
wbeaumont | 11:b1e6d7c18790 | 212 | else volt=deimos[cmd.con-1]->getHv(); |
wbeaumont | 9:20fc5a795ec4 | 213 | float2_2u16( volt , cmd.dataout , cmd.datain); |
wbeaumont | 9:20fc5a795ec4 | 214 | cmd.status=0; |
wbeaumont | 9:20fc5a795ec4 | 215 | } |
wbeaumont | 9:20fc5a795ec4 | 216 | else cmd.status=200; |
wbeaumont | 9:20fc5a795ec4 | 217 | goto DACENDCMD; |
wbeaumont | 7:5f8abd383a7d | 218 | } |
wbeaumont | 4:009703f995c6 | 219 | // set CAL level values |
wbeaumont | 4:009703f995c6 | 220 | if (!strcmp( cmd.cmd, "scll")) { |
wbeaumont | 4:009703f995c6 | 221 | if( cmd.ch !=0) { stch=cmd.ch+DACCAL1CH-1; endch=cmd.ch+DACCAL1CH; } else { stch=DACCAL1CH; endch=DACCAL1CH+4;}; |
wbeaumont | 4:009703f995c6 | 222 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 223 | cmd.ch=chc; |
wbeaumont | 4:009703f995c6 | 224 | dac[cmd.con-1][cmd.devnr-1].set_dac(cmd.ch-1,cmd.datain);cmd.dataout=cmd.datain;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 225 | } |
wbeaumont | 4:009703f995c6 | 226 | goto DACENDCMD; |
wbeaumont | 4:009703f995c6 | 227 | } |
wbeaumont | 3:badf265a8898 | 228 | |
wbeaumont | 4:009703f995c6 | 229 | if (!strcmp( cmd.cmd, "gcll")){ |
wbeaumont | 4:009703f995c6 | 230 | if( cmd.ch !=0) { stch=cmd.ch+DACCAL1CH-1; endch=cmd.ch+DACCAL1CH; } else { stch=DACCAL1CH; endch=DACCAL1CH+4;}; |
wbeaumont | 4:009703f995c6 | 231 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 232 | cmd.ch=chc; |
wbeaumont | 4:009703f995c6 | 233 | do16=dac[cmd.con-1][cmd.devnr-1].get_dac(cmd.ch-1);cmd.dataout=do16;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 234 | } |
wbeaumont | 4:009703f995c6 | 235 | goto DACENDCMD; |
wbeaumont | 4:009703f995c6 | 236 | } |
wbeaumont | 4:009703f995c6 | 237 | |
wbeaumont | 4:009703f995c6 | 238 | |
wbeaumont | 4:009703f995c6 | 239 | // channel related commands |
wbeaumont | 4:009703f995c6 | 240 | if( cmd.ch !=0) { stch=cmd.ch-1; endch=cmd.ch; } else { stch=0; endch=31;}; |
wbeaumont | 4:009703f995c6 | 241 | if (!strcmp( cmd.cmd, "sdac")) { |
wbeaumont | 4:009703f995c6 | 242 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 243 | dac[cmd.con-1][cmd.devnr-1].set_dac(chc,cmd.datain);cmd.dataout=cmd.datain;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 244 | } |
wbeaumont | 4:009703f995c6 | 245 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 246 | } |
wbeaumont | 5:4177f8012a25 | 247 | if (!strcmp( cmd.cmd, "svlt")) { |
wbeaumont | 5:4177f8012a25 | 248 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 5:4177f8012a25 | 249 | float volt= u162float( cmd.dataout , cmd.datain); |
wbeaumont | 5:4177f8012a25 | 250 | dac[cmd.con-1][cmd.devnr-1].set_volt(chc,volt);cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 251 | } |
wbeaumont | 5:4177f8012a25 | 252 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 253 | } |
wbeaumont | 4:009703f995c6 | 254 | // next is not very usefull for multiple channels |
wbeaumont | 4:009703f995c6 | 255 | if (!strcmp( cmd.cmd, "rdac")) { |
wbeaumont | 4:009703f995c6 | 256 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 257 | do16=dac[cmd.con-1][cmd.devnr-1].get_dac(chc);cmd.dataout=do16;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 258 | } |
wbeaumont | 4:009703f995c6 | 259 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 260 | } |
wbeaumont | 5:4177f8012a25 | 261 | if (!strcmp( cmd.cmd, "gvlt")) { |
wbeaumont | 5:4177f8012a25 | 262 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 5:4177f8012a25 | 263 | float volt=dac[cmd.con-1][cmd.devnr-1].get_volt(chc); |
wbeaumont | 5:4177f8012a25 | 264 | float2_2u16( volt , cmd.dataout , cmd.datain); |
wbeaumont | 5:4177f8012a25 | 265 | cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 266 | } |
wbeaumont | 5:4177f8012a25 | 267 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 268 | } |
wbeaumont | 4:009703f995c6 | 269 | DACENDCMD : ; |
wbeaumont | 4:009703f995c6 | 270 | }break; |
wbeaumont | 10:efd3f490648c | 271 | case TEMP : {cmd.status=2; |
wbeaumont | 10:efd3f490648c | 272 | if( cmd.devnr < 1 || cmd.devnr > 3 ) { cmd.status =3; goto TEMPENDCMD; } |
wbeaumont | 5:4177f8012a25 | 273 | if (!strcmp( cmd.cmd, "rtmp")){ |
wbeaumont | 5:4177f8012a25 | 274 | float temperature=temp[cmd.con-1][cmd.devnr-1].getTemperature(); |
wbeaumont | 5:4177f8012a25 | 275 | float2_2u16(temperature,cmd.dataout,cmd.datain);cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 276 | } |
wbeaumont | 3:badf265a8898 | 277 | if (!strcmp( cmd.cmd, "rtpd")){ do16=temp[cmd.con-1][cmd.devnr-1].get_T();cmd.dataout=do16;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 278 | if (!strcmp( cmd.cmd, "gtid")){ do8=temp[cmd.con-1][cmd.devnr-1].getId();cmd.dataout=do8;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 279 | if (!strcmp( cmd.cmd, "rtcr")){ do16=temp[cmd.con-1][cmd.devnr-1].get_TcritSP();cmd.dataout=do16;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 280 | if (!strcmp( cmd.cmd, "stcr")){ temp[cmd.con-1][cmd.devnr-1].set_TcritSP(cmd.datain);cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 281 | if (!strcmp( cmd.cmd, "ghrv")) {do16=temp[cmd.con-1][cmd.devnr-1].getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 282 | if (!strcmp( cmd.cmd, "gscv")) {do16=temp[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 5:4177f8012a25 | 283 | if (!strcmp( cmd.cmd, "gtmp")) {do16=temp[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 284 | if (!strcmp( cmd.cmd, "ini1")) { temp[cmd.con-1][cmd.devnr-1].init1();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 285 | if (!strcmp( cmd.cmd, "ini2")) { temp[cmd.con-1][cmd.devnr-1].init2();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 10:efd3f490648c | 286 | TEMPENDCMD : ; |
wbeaumont | 10:efd3f490648c | 287 | }break; |
wbeaumont | 3:badf265a8898 | 288 | case SSCM: |
wbeaumont | 3:badf265a8898 | 289 | cmd.status=2; |
wbeaumont | 4:009703f995c6 | 290 | // generate internal CAL |
wbeaumont | 4:009703f995c6 | 291 | if (!strcmp( cmd.cmd, "acal")){toggle_cal(hwl,cmd.ch );cmd.status=0;} |
wbeaumont | 5:4177f8012a25 | 292 | // set calline lvl |
wbeaumont | 5:4177f8012a25 | 293 | if (!strcmp( cmd.cmd, "scll")){set_cal_line(hwl,cmd.ch, cmd.datain );cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 294 | // heartbeat |
wbeaumont | 5:4177f8012a25 | 295 | if (!strcmp( cmd.cmd, "t_hb")) { if ( cmd.datain ==0 ) heartbeat=false; |
wbeaumont | 5:4177f8012a25 | 296 | if ( cmd.datain ==1 ) heartbeat=true; |
wbeaumont | 5:4177f8012a25 | 297 | if ( cmd.datain ==2) heartbeat=!heartbeat;cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 298 | } |
wbeaumont | 4:009703f995c6 | 299 | //get main version |
wbeaumont | 3:badf265a8898 | 300 | if (!strcmp( cmd.cmd, "gmpv")) {do16=gv.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 301 | // get module serial nr |
wbeaumont | 4:009703f995c6 | 302 | if (!strcmp( cmd.cmd, "msnr")) {do8=get_serialnr(&hwl);cmd.dataout=(u16)do8; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 303 | // get version module version |
wbeaumont | 3:badf265a8898 | 304 | if (!strcmp( cmd.cmd, "gvhv")) {do16=gvc.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 305 | if (!strcmp( cmd.cmd, "gvsv")) {do16=gvc.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 306 | // get communication module version |
wbeaumont | 3:badf265a8898 | 307 | if (!strcmp( cmd.cmd, "gchv")) {do16=gvsscm.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 308 | if (!strcmp( cmd.cmd, "gcsv")) {do16=gvsscm.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 309 | // get spi module version |
wbeaumont | 4:009703f995c6 | 310 | if (!strcmp( cmd.cmd, "gshv")) {do16=spi.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 311 | if (!strcmp( cmd.cmd, "gssv")) {do16=spi.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 312 | // get bispi module version |
wbeaumont | 4:009703f995c6 | 313 | if (!strcmp( cmd.cmd, "gbhv")) {do16=spi_adc.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 314 | if (!strcmp( cmd.cmd, "gbsv")) {do16=spi_adc.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 315 | |
wbeaumont | 4:009703f995c6 | 316 | |
wbeaumont | 3:badf265a8898 | 317 | |
wbeaumont | 1:f792767b2223 | 318 | break; |
wbeaumont | 1:f792767b2223 | 319 | default : cmd.status=1; |
wbeaumont | 1:f792767b2223 | 320 | break; |
wbeaumont | 1:f792767b2223 | 321 | } // end switch |
wbeaumont | 4:009703f995c6 | 322 | encode_cmd ( cmdoutstr, &cmd); |
wbeaumont | 0:dcd70d1b89b1 | 323 | pc.printf( "%s", cmdoutstr); |
wbeaumont | 10:efd3f490648c | 324 | cmdready=false; |
wbeaumont | 0:dcd70d1b89b1 | 325 | }//end if cmdready |
wbeaumont | 0:dcd70d1b89b1 | 326 | else { |
wbeaumont | 1:f792767b2223 | 327 | if ( heartbeat) printf( "%03d>%s\n\r",(i++ % 1000),cmdin); |
wbeaumont | 10:efd3f490648c | 328 | wait(0.2); |
wbeaumont | 0:dcd70d1b89b1 | 329 | } |
wbeaumont | 0:dcd70d1b89b1 | 330 | }// end while |
wbeaumont | 0:dcd70d1b89b1 | 331 | |
wbeaumont | 0:dcd70d1b89b1 | 332 | } |