Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Sat Feb 27 18:42:37 2016 +0000
Revision:
74:f4d9c3403578
Parent:
73:29fccfe239a3
Child:
75:cc1942179a2f
Device settings&protocol update. Device.h; Not completed!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 54:d94145ba23f4 1 #ifndef __DEVICEPROTOCOL_H__
Diletant 54:d94145ba23f4 2 #define __DEVICEPROTOCOL_H__
Diletant 54:d94145ba23f4 3
Diletant 54:d94145ba23f4 4 #include "DeviceSettings.h"
Diletant 54:d94145ba23f4 5 #include "stdint.h"
Diletant 54:d94145ba23f4 6
Diletant 74:f4d9c3403578 7 #define BROADCAST_ADDRESS 0x1f
Diletant 74:f4d9c3403578 8 #define BROADCAST_FRAME 100 //100 mks
Diletant 74:f4d9c3403578 9
Diletant 74:f4d9c3403578 10 #define DELTA_PS 0xa0 //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
Diletant 74:f4d9c3403578 11 #define DELTA_BINS 0xb0 //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
Diletant 74:f4d9c3403578 12 #define DELTA_SF 0xb2 //B_DeltaSF command code: scale factor measurement data output in one packet
Diletant 74:f4d9c3403578 13 #define DEV_MODE 0xa5 //e. the code of the Device_Mode command //r. код команды Device_Mode
Diletant 74:f4d9c3403578 14 #define BIT_MODE 0xa7 //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
Diletant 74:f4d9c3403578 15 #define RATE 0x00 //e. the code of the Rate command //r. код команды Rate
Diletant 74:f4d9c3403578 16 #define DELTA 0x0f //e. the code of the Delta command //r. код команды Delta
Diletant 74:f4d9c3403578 17 #define D_PERIOD_W 0xf0 //e. the code of the D_Period_W command //r. код команды D_Period_W
Diletant 74:f4d9c3403578 18
Diletant 74:f4d9c3403578 19 #define MAINTENANCE 0x99 //e. the code of the Maintenance mode command //r. код команды Maintenance mode
Diletant 74:f4d9c3403578 20 //Maintenance command set versions
Diletant 74:f4d9c3403578 21 #define M0_MAINTENANCE 0x99 //: initial version
Diletant 74:f4d9c3403578 22 //Maintenance basic commands group
Diletant 74:f4d9c3403578 23 #define M0_BASIC 0xda //Basic maintenance commands group code
Diletant 74:f4d9c3403578 24 #define M0_CLEAR 0x00 //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
Diletant 74:f4d9c3403578 25 #define M0_MIRROR 0x01 //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника
Diletant 74:f4d9c3403578 26 #define M0_LDPAR_F 0x02 //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
Diletant 74:f4d9c3403578 27 #define M0_LDPAR_D 0x03 //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации
Diletant 74:f4d9c3403578 28 #define M0_START 0x04 //group command select: e. switch on the GLD //r. включить ГЛД
Diletant 74:f4d9c3403578 29 #define M0_STOP 0x40 //group command select: e. switch off the GLD //r. выключить ГЛД
Diletant 74:f4d9c3403578 30 #define M0_PULSE 0x0a //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
Diletant 74:f4d9c3403578 31 //Maintenance rate commands group
Diletant 74:f4d9c3403578 32 #define M0_RATE 0xdd //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate (Rate2, Rate3)
Diletant 74:f4d9c3403578 33 #define M0_RATE_0 0x00 //group command select: output parameters set 0?
Diletant 74:f4d9c3403578 34 #define M0_RATE_1 0x01 //group command select: output parameters set 1?
Diletant 74:f4d9c3403578 35 #define M0_RATE_2 0x02 //group command select: output parameters set 2
Diletant 74:f4d9c3403578 36 #define M0_RATE_3 0x03 //group command select: output parameters set 3
Diletant 74:f4d9c3403578 37 #define M0_RATE_4 0x04 //group command select: output parameters set 4
Diletant 74:f4d9c3403578 38 #define M0_RATE_7 0x07 //group command select: output parameters set 7
Diletant 74:f4d9c3403578 39
Diletant 74:f4d9c3403578 40 //Other maintenance commands
Diletant 74:f4d9c3403578 41 #define M0_STIMUL 0x0a //e. the code of the Stimul command //r. код команды Stimul
Diletant 74:f4d9c3403578 42 #define M0_RESET 0x80 //e. software device reset(restart) //r. программный сброс (рестарт) прибора
Diletant 74:f4d9c3403578 43
Diletant 74:f4d9c3403578 44 #define M0_CTL_R 0xd9 //e. reading the control register of the device //r. чтение регистра управления устройства
Diletant 74:f4d9c3403578 45 #define M0_CTL_M 0xd8 //e. modification of bit of the control register //r. модификация бита регистра управления
Diletant 74:f4d9c3403578 46
Diletant 74:f4d9c3403578 47 #define M0_TMP_W 0xe0 //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры)
Diletant 74:f4d9c3403578 48 #define M0_TMP_R 0xe1 //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры)
Diletant 74:f4d9c3403578 49 #define M0_E5R_W 0xe2 //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5
Diletant 74:f4d9c3403578 50 #define M0_ADC_R 0xe3 //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
Diletant 74:f4d9c3403578 51 #define M0_VIB_W 0xe4 //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода
Diletant 74:f4d9c3403578 52 #define M0_CNT_R 0xe5 //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
Diletant 74:f4d9c3403578 53 #define M0_GPH_W 0xe6 //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника
Diletant 74:f4d9c3403578 54 #define M0_FLG_R 0xe7 //e. reading data from the register of input flags //r. чтение данных из регистра входных флагов
Diletant 74:f4d9c3403578 55 #define M0_PARAM_W 0xe8 //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных
Diletant 74:f4d9c3403578 56 #define M0_PARAM_R 0xe9 //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных
Diletant 74:f4d9c3403578 57 #define M0_E5RA_W 0xea //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5
Diletant 74:f4d9c3403578 58
Diletant 74:f4d9c3403578 59 typedef enum _ResponseType {
Diletant 74:f4d9c3403578 60 RESPONSE_IMMEDIATE, //immediate response for most of requests
Diletant 74:f4d9c3403578 61 RESPONSE_DELAYED, //delayed response for broadcast requests
Diletant 74:f4d9c3403578 62 RESPONSE_PERIODIC //periodic response for some of requests
Diletant 74:f4d9c3403578 63 } ResponseType;
Diletant 74:f4d9c3403578 64
Diletant 74:f4d9c3403578 65 typedef enum _ResponseData {
Diletant 74:f4d9c3403578 66 RESPONSE_BUFFER, //response buffer content as is if not empty
Diletant 74:f4d9c3403578 67 RESPONSE_DELTA_BINS, //fill buffer with Delta_BINS data set
Diletant 74:f4d9c3403578 68 RESPONSE_DELTA_PS, //fill buffer with Delta_PS data set
Diletant 74:f4d9c3403578 69 RESPONSE_DELTA_SF, //fill buffer with Delta_SF data set
Diletant 74:f4d9c3403578 70 RESPONSE_RATE //fill buffer with M_Rate data set
Diletant 74:f4d9c3403578 71 } ResponseData;
Diletant 74:f4d9c3403578 72
Diletant 74:f4d9c3403578 73 #define OutputBufferSize 64
Diletant 74:f4d9c3403578 74 typedef struct _DeviceOutputBuffer {
Diletant 74:f4d9c3403578 75 uint8_t data[OutputBufferSize];
Diletant 74:f4d9c3403578 76 int count; //byte count
Diletant 74:f4d9c3403578 77 } DeviceOutputBuffer;
Diletant 74:f4d9c3403578 78
Diletant 74:f4d9c3403578 79 typedef struct _DeviceResponse {
Diletant 74:f4d9c3403578 80 ResponseType type; //how send: immediately/delayed/periodic
Diletant 74:f4d9c3403578 81 ResponseData data; //what send: buffer/Delta_BINS/Delta_PS/Delta_SF/M_Rate
Diletant 74:f4d9c3403578 82 uint32_t counter; //time from: broadcast line request/latch pulse/last response; values in mks;
Diletant 74:f4d9c3403578 83 uint32_t trigger; //counter value to response; values in mks;
Diletant 74:f4d9c3403578 84 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 85 DeviceOutputBuffer buffer;
Diletant 74:f4d9c3403578 86 uint8_t ready;
Diletant 74:f4d9c3403578 87 } DeviceResponse;
Diletant 74:f4d9c3403578 88
Diletant 74:f4d9c3403578 89 #define InputBufferSize 1024
Diletant 69:70849751d98e 90 typedef struct _DeviceInputBuffer {
Diletant 74:f4d9c3403578 91 uint8_t data[InputBufferSize];
Diletant 71:7835a18110bd 92 int start; //read start position
Diletant 71:7835a18110bd 93 int end; //write start position
Diletant 69:70849751d98e 94 } DeviceInputBuffer;
Diletant 69:70849751d98e 95
Diletant 74:f4d9c3403578 96 typedef struct _DeviceRequest {
Diletant 74:f4d9c3403578 97 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 98 DeviceInputBuffer buffer;
Diletant 74:f4d9c3403578 99 } DeviceRequest;
Diletant 71:7835a18110bd 100
Diletant 74:f4d9c3403578 101 typedef struct _DeviceProtocolDecoder {
Diletant 74:f4d9c3403578 102 uint8_t address;
Diletant 74:f4d9c3403578 103 uint8_t code;
Diletant 74:f4d9c3403578 104 uint8_t error;
Diletant 74:f4d9c3403578 105 uint8_t count;
Diletant 74:f4d9c3403578 106 uint16_t position;
Diletant 74:f4d9c3403578 107 uint16_t CRC;
Diletant 74:f4d9c3403578 108 } DeviceProtocolDecoder;
Diletant 54:d94145ba23f4 109
Diletant 74:f4d9c3403578 110 typedef struct _DeviceProtocolEncoder {
Diletant 74:f4d9c3403578 111 uint8_t error;
Diletant 74:f4d9c3403578 112 uint8_t count;
Diletant 74:f4d9c3403578 113 uint16_t position;
Diletant 74:f4d9c3403578 114 uint16_t CRC;
Diletant 74:f4d9c3403578 115 } DeviceProtocolEncoder;
Diletant 54:d94145ba23f4 116
Diletant 74:f4d9c3403578 117 void Decode(void);
Diletant 61:1b76fe74a0d9 118
Diletant 61:1b76fe74a0d9 119
Diletant 74:f4d9c3403578 120 uint8_t Decode8(void);
Diletant 74:f4d9c3403578 121 uint16_t Decode16(void);
Diletant 74:f4d9c3403578 122 void DecodeStart(void);
Diletant 74:f4d9c3403578 123 void DecodeEnd(void);
Diletant 74:f4d9c3403578 124 void DecodeCancel(void);
Diletant 74:f4d9c3403578 125 void DecodeFail(void);
Diletant 74:f4d9c3403578 126 void DecodeAddress(void);
Diletant 74:f4d9c3403578 127 void DecodeCRC(void);
Diletant 54:d94145ba23f4 128
Diletant 74:f4d9c3403578 129 void DecodeDeviceMode(void);
Diletant 74:f4d9c3403578 130 void DecodeDeltaBINS(void);
Diletant 74:f4d9c3403578 131 void DecodeDeltaPS(void);
Diletant 74:f4d9c3403578 132 void DecodeDelta(void); //Not used?
Diletant 74:f4d9c3403578 133 void DecodeDPeriodW(void); //Not used?
Diletant 74:f4d9c3403578 134 void DecodeMaintenanceMode(void);
Diletant 74:f4d9c3403578 135 void DecodeMStymul(void);
Diletant 74:f4d9c3403578 136 void DecodeMADCR(void);
Diletant 74:f4d9c3403578 137 void DecodeMTmpW(void);
Diletant 74:f4d9c3403578 138 void DecodeMe5rW(void);
Diletant 74:f4d9c3403578 139 void DecodeMCntR(void);
Diletant 74:f4d9c3403578 140 void DecodeMFlgR(void);
Diletant 74:f4d9c3403578 141 void DecodeMVibW(void);
Diletant 74:f4d9c3403578 142 void DecodeMGphW(void);
Diletant 74:f4d9c3403578 143 void DecodeMRate(void);
Diletant 74:f4d9c3403578 144 void DecodeMParamR(void);
Diletant 74:f4d9c3403578 145 void DecodeMParamW(void);
Diletant 74:f4d9c3403578 146 void DecodeMControl(void);
Diletant 74:f4d9c3403578 147 void DecodeMClear(void);
Diletant 74:f4d9c3403578 148 void DecodeMMirror(void);
Diletant 74:f4d9c3403578 149 void DecodeMLdParF(void);
Diletant 74:f4d9c3403578 150 void DecodeMLdParD(void);
Diletant 74:f4d9c3403578 151 void DecodeMStart(void);
Diletant 74:f4d9c3403578 152 void DecodeMStop(void);
Diletant 74:f4d9c3403578 153 void DecodeMPulse(void);
Diletant 74:f4d9c3403578 154 void DecodeMRate2(void);
Diletant 74:f4d9c3403578 155 void DecodeMRate3(void);
Diletant 74:f4d9c3403578 156 void DecodeMe5raW(void);
Diletant 64:8179dacbf32b 157
Diletant 72:f5e189c62bcb 158 void Encode8(uint8_t);
Diletant 72:f5e189c62bcb 159 void Encode16(uint16_t);
Diletant 73:29fccfe239a3 160
Diletant 73:29fccfe239a3 161 void EncodeStart(void);
Diletant 73:29fccfe239a3 162 void EncodeEnd(void);
Diletant 73:29fccfe239a3 163
Diletant 72:f5e189c62bcb 164 void EncodeDeviceMode(void);
Diletant 72:f5e189c62bcb 165 void EncodeSysRgR(void);
Diletant 73:29fccfe239a3 166
Diletant 72:f5e189c62bcb 167 void EncodeCRC(void);
Diletant 72:f5e189c62bcb 168
Diletant 54:d94145ba23f4 169 #endif /* __DEVICEPROTOCOL_H__ */