![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
n
Fork of LG by
Command.c@17:44b2801ac94b, 2016-02-01 (annotated)
- Committer:
- DarkPatrick
- Date:
- Mon Feb 01 07:17:28 2016 +0000
- Revision:
- 17:44b2801ac94b
- Parent:
- 0:8ad47e2b6f00
- Child:
- 20:e56d63c1ca05
some comment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "stdlib.h" |
igor_v | 0:8ad47e2b6f00 | 2 | #include "LPC17xx.h" |
igor_v | 0:8ad47e2b6f00 | 3 | #include "Command.h" |
igor_v | 0:8ad47e2b6f00 | 4 | #include "el_lin.h" |
igor_v | 0:8ad47e2b6f00 | 5 | #include "vibro.h" |
igor_v | 0:8ad47e2b6f00 | 6 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 7 | #include "uart_m.h" |
igor_v | 0:8ad47e2b6f00 | 8 | #include "CntrlGLD.h" |
igor_v | 0:8ad47e2b6f00 | 9 | #include "QEI.h" |
igor_v | 0:8ad47e2b6f00 | 10 | #include "InputOutput.h" |
igor_v | 0:8ad47e2b6f00 | 11 | #include "SPI.h" |
igor_v | 0:8ad47e2b6f00 | 12 | unsigned int Rate_Flag; |
igor_v | 0:8ad47e2b6f00 | 13 | unsigned int PC_Comand; |
igor_v | 0:8ad47e2b6f00 | 14 | unsigned int n; |
igor_v | 0:8ad47e2b6f00 | 15 | unsigned int CountBuFFIn; |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int ParamIn; |
igor_v | 0:8ad47e2b6f00 | 17 | unsigned int Err; |
igor_v | 0:8ad47e2b6f00 | 18 | unsigned int N=0,CRC_N; |
igor_v | 0:8ad47e2b6f00 | 19 | unsigned int Param1=0; |
igor_v | 0:8ad47e2b6f00 | 20 | unsigned int Param2=0; |
igor_v | 0:8ad47e2b6f00 | 21 | unsigned int Param3=0; |
igor_v | 0:8ad47e2b6f00 | 22 | unsigned int Param4=0; |
igor_v | 0:8ad47e2b6f00 | 23 | |
igor_v | 0:8ad47e2b6f00 | 24 | /* |
DarkPatrick | 17:44b2801ac94b | 25 | some comment here |
igor_v | 0:8ad47e2b6f00 | 26 | void exec_CMD(void) //r. === ��������� ������������� ���������� � ���������� ������� |
igor_v | 0:8ad47e2b6f00 | 27 | { |
igor_v | 0:8ad47e2b6f00 | 28 | unsigned int Comand_code; |
igor_v | 0:8ad47e2b6f00 | 29 | |
igor_v | 0:8ad47e2b6f00 | 30 | //rx_buf_copy = 1; //r. ����������� ����� ����������� ��������� ������ |
igor_v | 0:8ad47e2b6f00 | 31 | |
igor_v | 0:8ad47e2b6f00 | 32 | Comand_code = (rcv_buf[2] & 0xFF) << 8; |
igor_v | 0:8ad47e2b6f00 | 33 | PC_Comand = Comand_code | (rcv_buf[3] & 0xFF); //e. save it in the memory for echo-transmission //r. ��������� ��� � ������ ��� �������� �������� |
igor_v | 0:8ad47e2b6f00 | 34 | }*/ |
igor_v | 0:8ad47e2b6f00 | 35 | void CMD_Maintenance(void) |
igor_v | 0:8ad47e2b6f00 | 36 | { |
igor_v | 0:8ad47e2b6f00 | 37 | BuffTemp[0] = Main.SOC_Out; |
igor_v | 0:8ad47e2b6f00 | 38 | BuffTemp[1] = Main.My_Addres; |
igor_v | 0:8ad47e2b6f00 | 39 | BuffTemp[2] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 40 | BuffTemp[3] = Main.GLD_Serial; |
igor_v | 0:8ad47e2b6f00 | 41 | BuffTemp[4]=0x00; |
igor_v | 0:8ad47e2b6f00 | 42 | BuffTemp[5]=0x00; |
igor_v | 0:8ad47e2b6f00 | 43 | Check(BuffTemp, 8); |
igor_v | 0:8ad47e2b6f00 | 44 | WriteConN (BuffTemp,8); |
igor_v | 0:8ad47e2b6f00 | 45 | } |
igor_v | 0:8ad47e2b6f00 | 46 | |
igor_v | 0:8ad47e2b6f00 | 47 | void CMD_Rate(void) |
igor_v | 0:8ad47e2b6f00 | 48 | { |
igor_v | 0:8ad47e2b6f00 | 49 | |
igor_v | 0:8ad47e2b6f00 | 50 | unsigned int T_VibH , T_VibL; // ������� ������������. |
igor_v | 0:8ad47e2b6f00 | 51 | unsigned int Cnt_PlsL , Cnt_PlsH; // ������� +. |
igor_v | 0:8ad47e2b6f00 | 52 | unsigned int Cnt_MnsL , Cnt_MnsH; // ������� -. |
igor_v | 0:8ad47e2b6f00 | 53 | unsigned int Cnt_DifL , Cnt_DifH; // �������� ���������. |
igor_v | 0:8ad47e2b6f00 | 54 | unsigned int F_rasL , F_rasH; // ������� �����������. |
igor_v | 0:8ad47e2b6f00 | 55 | |
igor_v | 0:8ad47e2b6f00 | 56 | unsigned int HF_regL , HF_regH; // ����� ���������� ���. �� ������� |
igor_v | 0:8ad47e2b6f00 | 57 | unsigned int HF_difL , HF_difH; // ������ ������ ����������� ���. �� ������� |
igor_v | 0:8ad47e2b6f00 | 58 | |
igor_v | 0:8ad47e2b6f00 | 59 | unsigned int WP_regL , WP_regH; |
igor_v | 0:8ad47e2b6f00 | 60 | |
igor_v | 0:8ad47e2b6f00 | 61 | unsigned int ADC1L, ADC2L, ADC3L, ADC4L, ADC5L; |
igor_v | 0:8ad47e2b6f00 | 62 | unsigned int ADC1H, ADC2H, ADC3H, ADC4H, ADC5H; |
igor_v | 0:8ad47e2b6f00 | 63 | |
igor_v | 0:8ad47e2b6f00 | 64 | |
igor_v | 0:8ad47e2b6f00 | 65 | LoopOn |
igor_v | 0:8ad47e2b6f00 | 66 | // Main.T_Vib=(unsigned int)((7680000*16/Main.Frq)*4096); |
igor_v | 0:8ad47e2b6f00 | 67 | Main.T_Vib=(unsigned int)((7680000*16/(Main.Frq>>12))); |
igor_v | 0:8ad47e2b6f00 | 68 | Main.Firmware_Version=0xff; /// ������������� ������� |
igor_v | 0:8ad47e2b6f00 | 69 | |
igor_v | 0:8ad47e2b6f00 | 70 | T_VibH = ( Main.T_Vib>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 71 | T_VibL = ( Main.T_Vib ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 72 | |
igor_v | 0:8ad47e2b6f00 | 73 | Cnt_PlsH = ( Main.Cnt_Pls>>8) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 74 | Cnt_PlsL = ( Main.Cnt_Pls ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 75 | |
igor_v | 0:8ad47e2b6f00 | 76 | Cnt_MnsH = ( Main.Cnt_Mns>>8) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 77 | Cnt_MnsL = ( Main.Cnt_Mns ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 78 | |
igor_v | 0:8ad47e2b6f00 | 79 | Cnt_DifH = ( Main.Cnt_Dif>>8) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 80 | Cnt_DifL = ( Main.Cnt_Dif ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 81 | |
igor_v | 0:8ad47e2b6f00 | 82 | F_rasH = ( Main.F_ras>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 83 | F_rasL = ( Main.F_ras ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 84 | |
igor_v | 0:8ad47e2b6f00 | 85 | ADC1H = ( Spi.ADC1>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 86 | ADC1L = ( Spi.ADC1 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 87 | |
igor_v | 0:8ad47e2b6f00 | 88 | ADC2H = ( Spi.ADC2>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 89 | ADC2L = ( Spi.ADC2 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 90 | |
igor_v | 0:8ad47e2b6f00 | 91 | ADC3H = ( Spi.ADC3>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 92 | ADC3L = ( Spi.ADC3 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 93 | |
igor_v | 0:8ad47e2b6f00 | 94 | ADC4H = ( Spi.ADC4>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 95 | ADC4L = ( Spi.ADC4 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 96 | |
igor_v | 0:8ad47e2b6f00 | 97 | ADC5H = ( Spi.ADC5>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 98 | ADC5L = ( Spi.ADC5 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 99 | |
igor_v | 0:8ad47e2b6f00 | 100 | WP_regH = ( Spi.DAC_B>>8 ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 101 | WP_regL = ( Spi.DAC_B ) TakeByte; |
igor_v | 0:8ad47e2b6f00 | 102 | |
igor_v | 0:8ad47e2b6f00 | 103 | HF_regH=0xff; |
igor_v | 0:8ad47e2b6f00 | 104 | HF_regL=0xff; |
igor_v | 0:8ad47e2b6f00 | 105 | |
igor_v | 0:8ad47e2b6f00 | 106 | HF_difH=0xff; |
igor_v | 0:8ad47e2b6f00 | 107 | HF_difL=0xff; |
igor_v | 0:8ad47e2b6f00 | 108 | |
igor_v | 0:8ad47e2b6f00 | 109 | |
igor_v | 0:8ad47e2b6f00 | 110 | BuffTemp[ 0] = Main.SOC_Out; |
igor_v | 0:8ad47e2b6f00 | 111 | BuffTemp[ 1] = Main.My_Addres; |
igor_v | 0:8ad47e2b6f00 | 112 | |
igor_v | 0:8ad47e2b6f00 | 113 | BuffTemp[ 2] = Cnt_PlsH;//������� ���� �������� +. |
igor_v | 0:8ad47e2b6f00 | 114 | BuffTemp[ 3] = Cnt_PlsL;//������� ���� �������� +. |
igor_v | 0:8ad47e2b6f00 | 115 | |
igor_v | 0:8ad47e2b6f00 | 116 | BuffTemp[ 4] = Cnt_MnsH;//������� ���� �������� -. |
igor_v | 0:8ad47e2b6f00 | 117 | BuffTemp[ 5] = Cnt_MnsL;//������� ���� �������� -. |
igor_v | 0:8ad47e2b6f00 | 118 | |
igor_v | 0:8ad47e2b6f00 | 119 | BuffTemp[ 6] = Cnt_DifH;//������� ���� �������� ��������� |
igor_v | 0:8ad47e2b6f00 | 120 | BuffTemp[ 7] = Cnt_DifL;//������� ���� �������� ��������� |
igor_v | 0:8ad47e2b6f00 | 121 | |
igor_v | 0:8ad47e2b6f00 | 122 | BuffTemp[ 8] = F_rasH; |
igor_v | 0:8ad47e2b6f00 | 123 | BuffTemp[ 9] = F_rasL; |
igor_v | 0:8ad47e2b6f00 | 124 | |
igor_v | 0:8ad47e2b6f00 | 125 | BuffTemp[10] = HF_regH; |
igor_v | 0:8ad47e2b6f00 | 126 | BuffTemp[11] = HF_regL; |
igor_v | 0:8ad47e2b6f00 | 127 | |
igor_v | 0:8ad47e2b6f00 | 128 | BuffTemp[12] = HF_difH; |
igor_v | 0:8ad47e2b6f00 | 129 | BuffTemp[13] = HF_difL; |
igor_v | 0:8ad47e2b6f00 | 130 | |
igor_v | 0:8ad47e2b6f00 | 131 | BuffTemp[14] = T_VibH ;// |
igor_v | 0:8ad47e2b6f00 | 132 | BuffTemp[15] = T_VibL; //? |
igor_v | 0:8ad47e2b6f00 | 133 | |
igor_v | 0:8ad47e2b6f00 | 134 | BuffTemp[16] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 135 | BuffTemp[17] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 136 | |
igor_v | 0:8ad47e2b6f00 | 137 | BuffTemp[18] = T_VibH>>1; |
igor_v | 0:8ad47e2b6f00 | 138 | BuffTemp[19] = T_VibL; |
igor_v | 0:8ad47e2b6f00 | 139 | |
igor_v | 0:8ad47e2b6f00 | 140 | BuffTemp[20] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 141 | BuffTemp[21] = Main.Firmware_Version;//�� |
igor_v | 0:8ad47e2b6f00 | 142 | |
igor_v | 0:8ad47e2b6f00 | 143 | BuffTemp[22] = WP_regH; //��� Spi.DAC_B |
igor_v | 0:8ad47e2b6f00 | 144 | BuffTemp[23] = WP_regL; //��� |
igor_v | 0:8ad47e2b6f00 | 145 | |
igor_v | 0:8ad47e2b6f00 | 146 | BuffTemp[24] = Main.Firmware_Version;// �� |
igor_v | 0:8ad47e2b6f00 | 147 | BuffTemp[25] = Main.Firmware_Version;// �� |
igor_v | 0:8ad47e2b6f00 | 148 | |
igor_v | 0:8ad47e2b6f00 | 149 | BuffTemp[26] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 150 | BuffTemp[27] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 151 | |
igor_v | 0:8ad47e2b6f00 | 152 | BuffTemp[28] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 153 | BuffTemp[29] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 154 | |
igor_v | 0:8ad47e2b6f00 | 155 | BuffTemp[30] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 156 | BuffTemp[31] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 157 | |
igor_v | 0:8ad47e2b6f00 | 158 | BuffTemp[32] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 159 | BuffTemp[33] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 160 | |
igor_v | 0:8ad47e2b6f00 | 161 | BuffTemp[34] = ADC1H; |
igor_v | 0:8ad47e2b6f00 | 162 | BuffTemp[35] = ADC1L; |
igor_v | 0:8ad47e2b6f00 | 163 | |
igor_v | 0:8ad47e2b6f00 | 164 | BuffTemp[36] = 0x00;//ADC6 |
igor_v | 0:8ad47e2b6f00 | 165 | BuffTemp[37] = 0x00;//ADC6 |
igor_v | 0:8ad47e2b6f00 | 166 | |
igor_v | 0:8ad47e2b6f00 | 167 | BuffTemp[38] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 168 | BuffTemp[39] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 169 | BuffTemp[40] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 170 | BuffTemp[41] = Main.Firmware_Version; |
igor_v | 0:8ad47e2b6f00 | 171 | |
igor_v | 0:8ad47e2b6f00 | 172 | |
igor_v | 0:8ad47e2b6f00 | 173 | Check(BuffTemp, 44); |
igor_v | 0:8ad47e2b6f00 | 174 | WriteConN (BuffTemp,44); |
igor_v | 0:8ad47e2b6f00 | 175 | LoopOff |
igor_v | 0:8ad47e2b6f00 | 176 | } |
igor_v | 0:8ad47e2b6f00 | 177 | |
igor_v | 0:8ad47e2b6f00 | 178 | void CMD_M_Control_D8()///���������\����� ��������� ���������� |
igor_v | 0:8ad47e2b6f00 | 179 | { |
igor_v | 0:8ad47e2b6f00 | 180 | int bit,NReg; |
igor_v | 0:8ad47e2b6f00 | 181 | BuffTemp[0] = Main.SOC_Out; //DD |
igor_v | 0:8ad47e2b6f00 | 182 | BuffTemp[1] = Main.My_Addres; //00 |
igor_v | 0:8ad47e2b6f00 | 183 | BuffTemp[2] = Main.CMD_In; //D8 |
igor_v | 0:8ad47e2b6f00 | 184 | //10? |
igor_v | 0:8ad47e2b6f00 | 185 | if((Param1&0x80)) |
igor_v | 0:8ad47e2b6f00 | 186 | { |
igor_v | 0:8ad47e2b6f00 | 187 | bit=1; |
igor_v | 0:8ad47e2b6f00 | 188 | } |
igor_v | 0:8ad47e2b6f00 | 189 | else |
igor_v | 0:8ad47e2b6f00 | 190 | { |
igor_v | 0:8ad47e2b6f00 | 191 | bit=0; |
igor_v | 0:8ad47e2b6f00 | 192 | } |
igor_v | 0:8ad47e2b6f00 | 193 | |
igor_v | 0:8ad47e2b6f00 | 194 | if ((Param1 & 0x10) == 0) |
igor_v | 0:8ad47e2b6f00 | 195 | { |
igor_v | 0:8ad47e2b6f00 | 196 | NReg=0; |
igor_v | 0:8ad47e2b6f00 | 197 | switch(Param1&0xf) // Main.RgConA |
igor_v | 0:8ad47e2b6f00 | 198 | { |
igor_v | 0:8ad47e2b6f00 | 199 | case 0x0: |
igor_v | 0:8ad47e2b6f00 | 200 | Main.RgConA|=bit; |
igor_v | 0:8ad47e2b6f00 | 201 | break; |
igor_v | 0:8ad47e2b6f00 | 202 | |
igor_v | 0:8ad47e2b6f00 | 203 | case 0x1: |
igor_v | 0:8ad47e2b6f00 | 204 | Main.RgConA|=bit<<0x1; |
igor_v | 0:8ad47e2b6f00 | 205 | break; |
igor_v | 0:8ad47e2b6f00 | 206 | |
igor_v | 0:8ad47e2b6f00 | 207 | case 0x2: |
igor_v | 0:8ad47e2b6f00 | 208 | Main.RgConA|=bit<<0x2; |
igor_v | 0:8ad47e2b6f00 | 209 | break; |
igor_v | 0:8ad47e2b6f00 | 210 | |
igor_v | 0:8ad47e2b6f00 | 211 | case 0x3: |
igor_v | 0:8ad47e2b6f00 | 212 | Main.RgConA|=bit<<0x3; |
igor_v | 0:8ad47e2b6f00 | 213 | break; |
igor_v | 0:8ad47e2b6f00 | 214 | |
igor_v | 0:8ad47e2b6f00 | 215 | case 0x4: |
igor_v | 0:8ad47e2b6f00 | 216 | Main.RgConA|=bit<<0x4; |
igor_v | 0:8ad47e2b6f00 | 217 | break; |
igor_v | 0:8ad47e2b6f00 | 218 | |
igor_v | 0:8ad47e2b6f00 | 219 | case 0x5: |
igor_v | 0:8ad47e2b6f00 | 220 | Main.RgConA|=bit<<0x5; |
igor_v | 0:8ad47e2b6f00 | 221 | break; |
igor_v | 0:8ad47e2b6f00 | 222 | |
igor_v | 0:8ad47e2b6f00 | 223 | case 0x6: |
igor_v | 0:8ad47e2b6f00 | 224 | Main.RgConA|=bit<<0x6; |
igor_v | 0:8ad47e2b6f00 | 225 | break; |
igor_v | 0:8ad47e2b6f00 | 226 | |
igor_v | 0:8ad47e2b6f00 | 227 | case 0x7: |
igor_v | 0:8ad47e2b6f00 | 228 | Main.RgConA|=bit<<0x7; |
igor_v | 0:8ad47e2b6f00 | 229 | break; |
igor_v | 0:8ad47e2b6f00 | 230 | } |
igor_v | 0:8ad47e2b6f00 | 231 | BuffTemp[3] = NReg<<4; |
igor_v | 0:8ad47e2b6f00 | 232 | BuffTemp[4] = (Main.RgConA>>8 )& 0xff; |
igor_v | 0:8ad47e2b6f00 | 233 | BuffTemp[5] = Main.RgConA & 0xff; |
igor_v | 0:8ad47e2b6f00 | 234 | } |
igor_v | 0:8ad47e2b6f00 | 235 | else |
igor_v | 0:8ad47e2b6f00 | 236 | { |
igor_v | 0:8ad47e2b6f00 | 237 | NReg=1; // Main.RgConB |
igor_v | 0:8ad47e2b6f00 | 238 | switch(Param1&0xf) // Main.RgConB |
igor_v | 0:8ad47e2b6f00 | 239 | { |
igor_v | 0:8ad47e2b6f00 | 240 | case 0x0: |
igor_v | 0:8ad47e2b6f00 | 241 | Main.RgConB|=bit; |
igor_v | 0:8ad47e2b6f00 | 242 | break; |
igor_v | 0:8ad47e2b6f00 | 243 | case 0x1: |
igor_v | 0:8ad47e2b6f00 | 244 | Main.RgConB|=bit<1; |
igor_v | 0:8ad47e2b6f00 | 245 | break; |
igor_v | 0:8ad47e2b6f00 | 246 | case 0x2: |
igor_v | 0:8ad47e2b6f00 | 247 | Main.RgConB|=bit<2; |
igor_v | 0:8ad47e2b6f00 | 248 | break; |
igor_v | 0:8ad47e2b6f00 | 249 | } |
igor_v | 0:8ad47e2b6f00 | 250 | BuffTemp[3] = NReg<<4; |
igor_v | 0:8ad47e2b6f00 | 251 | BuffTemp[4] = (Main.RgConB>>8 ) & 0xff; |
igor_v | 0:8ad47e2b6f00 | 252 | BuffTemp[5] = Main.RgConB & 0xff; |
igor_v | 0:8ad47e2b6f00 | 253 | } |
igor_v | 0:8ad47e2b6f00 | 254 | |
igor_v | 0:8ad47e2b6f00 | 255 | Check(BuffTemp, CRC_N); |
igor_v | 0:8ad47e2b6f00 | 256 | WriteConN (BuffTemp,CRC_N); |
igor_v | 0:8ad47e2b6f00 | 257 | } |
igor_v | 0:8ad47e2b6f00 | 258 | |
igor_v | 0:8ad47e2b6f00 | 259 | void CMD_M_Control_D9()///������ ��������� ���������� |
igor_v | 0:8ad47e2b6f00 | 260 | { |
igor_v | 0:8ad47e2b6f00 | 261 | int bit,NReg; |
igor_v | 0:8ad47e2b6f00 | 262 | BuffTemp[0] = Main.SOC_Out; //DD |
igor_v | 0:8ad47e2b6f00 | 263 | BuffTemp[1] = Main.My_Addres; //00 |
igor_v | 0:8ad47e2b6f00 | 264 | BuffTemp[2] = Main.CMD_In; //D9 |
igor_v | 0:8ad47e2b6f00 | 265 | if ((Param1 & 0x10) == 0) |
igor_v | 0:8ad47e2b6f00 | 266 | { |
igor_v | 0:8ad47e2b6f00 | 267 | BuffTemp[3]=0<<4; |
igor_v | 0:8ad47e2b6f00 | 268 | BuffTemp[4] = (Main.RgConA>>8 )& 0xff; |
igor_v | 0:8ad47e2b6f00 | 269 | BuffTemp[5] = Main.RgConA & 0xff; |
igor_v | 0:8ad47e2b6f00 | 270 | } |
igor_v | 0:8ad47e2b6f00 | 271 | else |
igor_v | 0:8ad47e2b6f00 | 272 | { |
igor_v | 0:8ad47e2b6f00 | 273 | BuffTemp[3]=1<<4; |
igor_v | 0:8ad47e2b6f00 | 274 | BuffTemp[4] = (Main.RgConB>>8 ) & 0xff; |
igor_v | 0:8ad47e2b6f00 | 275 | BuffTemp[5] = Main.RgConB & 0xff; |
igor_v | 0:8ad47e2b6f00 | 276 | } |
igor_v | 0:8ad47e2b6f00 | 277 | Check(BuffTemp, CRC_N); |
igor_v | 0:8ad47e2b6f00 | 278 | WriteConN (BuffTemp,CRC_N); |
igor_v | 0:8ad47e2b6f00 | 279 | } |
igor_v | 0:8ad47e2b6f00 | 280 | // (����� (���) ���� 0...3, ������� ���� ���������� ����, ������� ���� ���� ����) |
igor_v | 0:8ad47e2b6f00 | 281 | void CMD_M_Stymul() |
igor_v | 0:8ad47e2b6f00 | 282 | { |
igor_v | 0:8ad47e2b6f00 | 283 | int temp; |
igor_v | 0:8ad47e2b6f00 | 284 | temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 0:8ad47e2b6f00 | 285 | // temp=0; |
igor_v | 0:8ad47e2b6f00 | 286 | temp=temp&0xFFFF; |
igor_v | 0:8ad47e2b6f00 | 287 | DACF =(temp*K_DAC)+deltaDAC; |
igor_v | 0:8ad47e2b6f00 | 288 | Spi.DAC_B =(unsigned int)(DACF) /*(unsigned int)(temp*K_DAC+deltaDAC)*/; // K_DAC); |
igor_v | 0:8ad47e2b6f00 | 289 | |
igor_v | 0:8ad47e2b6f00 | 290 | //int temp; |
igor_v | 0:8ad47e2b6f00 | 291 | // temp =((BuffTemp[4]<<8) | BuffTemp[5]); |
igor_v | 0:8ad47e2b6f00 | 292 | //temp = 65535 - temp; |
igor_v | 0:8ad47e2b6f00 | 293 | /*if(temp<1000) |
igor_v | 0:8ad47e2b6f00 | 294 | { |
igor_v | 0:8ad47e2b6f00 | 295 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 296 | } |
igor_v | 0:8ad47e2b6f00 | 297 | else if(temp>60000) |
igor_v | 0:8ad47e2b6f00 | 298 | { |
igor_v | 0:8ad47e2b6f00 | 299 | temp=65535; |
igor_v | 0:8ad47e2b6f00 | 300 | }*/ |
igor_v | 0:8ad47e2b6f00 | 301 | //Spi.DAC_B =(((BuffTemp[4]<<8) | BuffTemp[5])*K_DAC+deltaDAC);/*((BuffTemp[4]<<8) | BuffTemp[5])-0xFFFF*///; //((rcv_buf[4] << 8) | (int)rcv_buf[5]);K_DAC+deltaDAC |
igor_v | 0:8ad47e2b6f00 | 302 | //BuffTemp[0] = temp; //DD |
igor_v | 0:8ad47e2b6f00 | 303 | //WriteConN (BuffTemp,1); |
igor_v | 0:8ad47e2b6f00 | 304 | } |
igor_v | 0:8ad47e2b6f00 | 305 | |
igor_v | 0:8ad47e2b6f00 | 306 | unsigned int Check(char *c, unsigned int Count) |
igor_v | 0:8ad47e2b6f00 | 307 | { |
igor_v | 0:8ad47e2b6f00 | 308 | int i=1; |
igor_v | 0:8ad47e2b6f00 | 309 | unsigned int temp,CRC; |
igor_v | 0:8ad47e2b6f00 | 310 | |
igor_v | 0:8ad47e2b6f00 | 311 | |
igor_v | 0:8ad47e2b6f00 | 312 | temp=1; |
igor_v | 0:8ad47e2b6f00 | 313 | CRC=0; |
igor_v | 0:8ad47e2b6f00 | 314 | |
igor_v | 0:8ad47e2b6f00 | 315 | |
igor_v | 0:8ad47e2b6f00 | 316 | for(;i<Count-2;i++) |
igor_v | 0:8ad47e2b6f00 | 317 | { |
igor_v | 0:8ad47e2b6f00 | 318 | CRC+=c[i]; |
igor_v | 0:8ad47e2b6f00 | 319 | } |
igor_v | 0:8ad47e2b6f00 | 320 | |
igor_v | 0:8ad47e2b6f00 | 321 | if(c[Count-2]!=((CRC>>8)&0xFF)) |
igor_v | 0:8ad47e2b6f00 | 322 | { |
igor_v | 0:8ad47e2b6f00 | 323 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 324 | Main.RsErrLine = (Main.RsErrLine)&=0x2; |
igor_v | 0:8ad47e2b6f00 | 325 | } |
igor_v | 0:8ad47e2b6f00 | 326 | |
igor_v | 0:8ad47e2b6f00 | 327 | if(c[Count-1]!=((CRC>>0)&0xFF)) |
igor_v | 0:8ad47e2b6f00 | 328 | { |
igor_v | 0:8ad47e2b6f00 | 329 | temp=0; |
igor_v | 0:8ad47e2b6f00 | 330 | // Main.RsErrLine= (Main.RsErrLine)=0x2; |
igor_v | 0:8ad47e2b6f00 | 331 | } |
igor_v | 0:8ad47e2b6f00 | 332 | |
igor_v | 0:8ad47e2b6f00 | 333 | c[Count-2]=(CRC>>8)&0xFF; |
igor_v | 0:8ad47e2b6f00 | 334 | c[Count-1]=(CRC>>0)&0xFF; |
igor_v | 0:8ad47e2b6f00 | 335 | |
igor_v | 0:8ad47e2b6f00 | 336 | |
igor_v | 0:8ad47e2b6f00 | 337 | |
igor_v | 0:8ad47e2b6f00 | 338 | return temp; |
igor_v | 0:8ad47e2b6f00 | 339 | } |
igor_v | 0:8ad47e2b6f00 | 340 | |
igor_v | 0:8ad47e2b6f00 | 341 | int Getlengf(void) |
igor_v | 0:8ad47e2b6f00 | 342 | { |
igor_v | 0:8ad47e2b6f00 | 343 | unsigned int lengf=0; |
igor_v | 0:8ad47e2b6f00 | 344 | switch(Main.CMD_In) |
igor_v | 0:8ad47e2b6f00 | 345 | { |
igor_v | 0:8ad47e2b6f00 | 346 | case 0x99://maintainance |
igor_v | 0:8ad47e2b6f00 | 347 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 348 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 349 | break; |
igor_v | 0:8ad47e2b6f00 | 350 | |
igor_v | 0:8ad47e2b6f00 | 351 | case 0x0A: //m_stymul |
igor_v | 0:8ad47e2b6f00 | 352 | lengf=8; |
igor_v | 0:8ad47e2b6f00 | 353 | break; |
igor_v | 0:8ad47e2b6f00 | 354 | |
igor_v | 0:8ad47e2b6f00 | 355 | case 0xA5://DeviceMode |
igor_v | 0:8ad47e2b6f00 | 356 | |
igor_v | 0:8ad47e2b6f00 | 357 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 358 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 359 | break; |
igor_v | 0:8ad47e2b6f00 | 360 | |
igor_v | 0:8ad47e2b6f00 | 361 | case 0xDD://m_rate |
igor_v | 0:8ad47e2b6f00 | 362 | |
igor_v | 0:8ad47e2b6f00 | 363 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 364 | CRC_N=44; |
igor_v | 0:8ad47e2b6f00 | 365 | break; |
igor_v | 0:8ad47e2b6f00 | 366 | |
igor_v | 0:8ad47e2b6f00 | 367 | case 0xB0://DeviceMode |
igor_v | 0:8ad47e2b6f00 | 368 | |
igor_v | 0:8ad47e2b6f00 | 369 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 370 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 371 | break; |
igor_v | 0:8ad47e2b6f00 | 372 | |
igor_v | 0:8ad47e2b6f00 | 373 | case 0xD8://m_control |
igor_v | 0:8ad47e2b6f00 | 374 | |
igor_v | 0:8ad47e2b6f00 | 375 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 376 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 377 | break; |
igor_v | 0:8ad47e2b6f00 | 378 | |
igor_v | 0:8ad47e2b6f00 | 379 | case 0xD9://m_control |
igor_v | 0:8ad47e2b6f00 | 380 | |
igor_v | 0:8ad47e2b6f00 | 381 | lengf=6; |
igor_v | 0:8ad47e2b6f00 | 382 | CRC_N=8; |
igor_v | 0:8ad47e2b6f00 | 383 | break; |
igor_v | 0:8ad47e2b6f00 | 384 | } |
igor_v | 0:8ad47e2b6f00 | 385 | return lengf; |
igor_v | 0:8ad47e2b6f00 | 386 | } |
igor_v | 0:8ad47e2b6f00 | 387 | |
igor_v | 0:8ad47e2b6f00 | 388 | void Read_CMD(void) |
igor_v | 0:8ad47e2b6f00 | 389 | { |
igor_v | 0:8ad47e2b6f00 | 390 | Main.SOC_Out=0xDD; |
igor_v | 0:8ad47e2b6f00 | 391 | Main.RsErrLine = (Main.RsErrLine)& 0xffff; |
igor_v | 0:8ad47e2b6f00 | 392 | |
igor_v | 0:8ad47e2b6f00 | 393 | |
igor_v | 0:8ad47e2b6f00 | 394 | CountBuFFIn=ReadChekCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 395 | if(CountBuFFIn==1) |
igor_v | 0:8ad47e2b6f00 | 396 | { |
igor_v | 0:8ad47e2b6f00 | 397 | if (BuffTemp[0] != SOC_In) |
igor_v | 0:8ad47e2b6f00 | 398 | { |
igor_v | 0:8ad47e2b6f00 | 399 | ReadCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 400 | Main.RsErrLine += 0x100;//WriteCon("\n\r ...Error.... "); |
igor_v | 0:8ad47e2b6f00 | 401 | BuffTemp[99]=Main.RsErrLine; |
igor_v | 0:8ad47e2b6f00 | 402 | } |
igor_v | 0:8ad47e2b6f00 | 403 | } |
igor_v | 0:8ad47e2b6f00 | 404 | else if(CountBuFFIn==2) |
igor_v | 0:8ad47e2b6f00 | 405 | { |
igor_v | 0:8ad47e2b6f00 | 406 | if (BuffTemp[1] != Main.My_Addres) |
igor_v | 0:8ad47e2b6f00 | 407 | { |
igor_v | 0:8ad47e2b6f00 | 408 | ReadCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 409 | Main.RsErrLine += 0x1;//WriteCon("\n\r ...Error_ADDRES.... "); |
igor_v | 0:8ad47e2b6f00 | 410 | } |
igor_v | 0:8ad47e2b6f00 | 411 | } |
igor_v | 0:8ad47e2b6f00 | 412 | else if(CountBuFFIn==3) |
igor_v | 0:8ad47e2b6f00 | 413 | { |
igor_v | 0:8ad47e2b6f00 | 414 | Main.CMD_In=BuffTemp[2]; |
igor_v | 0:8ad47e2b6f00 | 415 | N=Getlengf(); |
igor_v | 0:8ad47e2b6f00 | 416 | } |
igor_v | 0:8ad47e2b6f00 | 417 | |
igor_v | 0:8ad47e2b6f00 | 418 | else if(CountBuFFIn==4 && N==6) |
igor_v | 0:8ad47e2b6f00 | 419 | { |
igor_v | 0:8ad47e2b6f00 | 420 | Param1=BuffTemp[3]; |
igor_v | 0:8ad47e2b6f00 | 421 | } |
igor_v | 0:8ad47e2b6f00 | 422 | else if((CountBuFFIn==5)&&(N==7)) |
igor_v | 0:8ad47e2b6f00 | 423 | { |
igor_v | 0:8ad47e2b6f00 | 424 | //LoopOn |
igor_v | 0:8ad47e2b6f00 | 425 | Param1=BuffTemp[3]; |
igor_v | 0:8ad47e2b6f00 | 426 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 427 | |
igor_v | 0:8ad47e2b6f00 | 428 | } |
igor_v | 0:8ad47e2b6f00 | 429 | else if((CountBuFFIn==6)&&(N==8)) |
igor_v | 0:8ad47e2b6f00 | 430 | { |
igor_v | 0:8ad47e2b6f00 | 431 | Param1=BuffTemp[3]; |
igor_v | 0:8ad47e2b6f00 | 432 | Param2=BuffTemp[4]; |
igor_v | 0:8ad47e2b6f00 | 433 | Param3=BuffTemp[5]; |
igor_v | 0:8ad47e2b6f00 | 434 | } |
igor_v | 0:8ad47e2b6f00 | 435 | else if(CountBuFFIn > (N-1)) |
igor_v | 0:8ad47e2b6f00 | 436 | { |
igor_v | 0:8ad47e2b6f00 | 437 | ReadCon(BuffTemp); |
igor_v | 0:8ad47e2b6f00 | 438 | if(Check(BuffTemp, CountBuFFIn)) |
igor_v | 0:8ad47e2b6f00 | 439 | { |
igor_v | 0:8ad47e2b6f00 | 440 | switch(Main.CMD_In) |
igor_v | 0:8ad47e2b6f00 | 441 | { |
igor_v | 0:8ad47e2b6f00 | 442 | case CMD_MAINT: |
igor_v | 0:8ad47e2b6f00 | 443 | CMD_Maintenance(); |
igor_v | 0:8ad47e2b6f00 | 444 | break; |
igor_v | 0:8ad47e2b6f00 | 445 | case 0xD8: |
igor_v | 0:8ad47e2b6f00 | 446 | CMD_M_Control_D8(); |
igor_v | 0:8ad47e2b6f00 | 447 | case 0xD9: |
igor_v | 0:8ad47e2b6f00 | 448 | CMD_M_Control_D9(); |
igor_v | 0:8ad47e2b6f00 | 449 | break; |
igor_v | 0:8ad47e2b6f00 | 450 | case 0x0A: |
igor_v | 0:8ad47e2b6f00 | 451 | CMD_M_Stymul(Param1,Param2,Param3); |
igor_v | 0:8ad47e2b6f00 | 452 | break; |
igor_v | 0:8ad47e2b6f00 | 453 | case 0xDD: |
igor_v | 0:8ad47e2b6f00 | 454 | Rate_Flag=1; |
igor_v | 0:8ad47e2b6f00 | 455 | break; |
igor_v | 0:8ad47e2b6f00 | 456 | Main.RsErrLine = 0; |
igor_v | 0:8ad47e2b6f00 | 457 | } |
igor_v | 0:8ad47e2b6f00 | 458 | |
igor_v | 0:8ad47e2b6f00 | 459 | } |
igor_v | 0:8ad47e2b6f00 | 460 | } |
igor_v | 0:8ad47e2b6f00 | 461 | } |
igor_v | 0:8ad47e2b6f00 | 462 | |
igor_v | 0:8ad47e2b6f00 | 463 |