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