![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
firmware for the SOLID Slow Control Module for SM1
Dependencies: S_SCTRL_SMlib adc_ad9249 mbed sscm_comm AD5384 SWSPI T_adt7320
main.cpp@6:3a92f9f93d80, 2014-10-23 (annotated)
- Committer:
- wbeaumont
- Date:
- Thu Oct 23 17:42:54 2014 +0000
- Revision:
- 6:3a92f9f93d80
- Parent:
- 5:4177f8012a25
- Child:
- 7:5f8abd383a7d
no change in the mainprogram only to follow the chain in the sscm_comm module
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 | 1:f792767b2223 | 25 | */ |
wbeaumont | 0:dcd70d1b89b1 | 26 | |
wbeaumont | 6:3a92f9f93d80 | 27 | #define VERSION "1.71" |
wbeaumont | 0:dcd70d1b89b1 | 28 | |
wbeaumont | 2:d18b1a1643e8 | 29 | |
wbeaumont | 3:badf265a8898 | 30 | #include "SWSPI_BI.h" |
wbeaumont | 0:dcd70d1b89b1 | 31 | #include "solid_sctrl_def.h" |
wbeaumont | 0:dcd70d1b89b1 | 32 | #include "S_SCTRL_SM1_PinDef.h" |
wbeaumont | 0:dcd70d1b89b1 | 33 | #include "S_SCTRL_SM1_hwfunct.h" |
wbeaumont | 4:009703f995c6 | 34 | #include "DEIMOS32.h" |
wbeaumont | 2:d18b1a1643e8 | 35 | #include "AD9249.h" |
wbeaumont | 2:d18b1a1643e8 | 36 | #include "AD5384.h" |
wbeaumont | 3:badf265a8898 | 37 | #include "adt7320.h" |
wbeaumont | 3:badf265a8898 | 38 | #include "getVersion.h" |
wbeaumont | 0:dcd70d1b89b1 | 39 | |
wbeaumont | 0:dcd70d1b89b1 | 40 | #define DEBUGPF(x) printf((x)); |
wbeaumont | 0:dcd70d1b89b1 | 41 | |
wbeaumont | 0:dcd70d1b89b1 | 42 | |
wbeaumont | 0:dcd70d1b89b1 | 43 | #define MAXCMDLLENGTH 256 |
wbeaumont | 0:dcd70d1b89b1 | 44 | |
wbeaumont | 0:dcd70d1b89b1 | 45 | #include "sscm_comm.h" |
wbeaumont | 0:dcd70d1b89b1 | 46 | using namespace sscm_comm ; |
wbeaumont | 0:dcd70d1b89b1 | 47 | |
wbeaumont | 0:dcd70d1b89b1 | 48 | |
wbeaumont | 0:dcd70d1b89b1 | 49 | |
wbeaumont | 0:dcd70d1b89b1 | 50 | Serial pc(USBTX,USBRX); |
wbeaumont | 0:dcd70d1b89b1 | 51 | |
wbeaumont | 0:dcd70d1b89b1 | 52 | |
wbeaumont | 0:dcd70d1b89b1 | 53 | char cmdin[MAXCMDLLENGTH]; |
wbeaumont | 0:dcd70d1b89b1 | 54 | u8 cmdready; |
wbeaumont | 0:dcd70d1b89b1 | 55 | bool cmdstart=false; |
wbeaumont | 0:dcd70d1b89b1 | 56 | |
wbeaumont | 0:dcd70d1b89b1 | 57 | |
wbeaumont | 0:dcd70d1b89b1 | 58 | void pc_callback() { |
wbeaumont | 0:dcd70d1b89b1 | 59 | // Note: you need to actually read from the serial to clear the RX interrupt |
wbeaumont | 0:dcd70d1b89b1 | 60 | static unsigned char cnt; |
wbeaumont | 0:dcd70d1b89b1 | 61 | |
wbeaumont | 0:dcd70d1b89b1 | 62 | char c; |
wbeaumont | 0:dcd70d1b89b1 | 63 | c=pc.getc(); |
wbeaumont | 0:dcd70d1b89b1 | 64 | if( c== CMDSTART && !cmdready ) { cnt=0; cmdstart=true; cmdready=false; } |
wbeaumont | 0:dcd70d1b89b1 | 65 | if ( cmdstart) { |
wbeaumont | 0:dcd70d1b89b1 | 66 | cmdin[cnt]=c; cnt++; |
wbeaumont | 0:dcd70d1b89b1 | 67 | if (c== CMDSTOP ) { cmdready=true;} |
wbeaumont | 0:dcd70d1b89b1 | 68 | } |
wbeaumont | 0:dcd70d1b89b1 | 69 | |
wbeaumont | 0:dcd70d1b89b1 | 70 | |
wbeaumont | 0:dcd70d1b89b1 | 71 | |
wbeaumont | 0:dcd70d1b89b1 | 72 | //printf("%c:",c ); |
wbeaumont | 0:dcd70d1b89b1 | 73 | } |
wbeaumont | 0:dcd70d1b89b1 | 74 | |
wbeaumont | 0:dcd70d1b89b1 | 75 | |
wbeaumont | 0:dcd70d1b89b1 | 76 | |
wbeaumont | 0:dcd70d1b89b1 | 77 | |
wbeaumont | 0:dcd70d1b89b1 | 78 | int main() { |
wbeaumont | 0:dcd70d1b89b1 | 79 | pc.attach(pc_callback); |
wbeaumont | 0:dcd70d1b89b1 | 80 | ssc_cmd cmd; |
wbeaumont | 1:f792767b2223 | 81 | bool heartbeat=true; |
wbeaumont | 0:dcd70d1b89b1 | 82 | int i = 0; |
wbeaumont | 0:dcd70d1b89b1 | 83 | HWlines hwl ; |
wbeaumont | 0:dcd70d1b89b1 | 84 | assignports( &hwl ); |
wbeaumont | 0:dcd70d1b89b1 | 85 | setdefault(hwl ); |
wbeaumont | 3:badf265a8898 | 86 | // reuse getVesion |
wbeaumont | 3:badf265a8898 | 87 | getVersion gv( VERSION, VERSION , __TIME__, __DATE__ ); |
wbeaumont | 3:badf265a8898 | 88 | getVersion gvc; |
wbeaumont | 3:badf265a8898 | 89 | getsscmVersion gvsscm; |
wbeaumont | 2:d18b1a1643e8 | 90 | SWSPI spi(hwl.mosi[0],hwl.miso[0],hwl.sclk[0]); // mosi, miso, sclk |
wbeaumont | 2:d18b1a1643e8 | 91 | SWSPI spi2(hwl.mosi[1],hwl.miso[1],hwl.sclk[1]); // mosi, miso, sclk |
wbeaumont | 0:dcd70d1b89b1 | 92 | |
wbeaumont | 0:dcd70d1b89b1 | 93 | SWSPI_BI spi_adc(hwl.msio[0],hwl.direction[0],hwl.stio_mo[0] ,hwl.sclk[0]); // msio, dir , sclk |
wbeaumont | 0:dcd70d1b89b1 | 94 | SWSPI_BI spi_adc2(hwl.msio[1],hwl.direction[1],hwl.stio_mo[1],hwl.sclk[1]); // msio, dir , sclk |
wbeaumont | 0:dcd70d1b89b1 | 95 | // initalize ADC classes |
wbeaumont | 0:dcd70d1b89b1 | 96 | AD9249 adc[2][2]={AD9249( &spi_adc,hwl.csb1[0]), AD9249( &spi_adc,hwl.csb2[0]), |
wbeaumont | 0:dcd70d1b89b1 | 97 | AD9249( &spi_adc2,hwl.csb1[1]), AD9249 ( &spi_adc2,hwl.csb2[1])}; |
wbeaumont | 4:009703f995c6 | 98 | 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 | 99 | 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 | 100 | adt7320(&spi2, hwl.t_cs[1]),adt7320(&spi2, hwl.tc_cs1[1]),adt7320(&spi2, hwl.tc_cs2[1]) }; |
wbeaumont | 0:dcd70d1b89b1 | 101 | |
wbeaumont | 0:dcd70d1b89b1 | 102 | |
wbeaumont | 0:dcd70d1b89b1 | 103 | |
wbeaumont | 0:dcd70d1b89b1 | 104 | pc.printf("\nSOLID SLOW CONTROL for SM1 version %s %s %s \n\r",VERSION,__DATE__,__TIME__ ); |
wbeaumont | 4:009703f995c6 | 105 | |
wbeaumont | 4:009703f995c6 | 106 | for (u8 cc= 1; cc < 3 ; cc++) { |
wbeaumont | 4:009703f995c6 | 107 | dac[cc-1][0].init1(); |
wbeaumont | 4:009703f995c6 | 108 | |
wbeaumont | 4:009703f995c6 | 109 | } |
wbeaumont | 4:009703f995c6 | 110 | |
wbeaumont | 0:dcd70d1b89b1 | 111 | cmdready=false; |
wbeaumont | 0:dcd70d1b89b1 | 112 | while (1) { |
wbeaumont | 0:dcd70d1b89b1 | 113 | wait(0.5); |
wbeaumont | 3:badf265a8898 | 114 | char cmdoutstr[100]; |
wbeaumont | 0:dcd70d1b89b1 | 115 | if (cmdready) { |
wbeaumont | 0:dcd70d1b89b1 | 116 | cmdready=false; |
wbeaumont | 0:dcd70d1b89b1 | 117 | int decresult=decode_cmd(cmdin,&cmd); |
wbeaumont | 4:009703f995c6 | 118 | //printf("decode result = %d \n\r" ,decresult); |
wbeaumont | 4:009703f995c6 | 119 | if( decresult){ |
wbeaumont | 4:009703f995c6 | 120 | decresult=abs(decresult); |
wbeaumont | 4:009703f995c6 | 121 | u8 errcode=(u8)decresult ; |
wbeaumont | 4:009703f995c6 | 122 | errcode = 0xE0 + errcode; |
wbeaumont | 4:009703f995c6 | 123 | cmd.status=errcode; |
wbeaumont | 4:009703f995c6 | 124 | encode_cmd ( cmdoutstr, &cmd); pc.printf( "%s", cmdoutstr); |
wbeaumont | 4:009703f995c6 | 125 | continue; |
wbeaumont | 4:009703f995c6 | 126 | } |
wbeaumont | 4:009703f995c6 | 127 | |
wbeaumont | 4:009703f995c6 | 128 | |
wbeaumont | 3:badf265a8898 | 129 | |
wbeaumont | 0:dcd70d1b89b1 | 130 | |
wbeaumont | 0:dcd70d1b89b1 | 131 | u8 do8; // dataout |
wbeaumont | 0:dcd70d1b89b1 | 132 | u16 do16; |
wbeaumont | 4:009703f995c6 | 133 | int chc=0, stch=0 ,endch=0; |
wbeaumont | 1:f792767b2223 | 134 | cmd.status=1; // use it for the moment as error handling , |
wbeaumont | 1:f792767b2223 | 135 | switch ( cmd.dev) { |
wbeaumont | 2:d18b1a1643e8 | 136 | |
wbeaumont | 4:009703f995c6 | 137 | case ADC : { |
wbeaumont | 1:f792767b2223 | 138 | cmd.status=2; |
wbeaumont | 4:009703f995c6 | 139 | //pc.printf("ADC cmd = %s \n\r",cmd.cmd); |
wbeaumont | 4:009703f995c6 | 140 | //pc.printf("check now ranges %d %d \n\r",cmd.con, cmd.devnr); |
wbeaumont | 1:f792767b2223 | 141 | 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 | 142 | 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 | 143 | if (!strcmp( cmd.cmd, "rpa1")) { adc[cmd.con-1][cmd.devnr-1].readPattern1(do16 ); cmd.dataout=do16; cmd.status=0; } |
wbeaumont | 2:d18b1a1643e8 | 144 | if (!strcmp( cmd.cmd, "rpa2")) { adc[cmd.con-1][cmd.devnr-1].readPattern2(do16 ); cmd.dataout=do16; cmd.status=0; } |
wbeaumont | 2:d18b1a1643e8 | 145 | 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 | 146 | 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 | 147 | 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 | 148 | 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 | 149 | if (!strcmp( cmd.cmd, "ghrv")) {do16=adc[cmd.con-1][cmd.devnr-1].getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 150 | if (!strcmp( cmd.cmd, "gscv")) {do16=adc[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 151 | if (!strcmp( cmd.cmd, "ini1")) { adc[cmd.con-1][cmd.devnr-1].init1();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 152 | if (!strcmp( cmd.cmd, "ini2")) { adc[cmd.con-1][cmd.devnr-1].init2();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 153 | }break; |
wbeaumont | 4:009703f995c6 | 154 | case DAC :{ |
wbeaumont | 4:009703f995c6 | 155 | cmd.status=2; |
wbeaumont | 4:009703f995c6 | 156 | 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 | 157 | 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 | 158 | 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 | 159 | 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 | 160 | 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 | 161 | 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 | 162 | 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 | 163 | // set output register bias channel |
wbeaumont | 4:009703f995c6 | 164 | if (!strcmp( cmd.cmd, "sbid")) { 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 | 4:009703f995c6 | 165 | if (!strcmp( cmd.cmd, "gbid")) {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 | 4:009703f995c6 | 166 | // set CAL level values |
wbeaumont | 4:009703f995c6 | 167 | if (!strcmp( cmd.cmd, "scll")) { |
wbeaumont | 4:009703f995c6 | 168 | if( cmd.ch !=0) { stch=cmd.ch+DACCAL1CH-1; endch=cmd.ch+DACCAL1CH; } else { stch=DACCAL1CH; endch=DACCAL1CH+4;}; |
wbeaumont | 4:009703f995c6 | 169 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 170 | cmd.ch=chc; |
wbeaumont | 4:009703f995c6 | 171 | dac[cmd.con-1][cmd.devnr-1].set_dac(cmd.ch-1,cmd.datain);cmd.dataout=cmd.datain;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 172 | } |
wbeaumont | 4:009703f995c6 | 173 | goto DACENDCMD; |
wbeaumont | 4:009703f995c6 | 174 | } |
wbeaumont | 3:badf265a8898 | 175 | |
wbeaumont | 4:009703f995c6 | 176 | if (!strcmp( cmd.cmd, "gcll")){ |
wbeaumont | 4:009703f995c6 | 177 | if( cmd.ch !=0) { stch=cmd.ch+DACCAL1CH-1; endch=cmd.ch+DACCAL1CH; } else { stch=DACCAL1CH; endch=DACCAL1CH+4;}; |
wbeaumont | 4:009703f995c6 | 178 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 179 | cmd.ch=chc; |
wbeaumont | 4:009703f995c6 | 180 | do16=dac[cmd.con-1][cmd.devnr-1].get_dac(cmd.ch-1);cmd.dataout=do16;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 181 | } |
wbeaumont | 4:009703f995c6 | 182 | goto DACENDCMD; |
wbeaumont | 4:009703f995c6 | 183 | } |
wbeaumont | 4:009703f995c6 | 184 | |
wbeaumont | 4:009703f995c6 | 185 | |
wbeaumont | 4:009703f995c6 | 186 | // channel related commands |
wbeaumont | 4:009703f995c6 | 187 | if( cmd.ch !=0) { stch=cmd.ch-1; endch=cmd.ch; } else { stch=0; endch=31;}; |
wbeaumont | 4:009703f995c6 | 188 | if (!strcmp( cmd.cmd, "sdac")) { |
wbeaumont | 4:009703f995c6 | 189 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 190 | dac[cmd.con-1][cmd.devnr-1].set_dac(chc,cmd.datain);cmd.dataout=cmd.datain;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 191 | } |
wbeaumont | 4:009703f995c6 | 192 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 193 | } |
wbeaumont | 5:4177f8012a25 | 194 | if (!strcmp( cmd.cmd, "svlt")) { |
wbeaumont | 5:4177f8012a25 | 195 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 5:4177f8012a25 | 196 | float volt= u162float( cmd.dataout , cmd.datain); |
wbeaumont | 5:4177f8012a25 | 197 | dac[cmd.con-1][cmd.devnr-1].set_volt(chc,volt);cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 198 | } |
wbeaumont | 5:4177f8012a25 | 199 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 200 | } |
wbeaumont | 4:009703f995c6 | 201 | // next is not very usefull for multiple channels |
wbeaumont | 4:009703f995c6 | 202 | if (!strcmp( cmd.cmd, "rdac")) { |
wbeaumont | 4:009703f995c6 | 203 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 4:009703f995c6 | 204 | do16=dac[cmd.con-1][cmd.devnr-1].get_dac(chc);cmd.dataout=do16;cmd.status=0; |
wbeaumont | 4:009703f995c6 | 205 | } |
wbeaumont | 4:009703f995c6 | 206 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 207 | } |
wbeaumont | 5:4177f8012a25 | 208 | if (!strcmp( cmd.cmd, "gvlt")) { |
wbeaumont | 5:4177f8012a25 | 209 | for (chc= stch ; chc < endch; chc++){ |
wbeaumont | 5:4177f8012a25 | 210 | float volt=dac[cmd.con-1][cmd.devnr-1].get_volt(chc); |
wbeaumont | 5:4177f8012a25 | 211 | float2_2u16( volt , cmd.dataout , cmd.datain); |
wbeaumont | 5:4177f8012a25 | 212 | cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 213 | } |
wbeaumont | 5:4177f8012a25 | 214 | goto DACENDCMD; |
wbeaumont | 5:4177f8012a25 | 215 | } |
wbeaumont | 4:009703f995c6 | 216 | DACENDCMD : ; |
wbeaumont | 4:009703f995c6 | 217 | }break; |
wbeaumont | 3:badf265a8898 | 218 | case TEMP : cmd.status=2; |
wbeaumont | 5:4177f8012a25 | 219 | if (!strcmp( cmd.cmd, "rtmp")){ |
wbeaumont | 5:4177f8012a25 | 220 | float temperature=temp[cmd.con-1][cmd.devnr-1].getTemperature(); |
wbeaumont | 5:4177f8012a25 | 221 | float2_2u16(temperature,cmd.dataout,cmd.datain);cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 222 | } |
wbeaumont | 3:badf265a8898 | 223 | if (!strcmp( cmd.cmd, "rtpd")){ do16=temp[cmd.con-1][cmd.devnr-1].get_T();cmd.dataout=do16;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 224 | if (!strcmp( cmd.cmd, "gtid")){ do8=temp[cmd.con-1][cmd.devnr-1].getId();cmd.dataout=do8;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 225 | if (!strcmp( cmd.cmd, "rtcr")){ do16=temp[cmd.con-1][cmd.devnr-1].get_TcritSP();cmd.dataout=do16;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 226 | 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 | 227 | if (!strcmp( cmd.cmd, "ghrv")) {do16=temp[cmd.con-1][cmd.devnr-1].getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 228 | if (!strcmp( cmd.cmd, "gscv")) {do16=temp[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 5:4177f8012a25 | 229 | if (!strcmp( cmd.cmd, "gtmp")) {do16=temp[cmd.con-1][cmd.devnr-1].getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 230 | if (!strcmp( cmd.cmd, "ini1")) { temp[cmd.con-1][cmd.devnr-1].init1();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 231 | if (!strcmp( cmd.cmd, "ini2")) { temp[cmd.con-1][cmd.devnr-1].init2();cmd.dataout=cmd.datain;cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 232 | break; |
wbeaumont | 3:badf265a8898 | 233 | case SSCM: |
wbeaumont | 3:badf265a8898 | 234 | cmd.status=2; |
wbeaumont | 4:009703f995c6 | 235 | // generate internal CAL |
wbeaumont | 4:009703f995c6 | 236 | if (!strcmp( cmd.cmd, "acal")){toggle_cal(hwl,cmd.ch );cmd.status=0;} |
wbeaumont | 5:4177f8012a25 | 237 | // set calline lvl |
wbeaumont | 5:4177f8012a25 | 238 | if (!strcmp( cmd.cmd, "scll")){set_cal_line(hwl,cmd.ch, cmd.datain );cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 239 | // heartbeat |
wbeaumont | 5:4177f8012a25 | 240 | if (!strcmp( cmd.cmd, "t_hb")) { if ( cmd.datain ==0 ) heartbeat=false; |
wbeaumont | 5:4177f8012a25 | 241 | if ( cmd.datain ==1 ) heartbeat=true; |
wbeaumont | 5:4177f8012a25 | 242 | if ( cmd.datain ==2) heartbeat=!heartbeat;cmd.status=0; |
wbeaumont | 5:4177f8012a25 | 243 | } |
wbeaumont | 4:009703f995c6 | 244 | //get main version |
wbeaumont | 3:badf265a8898 | 245 | if (!strcmp( cmd.cmd, "gmpv")) {do16=gv.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 246 | // get module serial nr |
wbeaumont | 4:009703f995c6 | 247 | if (!strcmp( cmd.cmd, "msnr")) {do8=get_serialnr(&hwl);cmd.dataout=(u16)do8; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 248 | // get version module version |
wbeaumont | 3:badf265a8898 | 249 | if (!strcmp( cmd.cmd, "gvhv")) {do16=gvc.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 250 | if (!strcmp( cmd.cmd, "gvsv")) {do16=gvc.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 251 | // get communication module version |
wbeaumont | 3:badf265a8898 | 252 | if (!strcmp( cmd.cmd, "gchv")) {do16=gvsscm.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 3:badf265a8898 | 253 | if (!strcmp( cmd.cmd, "gcsv")) {do16=gvsscm.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 254 | // get spi module version |
wbeaumont | 4:009703f995c6 | 255 | if (!strcmp( cmd.cmd, "gshv")) {do16=spi.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 256 | if (!strcmp( cmd.cmd, "gssv")) {do16=spi.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 257 | // get bispi module version |
wbeaumont | 4:009703f995c6 | 258 | if (!strcmp( cmd.cmd, "gbhv")) {do16=spi_adc.getHdrVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 259 | if (!strcmp( cmd.cmd, "gbsv")) {do16=spi_adc.getSrcVersion();cmd.dataout=do16; cmd.status=0;} |
wbeaumont | 4:009703f995c6 | 260 | |
wbeaumont | 4:009703f995c6 | 261 | |
wbeaumont | 3:badf265a8898 | 262 | |
wbeaumont | 1:f792767b2223 | 263 | break; |
wbeaumont | 1:f792767b2223 | 264 | default : cmd.status=1; |
wbeaumont | 1:f792767b2223 | 265 | break; |
wbeaumont | 1:f792767b2223 | 266 | } // end switch |
wbeaumont | 4:009703f995c6 | 267 | encode_cmd ( cmdoutstr, &cmd); |
wbeaumont | 0:dcd70d1b89b1 | 268 | pc.printf( "%s", cmdoutstr); |
wbeaumont | 0:dcd70d1b89b1 | 269 | }//end if cmdready |
wbeaumont | 0:dcd70d1b89b1 | 270 | else { |
wbeaumont | 1:f792767b2223 | 271 | if ( heartbeat) printf( "%03d>%s\n\r",(i++ % 1000),cmdin); |
wbeaumont | 0:dcd70d1b89b1 | 272 | } |
wbeaumont | 0:dcd70d1b89b1 | 273 | }// end while |
wbeaumont | 0:dcd70d1b89b1 | 274 | |
wbeaumont | 0:dcd70d1b89b1 | 275 | } |