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