Communication for solid slow control.

Fork of sscm_comm by wimbeaumont Project

Committer:
wbeaumont
Date:
Thu Oct 02 10:47:18 2014 +0000
Revision:
5:357fa8928d63
Parent:
4:66d1a4200f67
Child:
6:d9a96735d0fb
changed to u16 format for datain dataout

Who changed what in which revision?

UserRevisionLine numberNew 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 5:357fa8928d63 11 #define SSCM_LIB_SRC_VERSION "2.00"
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 5:357fa8928d63 22 u16 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 5:357fa8928d63 39 part[0]=input[ic++];part[1]=input[ic++];part[2]=input[ic++];part[3]=input[ic++];part[4]=0;sc->datain = (u16)strtol(part, NULL, 16);
wbeaumont 2:1f9887337a1b 40 if( input[ic++] != SEP ) rv= -6;
wbeaumont 0:2afae79ea9ca 41 else {
wbeaumont 5:357fa8928d63 42 part[0]=input[ic++];part[1]=input[ic++];part[2]=input[ic++];part[3]=input[ic++];part[4]=0;sc->dataout = (u16)strtol(part, NULL, 16);
wbeaumont 2:1f9887337a1b 43 if( input[ic++] != SEP ) rv= -7;
wbeaumont 4:66d1a4200f67 44 else {
wbeaumont 4:66d1a4200f67 45 part[0]=input[ic++];part[1]=input[ic++];part[4]=0;sc->status = (u8)strtol(part, NULL, 16);
wbeaumont 4:66d1a4200f67 46 if( input[ic++] != SEP ) rv= -8;
wbeaumont 0:2afae79ea9ca 47 else rv=0;
wbeaumont 0:2afae79ea9ca 48
wbeaumont 4:66d1a4200f67 49 } } } } }} } }
wbeaumont 2:1f9887337a1b 50 int crr=check_ranges( sc); if ( crr < 0 ) rv=crr ;
wbeaumont 0:2afae79ea9ca 51 for( int i=0;i<27;i++) input[i]=0;
wbeaumont 0:2afae79ea9ca 52
wbeaumont 0:2afae79ea9ca 53 return rv;
wbeaumont 0:2afae79ea9ca 54 }
wbeaumont 0:2afae79ea9ca 55
wbeaumont 2:1f9887337a1b 56 int sscm_comm::check_ranges( ssc_cmd* sc ){
wbeaumont 2:1f9887337a1b 57
wbeaumont 2:1f9887337a1b 58 int rv =1; // no check done
wbeaumont 2:1f9887337a1b 59 // devnr check
wbeaumont 3:e9053e5e7175 60 if ( sc->con <1 || sc->con >2 ){ rv= -43; goto RVOUT;}
wbeaumont 2:1f9887337a1b 61 switch ( sc->dev) {
wbeaumont 2:1f9887337a1b 62 case ADC : if(sc->devnr < 1 || sc->devnr > 2 ) rv=-23; break;
wbeaumont 2:1f9887337a1b 63 default : rv=1;
wbeaumont 2:1f9887337a1b 64
wbeaumont 2:1f9887337a1b 65
wbeaumont 2:1f9887337a1b 66 }
wbeaumont 3:e9053e5e7175 67 RVOUT: return rv;
wbeaumont 2:1f9887337a1b 68
wbeaumont 2:1f9887337a1b 69 }
wbeaumont 2:1f9887337a1b 70
wbeaumont 0:2afae79ea9ca 71 void sscm_comm::encode_cmd ( char *output , ssc_cmd *sc) {
wbeaumont 4:66d1a4200f67 72 sprintf(output,"%c%02X%c%02X%c%02X%c%02X%c%c%c%c%c%c%02X%c%04X%c%04X%c%02X%c%c\0",
wbeaumont 2:1f9887337a1b 73 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 4:66d1a4200f67 74 SEP,sc->ch,SEP,sc->datain,SEP,sc->dataout,SEP,sc->status,SEP,CMDSTOP);
wbeaumont 0:2afae79ea9ca 75 }
wbeaumont 0:2afae79ea9ca 76
wbeaumont 0:2afae79ea9ca 77
wbeaumont 0:2afae79ea9ca 78 void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr ){
wbeaumont 1:288db0531b1f 79 // to be implemented
wbeaumont 1:288db0531b1f 80 modulenr=0;
wbeaumont 1:288db0531b1f 81
wbeaumont 0:2afae79ea9ca 82
wbeaumont 0:2afae79ea9ca 83 }