Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Mon Feb 29 02:43:14 2016 +0000
Revision:
76:1c54a614564d
Parent:
75:cc1942179a2f
Child:
77:8d582faecf6b
Device&settings&protocol update. Not final!!!

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 76:1c54a614564d 10 #define DELTA_PS 0xa000 //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
Diletant 76:1c54a614564d 11 #define DELTA_BINS 0xb000 //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
Diletant 76:1c54a614564d 12 #define DELTA_SF 0xb200 //B_DeltaSF command code: scale factor measurement data output in one packet
Diletant 76:1c54a614564d 13 #define DEV_MODE 0xa500 //e. the code of the Device_Mode command //r. код команды Device_Mode
Diletant 76:1c54a614564d 14 #define BIT_MODE 0xa700 //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
Diletant 76:1c54a614564d 15 #define RATE 0x0000 //e. the code of the Rate command //r. код команды Rate
Diletant 76:1c54a614564d 16 #define DELTA 0x0f00 //e. the code of the Delta command //r. код команды Delta
Diletant 76:1c54a614564d 17 #define D_PERIOD_W 0xf000 //e. the code of the D_Period_W command //r. код команды D_Period_W
Diletant 74:f4d9c3403578 18
Diletant 76:1c54a614564d 19 #define MAINTENANCE 0x9900 //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 76:1c54a614564d 23 #define M0_BASIC 0xda00 //Basic maintenance commands group code
Diletant 76:1c54a614564d 24 #define M0_CLEAR 0xda00 //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
Diletant 76:1c54a614564d 25 #define M0_MIRROR 0xda01 //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника
Diletant 76:1c54a614564d 26 #define M0_LDPAR_F 0xda02 //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
Diletant 76:1c54a614564d 27 #define M0_LDPAR_D 0xda03 //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации
Diletant 76:1c54a614564d 28 #define M0_START 0xda04 //group command select: e. switch on the GLD //r. включить ГЛД
Diletant 76:1c54a614564d 29 #define M0_STOP 0xda40 //group command select: e. switch off the GLD //r. выключить ГЛД
Diletant 76:1c54a614564d 30 #define M0_PULSE 0xda0a //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
Diletant 74:f4d9c3403578 31 //Maintenance rate commands group
Diletant 76:1c54a614564d 32 #define M0_RATE 0xdd00 //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate (Rate2, Rate3)
Diletant 76:1c54a614564d 33 #define M0_RATE_0 0xdd00 //group command select: output parameters set 0?
Diletant 76:1c54a614564d 34 #define M0_RATE_1 0xdd01 //group command select: output parameters set 1?
Diletant 76:1c54a614564d 35 #define M0_RATE_2 0xdd02 //group command select: output parameters set 2
Diletant 76:1c54a614564d 36 #define M0_RATE_3 0xdd03 //group command select: output parameters set 3
Diletant 76:1c54a614564d 37 #define M0_RATE_4 0xdd04 //group command select: output parameters set 4
Diletant 76:1c54a614564d 38 #define M0_RATE_7 0xdd07 //group command select: output parameters set 7
Diletant 74:f4d9c3403578 39
Diletant 74:f4d9c3403578 40 //Other maintenance commands
Diletant 76:1c54a614564d 41 #define M0_STIMUL 0x0a00 //e. the code of the Stimul command //r. код команды Stimul
Diletant 76:1c54a614564d 42 #define M0_RESET 0x8000 //e. software device reset(restart) //r. программный сброс (рестарт) прибора
Diletant 74:f4d9c3403578 43
Diletant 76:1c54a614564d 44 #define M0_CTL_R 0xd900 //e. reading the control register of the device //r. чтение регистра управления устройства
Diletant 76:1c54a614564d 45 #define M0_CTL_M 0xd800 //e. modification of bit of the control register //r. модификация бита регистра управления
Diletant 74:f4d9c3403578 46
Diletant 76:1c54a614564d 47 #define M0_TMP_W 0xe000 //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры)
Diletant 76:1c54a614564d 48 #define M0_TMP_R 0xe100 //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры)
Diletant 76:1c54a614564d 49 #define M0_E5R_W 0xe200 //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5
Diletant 76:1c54a614564d 50 #define M0_ADC_R 0xe300 //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
Diletant 76:1c54a614564d 51 #define M0_VIB_W 0xe400 //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода
Diletant 76:1c54a614564d 52 #define M0_CNT_R 0xe500 //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
Diletant 76:1c54a614564d 53 #define M0_GPH_W 0xe600 //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника
Diletant 76:1c54a614564d 54 #define M0_FLG_R 0xe700 //e. reading data from the register of input flags //r. чтение данных из регистра входных флагов
Diletant 76:1c54a614564d 55 #define M0_PARAM_W 0xe800 //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных
Diletant 76:1c54a614564d 56 #define M0_PARAM_R 0xe900 //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных
Diletant 76:1c54a614564d 57 #define M0_E5RA_W 0xea00 //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 76:1c54a614564d 60 RESPONSE_NONE, //no sheduled response
Diletant 74:f4d9c3403578 61 RESPONSE_IMMEDIATE, //immediate response for most of requests
Diletant 74:f4d9c3403578 62 RESPONSE_DELAYED, //delayed response for broadcast requests
Diletant 74:f4d9c3403578 63 RESPONSE_PERIODIC //periodic response for some of requests
Diletant 74:f4d9c3403578 64 } ResponseType;
Diletant 74:f4d9c3403578 65
Diletant 74:f4d9c3403578 66 typedef enum _ResponseData {
Diletant 74:f4d9c3403578 67 RESPONSE_BUFFER, //response buffer content as is if not empty
Diletant 74:f4d9c3403578 68 RESPONSE_DELTA_BINS, //fill buffer with Delta_BINS data set
Diletant 74:f4d9c3403578 69 RESPONSE_DELTA_PS, //fill buffer with Delta_PS data set
Diletant 74:f4d9c3403578 70 RESPONSE_DELTA_SF, //fill buffer with Delta_SF data set
Diletant 74:f4d9c3403578 71 RESPONSE_RATE //fill buffer with M_Rate data set
Diletant 74:f4d9c3403578 72 } ResponseData;
Diletant 74:f4d9c3403578 73
Diletant 74:f4d9c3403578 74 #define OutputBufferSize 64
Diletant 74:f4d9c3403578 75 typedef struct _DeviceOutputBuffer {
Diletant 74:f4d9c3403578 76 uint8_t data[OutputBufferSize];
Diletant 74:f4d9c3403578 77 int count; //byte count
Diletant 74:f4d9c3403578 78 } DeviceOutputBuffer;
Diletant 74:f4d9c3403578 79
Diletant 74:f4d9c3403578 80 typedef struct _DeviceResponse {
Diletant 76:1c54a614564d 81 uint8_t enabled; //
Diletant 74:f4d9c3403578 82 ResponseType type; //how send: immediately/delayed/periodic
Diletant 76:1c54a614564d 83 //ResponseData data; //what send: buffer/Delta_BINS/Delta_PS/Delta_SF/M_Rate
Diletant 76:1c54a614564d 84 uint16_t code; //Request code
Diletant 74:f4d9c3403578 85 uint32_t counter; //time from: broadcast line request/latch pulse/last response; values in mks;
Diletant 74:f4d9c3403578 86 uint32_t trigger; //counter value to response; values in mks;
Diletant 75:cc1942179a2f 87 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 88 DeviceOutputBuffer buffer;
Diletant 74:f4d9c3403578 89 uint8_t ready;
Diletant 74:f4d9c3403578 90 } DeviceResponse;
Diletant 74:f4d9c3403578 91
Diletant 74:f4d9c3403578 92 #define InputBufferSize 1024
Diletant 69:70849751d98e 93 typedef struct _DeviceInputBuffer {
Diletant 74:f4d9c3403578 94 uint8_t data[InputBufferSize];
Diletant 71:7835a18110bd 95 int start; //read start position
Diletant 71:7835a18110bd 96 int end; //write start position
Diletant 69:70849751d98e 97 } DeviceInputBuffer;
Diletant 69:70849751d98e 98
Diletant 74:f4d9c3403578 99 typedef struct _DeviceRequest {
Diletant 74:f4d9c3403578 100 uint32_t rate; //response baud rate
Diletant 74:f4d9c3403578 101 DeviceInputBuffer buffer;
Diletant 74:f4d9c3403578 102 } DeviceRequest;
Diletant 71:7835a18110bd 103
Diletant 74:f4d9c3403578 104 typedef struct _DeviceProtocolDecoder {
Diletant 75:cc1942179a2f 105 uint8_t error; //Decode error encountered
Diletant 75:cc1942179a2f 106 uint8_t count; //Decoded bytes count
Diletant 76:1c54a614564d 107 uint8_t address; //Decoded request address
Diletant 76:1c54a614564d 108 uint8_t version; //Decoded protocol version (currently only 0 version exist)
Diletant 76:1c54a614564d 109 uint16_t code; //Decoded command code
Diletant 75:cc1942179a2f 110 uint16_t position;//Current decoder position in input buffer
Diletant 75:cc1942179a2f 111 uint16_t CRC; //Current/final CRC of decoded packet
Diletant 74:f4d9c3403578 112 } DeviceProtocolDecoder;
Diletant 54:d94145ba23f4 113
Diletant 74:f4d9c3403578 114 typedef struct _DeviceProtocolEncoder {
Diletant 74:f4d9c3403578 115 uint8_t error;
Diletant 74:f4d9c3403578 116 uint8_t count;
Diletant 74:f4d9c3403578 117 uint16_t position;
Diletant 74:f4d9c3403578 118 uint16_t CRC;
Diletant 74:f4d9c3403578 119 } DeviceProtocolEncoder;
Diletant 54:d94145ba23f4 120
Diletant 74:f4d9c3403578 121 void Decode(void);
Diletant 75:cc1942179a2f 122 void Encode(void);
Diletant 75:cc1942179a2f 123 void Transmit(void);
Diletant 61:1b76fe74a0d9 124
Diletant 74:f4d9c3403578 125 uint8_t Decode8(void);
Diletant 74:f4d9c3403578 126 uint16_t Decode16(void);
Diletant 74:f4d9c3403578 127 void DecodeStart(void);
Diletant 74:f4d9c3403578 128 void DecodeEnd(void);
Diletant 74:f4d9c3403578 129 void DecodeCancel(void);
Diletant 74:f4d9c3403578 130 void DecodeFail(void);
Diletant 74:f4d9c3403578 131 void DecodeAddress(void);
Diletant 76:1c54a614564d 132 void DecodeCode(void);
Diletant 76:1c54a614564d 133 void DecodeCode2(void);
Diletant 74:f4d9c3403578 134 void DecodeCRC(void);
Diletant 54:d94145ba23f4 135
Diletant 74:f4d9c3403578 136 void DecodeDeviceMode(void);
Diletant 76:1c54a614564d 137 void DecodeDelta(void);
Diletant 74:f4d9c3403578 138 void DecodeMaintenanceMode(void);
Diletant 76:1c54a614564d 139 void DecodeMBasic(void);
Diletant 74:f4d9c3403578 140 void DecodeMStymul(void);
Diletant 74:f4d9c3403578 141 void DecodeMADCR(void);
Diletant 74:f4d9c3403578 142 void DecodeMTmpW(void);
Diletant 74:f4d9c3403578 143 void DecodeMe5rW(void);
Diletant 74:f4d9c3403578 144 void DecodeMCntR(void);
Diletant 74:f4d9c3403578 145 void DecodeMFlgR(void);
Diletant 74:f4d9c3403578 146 void DecodeMVibW(void);
Diletant 74:f4d9c3403578 147 void DecodeMGphW(void);
Diletant 74:f4d9c3403578 148 void DecodeMRate(void);
Diletant 74:f4d9c3403578 149 void DecodeMParamR(void);
Diletant 74:f4d9c3403578 150 void DecodeMParamW(void);
Diletant 74:f4d9c3403578 151 void DecodeMControl(void);
Diletant 74:f4d9c3403578 152 void DecodeMClear(void);
Diletant 74:f4d9c3403578 153 void DecodeMMirror(void);
Diletant 74:f4d9c3403578 154 void DecodeMLdParF(void);
Diletant 74:f4d9c3403578 155 void DecodeMLdParD(void);
Diletant 74:f4d9c3403578 156 void DecodeMStart(void);
Diletant 74:f4d9c3403578 157 void DecodeMStop(void);
Diletant 74:f4d9c3403578 158 void DecodeMPulse(void);
Diletant 74:f4d9c3403578 159 void DecodeMRate2(void);
Diletant 74:f4d9c3403578 160 void DecodeMRate3(void);
Diletant 74:f4d9c3403578 161 void DecodeMe5raW(void);
Diletant 64:8179dacbf32b 162
Diletant 72:f5e189c62bcb 163 void Encode8(uint8_t);
Diletant 72:f5e189c62bcb 164 void Encode16(uint16_t);
Diletant 73:29fccfe239a3 165
Diletant 73:29fccfe239a3 166 void EncodeStart(void);
Diletant 73:29fccfe239a3 167 void EncodeEnd(void);
Diletant 76:1c54a614564d 168 void EncodeAddress(void);
Diletant 76:1c54a614564d 169 void EncodeCRC(void);
Diletant 73:29fccfe239a3 170
Diletant 72:f5e189c62bcb 171 void EncodeDeviceMode(void);
Diletant 72:f5e189c62bcb 172 void EncodeSysRgR(void);
Diletant 73:29fccfe239a3 173
Diletant 76:1c54a614564d 174 void EncodeBINSDiff(void);
Diletant 76:1c54a614564d 175 void EncodeValidBINS(void);
Diletant 72:f5e189c62bcb 176
Diletant 54:d94145ba23f4 177 #endif /* __DEVICEPROTOCOL_H__ */