#include "unitsimulator.h" #include #include "xlru_bytes_def.h" #include "xlru_lcu.h" uint8_t LCU_Status_byte[5] = {0, 0, 0, 0, 0}; uint8_t PPS_Status_byte[6] = {0, 0, 0, 0, 0, 0}; uint8_t PSM_Status_byte[4] = {0, 0, 0, 0}; //00000001 0x01 //00000010 0x02 //00000100 0x04 //00001000 0x08 //00010000 0x10 //00100000 0x20 //01000000 0x40 //10000000 0x80 //LSB #define PSM_IN_AMP_LSB (double)0.1 //DC_BUS_CURRENT measure #define PSM_OUT_VOLT_LSB (double)0.1 //5V, 3V3_int, 15V, -15V measure #define PPS_CURR_LSB (double)0.1 struct comm_header_t //5 { char som; char unit; char fcs; char comm_status; char msg_id; } __attribute__((packed)); //************************************ //PSM struct psm_status_body_t { comm_header_t header; //non corrisponde con la definizione pag 21, documento TNXXXXXX GRIFO-E PSM IDD Rev.0_Draft1.docx char sts; char hazard; char fast; char wow; char ac; char bs; char dc; char pfc; char out_rail[4]; char in_amp[2]; char volts[4][4]; char temperature[2]; char eti[4]; char counter[4]; char sw_major[2]; char sw_minor[2]; char unc_counter[2]; char byte4[2]; char byte3[2]; char byte2[2]; char byte1[2]; //char spare1[2]; char last_recycle; char last_recycle_reason; //char spare1; //55 } __attribute__((packed)); //************************************ //PPS struct pps_status_body_t { comm_header_t header; //5 char sts; char health; char wow; char hazard; char current_limit; char hold_up_status[2]; char rx_board[2]; char tx1_board[2]; char tx2_board[2]; char tx3_board[2]; char general[2]; char rx_version[2]; char rx_release[2]; char tx1_version[2]; char tx1_release[2]; char tx2_version[2]; char tx2_release[2]; char tx3_version[2]; char tx3_release[2]; char rx_temp[2]; char tx1_temp[2]; char tx2_temp[2]; char tx3_temp[2]; char inlet_temp[2]; char outlet_temp[2]; char curr[2]; //52 char tx1_curr[2]; //54 char tx2_curr[2]; //56 char tx3_curr[2]; //58 char tx1_curr_max[2]; //60 char tx2_curr_max[2]; //62 char tx3_curr_max[2]; //64 char tx1_curr_avg[2]; //66 char tx2_curr_avg[2]; //68 char tx3_curr_avg[2]; //70 char rx_phaseR_min[2]; //72 char rx_phaseS_min[2]; //74 char rx_phaseT_min[2]; //76 char rx_phaseR_max[2]; //78 char rx_phaseS_max[2]; //80 char rx_phaseT_max[2]; //82 char spare1[2]; //84 } __attribute__((packed)); //************************************ //LCU struct lcu_status_body_t { comm_header_t header; //5 char sts; char bit; char bypass; char health; char hazard; char spare1[2]; char spare2[2]; char byte1[2]; char byte2[2]; char byte3[2]; char byte4[2]; char byte5[2]; char board_temp[2]; char mts[2]; char mfs[2]; char ts1[2]; char ts2[2]; char ts3[2]; char ts4[2]; char ts5[2]; char ts6[2]; char spare3[2]; char fs1[2]; char fs2[2]; char ps[2]; char spare4[2]; char ver[2]; char rel[2]; char override; char spare5; char spare6[2]; //60 } __attribute__((packed)); //************************************ //LCU struct lcu_eti_body_t { comm_header_t header; //5 char spare1[2]; char spare2[2]; char spare3[2]; char eti[6]; char spare4[2]; //14 } __attribute__((packed)); template struct lru_generic_message_t { typedef T_ payload_t; enum { payload_size=sizeof(T_)}; union msg_union_t { struct msg_raw_t { char d[payload_size]; } raw; T_ sts; } payload; char checksum[2]; //2 char eom; //1 //Payload size check static_assert(payload_size>=(S_+5), "payload too small"); static_assert(payload_size<=(S_+5), "payload too big"); } __attribute__((packed)); template void checksum(char* r, const T_& msg) { unsigned int size=sizeof msg; unsigned int chk=0; const unsigned char* p=reinterpret_cast(&msg); for(unsigned int i=0; i>4]; r[1]="0123456789ABCDEF"[chk & 0x0F]; } static lru_generic_message_t psm_status; static lru_generic_message_t pps_status; static lru_generic_message_t lcu_status; static lru_generic_message_t lcu_eti; static char last_fcs; static char last_unit; static void psm_init() { memset(&psm_status, STATUS_SPARE, sizeof psm_status); psm_status.payload.sts.header.som=SOM_REPLY; psm_status.payload.sts.header.unit='1'; psm_status.payload.sts.header.fcs='a'; psm_status.payload.sts.header.comm_status=ACK_NO_ERROR; psm_status.payload.sts.header.msg_id='S'; psm_status.payload.sts.sts='G'; psm_status.payload.sts.hazard='N'; psm_status.payload.sts.fast='c'; psm_status.payload.sts.wow='w'; psm_status.payload.sts.ac='A'; psm_status.payload.sts.bs='N'; psm_status.payload.sts.dc='N'; psm_status.payload.sts.pfc='N'; psm_status.payload.sts.out_rail[0]='N'; psm_status.payload.sts.out_rail[1]='N'; psm_status.payload.sts.out_rail[2]='N'; psm_status.payload.sts.out_rail[3]='N'; psm_status.payload.sts.last_recycle = '_'; memset(psm_status.payload.sts.in_amp, '0', sizeof(psm_status.payload.sts.in_amp)); memset(psm_status.payload.sts.volts, '0', sizeof(psm_status.payload.sts.volts)); memset(psm_status.payload.sts.temperature, '0', sizeof(psm_status.payload.sts.temperature)); memset(psm_status.payload.sts.eti, '0', sizeof(psm_status.payload.sts.eti)); memset(psm_status.payload.sts.counter, '0', sizeof(psm_status.payload.sts.counter)); memset(psm_status.payload.sts.sw_major, '0', sizeof(psm_status.payload.sts.sw_major)); memset(psm_status.payload.sts.sw_minor, '0', sizeof(psm_status.payload.sts.sw_minor)); memset(psm_status.payload.sts.unc_counter, '0', sizeof(psm_status.payload.sts.unc_counter)); memset(psm_status.payload.sts.byte1, '0', sizeof(psm_status.payload.sts.byte1)); memset(psm_status.payload.sts.byte2, '0', sizeof(psm_status.payload.sts.byte2)); memset(psm_status.payload.sts.byte3, '0', sizeof(psm_status.payload.sts.byte3)); memset(psm_status.payload.sts.byte4, '0', sizeof(psm_status.payload.sts.byte4)); checksum(psm_status.checksum, psm_status.payload.raw); psm_status.eom='\r'; qDebug()<<"PSM payload size="<4) { const char* m=accumulator.constData(); if (m[0]==SOM) { char u=m[1]; unit=u-'0'; if ((unit<0) || (unit>3)) unit=0; last_fcs=m[2]; last_unit=u; pendingMessage=accumulator; if (u=='1') { Q_EMIT psmCommand(QString("%1").arg(m[5])); } break; } } accumulator.clear(); } } if (accumulator.size()>512) accumulator.clear(); return unit; } int UnitSimulator::get_type_mess(const QByteArray& data) { static QByteArray accumulator; const char* p=data.constData(); int n=data.size(); int type_mess=0; for(int i=0; i4) { const char* m=accumulator.constData(); if (m[0]==SOM) { if (m[4]=='T' || m[4]=='t') type_mess = 1; pendingMessage=accumulator; break; } } accumulator.clear(); } } if (accumulator.size()>512) accumulator.clear(); return type_mess; } QByteArray UnitSimulator::genPSMStatus() const { psm_status.payload.sts.header.fcs=last_fcs; psm_status.payload.sts.header.unit=last_unit; checksum(psm_status.checksum, psm_status.payload.raw); QByteArray d(&psm_status.payload.raw.d[0], sizeof psm_status); qDebug()<<"SIM"<