Communication for solid slow control.

Fork of sscm_comm by wimbeaumont Project

sscm_comm.cpp

Committer:
wbeaumont
Date:
2014-09-23
Revision:
1:288db0531b1f
Parent:
0:2afae79ea9ca
Child:
2:1f9887337a1b

File content as of revision 1:288db0531b1f:


#include "mbed.h"
#include "sscm_comm.h"


#define SSCM_LIB_SRC_VERSION "1.01"

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;
else { 
    part[0]=input[4];part[1]=input[5];part[2]=0;sc->con = (u8)strtol(part, NULL, 16);
    if( input[6] != SEP ) rv= -2;
    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 { 
         sc->cmd[0]=input[10];sc->cmd[1]=input[11];sc->cmd[2]=input[12];sc->cmd[3]=input[13];
         if( input[14] != SEP ) rv= -4;   
         else {      
            part[0]=input[15];part[1]=input[16];part[2]=0;sc->ch = (u8)strtol(part, NULL, 16);
            if( input[17] != SEP ) rv= -5;
            else{
                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);
                if( input[22] != SEP ) rv= -6;
            else {
                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);
                if( input[26] != SEP ) rv= -7;
                else rv=0;
                
      }  } }  } }} 
for( int i=0;i<27;i++) input[i]=0;

return rv;
}

void sscm_comm::encode_cmd ( char *output , ssc_cmd *sc) {
    sprintf(output,"%c%02X%c%02X%c%02X%c%c%c%c%c%c%02X%c%04X%c%04X%c%c",
        CMDSTART,sc->module,SEP,sc->con,SEP,sc->dev,SEP,sc->cmd[0],sc->cmd[1],sc->cmd[2],sc->cmd[3],
        SEP,sc->ch,SEP,sc->datain,SEP,sc->dataout,SEP,CMDSTOP);
    }
    
    
 void sscm_comm::getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr ){
    // to be implemented  
    modulenr=0;
    

}