functions for the communication between SOLID slow control modules and Cprograms

Dependents:   sscm SPItest sscm

Revision:
3:e9053e5e7175
Parent:
2:1f9887337a1b
Child:
4:66d1a4200f67
diff -r 1f9887337a1b -r e9053e5e7175 sscm_comm.cpp
--- a/sscm_comm.cpp	Wed Sep 24 09:12:42 2014 +0000
+++ b/sscm_comm.cpp	Wed Sep 24 10:29:42 2014 +0000
@@ -8,7 +8,7 @@
 #include "sscm_comm.h"
 
 
-#define SSCM_LIB_SRC_VERSION "1.20"
+#define SSCM_LIB_SRC_VERSION "1.31"
 
 using namespace sscm_comm;
 
@@ -30,7 +30,7 @@
             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[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);
@@ -54,18 +54,19 @@
      
      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;
          default     :    rv=1;
          
          
                    }
-     return rv; 
+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%c",
+    sprintf(output,"%c%02X%c%02X%c%02X%c%02X%c%c%c%c%c%c%02X%c%04X%c%04X%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,CMDSTOP);
     }