functions for the communication between SOLID slow control modules and Cprograms

Dependents:   sscm SPItest sscm

Committer:
wbeaumont
Date:
Fri Oct 23 11:22:36 2015 +0000
Revision:
12:cf007e9619e1
Parent:
11:1fb5d6810b29
production version archiving

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wbeaumont 0:2afae79ea9ca 1 #ifndef SSCM_COMM_H
wbeaumont 0:2afae79ea9ca 2 #define SSCM_COMM_H
wbeaumont 1:288db0531b1f 3 /*
wbeaumont 5:357fa8928d63 4 * v 1.01 inital published , tested
wbeaumont 5:357fa8928d63 5 * v 1.20 added devnr, added range checking
wbeaumont 5:357fa8928d63 6 * v 1.30 added \0 to cmd field
wbeaumont 5:357fa8928d63 7 * v 1.40 added status in cmd , added SSCM as device
wbeaumont 5:357fa8928d63 8 * v 2.00 corrected the type for data in data out
wbeaumont 6:d9a96735d0fb 9 * v 3.00 added x, y , removed ch (replaced by x
wbeaumont 7:6d3c421026df 10 * v 3.01 corrected name SSCCM to SSCM
wbeaumont 7:6d3c421026df 11 * v 3.20 added version functions
wbeaumont 7:6d3c421026df 12 * v 3.30 version functions moved to getVersion class
wbeaumont 8:ff6ba217a089 13 * v 3.40 added fdatain and fdataout for float communication
wbeaumont 11:1fb5d6810b29 14 * v 3.41 removed fdataout , renamed fdatain to fdata
wbeaumont 12:cf007e9619e1 15 *
wbeaumont 12:cf007e9619e1 16 * (C) Wim Beaumont Univeristeit Antwerpen 2014 , 2015
wbeaumont 1:288db0531b1f 17 */
wbeaumont 0:2afae79ea9ca 18
wbeaumont 11:1fb5d6810b29 19 #define SSCM_COMM_LIB_HDR_VERSION "3.41"
wbeaumont 7:6d3c421026df 20
wbeaumont 7:6d3c421026df 21 #include "getVersion.h"
wbeaumont 0:2afae79ea9ca 22
wbeaumont 0:2afae79ea9ca 23
wbeaumont 7:6d3c421026df 24 namespace sscm_comm {
wbeaumont 0:2afae79ea9ca 25 //public :
wbeaumont 0:2afae79ea9ca 26
wbeaumont 7:6d3c421026df 27 enum ssc_dev{ ADC=1, DAC=2, TEMP=3,SSCM=4};
wbeaumont 0:2afae79ea9ca 28 typedef unsigned char u8;
wbeaumont 5:357fa8928d63 29 typedef unsigned short u16;
wbeaumont 0:2afae79ea9ca 30 typedef struct {
wbeaumont 0:2afae79ea9ca 31 u8 module; // 1 char 0 --F
wbeaumont 0:2afae79ea9ca 32 u8 con; // 1 char 0--2
wbeaumont 0:2afae79ea9ca 33 ssc_dev dev; // 2 char 01--03
wbeaumont 2:1f9887337a1b 34 u8 devnr;
wbeaumont 6:d9a96735d0fb 35 char cmd[5]; // 4 char + \0
wbeaumont 6:d9a96735d0fb 36 u8 ch; // identify the channel or register address for the firmware
wbeaumont 6:d9a96735d0fb 37 u8 x; // char 00 -- 32 x coordinate MPPC not used for the firmware ,so not coded in the string
wbeaumont 6:d9a96735d0fb 38 u8 y; // y coordinate MPPC not used for the communication to the SSCM y coordinate MPPC
wbeaumont 5:357fa8928d63 39 u16 datain; // 2 char 0000 -- FFFF
wbeaumont 5:357fa8928d63 40 u16 dataout;// 2 char 00 -- FF
wbeaumont 11:1fb5d6810b29 41 float fdata ;
wbeaumont 4:66d1a4200f67 42 u8 status;
wbeaumont 0:2afae79ea9ca 43 } ssc_cmd;
wbeaumont 0:2afae79ea9ca 44
wbeaumont 0:2afae79ea9ca 45 const char CMDSTART= '$';
wbeaumont 0:2afae79ea9ca 46 const char CMDSTOP= '#';
wbeaumont 0:2afae79ea9ca 47 const char SEP= ';';
wbeaumont 0:2afae79ea9ca 48
wbeaumont 0:2afae79ea9ca 49 // decode the string sent to the uP to the original cmd structure , for the moment the input string is cleared
wbeaumont 0:2afae79ea9ca 50 // param input : input string at least char [30]
wbeaumont 0:2afae79ea9ca 51 // param ssc_cmd the cmd structure to be filled
wbeaumont 0:2afae79ea9ca 52 int decode_cmd(char* input, ssc_cmd * sc);
wbeaumont 0:2afae79ea9ca 53
wbeaumont 0:2afae79ea9ca 54
wbeaumont 0:2afae79ea9ca 55 // param output the string to be sent to the SSCM
wbeaumont 0:2afae79ea9ca 56 // param sc the cmd to be sent to the SSCM
wbeaumont 0:2afae79ea9ca 57 void encode_cmd ( char *output , ssc_cmd *sc);
wbeaumont 0:2afae79ea9ca 58
wbeaumont 0:2afae79ea9ca 59 // to get info of the module nr , connector serial number for a given plane
wbeaumont 0:2afae79ea9ca 60 // param plane plane nr for which the cmd coordinates has to be known
wbeaumont 0:2afae79ea9ca 61 // param modulenr the module nr ( first nr in the cmd structure
wbeaumont 0:2afae79ea9ca 62 // param connr connector number ( 1 or 2)
wbeaumont 0:2afae79ea9ca 63 // param serailnr the serial nr of the board ( can be used for verification) .
wbeaumont 0:2afae79ea9ca 64
wbeaumont 0:2afae79ea9ca 65 void getmodulecordinate(u8 plane, u8& modulenr, u8& connr ,u8& serialnr );
wbeaumont 6:d9a96735d0fb 66 void get_mppc_dac_chnr(u8 plane, u8 x , u8 y, u8& ch,u8& modulenr, u8& connr ,u8&dacch, u8& serialnr );
wbeaumont 6:d9a96735d0fb 67 void get_mppc_adc_chnr(u8 plane, u8 x , u8 y, u8& ch,u8& modulenr, u8& connr , u8& adcdevnr, u8& adcchnr , u8& serialnr );
wbeaumont 2:1f9887337a1b 68 // check if ranges are correct
wbeaumont 2:1f9887337a1b 69 // v 1.20 only check ADC devnr range broadcast not supported
wbeaumont 2:1f9887337a1b 70 int check_ranges( ssc_cmd* sc );
wbeaumont 7:6d3c421026df 71
wbeaumont 7:6d3c421026df 72 // returns the version and sub version nr.
wbeaumont 7:6d3c421026df 73 // param hexversion : 16 bits MSB byt contains the version nr, LSB byte contains the subversion nr (hex)
wbeaumont 7:6d3c421026df 74 // param version : will be set to the version
wbeaumont 7:6d3c421026df 75 // param subversion : will be set to the subversion
wbeaumont 7:6d3c421026df 76 void get_dec_version( u16 hexversion , u8& version, u8& subversion);
wbeaumont 7:6d3c421026df 77
wbeaumont 7:6d3c421026df 78 // reuse vesion class
wbeaumont 2:1f9887337a1b 79
wbeaumont 7:6d3c421026df 80 class getsscmVersion:
wbeaumont 7:6d3c421026df 81 public getVersion
wbeaumont 0:2afae79ea9ca 82
wbeaumont 7:6d3c421026df 83 {
wbeaumont 7:6d3c421026df 84 public: getsscmVersion() ;
wbeaumont 7:6d3c421026df 85 };
wbeaumont 0:2afae79ea9ca 86
wbeaumont 10:0675c2e3d330 87
wbeaumont 10:0675c2e3d330 88 void float2_2u16( float in, u16& msb, u16& lsb);
wbeaumont 10:0675c2e3d330 89
wbeaumont 10:0675c2e3d330 90 float u162float( u16 msb, u16 lsb);
wbeaumont 10:0675c2e3d330 91
wbeaumont 10:0675c2e3d330 92
wbeaumont 7:6d3c421026df 93 };
wbeaumont 0:2afae79ea9ca 94 #endif