Communication for solid slow control.

Fork of sscm_comm by wimbeaumont Project

Committer:
wbeaumont
Date:
Fri Oct 03 14:15:25 2014 +0000
Revision:
6:d9a96735d0fb
Parent:
5:357fa8928d63
Child:
7:6d3c421026df
added x and y field in the structure ( not to be used in the firmware , so not in the cmd string handling )  corrected some comments,  added temp ch range checking

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 6:d9a96735d0fb 11 #define SSCM_LIB_SRC_VERSION "3.01"
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 6:d9a96735d0fb 62 case ADC : if(sc->devnr < 1 || sc->devnr > 2 ){ rv=-23; break; }
wbeaumont 6:d9a96735d0fb 63 break;
wbeaumont 2:1f9887337a1b 64
wbeaumont 6:d9a96735d0fb 65 case TEMP : if( sc->ch <1 || sc->ch >2) {rv =-22 ;break;}
wbeaumont 6:d9a96735d0fb 66 break;
wbeaumont 6:d9a96735d0fb 67 default : rv=1;
wbeaumont 2:1f9887337a1b 68 }
wbeaumont 3:e9053e5e7175 69 RVOUT: return rv;
wbeaumont 2:1f9887337a1b 70
wbeaumont 2:1f9887337a1b 71 }
wbeaumont 2:1f9887337a1b 72
wbeaumont 0:2afae79ea9ca 73 void sscm_comm::encode_cmd ( char *output , ssc_cmd *sc) {
wbeaumont 4:66d1a4200f67 74 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 75 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 76 SEP,sc->ch,SEP,sc->datain,SEP,sc->dataout,SEP,sc->status,SEP,CMDSTOP);
wbeaumont 0:2afae79ea9ca 77 }
wbeaumont 0:2afae79ea9ca 78
wbeaumont 0:2afae79ea9ca 79
wbeaumont 0:2afae79ea9ca 80 void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr ){
wbeaumont 1:288db0531b1f 81 // to be implemented
wbeaumont 1:288db0531b1f 82 modulenr=0;
wbeaumont 6:d9a96735d0fb 83 }
wbeaumont 1:288db0531b1f 84
wbeaumont 6:d9a96735d0fb 85 char libversion_com[150]={'e','m','p','t','y','\0'};
wbeaumont 6:d9a96735d0fb 86
wbeaumont 0:2afae79ea9ca 87
wbeaumont 6:d9a96735d0fb 88 char* get_sscm_com_version(){
wbeaumont 6:d9a96735d0fb 89 sprintf(libversion_com,"sscmhw namespacelib versions src : %s header: %s date:%s %s \n\r",
wbeaumont 6:d9a96735d0fb 90 SSCM_LIB_SRC_VERSION,SSCM_COMM_LIB_HDR_VERSION , __DATE__,__TIME__);
wbeaumont 6:d9a96735d0fb 91 return libversion_com;
wbeaumont 6:d9a96735d0fb 92
wbeaumont 0:2afae79ea9ca 93 }
wbeaumont 6:d9a96735d0fb 94
wbeaumont 6:d9a96735d0fb 95
wbeaumont 6:d9a96735d0fb 96
wbeaumont 6:d9a96735d0fb 97 void sscm_comm::get_mppc_dac_chnr(u8 plane, u8 x , u8 y, u8& ch,u8& modulenr, u8& connr ,u8&dacch, u8& serialnr ) {};
wbeaumont 6:d9a96735d0fb 98 void sscm_comm::get_mppc_adc_chnr(u8 plane, u8 x , u8 y, u8& ch,u8& modulenr, u8& connr , u8& adcdevnr, u8& adcchnr , u8& serialnr ){};