Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Wed Feb 24 02:48:32 2016 +0000
Revision:
73:29fccfe239a3
Parent:
72:f5e189c62bcb
Child:
74:f4d9c3403578
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 73:29fccfe239a3 7 /*Move to DeviceCommunication.h*/
Diletant 69:70849751d98e 8 #define InputBufferSize 1024
Diletant 69:70849751d98e 9 typedef struct _DeviceInputBuffer {
Diletant 69:70849751d98e 10 uint8_t buffer[InputBufferSize];
Diletant 71:7835a18110bd 11 int start; //read start position
Diletant 71:7835a18110bd 12 int end; //write start position
Diletant 69:70849751d98e 13 } DeviceInputBuffer;
Diletant 73:29fccfe239a3 14 /*Move to DeviceCommunication.h*/
Diletant 71:7835a18110bd 15 #define OutputBufferSize 64
Diletant 69:70849751d98e 16 typedef struct _DeviceOutputBuffer {
Diletant 71:7835a18110bd 17 uint8_t buffer[OutputBufferSize];
Diletant 69:70849751d98e 18 int count; //byte count
Diletant 69:70849751d98e 19 } DeviceOutputBuffer;
Diletant 73:29fccfe239a3 20 /*Move to DeviceCommunication.h*/
Diletant 69:70849751d98e 21 typedef struct _DeviceCommunicationState {
Diletant 72:f5e189c62bcb 22 DeviceInputBuffer requestBuffer;
Diletant 72:f5e189c62bcb 23 DeviceOutputBuffer responseBuffer;
Diletant 69:70849751d98e 24 //Request settings
Diletant 71:7835a18110bd 25 uint32_t requestBaudRate;
Diletant 71:7835a18110bd 26 uint8_t requestCode;
Diletant 71:7835a18110bd 27 uint8_t requestSelect;
Diletant 69:70849751d98e 28 //Response settings
Diletant 72:f5e189c62bcb 29 uint8_t transmitterReady;
Diletant 71:7835a18110bd 30 uint8_t responseReady;
Diletant 71:7835a18110bd 31 uint8_t responseCode;
Diletant 71:7835a18110bd 32 uint8_t responseSelect;
Diletant 71:7835a18110bd 33 uint32_t responseBaudRate;
Diletant 69:70849751d98e 34 //Response broadcast and external latch delay
Diletant 71:7835a18110bd 35 uint32_t responseDelay; //Values in mks; 0 - immediate response
Diletant 71:7835a18110bd 36 uint32_t responseDelayClock; //Values in mks; response delay clock - send response if clock > delay;
Diletant 69:70849751d98e 37 //Periodical response
Diletant 71:7835a18110bd 38 uint32_t responsePeriod; //Values in mks; 0 - no periodic response; 2000 - 500Hz
Diletant 71:7835a18110bd 39 uint32_t responsePeriodClock; //Values in mks; response period clock - send response if clock > period;
Diletant 69:70849751d98e 40 } DeviceCommunicationState;
Diletant 69:70849751d98e 41
Diletant 73:29fccfe239a3 42 /*Move to DeviceCounters.h*/
Diletant 71:7835a18110bd 43 typedef struct _DeviceLatchState {
Diletant 71:7835a18110bd 44 //Latch mode
Diletant 71:7835a18110bd 45 DeviceLatchMode mode;
Diletant 71:7835a18110bd 46 } DeviceLatchState;
Diletant 71:7835a18110bd 47
Diletant 71:7835a18110bd 48 typedef struct _DeviceCountersState {
Diletant 71:7835a18110bd 49 //Latch
Diletant 71:7835a18110bd 50 DeviceLatchState latch;
Diletant 72:f5e189c62bcb 51 //Delta command mode
Diletant 72:f5e189c62bcb 52 DeviceDeltaMode deltaMode;
Diletant 71:7835a18110bd 53 } DeviceCountersState;
Diletant 71:7835a18110bd 54
Diletant 73:29fccfe239a3 55 /*Move to Device.h*/
Diletant 69:70849751d98e 56 typedef struct _DeviceState {
Diletant 69:70849751d98e 57 DeviceCommunicationState communication;
Diletant 71:7835a18110bd 58 DeviceCountersState counters;
Diletant 69:70849751d98e 59 } DeviceState;
Diletant 59:daf3a8ed255e 60
Diletant 59:daf3a8ed255e 61 /*
Diletant 54:d94145ba23f4 62 typedef struct {
Diletant 54:d94145ba23f4 63 uint8_t Offset;
Diletant 54:d94145ba23f4 64 uint8_t Mask;
Diletant 54:d94145ba23f4 65 uint8_t Value;
Diletant 54:d94145ba23f4 66 } DeviceMessageCheckPoint;
Diletant 54:d94145ba23f4 67
Diletant 54:d94145ba23f4 68 typedef enum{
Diletant 54:d94145ba23f4 69 DMID_DeviceMode
Diletant 54:d94145ba23f4 70 } DeviceMessageID;
Diletant 54:d94145ba23f4 71
Diletant 54:d94145ba23f4 72 typedef struct {
Diletant 54:d94145ba23f4 73 DeviceMessageID ID;
Diletant 54:d94145ba23f4 74 uint8_t Size;
Diletant 54:d94145ba23f4 75 uint8_t CheckPointCount;
Diletant 54:d94145ba23f4 76 DeviceMessageCheckPoint *CheckPointList;
Diletant 54:d94145ba23f4 77 } DeviceMessageCheck;
Diletant 59:daf3a8ed255e 78 */
Diletant 61:1b76fe74a0d9 79
Diletant 68:46937d192c39 80 #define BROADCAST_FRAME 100 //100 mks
Diletant 68:46937d192c39 81
Diletant 66:66124221f4b0 82 #define DELTA_PS 0xa0 //B_DeltaPS command code: output of accumulated pulses and ACS parameters as 22 indexed packets sequence
Diletant 66:66124221f4b0 83 #define DELTA_BINS 0xb0 //B_DeltaBINS command code: output of accumulated pulses and data validity attribute in one packet
Diletant 66:66124221f4b0 84 #define DELTA_SF 0xb2 //B_DeltaSF command code: scale factor measurement data output in one packet
Diletant 61:1b76fe74a0d9 85 #define DEV_MODE 0xa5 //e. the code of the Device_Mode command //r. код команды Device_Mode
Diletant 61:1b76fe74a0d9 86 #define BIT_MODE 0xa7 //e. the code of the B.I.T. command //r. код команды B.I.T.(встороенного тестирования)
Diletant 61:1b76fe74a0d9 87 #define RATE 0x00 //e. the code of the Rate command //r. код команды Rate
Diletant 61:1b76fe74a0d9 88 #define DELTA 0x0f //e. the code of the Delta command //r. код команды Delta
Diletant 61:1b76fe74a0d9 89 #define D_PERIOD_W 0xf0 //e. the code of the D_Period_W command //r. код команды D_Period_W
Diletant 61:1b76fe74a0d9 90
Diletant 61:1b76fe74a0d9 91 #define MAINTENANCE 0x99 //e. the code of the Maintenance mode command //r. код команды Maintenance mode
Diletant 63:823c7f1ec6c3 92 //Maintenance command set versions
Diletant 63:823c7f1ec6c3 93 #define M0_MAINTENANCE 0x99 //: initial version
Diletant 62:2d2dcf999fb5 94 //Maintenance basic commands group
Diletant 63:823c7f1ec6c3 95 #define M0_BASIC 0xda //Basic maintenance commands group code
Diletant 62:2d2dcf999fb5 96 #define M0_CLEAR 0x00 //group command select: e. reset of the register of errors of line 485 //r. очистка регистра ошибок линии 485
Diletant 62:2d2dcf999fb5 97 #define M0_MIRROR 0x01 //group command select: e. return previous contents of the receiver buffer //r. возврат предыдущего содержимого буфера приемника
Diletant 62:2d2dcf999fb5 98 #define M0_LDPAR_F 0x02 //group command select: e. load GLD parameters from Flash-memory //r. загрузить параметры ГЛД из флэш-памяти
Diletant 62:2d2dcf999fb5 99 #define M0_LDPAR_D 0x03 //group command select: e. set GLD parameters by procedure of initialization //r. установить параметры ГЛД процедурой инициализации
Diletant 62:2d2dcf999fb5 100 #define M0_START 0x04 //group command select: e. switch on the GLD //r. включить ГЛД
Diletant 62:2d2dcf999fb5 101 #define M0_STOP 0x40 //group command select: e. switch off the GLD //r. выключить ГЛД
Diletant 62:2d2dcf999fb5 102 #define M0_PULSE 0x0a //group command select: e. generation of the light-up pulse //r. генерация импульса поджига
Diletant 62:2d2dcf999fb5 103 //Maintenance rate commands group
Diletant 63:823c7f1ec6c3 104 #define M0_RATE 0xdd //e. delivery of a stack of parameters M_Rate (Rate2, Rate3) //r. выдача набора параметров M_Rate (Rate2, Rate3)
Diletant 62:2d2dcf999fb5 105 #define M0_RATE_0 0x00 //group command select: output parameters set 0?
Diletant 62:2d2dcf999fb5 106 #define M0_RATE_1 0x01 //group command select: output parameters set 1?
Diletant 62:2d2dcf999fb5 107 #define M0_RATE_2 0x02 //group command select: output parameters set 2
Diletant 62:2d2dcf999fb5 108 #define M0_RATE_3 0x03 //group command select: output parameters set 3
Diletant 62:2d2dcf999fb5 109 #define M0_RATE_4 0x04 //group command select: output parameters set 4
Diletant 62:2d2dcf999fb5 110 #define M0_RATE_7 0x07 //group command select: output parameters set 7
Diletant 62:2d2dcf999fb5 111
Diletant 61:1b76fe74a0d9 112 //Other maintenance commands
Diletant 63:823c7f1ec6c3 113 #define M0_STIMUL 0x0a //e. the code of the Stimul command //r. код команды Stimul
Diletant 63:823c7f1ec6c3 114 #define M0_RESET 0x80 //e. software device reset(restart) //r. программный сброс (рестарт) прибора
Diletant 61:1b76fe74a0d9 115
Diletant 63:823c7f1ec6c3 116 #define M0_CTL_R 0xd9 //e. reading the control register of the device //r. чтение регистра управления устройства
Diletant 63:823c7f1ec6c3 117 #define M0_CTL_M 0xd8 //e. modification of bit of the control register //r. модификация бита регистра управления
Diletant 61:1b76fe74a0d9 118
Diletant 63:823c7f1ec6c3 119 #define M0_TMP_W 0xe0 //e. writing to the AD7714 circuit (temperature sensors) //r. запись в схемы AD7714 (измерители температуры)
Diletant 63:823c7f1ec6c3 120 #define M0_TMP_R 0xe1 //e. reading from the AD7714 circuit (temperature sensors) //r. чтение из схем AD7714 (измерители температуры)
Diletant 63:823c7f1ec6c3 121 #define M0_E5R_W 0xe2 //e. writing to the register of a mode of the Elio5 card //r. запись в регистр режима платы Elio5
Diletant 63:823c7f1ec6c3 122 #define M0_ADC_R 0xe3 //e. reading data from the ADC of the Elio5 card //r. чтение данных из АЦП платы Elio5
Diletant 63:823c7f1ec6c3 123 #define M0_VIB_W 0xe4 //e. loading of the oscillation period of the dither drive //r. загрузка периода колебаний вибропривода
Diletant 63:823c7f1ec6c3 124 #define M0_CNT_R 0xe5 //e. reading data from the counters of the Elio5 card //r. чтение данных из счетчиков платы Elio5
Diletant 63:823c7f1ec6c3 125 #define M0_GPH_W 0xe6 //e. loading gain factors of photodetector channels //r. загрузка коэффициентов усиления каналов фотоприемника
Diletant 63:823c7f1ec6c3 126 #define M0_FLG_R 0xe7 //e. reading data from the register of input flags //r. чтение данных из регистра входных флагов
Diletant 63:823c7f1ec6c3 127 #define M0_PARAM_W 0xe8 //e. writing working parameter to the data memory //r. запись рабочего параметра в память данных
Diletant 63:823c7f1ec6c3 128 #define M0_PARAM_R 0xe9 //e. reading working parameter of the GLD from the data memory //r. чтение рабочего параметра GLD из памяти данных
Diletant 63:823c7f1ec6c3 129 #define M0_E5RA_W 0xea //e. writing in 1st additional (A) register of a mode of the Elio5 card //r. запись в 1-ый дополнительный (А) регистр режима платы Elio5
Diletant 54:d94145ba23f4 130
Diletant 54:d94145ba23f4 131 //Command: DeviceMode
Diletant 59:daf3a8ed255e 132 //DeviceMessageCheckPoint DeviceModeRequestCheck[] = {{0x00,0xff,0xcc},{0x02,0xff,0xcc},{0x03,0xf0,0x00}};
Diletant 59:daf3a8ed255e 133 //DeviceMessageCheckPoint DeviceModeResponseCheck[] = {{0x00,0xff,0xcc},{0x02,0xff,0x00}};
Diletant 73:29fccfe239a3 134 /*Move to DeviceCommunication.h*/
Diletant 54:d94145ba23f4 135 typedef enum
Diletant 54:d94145ba23f4 136 {
Diletant 63:823c7f1ec6c3 137 RESPONSE_IMMEDIATE, //external latch by RS422 B_Delta_BINS request with B_Delta_BINS format response
Diletant 63:823c7f1ec6c3 138 RESPONSE_BROADCAST //external latch mode with B_Delta_BINS format data and latch pulse request
Diletant 63:823c7f1ec6c3 139 } ResponseModes;
Diletant 73:29fccfe239a3 140 /*Move to DeviceCounters.h*/
Diletant 63:823c7f1ec6c3 141 typedef enum
Diletant 63:823c7f1ec6c3 142 {
Diletant 54:d94145ba23f4 143 Reserved,
Diletant 54:d94145ba23f4 144 DevModeLatch10kHz, //internal latch with frequency 10 kHz (power on default mode)
Diletant 54:d94145ba23f4 145 DevModeLatchMeander, //internal latch by signed meander pulses
Diletant 54:d94145ba23f4 146 DevModeLatchRS422PS, //external latch by RS422 B_Delta_PS request with B_Delta_PS format response
Diletant 54:d94145ba23f4 147 DevModeLatchRequestPS, //external latch by pulse request with B_Delta_PS format response
Diletant 54:d94145ba23f4 148 DevModeLatchRS422BINS, //external latch by RS422 B_Delta_BINS request with B_Delta_BINS format response
Diletant 54:d94145ba23f4 149 DevModeLatchRequestBINS //external latch mode with B_Delta_BINS format data and latch pulse request
Diletant 54:d94145ba23f4 150 } DeviceModes;
Diletant 62:2d2dcf999fb5 151 /*
Diletant 54:d94145ba23f4 152 typedef __packed struct {
Diletant 54:d94145ba23f4 153 uint8_t SOC; //Start Of Command: 0xCC
Diletant 54:d94145ba23f4 154 uint8_t Address; //Device address: 0x00, 0x01, 0x02, 0x1f
Diletant 54:d94145ba23f4 155 uint8_t Cmd; //Command code: 0xA5
Diletant 54:d94145ba23f4 156 uint8_t Reserved : 4; //Reserved
Diletant 54:d94145ba23f4 157 DeviceModes Mode : 4; //Device mode
Diletant 54:d94145ba23f4 158 uint8_t ChecksumHi; //Checksum Hi byte
Diletant 54:d94145ba23f4 159 uint8_t ChecksumLo; //Checksum Lo byte
Diletant 54:d94145ba23f4 160 } DeviceModeRequest;
Diletant 54:d94145ba23f4 161 typedef __packed struct {
Diletant 54:d94145ba23f4 162 uint8_t SOC; //Start Of Command: 0xCC
Diletant 54:d94145ba23f4 163 uint8_t Address; //Device address: 0x00, 0x01, 0x02, 0x1f
Diletant 54:d94145ba23f4 164 uint8_t Zero; //Reserved: 0x00
Diletant 54:d94145ba23f4 165 uint8_t Mode; //Device mode
Diletant 54:d94145ba23f4 166 uint8_t RgRHi; //Register RgR Hi byte
Diletant 54:d94145ba23f4 167 uint8_t RgRLo; //Register RgR Lo byte
Diletant 54:d94145ba23f4 168 uint8_t ChecksumHi; //Checksum Hi byte
Diletant 54:d94145ba23f4 169 uint8_t ChecksumLo; //Checksum Lo byte
Diletant 54:d94145ba23f4 170 } DeviceModeResponse;
Diletant 62:2d2dcf999fb5 171
Diletant 54:d94145ba23f4 172 DeviceMessageCheck DeviceRequestChecks[] = {
Diletant 54:d94145ba23f4 173 {DMID_DeviceMode, 6, 3, DeviceModeRequestCheck}
Diletant 54:d94145ba23f4 174 };
Diletant 54:d94145ba23f4 175
Diletant 54:d94145ba23f4 176 DeviceMessageCheck DeviceResponseChecks[] = {
Diletant 54:d94145ba23f4 177 {DMID_DeviceMode, 8, 2, DeviceModeResponseCheck}
Diletant 54:d94145ba23f4 178 };
Diletant 59:daf3a8ed255e 179 */
Diletant 54:d94145ba23f4 180
Diletant 69:70849751d98e 181 int PullRequest(DeviceInputBuffer *b);
Diletant 69:70849751d98e 182
Diletant 73:29fccfe239a3 183 void TransmitDelta(void);
Diletant 54:d94145ba23f4 184
Diletant 71:7835a18110bd 185 DeviceLatchMode DecodeLatchModeFromDeviceMode(uint8_t param);
Diletant 71:7835a18110bd 186 DeviceDeltaMode DecodeDeltaModeFromDeviceMode(uint8_t param);
Diletant 71:7835a18110bd 187 uint32_t DecodeResponseBaudRateFromDeltaBINS(uint8_t param);
Diletant 71:7835a18110bd 188 uint32_t DecodeRequestBaudRateFromDeltaBINS(uint8_t param);
Diletant 71:7835a18110bd 189 uint32_t DecodeResponsePeriodFromDeltaBINS(uint8_t param);
Diletant 64:8179dacbf32b 190
Diletant 72:f5e189c62bcb 191 void Encode8(uint8_t);
Diletant 72:f5e189c62bcb 192 void Encode16(uint16_t);
Diletant 73:29fccfe239a3 193
Diletant 73:29fccfe239a3 194 void EncodeStart(void);
Diletant 73:29fccfe239a3 195 void EncodeEnd(void);
Diletant 73:29fccfe239a3 196
Diletant 72:f5e189c62bcb 197 void EncodeDeviceMode(void);
Diletant 72:f5e189c62bcb 198 void EncodeSysRgR(void);
Diletant 73:29fccfe239a3 199
Diletant 72:f5e189c62bcb 200 void EncodeCRC(void);
Diletant 72:f5e189c62bcb 201
Diletant 54:d94145ba23f4 202 #endif /* __DEVICEPROTOCOL_H__ */