functions for the communication between SOLID slow control modules and Cprograms
sscm_comm.cpp@3:e9053e5e7175, 2014-09-24 (annotated)
- Committer:
- wbeaumont
- Date:
- Wed Sep 24 10:29:42 2014 +0000
- Revision:
- 3:e9053e5e7175
- Parent:
- 2:1f9887337a1b
- Child:
- 4:66d1a4200f67
added /0 to cmd , check connector range
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 2:1f9887337a1b | 1 | #if defined (TARGET_KL25Z) |
wbeaumont | 2:1f9887337a1b | 2 | // in mbed problems to call strtol |
wbeaumont | 2:1f9887337a1b | 3 | #include "mbed.h" // for the strtol |
wbeaumont | 2:1f9887337a1b | 4 | #else |
wbeaumont | 2:1f9887337a1b | 5 | #include <stlib.h> // for the strtol |
wbeaumont | 2:1f9887337a1b | 6 | #endif |
wbeaumont | 1:288db0531b1f | 7 | |
wbeaumont | 1:288db0531b1f | 8 | #include "sscm_comm.h" |
wbeaumont | 0:2afae79ea9ca | 9 | |
wbeaumont | 0:2afae79ea9ca | 10 | |
wbeaumont | 3:e9053e5e7175 | 11 | #define SSCM_LIB_SRC_VERSION "1.31" |
wbeaumont | 0:2afae79ea9ca | 12 | |
wbeaumont | 1:288db0531b1f | 13 | using namespace sscm_comm; |
wbeaumont | 0:2afae79ea9ca | 14 | |
wbeaumont | 0:2afae79ea9ca | 15 | int sscm_comm::decode_cmd(char* input, ssc_cmd * sc){ |
wbeaumont | 0:2afae79ea9ca | 16 | char part[6]; |
wbeaumont | 0:2afae79ea9ca | 17 | int rv=0; |
wbeaumont | 0:2afae79ea9ca | 18 | |
wbeaumont | 0:2afae79ea9ca | 19 | part[0]=input[0];part[1]=input[1];part[2]=0;sc->module = (u8)strtol(part, NULL, 16); |
wbeaumont | 2:1f9887337a1b | 20 | if( input[3] != SEP ) rv =-1; // tbd check for module range |
wbeaumont | 0:2afae79ea9ca | 21 | else { |
wbeaumont | 2:1f9887337a1b | 22 | u32 ic;//input counter |
wbeaumont | 0:2afae79ea9ca | 23 | part[0]=input[4];part[1]=input[5];part[2]=0;sc->con = (u8)strtol(part, NULL, 16); |
wbeaumont | 2:1f9887337a1b | 24 | if( input[6] != SEP ) rv= -2; // tbd check for connector range |
wbeaumont | 0:2afae79ea9ca | 25 | else { |
wbeaumont | 0:2afae79ea9ca | 26 | part[0]=input[7];part[1]=input[8];part[2]=0;sc->dev = (ssc_dev)strtol(part, NULL, 16); |
wbeaumont | 0:2afae79ea9ca | 27 | if( input[9] != SEP ) rv= -3; |
wbeaumont | 2:1f9887337a1b | 28 | else { ic=10; |
wbeaumont | 2:1f9887337a1b | 29 | part[0]=input[ic++];part[1]=input[ic++];part[2]=0;sc->devnr = (u8)strtol(part, NULL, 16); |
wbeaumont | 2:1f9887337a1b | 30 | if( input[ic++] != SEP ) rv= -9; |
wbeaumont | 2:1f9887337a1b | 31 | |
wbeaumont | 2:1f9887337a1b | 32 | else { |
wbeaumont | 3:e9053e5e7175 | 33 | sc->cmd[0]=input[ic++];sc->cmd[1]=input[ic++];sc->cmd[2]=input[ic++];sc->cmd[3]=input[ic++];sc->cmd[4]='\0'; |
wbeaumont | 2:1f9887337a1b | 34 | if( input[ic++] != SEP ) rv= -4; |
wbeaumont | 2:1f9887337a1b | 35 | else { |
wbeaumont | 2:1f9887337a1b | 36 | part[0]=input[ic++];part[1]=input[ic++];part[2]=0;sc->ch = (u8)strtol(part, NULL, 16); |
wbeaumont | 2:1f9887337a1b | 37 | if( input[ic++] != SEP ) rv= -5; |
wbeaumont | 0:2afae79ea9ca | 38 | else{ |
wbeaumont | 2:1f9887337a1b | 39 | part[0]=input[ic++];part[1]=input[ic++];part[2]=input[ic++];part[3]=input[ic++];part[4]=0;sc->datain = (u32)strtol(part, NULL, 16); |
wbeaumont | 2:1f9887337a1b | 40 | if( input[ic++] != SEP ) rv= -6; |
wbeaumont | 0:2afae79ea9ca | 41 | else { |
wbeaumont | 2:1f9887337a1b | 42 | part[0]=input[ic++];part[1]=input[ic++];part[2]=input[ic++];part[3]=input[ic++];part[4]=0;sc->dataout = (u32)strtol(part, NULL, 16); |
wbeaumont | 2:1f9887337a1b | 43 | if( input[ic++] != SEP ) rv= -7; |
wbeaumont | 0:2afae79ea9ca | 44 | else rv=0; |
wbeaumont | 0:2afae79ea9ca | 45 | |
wbeaumont | 2:1f9887337a1b | 46 | } } } } }} } |
wbeaumont | 2:1f9887337a1b | 47 | int crr=check_ranges( sc); if ( crr < 0 ) rv=crr ; |
wbeaumont | 0:2afae79ea9ca | 48 | for( int i=0;i<27;i++) input[i]=0; |
wbeaumont | 0:2afae79ea9ca | 49 | |
wbeaumont | 0:2afae79ea9ca | 50 | return rv; |
wbeaumont | 0:2afae79ea9ca | 51 | } |
wbeaumont | 0:2afae79ea9ca | 52 | |
wbeaumont | 2:1f9887337a1b | 53 | int sscm_comm::check_ranges( ssc_cmd* sc ){ |
wbeaumont | 2:1f9887337a1b | 54 | |
wbeaumont | 2:1f9887337a1b | 55 | int rv =1; // no check done |
wbeaumont | 2:1f9887337a1b | 56 | // devnr check |
wbeaumont | 3:e9053e5e7175 | 57 | if ( sc->con <1 || sc->con >2 ){ rv= -43; goto RVOUT;} |
wbeaumont | 2:1f9887337a1b | 58 | switch ( sc->dev) { |
wbeaumont | 2:1f9887337a1b | 59 | case ADC : if(sc->devnr < 1 || sc->devnr > 2 ) rv=-23; break; |
wbeaumont | 2:1f9887337a1b | 60 | default : rv=1; |
wbeaumont | 2:1f9887337a1b | 61 | |
wbeaumont | 2:1f9887337a1b | 62 | |
wbeaumont | 2:1f9887337a1b | 63 | } |
wbeaumont | 3:e9053e5e7175 | 64 | RVOUT: return rv; |
wbeaumont | 2:1f9887337a1b | 65 | |
wbeaumont | 2:1f9887337a1b | 66 | } |
wbeaumont | 2:1f9887337a1b | 67 | |
wbeaumont | 0:2afae79ea9ca | 68 | void sscm_comm::encode_cmd ( char *output , ssc_cmd *sc) { |
wbeaumont | 3:e9053e5e7175 | 69 | sprintf(output,"%c%02X%c%02X%c%02X%c%02X%c%c%c%c%c%c%02X%c%04X%c%04X%c%c\0", |
wbeaumont | 2:1f9887337a1b | 70 | CMDSTART,sc->module,SEP,sc->con,SEP,sc->dev,SEP,sc->devnr,SEP,sc->cmd[0],sc->cmd[1],sc->cmd[2],sc->cmd[3], |
wbeaumont | 0:2afae79ea9ca | 71 | SEP,sc->ch,SEP,sc->datain,SEP,sc->dataout,SEP,CMDSTOP); |
wbeaumont | 0:2afae79ea9ca | 72 | } |
wbeaumont | 0:2afae79ea9ca | 73 | |
wbeaumont | 0:2afae79ea9ca | 74 | |
wbeaumont | 0:2afae79ea9ca | 75 | void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr ){ |
wbeaumont | 1:288db0531b1f | 76 | // to be implemented |
wbeaumont | 1:288db0531b1f | 77 | modulenr=0; |
wbeaumont | 1:288db0531b1f | 78 | |
wbeaumont | 0:2afae79ea9ca | 79 | |
wbeaumont | 0:2afae79ea9ca | 80 | } |