functions for the communication between SOLID slow control modules and Cprograms

Dependents:   sscm SPItest sscm

Committer:
wbeaumont
Date:
Tue Sep 23 19:21:20 2014 +0000
Revision:
0:2afae79ea9ca
Child:
1:288db0531b1f
functions to be used for the communication between the SOLID slow control module and C programs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wbeaumont 0:2afae79ea9ca 1 #include sscm_comm.h
wbeaumont 0:2afae79ea9ca 2
wbeaumont 0:2afae79ea9ca 3
wbeaumont 0:2afae79ea9ca 4 #define SSCM_LIB_SRC_VERSION "1.00"
wbeaumont 0:2afae79ea9ca 5
wbeaumont 0:2afae79ea9ca 6 using namespace sscm_comm
wbeaumont 0:2afae79ea9ca 7
wbeaumont 0:2afae79ea9ca 8 int sscm_comm::decode_cmd(char* input, ssc_cmd * sc){
wbeaumont 0:2afae79ea9ca 9 char part[6];
wbeaumont 0:2afae79ea9ca 10 int rv=0;
wbeaumont 0:2afae79ea9ca 11
wbeaumont 0:2afae79ea9ca 12 part[0]=input[0];part[1]=input[1];part[2]=0;sc->module = (u8)strtol(part, NULL, 16);
wbeaumont 0:2afae79ea9ca 13 if( input[3] != SEP ) rv =-1;
wbeaumont 0:2afae79ea9ca 14 else {
wbeaumont 0:2afae79ea9ca 15 part[0]=input[4];part[1]=input[5];part[2]=0;sc->con = (u8)strtol(part, NULL, 16);
wbeaumont 0:2afae79ea9ca 16 if( input[6] != SEP ) rv= -2;
wbeaumont 0:2afae79ea9ca 17 else {
wbeaumont 0:2afae79ea9ca 18 part[0]=input[7];part[1]=input[8];part[2]=0;sc->dev = (ssc_dev)strtol(part, NULL, 16);
wbeaumont 0:2afae79ea9ca 19 if( input[9] != SEP ) rv= -3;
wbeaumont 0:2afae79ea9ca 20 else {
wbeaumont 0:2afae79ea9ca 21 sc->cmd[0]=input[10];sc->cmd[1]=input[11];sc->cmd[2]=input[12];sc->cmd[3]=input[13];
wbeaumont 0:2afae79ea9ca 22 if( input[14] != SEP ) rv= -4;
wbeaumont 0:2afae79ea9ca 23 else {
wbeaumont 0:2afae79ea9ca 24 part[0]=input[15];part[1]=input[16];part[2]=0;sc->ch = (u8)strtol(part, NULL, 16);
wbeaumont 0:2afae79ea9ca 25 if( input[17] != SEP ) rv= -5;
wbeaumont 0:2afae79ea9ca 26 else{
wbeaumont 0:2afae79ea9ca 27 part[0]=input[18];part[1]=input[19];part[2]=input[20];part[3]=input[21];part[4]=0;sc->datain = (u32)strtol(part, NULL, 16);
wbeaumont 0:2afae79ea9ca 28 if( input[22] != SEP ) rv= -6;
wbeaumont 0:2afae79ea9ca 29 else {
wbeaumont 0:2afae79ea9ca 30 part[0]=input[23];part[1]=input[24];part[2]=input[25];part[3]=input[26];part[4]=0;sc->dataout = (u32)strtol(part, NULL, 16);
wbeaumont 0:2afae79ea9ca 31 if( input[26] != SEP ) rv= -7;
wbeaumont 0:2afae79ea9ca 32 else rv=0;
wbeaumont 0:2afae79ea9ca 33
wbeaumont 0:2afae79ea9ca 34 } } } } }}
wbeaumont 0:2afae79ea9ca 35 for( int i=0;i<27;i++) input[i]=0;
wbeaumont 0:2afae79ea9ca 36
wbeaumont 0:2afae79ea9ca 37 return rv;
wbeaumont 0:2afae79ea9ca 38 }
wbeaumont 0:2afae79ea9ca 39
wbeaumont 0:2afae79ea9ca 40 void sscm_comm::encode_cmd ( char *output , ssc_cmd *sc) {
wbeaumont 0:2afae79ea9ca 41 sprintf(output,"%c%02X%c%02X%c%02X%c%c%c%c%c%c%02X%c%04X%c%04X%c%c",
wbeaumont 0:2afae79ea9ca 42 CMDSTART,sc->module,SEP,sc->con,SEP,sc->dev,SEP,sc->cmd[0],sc->cmd[1],sc->cmd[2],sc->cmd[3],
wbeaumont 0:2afae79ea9ca 43 SEP,sc->ch,SEP,sc->datain,SEP,sc->dataout,SEP,CMDSTOP);
wbeaumont 0:2afae79ea9ca 44 }
wbeaumont 0:2afae79ea9ca 45
wbeaumont 0:2afae79ea9ca 46
wbeaumont 0:2afae79ea9ca 47 void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr ){
wbeaumont 0:2afae79ea9ca 48 // to be implemented
wbeaumont 0:2afae79ea9ca 49
wbeaumont 0:2afae79ea9ca 50 }