Communication for solid slow control.

Fork of sscm_comm by wimbeaumont Project

Committer:
wbeaumont
Date:
Tue Sep 23 19:40:46 2014 +0000
Revision:
1:288db0531b1f
Parent:
0:2afae79ea9ca
Child:
2:1f9887337a1b
syntax corrections

Who changed what in which revision?

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