Communication for solid slow control.

Fork of sscm_comm by wimbeaumont Project

Files at this revision

API Documentation at this revision

Comitter:
NickRyder
Date:
Tue Oct 07 22:51:01 2014 +0000
Parent:
7:6d3c421026df
Commit message:
I must have tidied the sscm_comm library elsewhere.

Changed in this revision

sscm_comm.cpp Show annotated file Show diff for this revision Revisions of this file
sscm_comm.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6d3c421026df -r a68c382dea12 sscm_comm.cpp
--- a/sscm_comm.cpp	Sun Oct 05 17:11:51 2014 +0000
+++ b/sscm_comm.cpp	Tue Oct 07 22:51:01 2014 +0000
@@ -13,89 +13,156 @@
 using namespace sscm_comm;
 
 int  sscm_comm::decode_cmd(char* input, ssc_cmd * sc){
-char part[6];
-int rv=0;
-
-part[0]=input[0];part[1]=input[1];part[2]=0;sc->module = (u8)strtol(part, NULL, 16);
-if( input[3] != SEP ) rv =-1;  // tbd check for module range
-else { 
-    u16 ic;//input counter
-    part[0]=input[4];part[1]=input[5];part[2]=0;sc->con = (u8)strtol(part, NULL, 16);
-    if( input[6] != SEP ) rv= -2;  // tbd check for connector range 
-    else {
-        part[0]=input[7];part[1]=input[8];part[2]=0;sc->dev = (ssc_dev)strtol(part, NULL, 16);
-        if( input[9] != SEP ) rv= -3;
-        else { ic=10;
-            part[0]=input[ic++];part[1]=input[ic++];part[2]=0;sc->devnr = (u8)strtol(part, NULL, 16);
-            if( input[ic++] != SEP ) rv= -9;
-            
-            else {
-              sc->cmd[0]=input[ic++];sc->cmd[1]=input[ic++];sc->cmd[2]=input[ic++];sc->cmd[3]=input[ic++];sc->cmd[4]='\0';
-             if( input[ic++] != SEP ) rv= -4;   
-                else {      
-            part[0]=input[ic++];part[1]=input[ic++];part[2]=0;sc->ch = (u8)strtol(part, NULL, 16);
-            if( input[ic++] != SEP ) rv= -5;
-            else{
-                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);
-                if( input[ic++] != SEP ) rv= -6;
-            else {
-                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);
-                if( input[ic++] != SEP ) rv= -7;
-            else {
-                part[0]=input[ic++];part[1]=input[ic++];part[4]=0;sc->status = (u8)strtol(part, NULL, 16);
-                if( input[ic++] != SEP ) rv= -8;
-                else rv=0;
-                
-      }  } }  } }} } }
-      int crr=check_ranges( sc);  if ( crr < 0 ) rv=crr ;
-for( int i=0;i<27;i++) input[i]=0;
-
-return rv;
+    char part[6];
+    int rv = 0;
+    part[0] = input[0];
+    part[1] = input[1];
+    part[2] = 0;
+    sc->module = (u8) strtol(part, NULL, 16);
+    if(input[3] != SEP) {
+        rv =-1;  // tbd check for module range
+    } else { 
+        u16 ic;//input counter
+        part[0] = input[4];
+        part[1] = input[5];
+        part[2] = 0;
+        sc->con = (u8) strtol(part, NULL, 16);
+        if(input[6] != SEP) {
+            rv = -2;  // tbd check for connector range 
+        } else {
+            part[0] = input[7];
+            part[1] = input[8];
+            part[2] = 0;
+            sc->dev = (ssc_dev) strtol(part, NULL, 16);
+            if (input[9] != SEP) {
+                rv = -3;
+            } else {
+                ic = 10;
+                part[0] = input[ic++];
+                part[1] = input[ic++];
+                part[2] = 0;
+                sc->devnr = (u8) strtol(part, NULL, 16);
+                if (input[ic++] != SEP) {
+                    rv = -9;
+                } else {
+                    sc->cmd[0] = input[ic++];
+                    sc->cmd[1] = input[ic++];
+                    sc->cmd[2] = input[ic++];
+                    sc->cmd[3] = input[ic++];
+                    sc->cmd[4] = '\0';
+                    if (input[ic++] != SEP) {
+                        rv = -4;   
+                    } else {      
+                        part[0] = input[ic++];
+                        part[1] = input[ic++];
+                        part[2] = 0;
+                        sc->ch = (u8) strtol(part, NULL, 16);
+                        if (input[ic++] != SEP) {
+                            rv= -5;
+                        } else {
+                            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);
+                            if(input[ic++] != SEP)  {
+                                rv= -6;
+                            } else {
+                                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);
+                                if (input[ic++] != SEP) {
+                                    rv= -7;
+                                } else {
+                                    part[0] = input[ic++];
+                                    part[1] = input[ic++];
+                                    part[4] = 0;
+                                    sc->status = (u8) strtol(part, NULL, 16);
+                                    if (input[ic++] != SEP) {
+                                        rv = -8;
+                                    } else {
+                                        rv = 0;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    int crr = check_ranges(sc);
+    if (crr < 0) rv = crr;
+    for (int i = 0; i < 27; i++) {
+        input[i] = 0;
+    }
+    return rv;
 }
 
-int  sscm_comm::check_ranges( ssc_cmd* sc ){
-     
-     int rv =1;  // no check done 
-     // devnr check 
-        if ( sc->con <1 || sc->con >2 ){  rv= -43;  goto RVOUT;} 
-        switch ( sc->dev) {
-         case  ADC   :   if(sc->devnr < 1  ||   sc->devnr > 2 ){ rv=-23;  break; }
-         break;
-         
-         case TEMP   :  if( sc->ch <1 || sc->ch >2)  {rv =-22 ;break;}
-         break;
-         default : rv=1;
-                   }
-RVOUT:     return rv; 
-     
+int sscm_comm::check_ranges(ssc_cmd * sc) {
+    int rv = 1;  // no check done 
+    // devnr check 
+    if (sc->con < 1 || sc->con > 2) {
+        rv = -43;
+        goto RVOUT; // goto jail. Do not collect £200.
+    } 
+    switch (sc->dev) {
+         case  ADC:
+            if (sc->devnr < 1 || sc->devnr > 2) {
+                rv = -23;
+                break;
+            }
+            break;
+         case TEMP:
+            if (sc->ch < 1 || sc->ch > 2) {
+                rv = -22;
+                break;
+            }
+            break;
+         default:
+            rv = 1;
+    }
+RVOUT:
+    return rv; 
 }     
 
-void sscm_comm::encode_cmd ( char *output , ssc_cmd *sc) {
-    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",
-        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],
-        SEP,sc->ch,SEP,sc->datain,SEP,sc->dataout,SEP,sc->status,SEP,CMDSTOP);
-    }
+void sscm_comm::encode_cmd(char * output, ssc_cmd * sc) {
+    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",
+            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],
+            SEP, sc->ch, SEP, sc->datain, SEP, sc->dataout, SEP,
+            sc->status, SEP, CMDSTOP);
+}
     
-    
- void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr ){
+void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr, u8& serialnr) {
     // to be implemented  
     modulenr=0;
 }    
 
-
 /*
-
 u16 sscm_comm::getSrcVersion(){
-    return get_hex_version_nr(SSCM_COMM_LIB_SRC_VERSION );   
+    return get_hex_version_nr(SSCM_COMM_LIB_SRC_VERSION);   
 }
 
 u16 sscm_comm::getHdrVersion(){
-       return get_hex_version_nr(SSCM_COMM_LIB_HDR_VERSION );   
+    return get_hex_version_nr(SSCM_COMM_LIB_HDR_VERSION );   
 }    
 */ 
-void sscm_comm::get_mppc_dac_chnr(u8 plane,  u8 x , u8 y, u8& ch,u8& modulenr, u8& connr ,u8&dacch, u8& serialnr  ) {};
-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  ){};
+
+void sscm_comm::get_mppc_dac_chnr(u8 plane, u8 x, u8 y, u8& ch, u8& modulenr,
+                                  u8& connr, u8& dacch, u8& serialnr) {
+}
 
-
+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) {
+}
 
-sscm_comm::getsscmVersion::getsscmVersion():getVersion( SSCM_COMM_LIB_HDR_VERSION,SSCM_COMM_LIB_SRC_VERSION, __TIME__, __DATE__){};
+sscm_comm::getsscmVersion::getsscmVersion(): 
+    getVersion(SSCM_COMM_LIB_HDR_VERSION, SSCM_COMM_LIB_SRC_VERSION, __TIME__, __DATE__){
+}
diff -r 6d3c421026df -r a68c382dea12 sscm_comm.h
--- a/sscm_comm.h	Sun Oct 05 17:11:51 2014 +0000
+++ b/sscm_comm.h	Tue Oct 07 22:51:01 2014 +0000
@@ -18,66 +18,70 @@
 
 
 namespace sscm_comm    {
-//public :    
-
-enum ssc_dev{ ADC=1, DAC=2, TEMP=3,SSCM=4};
-typedef  unsigned char u8;
-typedef  unsigned short u16;
-typedef struct {
-        u8 module; // 1 char 0 --F
-        u8 con;    // 1 char 0--2
-        ssc_dev dev; // 2 char 01--03
-        u8 devnr;
-        char cmd[5]; // 4 char  + \0
-        u8 ch; //  identify the channel or register address for the firmware      
-        u8 x; //  char 00 -- 32   x coordinate MPPC   not used for the firmware ,so not coded in the string 
-        u8 y;  // y coordinate MPPC not used for the communication to the SSCM y coordinate MPPC 
-        u16 datain; // 2 char 0000 -- FFFF
-        u16 dataout;// 2 char 00 -- FF
-        u8 status;
+    //public :    
+    
+    enum ssc_dev{
+        ADC=1,
+        DAC=2,
+        TEMP=3,
+        SSCM=4
+    };
+    typedef  unsigned char u8;
+    typedef  unsigned short u16;
+    typedef struct {
+            u8 module; // 1 char 0 --F
+            u8 con;    // 1 char 0--2
+            ssc_dev dev; // 2 char 01--03
+            u8 devnr;
+            char cmd[5]; // 4 char  + \0
+            u8 ch; //  identify the channel or register address for the firmware      
+            u8 x; //  char 00 -- 32   x coordinate MPPC   not used for the firmware ,so not coded in the string 
+            u8 y;  // y coordinate MPPC not used for the communication to the SSCM y coordinate MPPC 
+            u16 datain; // 2 char 0000 -- FFFF
+            u16 dataout;// 2 char 00 -- FF
+            u8 status;
     } ssc_cmd;
-
-const char  CMDSTART= '$';
-const char  CMDSTOP= '#';
-const char SEP=  ';';
-
-// decode the string sent to the uP to the original cmd structure , for the moment the input string is cleared 
-// param input :  input string at least char [30]
-// param ssc_cmd  the cmd structure to be filled 
-int  decode_cmd(char* input, ssc_cmd * sc);
-
-
-// param output the string to be sent to the SSCM 
-// param sc the cmd to be sent to the SSCM 
-void encode_cmd ( char *output , ssc_cmd *sc);
+    
+    const char  CMDSTART= '$';
+    const char  CMDSTOP= '#';
+    const char SEP=  ';';
+    
+    // decode the string sent to the uP to the original cmd structure , for the moment the input string is cleared 
+    // param input :  input string at least char [30]
+    // param ssc_cmd  the cmd structure to be filled 
+    int decode_cmd(char * input, ssc_cmd * sc);
+    
+    // param output the string to be sent to the SSCM 
+    // param sc the cmd to be sent to the SSCM 
+    void encode_cmd(char * output, ssc_cmd *sc);
+        
+    // to get info of the module nr , connector serial number for a given plane 
+    // param  plane  plane nr for which the cmd coordinates has to be known
+    // param modulenr  the module nr  ( first nr in the cmd structure 
+    // param connr  connector number ( 1 or 2) 
+    // param serailnr  the serial nr of the board ( can be used for verification) .
     
-// to get info of the module nr , connector serial number for a given plane 
-// param  plane  plane nr for which the cmd coordinates has to be known
-// param modulenr  the module nr  ( first nr in the cmd structure 
-// param connr  connector number ( 1 or 2) 
-// param serailnr  the serial nr of the board ( can be used for verification) .
-
-void getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr );
-void get_mppc_dac_chnr(u8 plane,  u8 x , u8 y, u8& ch,u8& modulenr, u8& connr ,u8&dacch, u8& serialnr  );
-void get_mppc_adc_chnr(u8 plane,  u8 x , u8 y, u8& ch,u8& modulenr, u8& connr , u8& adcdevnr, u8& adcchnr , u8& serialnr  );
-// check if ranges are correct 
-// v 1.20  only check ADC devnr range broadcast not supported
-int  check_ranges( ssc_cmd* sc );
-
-// returns the version and sub version nr.  
-// param hexversion  : 16 bits   MSB byt contains the version nr, LSB byte contains the subversion nr (hex) 
-// param version  : will  be set to the version 
-// param subversion : will be set to the subversion 
-void get_dec_version( u16 hexversion , u8& version, u8& subversion);
-
-// reuse vesion class
-
-class getsscmVersion:
-     public  getVersion
-
-    { 
-    public: getsscmVersion()   ;
-};
+    void getmodulecordinate(u8 plane, u8& modulenr, u8& connr, u8& serialnr);
+    void get_mppc_dac_chnr(u8 plane, u8 x, u8 y, u8& ch, u8& modulenr, 
+                           u8& connr, u8&dacch, u8& serialnr);
+    void get_mppc_adc_chnr(u8 plane, u8 x, u8 y, u8& ch, u8& modulenr,
+                           u8& connr, u8& adcdevnr, u8& adcchnr, u8& serialnr);
+    // check if ranges are correct 
+    // v 1.20  only check ADC devnr range broadcast not supported
+    int check_ranges(ssc_cmd* sc);
+    
+    // returns the version and sub version nr.  
+    // param hexversion  : 16 bits   MSB byt contains the version nr, LSB byte contains the subversion nr (hex) 
+    // param version  : will  be set to the version 
+    // param subversion : will be set to the subversion 
+    void get_dec_version(u16 hexversion, u8& version, u8& subversion);
+    
+    // reuse vesion class
+    
+    class getsscmVersion: public  getVersion { 
+        public:
+            getsscmVersion();
+    };
 
 };
 #endif