Example project for the Rioux Chem control box
Rioux Chem Control Box
This is the example project for the Rioux Chem Control Box. I have posted some youtube videos to guide you through the hardware and software:
Rioux Chem Control Box - Hardware
http://www.youtube.com/watch?v=MoZ92GRYa4s
Rioux Chem Control Box - Software - Part I
http://www.youtube.com/watch?v=_MwaTLL4dyA==
Rioux Chem Control Box - Software - Part II
http://www.youtube.com/watch?v=j_P89izfgoQ
DRIVERS/CHEM_BOX_COMMON.cpp@9:c830667212f4, 2021-11-01 (annotated)
- Committer:
- wavenumber
- Date:
- Mon Nov 01 19:49:13 2021 +0000
- Revision:
- 9:c830667212f4
- Parent:
- 8:0cf1573051e8
Fixed Thermocouple sign extend error
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 0:7798270c1f52 | 1 | #include "mbed.h" |
emh203 | 0:7798270c1f52 | 2 | #include "CHEM_BOX_INTERFACE.h" |
emh203 | 0:7798270c1f52 | 3 | #include "MODSERIAL.h" |
emh203 | 0:7798270c1f52 | 4 | #include <stdio.h> |
emh203 | 0:7798270c1f52 | 5 | #include <stdarg.h> |
emh203 | 0:7798270c1f52 | 6 | |
emh203 | 0:7798270c1f52 | 7 | //Mbed Objects |
emh203 | 0:7798270c1f52 | 8 | |
wavenumber | 2:73a028278c5c | 9 | DigitalOut MBED_LED1(LED1); |
wavenumber | 2:73a028278c5c | 10 | |
emh203 | 0:7798270c1f52 | 11 | DigitalOut AIO_ADC1_CS(p30); |
emh203 | 0:7798270c1f52 | 12 | |
emh203 | 0:7798270c1f52 | 13 | DigitalOut AIO_ADC2_CS(p29); |
emh203 | 0:7798270c1f52 | 14 | |
emh203 | 0:7798270c1f52 | 15 | PwmOut BUZZER_CONTROL(p26); |
emh203 | 0:7798270c1f52 | 16 | |
emh203 | 0:7798270c1f52 | 17 | DigitalOut MCU_SR_CLEAR(p25); |
emh203 | 0:7798270c1f52 | 18 | |
emh203 | 0:7798270c1f52 | 19 | DigitalOut AIO_DAC1_CS(p24); |
emh203 | 0:7798270c1f52 | 20 | |
emh203 | 0:7798270c1f52 | 21 | DigitalOut AIO_DAC2_CS(p23); |
emh203 | 0:7798270c1f52 | 22 | |
wavenumber | 3:cb48919cd5e8 | 23 | DigitalOut RED_LED(p20); |
wavenumber | 3:cb48919cd5e8 | 24 | |
wavenumber | 3:cb48919cd5e8 | 25 | DigitalOut GREEN_LED(p14); |
wavenumber | 3:cb48919cd5e8 | 26 | |
wavenumber | 3:cb48919cd5e8 | 27 | |
emh203 | 0:7798270c1f52 | 28 | DigitalOut MFC_POWER_CONTROL(p22); |
emh203 | 0:7798270c1f52 | 29 | |
emh203 | 0:7798270c1f52 | 30 | PwmOut FAN_CONTROL(p21); |
emh203 | 0:7798270c1f52 | 31 | |
emh203 | 0:7798270c1f52 | 32 | SPI SPI1(p5,p6,p7); |
emh203 | 0:7798270c1f52 | 33 | |
emh203 | 0:7798270c1f52 | 34 | DigitalOut MCU_SR_LOAD(p8); |
emh203 | 0:7798270c1f52 | 35 | |
emh203 | 0:7798270c1f52 | 36 | SPI SPI0(p11,p12,p13); |
emh203 | 0:7798270c1f52 | 37 | |
emh203 | 0:7798270c1f52 | 38 | |
emh203 | 0:7798270c1f52 | 39 | BusOut TEMP_SENSE_ADDRESS(p15,p16,p17,p18); |
emh203 | 0:7798270c1f52 | 40 | |
emh203 | 0:7798270c1f52 | 41 | DigitalOut TEMP_SENSE_CS(p19); |
emh203 | 0:7798270c1f52 | 42 | |
emh203 | 0:7798270c1f52 | 43 | |
emh203 | 0:7798270c1f52 | 44 | MODSERIAL RS232_0(p9, p10, 1024, 1024); |
emh203 | 0:7798270c1f52 | 45 | |
emh203 | 0:7798270c1f52 | 46 | MODSERIAL RS232_1(p28, p27, 1024, 1024); |
emh203 | 0:7798270c1f52 | 47 | |
emh203 | 0:7798270c1f52 | 48 | // Make TX buffer 1024bytes and RX buffer use 512bytes. |
emh203 | 0:7798270c1f52 | 49 | MODSERIAL PC(USBTX, USBRX, 1024, 1024); // tx, rx |
emh203 | 0:7798270c1f52 | 50 | |
emh203 | 0:7798270c1f52 | 51 | //Local Variables |
emh203 | 0:7798270c1f52 | 52 | |
emh203 | 0:7798270c1f52 | 53 | |
wavenumber | 2:73a028278c5c | 54 | static uint8_t TerminalEcho = 1; |
wavenumber | 2:73a028278c5c | 55 | |
emh203 | 0:7798270c1f52 | 56 | static uint8_t HeaterBits = 0; |
emh203 | 0:7798270c1f52 | 57 | |
emh203 | 0:7798270c1f52 | 58 | static uint16_t SolenoidBits = 0; |
emh203 | 0:7798270c1f52 | 59 | |
emh203 | 0:7798270c1f52 | 60 | static uint8_t DigitalOutputBits = 0; |
emh203 | 0:7798270c1f52 | 61 | |
emh203 | 0:7798270c1f52 | 62 | Timeout BuzzTimeout; |
emh203 | 0:7798270c1f52 | 63 | |
emh203 | 0:7798270c1f52 | 64 | static uint16_t Thermocouple_FAULT = 0; |
emh203 | 0:7798270c1f52 | 65 | |
emh203 | 0:7798270c1f52 | 66 | static uint16_t Thermocouple_SCV = 0; |
emh203 | 0:7798270c1f52 | 67 | |
emh203 | 0:7798270c1f52 | 68 | static uint16_t Thermocouple_SCG = 0; |
emh203 | 0:7798270c1f52 | 69 | |
emh203 | 0:7798270c1f52 | 70 | static uint16_t Thermocouple_OC= 0; |
emh203 | 0:7798270c1f52 | 71 | |
emh203 | 0:7798270c1f52 | 72 | static float Temperature[12]; |
emh203 | 0:7798270c1f52 | 73 | |
emh203 | 0:7798270c1f52 | 74 | static float InternalTemperature[12]; |
emh203 | 0:7798270c1f52 | 75 | |
emh203 | 0:7798270c1f52 | 76 | static uint16_t ReadRawADC(uint8_t Channel); |
emh203 | 0:7798270c1f52 | 77 | |
emh203 | 0:7798270c1f52 | 78 | |
emh203 | 0:7798270c1f52 | 79 | //Local Functions |
emh203 | 0:7798270c1f52 | 80 | |
emh203 | 0:7798270c1f52 | 81 | void InitTerminal(); |
emh203 | 0:7798270c1f52 | 82 | |
emh203 | 0:7798270c1f52 | 83 | void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data); |
emh203 | 0:7798270c1f52 | 84 | |
emh203 | 0:7798270c1f52 | 85 | |
emh203 | 0:7798270c1f52 | 86 | |
emh203 | 0:7798270c1f52 | 87 | void InitChemBox() |
emh203 | 0:7798270c1f52 | 88 | { |
emh203 | 0:7798270c1f52 | 89 | |
emh203 | 0:7798270c1f52 | 90 | AIO_ADC1_CS = 1; |
emh203 | 0:7798270c1f52 | 91 | |
emh203 | 0:7798270c1f52 | 92 | AIO_ADC2_CS = 1; |
emh203 | 0:7798270c1f52 | 93 | |
emh203 | 0:7798270c1f52 | 94 | BUZZER_CONTROL.period_ms(1.0); |
emh203 | 0:7798270c1f52 | 95 | |
emh203 | 0:7798270c1f52 | 96 | MCU_SR_CLEAR = 1; |
emh203 | 0:7798270c1f52 | 97 | |
emh203 | 0:7798270c1f52 | 98 | AIO_ADC1_CS = 1; |
emh203 | 0:7798270c1f52 | 99 | |
emh203 | 0:7798270c1f52 | 100 | AIO_ADC2_CS = 1; |
emh203 | 0:7798270c1f52 | 101 | |
emh203 | 0:7798270c1f52 | 102 | MFC_POWER_CONTROL = 0; |
emh203 | 0:7798270c1f52 | 103 | |
emh203 | 0:7798270c1f52 | 104 | FAN_CONTROL.period_us(1000); |
emh203 | 0:7798270c1f52 | 105 | |
emh203 | 0:7798270c1f52 | 106 | FAN_CONTROL.write(0); |
emh203 | 0:7798270c1f52 | 107 | |
emh203 | 0:7798270c1f52 | 108 | SPI1.format(8,0); |
emh203 | 0:7798270c1f52 | 109 | |
emh203 | 0:7798270c1f52 | 110 | SPI1.frequency(4000000); |
emh203 | 0:7798270c1f52 | 111 | |
emh203 | 0:7798270c1f52 | 112 | MCU_SR_LOAD = 0; |
emh203 | 0:7798270c1f52 | 113 | |
emh203 | 0:7798270c1f52 | 114 | SPI0.format(8,0); |
emh203 | 0:7798270c1f52 | 115 | |
emh203 | 0:7798270c1f52 | 116 | SPI0.frequency(4000000); |
emh203 | 0:7798270c1f52 | 117 | |
emh203 | 0:7798270c1f52 | 118 | TEMP_SENSE_ADDRESS = 0; |
emh203 | 0:7798270c1f52 | 119 | |
emh203 | 0:7798270c1f52 | 120 | TEMP_SENSE_CS = 1; |
emh203 | 0:7798270c1f52 | 121 | |
emh203 | 0:7798270c1f52 | 122 | HeaterBits = 0; |
emh203 | 0:7798270c1f52 | 123 | |
emh203 | 0:7798270c1f52 | 124 | SolenoidBits = 0; |
emh203 | 0:7798270c1f52 | 125 | |
emh203 | 0:7798270c1f52 | 126 | DigitalOutputBits = 0; |
emh203 | 0:7798270c1f52 | 127 | |
emh203 | 0:7798270c1f52 | 128 | Thermocouple_FAULT = 0; |
emh203 | 0:7798270c1f52 | 129 | |
emh203 | 0:7798270c1f52 | 130 | Thermocouple_SCV = 0; |
emh203 | 0:7798270c1f52 | 131 | |
emh203 | 0:7798270c1f52 | 132 | Thermocouple_SCG = 0; |
emh203 | 0:7798270c1f52 | 133 | |
emh203 | 0:7798270c1f52 | 134 | Thermocouple_OC= 0; |
emh203 | 0:7798270c1f52 | 135 | |
emh203 | 0:7798270c1f52 | 136 | InitTerminal(); |
wavenumber | 6:6a870e1e52c1 | 137 | |
wavenumber | 6:6a870e1e52c1 | 138 | RS232_0.baud(19200); |
wavenumber | 6:6a870e1e52c1 | 139 | |
wavenumber | 8:0cf1573051e8 | 140 | RS232_1.baud(9600); |
wavenumber | 6:6a870e1e52c1 | 141 | |
wavenumber | 3:cb48919cd5e8 | 142 | |
emh203 | 0:7798270c1f52 | 143 | } |
emh203 | 0:7798270c1f52 | 144 | |
emh203 | 0:7798270c1f52 | 145 | |
emh203 | 0:7798270c1f52 | 146 | void SetFanSpeed(uint8_t S) |
emh203 | 0:7798270c1f52 | 147 | { |
emh203 | 0:7798270c1f52 | 148 | if(S>100) |
emh203 | 0:7798270c1f52 | 149 | S = 100; |
emh203 | 0:7798270c1f52 | 150 | |
emh203 | 0:7798270c1f52 | 151 | FAN_CONTROL = (float)(S)/100.0; |
emh203 | 0:7798270c1f52 | 152 | |
emh203 | 0:7798270c1f52 | 153 | } |
emh203 | 0:7798270c1f52 | 154 | |
emh203 | 0:7798270c1f52 | 155 | void EnableFan() |
emh203 | 0:7798270c1f52 | 156 | { |
emh203 | 0:7798270c1f52 | 157 | SetFanSpeed(100); |
emh203 | 0:7798270c1f52 | 158 | } |
emh203 | 0:7798270c1f52 | 159 | |
emh203 | 0:7798270c1f52 | 160 | void DisableFan() |
emh203 | 0:7798270c1f52 | 161 | { |
emh203 | 0:7798270c1f52 | 162 | SetFanSpeed(0); |
emh203 | 0:7798270c1f52 | 163 | } |
emh203 | 0:7798270c1f52 | 164 | |
emh203 | 0:7798270c1f52 | 165 | void BuzzOff() |
emh203 | 0:7798270c1f52 | 166 | { |
emh203 | 0:7798270c1f52 | 167 | BUZZER_CONTROL = 0; |
emh203 | 0:7798270c1f52 | 168 | } |
emh203 | 0:7798270c1f52 | 169 | |
emh203 | 0:7798270c1f52 | 170 | void Buzz(float Time) |
emh203 | 0:7798270c1f52 | 171 | { |
emh203 | 0:7798270c1f52 | 172 | BUZZER_CONTROL = 0.5; |
emh203 | 0:7798270c1f52 | 173 | BuzzTimeout.attach(&BuzzOff, Time); |
emh203 | 0:7798270c1f52 | 174 | |
emh203 | 0:7798270c1f52 | 175 | } |
emh203 | 0:7798270c1f52 | 176 | |
emh203 | 0:7798270c1f52 | 177 | |
emh203 | 0:7798270c1f52 | 178 | void EnableHeater(uint8_t RelayIndex) |
emh203 | 0:7798270c1f52 | 179 | { |
emh203 | 0:7798270c1f52 | 180 | HeaterBits |= (1<<RelayIndex); |
emh203 | 0:7798270c1f52 | 181 | } |
emh203 | 0:7798270c1f52 | 182 | |
emh203 | 0:7798270c1f52 | 183 | void DisableHeater(uint8_t RelayIndex) |
emh203 | 0:7798270c1f52 | 184 | { |
emh203 | 0:7798270c1f52 | 185 | HeaterBits &= ~(1<<RelayIndex); |
emh203 | 0:7798270c1f52 | 186 | } |
emh203 | 0:7798270c1f52 | 187 | |
emh203 | 0:7798270c1f52 | 188 | void EnableSolenoidValve(uint8_t SolenoidIndex) |
emh203 | 0:7798270c1f52 | 189 | { |
emh203 | 0:7798270c1f52 | 190 | SolenoidBits |= (1<<SolenoidIndex); |
emh203 | 0:7798270c1f52 | 191 | } |
emh203 | 0:7798270c1f52 | 192 | |
emh203 | 0:7798270c1f52 | 193 | void DisableSolenoidValue(uint8_t SolenoidIndex) |
emh203 | 0:7798270c1f52 | 194 | { |
emh203 | 0:7798270c1f52 | 195 | SolenoidBits &= ~(1<<SolenoidIndex); |
emh203 | 0:7798270c1f52 | 196 | } |
emh203 | 0:7798270c1f52 | 197 | |
emh203 | 0:7798270c1f52 | 198 | void DisableAllHeatersAndSolenoids() |
emh203 | 0:7798270c1f52 | 199 | { |
emh203 | 0:7798270c1f52 | 200 | |
emh203 | 0:7798270c1f52 | 201 | SolenoidBits = 0; |
emh203 | 0:7798270c1f52 | 202 | HeaterBits = 0; |
emh203 | 0:7798270c1f52 | 203 | |
emh203 | 0:7798270c1f52 | 204 | MCU_SR_CLEAR = 1; |
emh203 | 0:7798270c1f52 | 205 | |
emh203 | 0:7798270c1f52 | 206 | MCU_SR_CLEAR = 0; |
emh203 | 0:7798270c1f52 | 207 | |
emh203 | 0:7798270c1f52 | 208 | MCU_SR_CLEAR = 1; |
emh203 | 0:7798270c1f52 | 209 | |
emh203 | 0:7798270c1f52 | 210 | MCU_SR_LOAD = 1; |
emh203 | 0:7798270c1f52 | 211 | |
emh203 | 0:7798270c1f52 | 212 | MCU_SR_LOAD = 0; |
emh203 | 0:7798270c1f52 | 213 | } |
emh203 | 0:7798270c1f52 | 214 | |
emh203 | 0:7798270c1f52 | 215 | void EnableMiscDigitalOutput(uint8_t DigitalOutIndex) |
emh203 | 0:7798270c1f52 | 216 | { |
emh203 | 0:7798270c1f52 | 217 | DigitalOutputBits |= (1<<DigitalOutIndex); |
emh203 | 0:7798270c1f52 | 218 | } |
emh203 | 0:7798270c1f52 | 219 | |
emh203 | 0:7798270c1f52 | 220 | void DisableMiscDigitalOutput(uint8_t DigitalOutIndex) |
emh203 | 0:7798270c1f52 | 221 | { |
emh203 | 0:7798270c1f52 | 222 | DigitalOutputBits &= ~(1<<DigitalOutIndex); |
emh203 | 0:7798270c1f52 | 223 | } |
emh203 | 0:7798270c1f52 | 224 | |
emh203 | 0:7798270c1f52 | 225 | void FlushDigitalIO() |
emh203 | 0:7798270c1f52 | 226 | { |
emh203 | 0:7798270c1f52 | 227 | SPI1.format(8,0); |
emh203 | 0:7798270c1f52 | 228 | |
emh203 | 0:7798270c1f52 | 229 | SPI1.write((SolenoidBits >> 8) & 0xFF); |
emh203 | 0:7798270c1f52 | 230 | SPI1.write(SolenoidBits & 0xFF); |
emh203 | 0:7798270c1f52 | 231 | SPI1.write(HeaterBits & 0xFF); |
emh203 | 0:7798270c1f52 | 232 | SPI1.write(DigitalOutputBits & 0xFF); |
emh203 | 0:7798270c1f52 | 233 | |
emh203 | 0:7798270c1f52 | 234 | MCU_SR_LOAD = 1; |
emh203 | 0:7798270c1f52 | 235 | MCU_SR_LOAD = 0; |
emh203 | 0:7798270c1f52 | 236 | } |
emh203 | 0:7798270c1f52 | 237 | |
wavenumber | 2:73a028278c5c | 238 | //Make sure to call ReadThermocouple before you call this so internal variables are updated |
emh203 | 0:7798270c1f52 | 239 | uint16_t ReadThermocouple_OC() |
emh203 | 0:7798270c1f52 | 240 | { |
emh203 | 0:7798270c1f52 | 241 | return Thermocouple_OC; |
emh203 | 0:7798270c1f52 | 242 | } |
wavenumber | 2:73a028278c5c | 243 | //Make sure to call ReadThermocouple before you call this so internal variables are updated |
emh203 | 0:7798270c1f52 | 244 | uint16_t ReadThermocouple_SCG() |
emh203 | 0:7798270c1f52 | 245 | { |
emh203 | 0:7798270c1f52 | 246 | return Thermocouple_SCG; |
emh203 | 0:7798270c1f52 | 247 | } |
wavenumber | 2:73a028278c5c | 248 | //Make sure to call ReadThermocouple before you call this so internal variables are updated |
emh203 | 0:7798270c1f52 | 249 | uint16_t ReadThermocouple_SCV() |
emh203 | 0:7798270c1f52 | 250 | { |
emh203 | 0:7798270c1f52 | 251 | return Thermocouple_SCV; |
emh203 | 0:7798270c1f52 | 252 | } |
wavenumber | 2:73a028278c5c | 253 | //Make sure to call ReadThermocouple before you call this so internal variables are updated |
emh203 | 0:7798270c1f52 | 254 | uint16_t ReadThermocouple_FAULT() |
emh203 | 0:7798270c1f52 | 255 | { |
emh203 | 0:7798270c1f52 | 256 | return Thermocouple_FAULT; |
emh203 | 0:7798270c1f52 | 257 | } |
emh203 | 0:7798270c1f52 | 258 | |
emh203 | 0:7798270c1f52 | 259 | |
emh203 | 0:7798270c1f52 | 260 | float ReadInternalTemperature(uint8_t ThermocoupleIndex) |
emh203 | 0:7798270c1f52 | 261 | { |
emh203 | 0:7798270c1f52 | 262 | ReadThermocouple(ThermocoupleIndex); //this will yank out the Data |
emh203 | 0:7798270c1f52 | 263 | return InternalTemperature[ThermocoupleIndex]; |
emh203 | 0:7798270c1f52 | 264 | } |
emh203 | 0:7798270c1f52 | 265 | |
emh203 | 0:7798270c1f52 | 266 | |
emh203 | 0:7798270c1f52 | 267 | |
emh203 | 0:7798270c1f52 | 268 | float ReadThermocouple(uint8_t ThermocoupleIndex) |
emh203 | 0:7798270c1f52 | 269 | { |
emh203 | 0:7798270c1f52 | 270 | uint8_t i=0; |
emh203 | 0:7798270c1f52 | 271 | uint32_t ThermocoupleData = 0; |
emh203 | 0:7798270c1f52 | 272 | uint8_t TempData[4]; |
emh203 | 0:7798270c1f52 | 273 | |
emh203 | 0:7798270c1f52 | 274 | int16_t InternalTemp = 0; |
emh203 | 0:7798270c1f52 | 275 | int16_t ThermocoupleTemp = 0; |
emh203 | 0:7798270c1f52 | 276 | |
emh203 | 0:7798270c1f52 | 277 | //reset SPi format |
emh203 | 0:7798270c1f52 | 278 | SPI1.format(8,0); |
emh203 | 0:7798270c1f52 | 279 | |
emh203 | 0:7798270c1f52 | 280 | TEMP_SENSE_ADDRESS = ThermocoupleIndex & 0x1f; |
emh203 | 0:7798270c1f52 | 281 | |
emh203 | 0:7798270c1f52 | 282 | TEMP_SENSE_CS = 0; |
emh203 | 0:7798270c1f52 | 283 | |
emh203 | 0:7798270c1f52 | 284 | for(i=0;i<4;i++) |
emh203 | 0:7798270c1f52 | 285 | TempData[i] = SPI1.write(0); |
emh203 | 0:7798270c1f52 | 286 | |
emh203 | 0:7798270c1f52 | 287 | TEMP_SENSE_CS = 1; |
emh203 | 0:7798270c1f52 | 288 | |
emh203 | 0:7798270c1f52 | 289 | |
emh203 | 0:7798270c1f52 | 290 | ThermocoupleData = (uint32_t)(TempData[3]) | |
emh203 | 0:7798270c1f52 | 291 | (((uint32_t)(TempData[2]))<<8) | |
emh203 | 0:7798270c1f52 | 292 | (((uint32_t)(TempData[1]))<<16) | |
emh203 | 0:7798270c1f52 | 293 | (((uint32_t)(TempData[0]))<<24); |
emh203 | 0:7798270c1f52 | 294 | |
emh203 | 0:7798270c1f52 | 295 | |
emh203 | 0:7798270c1f52 | 296 | if(ThermocoupleData & 0x01) |
emh203 | 0:7798270c1f52 | 297 | Thermocouple_OC |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 298 | else |
emh203 | 0:7798270c1f52 | 299 | Thermocouple_OC &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 300 | |
emh203 | 0:7798270c1f52 | 301 | if(ThermocoupleData & 0x02) |
emh203 | 0:7798270c1f52 | 302 | Thermocouple_SCG |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 303 | else |
emh203 | 0:7798270c1f52 | 304 | Thermocouple_SCG &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 305 | |
emh203 | 0:7798270c1f52 | 306 | if(ThermocoupleData & 0x04) |
emh203 | 0:7798270c1f52 | 307 | Thermocouple_SCV |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 308 | else |
emh203 | 0:7798270c1f52 | 309 | Thermocouple_SCV &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 310 | |
emh203 | 0:7798270c1f52 | 311 | if(ThermocoupleData & (1<<16)) |
emh203 | 0:7798270c1f52 | 312 | Thermocouple_FAULT |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 313 | else |
emh203 | 0:7798270c1f52 | 314 | Thermocouple_FAULT &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 315 | |
emh203 | 0:7798270c1f52 | 316 | if(ThermocoupleData & (1<<15)) |
emh203 | 0:7798270c1f52 | 317 | InternalTemp = (int16_t) ( ( (ThermocoupleData>>4) & 0xFFF) | 0xF000); //Sign extend in this case.... we need to map a 12 bit signed number to 16-bits |
emh203 | 0:7798270c1f52 | 318 | else |
emh203 | 0:7798270c1f52 | 319 | InternalTemp = (int16_t)( ( (ThermocoupleData>>4) & 0xFFF)); |
emh203 | 0:7798270c1f52 | 320 | |
emh203 | 0:7798270c1f52 | 321 | |
wavenumber | 9:c830667212f4 | 322 | if(ThermocoupleData & (0x80000000)) |
emh203 | 0:7798270c1f52 | 323 | ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF) | 0xC000); //Sign extend in this case.... we need to map a 14 bit signed number to 16-bits |
emh203 | 0:7798270c1f52 | 324 | else |
emh203 | 0:7798270c1f52 | 325 | ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF)); |
emh203 | 0:7798270c1f52 | 326 | |
emh203 | 0:7798270c1f52 | 327 | Temperature[ThermocoupleIndex] = (float)ThermocoupleTemp/4.0; |
emh203 | 0:7798270c1f52 | 328 | |
emh203 | 0:7798270c1f52 | 329 | InternalTemperature[ThermocoupleIndex] = (float)InternalTemp/16.0;; |
emh203 | 0:7798270c1f52 | 330 | |
emh203 | 0:7798270c1f52 | 331 | return Temperature[ThermocoupleIndex]; |
emh203 | 0:7798270c1f52 | 332 | } |
emh203 | 0:7798270c1f52 | 333 | |
emh203 | 0:7798270c1f52 | 334 | float ReadMFC_AnalogInput(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 335 | { |
emh203 | 0:7798270c1f52 | 336 | if(Channel > 7) |
emh203 | 0:7798270c1f52 | 337 | Channel = 7; |
emh203 | 0:7798270c1f52 | 338 | |
emh203 | 0:7798270c1f52 | 339 | return ((float)(ReadRawADC(Channel)) /4095.0) * 5.0; |
emh203 | 0:7798270c1f52 | 340 | |
emh203 | 0:7798270c1f52 | 341 | } |
emh203 | 0:7798270c1f52 | 342 | |
emh203 | 0:7798270c1f52 | 343 | void EnableMFC_Power() |
emh203 | 0:7798270c1f52 | 344 | { |
emh203 | 0:7798270c1f52 | 345 | MFC_POWER_CONTROL = 1; |
emh203 | 0:7798270c1f52 | 346 | } |
emh203 | 0:7798270c1f52 | 347 | |
emh203 | 0:7798270c1f52 | 348 | void DisableMFC_Power() |
emh203 | 0:7798270c1f52 | 349 | { |
emh203 | 0:7798270c1f52 | 350 | MFC_POWER_CONTROL = 0; |
emh203 | 0:7798270c1f52 | 351 | } |
emh203 | 0:7798270c1f52 | 352 | |
emh203 | 0:7798270c1f52 | 353 | |
emh203 | 0:7798270c1f52 | 354 | float ReadMISC_AnalogInput(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 355 | { |
emh203 | 0:7798270c1f52 | 356 | |
emh203 | 0:7798270c1f52 | 357 | if(Channel > 3) |
emh203 | 0:7798270c1f52 | 358 | Channel = 3; |
emh203 | 0:7798270c1f52 | 359 | |
emh203 | 0:7798270c1f52 | 360 | return ((float)(ReadRawADC(Channel + 9)) /4095.0) * 5.0; |
emh203 | 0:7798270c1f52 | 361 | |
emh203 | 0:7798270c1f52 | 362 | } |
emh203 | 0:7798270c1f52 | 363 | |
wavenumber | 3:cb48919cd5e8 | 364 | |
wavenumber | 3:cb48919cd5e8 | 365 | |
emh203 | 0:7798270c1f52 | 366 | float Read4to20(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 367 | { |
emh203 | 0:7798270c1f52 | 368 | |
emh203 | 0:7798270c1f52 | 369 | if(Channel > 1) |
emh203 | 0:7798270c1f52 | 370 | Channel = 1; |
emh203 | 0:7798270c1f52 | 371 | |
wavenumber | 7:de452fceafc1 | 372 | return (((float)(ReadRawADC(Channel + 7)) /4095.0) * 5.0) / 82; |
emh203 | 0:7798270c1f52 | 373 | |
emh203 | 0:7798270c1f52 | 374 | } |
emh203 | 0:7798270c1f52 | 375 | |
emh203 | 0:7798270c1f52 | 376 | |
wavenumber | 3:cb48919cd5e8 | 377 | float ReadBP_AnalogInput() |
wavenumber | 3:cb48919cd5e8 | 378 | { |
wavenumber | 3:cb48919cd5e8 | 379 | |
wavenumber | 3:cb48919cd5e8 | 380 | return ((float)(ReadRawADC(15)) /4095.0) * 10.0; |
wavenumber | 3:cb48919cd5e8 | 381 | |
wavenumber | 3:cb48919cd5e8 | 382 | } |
wavenumber | 3:cb48919cd5e8 | 383 | |
wavenumber | 3:cb48919cd5e8 | 384 | |
wavenumber | 3:cb48919cd5e8 | 385 | |
wavenumber | 3:cb48919cd5e8 | 386 | |
wavenumber | 3:cb48919cd5e8 | 387 | static uint16_t ReadRawADC_Single(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 388 | { |
emh203 | 0:7798270c1f52 | 389 | uint8_t ControlByte[3]; |
emh203 | 0:7798270c1f52 | 390 | uint8_t ADC_Data[3]; |
emh203 | 0:7798270c1f52 | 391 | uint16_t V; |
emh203 | 0:7798270c1f52 | 392 | |
emh203 | 0:7798270c1f52 | 393 | SPI0.format(8,0); //The ADC requires mode 0,0 |
emh203 | 0:7798270c1f52 | 394 | |
emh203 | 0:7798270c1f52 | 395 | /*See Microchip manual DS21298E-page 21*/ |
emh203 | 0:7798270c1f52 | 396 | |
emh203 | 0:7798270c1f52 | 397 | ControlByte[0] = (((Channel&0x07)>>2) & 0x01) | (3<<1); |
emh203 | 0:7798270c1f52 | 398 | ControlByte[1] = Channel<<6; |
emh203 | 0:7798270c1f52 | 399 | ControlByte[2] = 0; |
emh203 | 0:7798270c1f52 | 400 | |
emh203 | 0:7798270c1f52 | 401 | |
emh203 | 0:7798270c1f52 | 402 | if(Channel<8) |
emh203 | 0:7798270c1f52 | 403 | AIO_ADC1_CS = 0; |
emh203 | 0:7798270c1f52 | 404 | else |
emh203 | 0:7798270c1f52 | 405 | AIO_ADC2_CS = 0; |
emh203 | 0:7798270c1f52 | 406 | |
emh203 | 0:7798270c1f52 | 407 | //unroll the loop |
emh203 | 0:7798270c1f52 | 408 | ADC_Data[0] = SPI0.write(ControlByte[0]); |
emh203 | 0:7798270c1f52 | 409 | ADC_Data[1] = SPI0.write(ControlByte[1]); |
emh203 | 0:7798270c1f52 | 410 | ADC_Data[2] = SPI0.write(ControlByte[2]); |
emh203 | 0:7798270c1f52 | 411 | |
emh203 | 0:7798270c1f52 | 412 | AIO_ADC1_CS = 1; |
emh203 | 0:7798270c1f52 | 413 | AIO_ADC2_CS = 1; |
emh203 | 0:7798270c1f52 | 414 | |
emh203 | 0:7798270c1f52 | 415 | |
emh203 | 0:7798270c1f52 | 416 | V = ((uint16_t)(ADC_Data[1])<<8 | (uint16_t)(ADC_Data[2])) & 0xFFF; |
emh203 | 0:7798270c1f52 | 417 | |
emh203 | 0:7798270c1f52 | 418 | return (V); |
emh203 | 0:7798270c1f52 | 419 | |
emh203 | 0:7798270c1f52 | 420 | } |
emh203 | 0:7798270c1f52 | 421 | |
wavenumber | 3:cb48919cd5e8 | 422 | #define FILTER_SIZE 64 |
wavenumber | 3:cb48919cd5e8 | 423 | |
wavenumber | 3:cb48919cd5e8 | 424 | static uint16_t ReadRawADC(uint8_t Channel) |
wavenumber | 3:cb48919cd5e8 | 425 | { |
wavenumber | 3:cb48919cd5e8 | 426 | uint32_t Value = 0; |
wavenumber | 3:cb48919cd5e8 | 427 | |
wavenumber | 3:cb48919cd5e8 | 428 | for(int i=0;i<FILTER_SIZE;i++) |
wavenumber | 3:cb48919cd5e8 | 429 | { |
wavenumber | 3:cb48919cd5e8 | 430 | Value+=ReadRawADC_Single(Channel); |
wavenumber | 3:cb48919cd5e8 | 431 | } |
wavenumber | 3:cb48919cd5e8 | 432 | |
wavenumber | 3:cb48919cd5e8 | 433 | Value = Value / FILTER_SIZE; |
wavenumber | 3:cb48919cd5e8 | 434 | |
wavenumber | 3:cb48919cd5e8 | 435 | return Value; |
wavenumber | 3:cb48919cd5e8 | 436 | |
wavenumber | 3:cb48919cd5e8 | 437 | } |
emh203 | 0:7798270c1f52 | 438 | |
emh203 | 0:7798270c1f52 | 439 | void WriteMFC_AnalogOut(uint8_t Channel,float Value) |
emh203 | 0:7798270c1f52 | 440 | { |
emh203 | 0:7798270c1f52 | 441 | |
emh203 | 0:7798270c1f52 | 442 | if(Channel>7) |
emh203 | 0:7798270c1f52 | 443 | Channel = 7; |
emh203 | 0:7798270c1f52 | 444 | |
emh203 | 0:7798270c1f52 | 445 | if(Value >5.0) |
emh203 | 0:7798270c1f52 | 446 | Value = 5.0; |
emh203 | 0:7798270c1f52 | 447 | |
emh203 | 0:7798270c1f52 | 448 | if(Value<0.0) |
emh203 | 0:7798270c1f52 | 449 | Value = 0.0; |
emh203 | 0:7798270c1f52 | 450 | |
emh203 | 0:7798270c1f52 | 451 | WriteRAW_DAC_Value(Channel,(uint16_t)((Value/5.0) * 4095)); |
emh203 | 0:7798270c1f52 | 452 | |
emh203 | 0:7798270c1f52 | 453 | } |
emh203 | 0:7798270c1f52 | 454 | |
emh203 | 0:7798270c1f52 | 455 | void WriteMISC_AnalogOut(uint8_t Channel,float Value) |
emh203 | 0:7798270c1f52 | 456 | { |
emh203 | 0:7798270c1f52 | 457 | if(Channel>3) |
emh203 | 0:7798270c1f52 | 458 | Channel = 3; |
emh203 | 0:7798270c1f52 | 459 | |
emh203 | 0:7798270c1f52 | 460 | if(Value >5.0) |
emh203 | 0:7798270c1f52 | 461 | Value = 5.0; |
emh203 | 0:7798270c1f52 | 462 | |
emh203 | 0:7798270c1f52 | 463 | if(Value<0.0) |
emh203 | 0:7798270c1f52 | 464 | Value = 0.0; |
emh203 | 0:7798270c1f52 | 465 | |
emh203 | 0:7798270c1f52 | 466 | WriteRAW_DAC_Value(8+Channel,(uint16_t)((Value/5.0)*4095)); |
emh203 | 0:7798270c1f52 | 467 | } |
emh203 | 0:7798270c1f52 | 468 | |
wavenumber | 3:cb48919cd5e8 | 469 | void WriteBP_AnalogOut(float Value) |
wavenumber | 3:cb48919cd5e8 | 470 | { |
wavenumber | 3:cb48919cd5e8 | 471 | |
wavenumber | 3:cb48919cd5e8 | 472 | if(Value >10.0) |
wavenumber | 3:cb48919cd5e8 | 473 | Value = 10.0; |
wavenumber | 3:cb48919cd5e8 | 474 | |
wavenumber | 3:cb48919cd5e8 | 475 | if(Value<0.0) |
wavenumber | 3:cb48919cd5e8 | 476 | Value = 0.0; |
wavenumber | 3:cb48919cd5e8 | 477 | |
wavenumber | 3:cb48919cd5e8 | 478 | WriteRAW_DAC_Value(12,(uint16_t)((Value/10.0)*4095)); |
wavenumber | 3:cb48919cd5e8 | 479 | } |
wavenumber | 3:cb48919cd5e8 | 480 | |
emh203 | 0:7798270c1f52 | 481 | |
emh203 | 0:7798270c1f52 | 482 | void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data) |
emh203 | 0:7798270c1f52 | 483 | { |
emh203 | 0:7798270c1f52 | 484 | |
emh203 | 0:7798270c1f52 | 485 | uint16_t DataOut; |
emh203 | 0:7798270c1f52 | 486 | |
emh203 | 0:7798270c1f52 | 487 | if(Channel<8) |
emh203 | 0:7798270c1f52 | 488 | AIO_DAC1_CS = 0; |
emh203 | 0:7798270c1f52 | 489 | else |
wavenumber | 3:cb48919cd5e8 | 490 | { |
emh203 | 0:7798270c1f52 | 491 | AIO_DAC2_CS = 0; |
wavenumber | 3:cb48919cd5e8 | 492 | Channel -= 8; |
wavenumber | 3:cb48919cd5e8 | 493 | } |
emh203 | 0:7798270c1f52 | 494 | |
emh203 | 0:7798270c1f52 | 495 | SPI0.format(8,1); //The DAC requires mode 0,1 |
emh203 | 0:7798270c1f52 | 496 | |
emh203 | 0:7798270c1f52 | 497 | DataOut = ((uint16_t)(Channel) & 0x7)<<12 | (Data & 0xFFF); |
emh203 | 0:7798270c1f52 | 498 | |
emh203 | 0:7798270c1f52 | 499 | SPI0.write((DataOut>>8)&0xFF); |
emh203 | 0:7798270c1f52 | 500 | SPI0.write(DataOut&0xFF); |
emh203 | 0:7798270c1f52 | 501 | |
emh203 | 0:7798270c1f52 | 502 | AIO_DAC1_CS = 1; |
emh203 | 0:7798270c1f52 | 503 | AIO_DAC2_CS = 1; |
emh203 | 0:7798270c1f52 | 504 | |
emh203 | 0:7798270c1f52 | 505 | } |
emh203 | 0:7798270c1f52 | 506 | |
emh203 | 0:7798270c1f52 | 507 | |
emh203 | 0:7798270c1f52 | 508 | |
emh203 | 0:7798270c1f52 | 509 | |
emh203 | 0:7798270c1f52 | 510 | #define MAX_TERMINAL_LINE_CHARS 128 |
emh203 | 0:7798270c1f52 | 511 | #define MAX_TERMINAL_CMD_CHARS 64 |
emh203 | 0:7798270c1f52 | 512 | |
emh203 | 0:7798270c1f52 | 513 | #ifndef TRUE |
emh203 | 0:7798270c1f52 | 514 | #define TRUE 1 |
emh203 | 0:7798270c1f52 | 515 | #endif |
emh203 | 0:7798270c1f52 | 516 | |
emh203 | 0:7798270c1f52 | 517 | #ifndef FALSE |
emh203 | 0:7798270c1f52 | 518 | #define FALSE 0 |
emh203 | 0:7798270c1f52 | 519 | #endif |
emh203 | 0:7798270c1f52 | 520 | |
emh203 | 0:7798270c1f52 | 521 | typedef void (*TerminalCallback)(char *); |
emh203 | 0:7798270c1f52 | 522 | |
emh203 | 0:7798270c1f52 | 523 | |
emh203 | 0:7798270c1f52 | 524 | typedef struct |
emh203 | 0:7798270c1f52 | 525 | { |
emh203 | 0:7798270c1f52 | 526 | const char *CommandString; |
emh203 | 0:7798270c1f52 | 527 | TerminalCallback Callback; |
emh203 | 0:7798270c1f52 | 528 | const char *HelpString; |
emh203 | 0:7798270c1f52 | 529 | |
emh203 | 0:7798270c1f52 | 530 | } TerminalCallbackRecord; |
emh203 | 0:7798270c1f52 | 531 | |
emh203 | 0:7798270c1f52 | 532 | //Callback function prototypes |
emh203 | 0:7798270c1f52 | 533 | void TerminalCmd_Help(char *arg); |
emh203 | 0:7798270c1f52 | 534 | void TerminalCmd_Stub(char *arg); |
emh203 | 0:7798270c1f52 | 535 | void TerminalCmd_EnableHeater(char *arg); |
emh203 | 0:7798270c1f52 | 536 | void TerminalCmd_DisableHeater(char *arg); |
emh203 | 0:7798270c1f52 | 537 | void TerminalCmd_EnableSolenoidValve(char *arg); |
emh203 | 0:7798270c1f52 | 538 | void TerminalCmd_DisableSolenoidValue(char *arg); |
emh203 | 0:7798270c1f52 | 539 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg); |
emh203 | 0:7798270c1f52 | 540 | void TerminalCmd_EnableMiscDigitalOutput(char *arg); |
emh203 | 0:7798270c1f52 | 541 | void TerminalCmd_DisableMiscDigitalOutput(char *arg); |
emh203 | 0:7798270c1f52 | 542 | void TerminalCmd_FlushDigitalIO(char *arg); |
emh203 | 0:7798270c1f52 | 543 | void TerminalCmd_FanOn(char *arg); |
emh203 | 0:7798270c1f52 | 544 | void TerminalCmd_FanOff(char *arg); |
emh203 | 0:7798270c1f52 | 545 | void TerminalCmd_Buzz(char *arg); |
emh203 | 0:7798270c1f52 | 546 | void TerminalCmd_T(char *arg); |
emh203 | 0:7798270c1f52 | 547 | void TerminalCmd_MFCI(char *arg); |
emh203 | 0:7798270c1f52 | 548 | void TerminalCmd_MFCO(char *arg); |
emh203 | 0:7798270c1f52 | 549 | void TerminalCmd_4TO20(char *arg); |
emh203 | 0:7798270c1f52 | 550 | void TerminalCmd_AIN(char *arg); |
emh203 | 0:7798270c1f52 | 551 | void TerminalCmd_MFCON(char *arg); |
emh203 | 0:7798270c1f52 | 552 | void TerminalCmd_MFCOFF(char *arg); |
emh203 | 0:7798270c1f52 | 553 | void TerminalCmd_AOUT(char *arg); |
emh203 | 0:7798270c1f52 | 554 | void TerminalCmd_Reset(char *arg); |
wavenumber | 2:73a028278c5c | 555 | void TerminalCmd_ECHO_OFF(char *arg); |
wavenumber | 3:cb48919cd5e8 | 556 | void TerminalCmd_BPOUT(char *arg); |
wavenumber | 3:cb48919cd5e8 | 557 | void TerminalCmd_BPIN(char *arg); |
wavenumber | 6:6a870e1e52c1 | 558 | void TerminalCmd_P0(char *arg); |
wavenumber | 6:6a870e1e52c1 | 559 | void TerminalCmd_P1(char *arg); |
wavenumber | 8:0cf1573051e8 | 560 | void TerminalCmd_P0B(char *arg); |
wavenumber | 8:0cf1573051e8 | 561 | void TerminalCmd_P1B(char *arg); |
emh203 | 0:7798270c1f52 | 562 | |
emh203 | 0:7798270c1f52 | 563 | //Populate this array with the callback functions and their terminal command string |
emh203 | 0:7798270c1f52 | 564 | TerminalCallbackRecord MyTerminalCallbackRecords[] ={ {"reset",TerminalCmd_Reset,"Resets the CHEM box"}, |
emh203 | 0:7798270c1f52 | 565 | |
emh203 | 0:7798270c1f52 | 566 | {"help",TerminalCmd_Help,"Lists available commands"}, |
emh203 | 0:7798270c1f52 | 567 | |
emh203 | 0:7798270c1f52 | 568 | {"EH",TerminalCmd_EnableHeater,"Enables a heater channel. Argument should be between 0 and 7. Outputs will update when a FDIO command is issued"}, |
emh203 | 0:7798270c1f52 | 569 | |
emh203 | 0:7798270c1f52 | 570 | {"DH",TerminalCmd_DisableHeater,"Disables a heater channel. Argument should be between 0 and 7. Outputs will update when a FDIO command is issued"}, |
emh203 | 0:7798270c1f52 | 571 | |
emh203 | 0:7798270c1f52 | 572 | {"ESV",TerminalCmd_EnableSolenoidValve,"Enables a solenoid channel. Argument should be between 0 and 11. Outputs will update when a FDIO command is issued"}, |
emh203 | 0:7798270c1f52 | 573 | |
emh203 | 0:7798270c1f52 | 574 | {"DSV",TerminalCmd_DisableSolenoidValue,"Disables a solenoid channel. Argument should be between 0 and 11. Outputs will update when a FFDIO command is issued"}, |
emh203 | 0:7798270c1f52 | 575 | |
emh203 | 0:7798270c1f52 | 576 | {"DAHAS",TerminalCmd_DisableAllHeatersAndSolenoids,"Disables all heaters and solenoids. Command is immediately executed."}, |
emh203 | 0:7798270c1f52 | 577 | |
emh203 | 0:7798270c1f52 | 578 | {"EMDO",TerminalCmd_EnableMiscDigitalOutput,"Enables a misc. digital output. Argument should be between 0 and 3. Output will update when a FDIO command is issued"}, |
emh203 | 0:7798270c1f52 | 579 | |
emh203 | 0:7798270c1f52 | 580 | {"DMDO",TerminalCmd_DisableMiscDigitalOutput,"Enables a misc. digital output. Argument should be between 0 and 3. Output will update when a FDIO command is issued"}, |
emh203 | 0:7798270c1f52 | 581 | |
emh203 | 0:7798270c1f52 | 582 | {"FDIO",TerminalCmd_FlushDigitalIO,"Updates the all of the digital IO channels"}, |
emh203 | 0:7798270c1f52 | 583 | |
emh203 | 0:7798270c1f52 | 584 | {"FON",TerminalCmd_FanOn,"Turns on the fans"}, |
emh203 | 0:7798270c1f52 | 585 | |
emh203 | 0:7798270c1f52 | 586 | {"FOFF",TerminalCmd_FanOff,"Turns off the fans"}, |
emh203 | 0:7798270c1f52 | 587 | |
emh203 | 0:7798270c1f52 | 588 | {"BUZZ",TerminalCmd_Buzz,"Buzz for a little bit. Argument should be a floating point number representing the number of seconds to buzz"}, |
emh203 | 0:7798270c1f52 | 589 | |
emh203 | 0:7798270c1f52 | 590 | {"T",TerminalCmd_T,"Read thermocouple channel"}, |
emh203 | 0:7798270c1f52 | 591 | |
emh203 | 0:7798270c1f52 | 592 | {"MFCI",TerminalCmd_MFCI,"Reads in voltage from MFC channel"}, |
emh203 | 0:7798270c1f52 | 593 | |
emh203 | 0:7798270c1f52 | 594 | {"MFCO",TerminalCmd_MFCO,"Sets voltage at MFC output channel. First argument should be the channel. Second argument should be the voltage. I.E. MFCO 1.45"}, |
emh203 | 0:7798270c1f52 | 595 | |
emh203 | 0:7798270c1f52 | 596 | {"AOUT",TerminalCmd_AOUT,"Sets voltage at misc. output channel. First argument should be the channel. Second argument should be the voltage. I.E. AOUT 3.211"}, |
emh203 | 0:7798270c1f52 | 597 | |
emh203 | 0:7798270c1f52 | 598 | {"4TO20",TerminalCmd_4TO20,"Reads a 4 to 20 mA channel"}, |
emh203 | 0:7798270c1f52 | 599 | |
emh203 | 0:7798270c1f52 | 600 | {"AIN",TerminalCmd_AIN,"Reads a general purpose analog in channel"}, |
emh203 | 0:7798270c1f52 | 601 | |
emh203 | 0:7798270c1f52 | 602 | {"MFCON",TerminalCmd_MFCON,"Turns on the MFC power"}, |
emh203 | 0:7798270c1f52 | 603 | |
wavenumber | 2:73a028278c5c | 604 | {"MFCOFF",TerminalCmd_MFCOFF,"Turns off the MFC power"}, |
wavenumber | 2:73a028278c5c | 605 | |
wavenumber | 3:cb48919cd5e8 | 606 | {"BPOUT",TerminalCmd_BPOUT,"Sets a control voltage between 0 and 10 for the backpressure regulator. I.E. BPOUT 1.21"}, |
wavenumber | 3:cb48919cd5e8 | 607 | |
wavenumber | 3:cb48919cd5e8 | 608 | {"BPIN",TerminalCmd_BPIN,"Reads the Back pressure regulator feedback. I.E. BPIN "}, |
wavenumber | 3:cb48919cd5e8 | 609 | |
wavenumber | 8:0cf1573051e8 | 610 | {"P0",TerminalCmd_P0,"Sends a command over RS232 port 0. A carriage return will be added automatically."}, |
wavenumber | 6:6a870e1e52c1 | 611 | |
wavenumber | 8:0cf1573051e8 | 612 | {"P1",TerminalCmd_P1,"Sends a command over RS232 port 1. A carriage return and line feed will be added automatically."}, |
wavenumber | 6:6a870e1e52c1 | 613 | |
wavenumber | 8:0cf1573051e8 | 614 | {"P0B",TerminalCmd_P0B,"Change the baud rate of Port 0 (default 19200)"}, |
wavenumber | 8:0cf1573051e8 | 615 | |
wavenumber | 8:0cf1573051e8 | 616 | {"P1B",TerminalCmd_P1B,"Change the baud rate of Port 1 (default 9600)"}, |
wavenumber | 8:0cf1573051e8 | 617 | |
wavenumber | 2:73a028278c5c | 618 | {"ECHO_OFF",TerminalCmd_ECHO_OFF,"Disables echoing of characters"} |
emh203 | 0:7798270c1f52 | 619 | }; |
emh203 | 0:7798270c1f52 | 620 | |
emh203 | 0:7798270c1f52 | 621 | |
emh203 | 0:7798270c1f52 | 622 | extern "C" void mbed_reset(); |
emh203 | 0:7798270c1f52 | 623 | |
emh203 | 0:7798270c1f52 | 624 | void TerminalCmd_Reset(char *arg) |
emh203 | 0:7798270c1f52 | 625 | { |
emh203 | 0:7798270c1f52 | 626 | mbed_reset(); |
emh203 | 0:7798270c1f52 | 627 | } |
emh203 | 0:7798270c1f52 | 628 | |
wavenumber | 2:73a028278c5c | 629 | |
wavenumber | 2:73a028278c5c | 630 | |
emh203 | 0:7798270c1f52 | 631 | void TerminalCmd_Stub(char *arg) |
emh203 | 0:7798270c1f52 | 632 | { |
emh203 | 0:7798270c1f52 | 633 | PC.printf("stub \r\n"); |
emh203 | 0:7798270c1f52 | 634 | } |
emh203 | 0:7798270c1f52 | 635 | |
wavenumber | 2:73a028278c5c | 636 | void TerminalCmd_ECHO_OFF(char *arg) |
wavenumber | 2:73a028278c5c | 637 | { |
wavenumber | 2:73a028278c5c | 638 | TerminalEcho = 0; |
wavenumber | 2:73a028278c5c | 639 | } |
wavenumber | 2:73a028278c5c | 640 | |
wavenumber | 7:de452fceafc1 | 641 | uint8_t RS232_Buff[2][256]; |
wavenumber | 7:de452fceafc1 | 642 | |
wavenumber | 7:de452fceafc1 | 643 | uint32_t RS232_Idx[2]; |
wavenumber | 7:de452fceafc1 | 644 | |
wavenumber | 7:de452fceafc1 | 645 | |
wavenumber | 7:de452fceafc1 | 646 | void ResetRS232_Response(uint32_t Channel) |
wavenumber | 7:de452fceafc1 | 647 | { |
wavenumber | 7:de452fceafc1 | 648 | if(Channel == 0) |
wavenumber | 7:de452fceafc1 | 649 | { |
wavenumber | 7:de452fceafc1 | 650 | RS232_Idx[0] = 0; |
wavenumber | 7:de452fceafc1 | 651 | } |
wavenumber | 7:de452fceafc1 | 652 | else |
wavenumber | 7:de452fceafc1 | 653 | { |
wavenumber | 7:de452fceafc1 | 654 | RS232_Idx[1] = 0; |
wavenumber | 7:de452fceafc1 | 655 | } |
wavenumber | 7:de452fceafc1 | 656 | } |
wavenumber | 6:6a870e1e52c1 | 657 | |
wavenumber | 6:6a870e1e52c1 | 658 | void TerminalCmd_P0(char *arg) |
wavenumber | 6:6a870e1e52c1 | 659 | { |
wavenumber | 7:de452fceafc1 | 660 | ResetRS232_Response(0); |
wavenumber | 6:6a870e1e52c1 | 661 | RS232_0.printf("%s\r",arg); |
wavenumber | 6:6a870e1e52c1 | 662 | } |
wavenumber | 6:6a870e1e52c1 | 663 | |
wavenumber | 8:0cf1573051e8 | 664 | void TerminalCmd_P1(char *arg) |
wavenumber | 8:0cf1573051e8 | 665 | { |
wavenumber | 8:0cf1573051e8 | 666 | ResetRS232_Response(1); |
wavenumber | 8:0cf1573051e8 | 667 | RS232_1.printf("%s\r\n",arg); |
wavenumber | 8:0cf1573051e8 | 668 | } |
wavenumber | 8:0cf1573051e8 | 669 | |
wavenumber | 7:de452fceafc1 | 670 | |
wavenumber | 7:de452fceafc1 | 671 | void ProcessRS232() |
wavenumber | 7:de452fceafc1 | 672 | { |
wavenumber | 7:de452fceafc1 | 673 | uint8_t Val; |
wavenumber | 7:de452fceafc1 | 674 | |
wavenumber | 7:de452fceafc1 | 675 | while(RS232_0.readable()) |
wavenumber | 7:de452fceafc1 | 676 | { |
wavenumber | 7:de452fceafc1 | 677 | Val = RS232_0.getc(); |
wavenumber | 7:de452fceafc1 | 678 | |
wavenumber | 7:de452fceafc1 | 679 | if(Val == 0x03) |
wavenumber | 7:de452fceafc1 | 680 | { |
wavenumber | 7:de452fceafc1 | 681 | |
wavenumber | 7:de452fceafc1 | 682 | if(RS232_Idx[0]>0) |
wavenumber | 7:de452fceafc1 | 683 | { |
wavenumber | 7:de452fceafc1 | 684 | RS232_Buff[0][RS232_Idx[0]++] = 0; |
wavenumber | 7:de452fceafc1 | 685 | PC.printf("P:0:%s\r\n",&RS232_Buff[0][0]); |
wavenumber | 7:de452fceafc1 | 686 | ResetRS232_Response(0); |
wavenumber | 7:de452fceafc1 | 687 | break; |
wavenumber | 7:de452fceafc1 | 688 | } |
wavenumber | 7:de452fceafc1 | 689 | } |
wavenumber | 7:de452fceafc1 | 690 | else |
wavenumber | 7:de452fceafc1 | 691 | { |
wavenumber | 7:de452fceafc1 | 692 | if((Val>0x020) && (Val<0x7F) && (RS232_Idx[0]<(sizeof(RS232_Buff)-1))) |
wavenumber | 7:de452fceafc1 | 693 | { |
wavenumber | 7:de452fceafc1 | 694 | RS232_Buff[0][RS232_Idx[0]++] = Val; |
wavenumber | 7:de452fceafc1 | 695 | } |
wavenumber | 7:de452fceafc1 | 696 | } |
wavenumber | 7:de452fceafc1 | 697 | } |
wavenumber | 7:de452fceafc1 | 698 | |
wavenumber | 7:de452fceafc1 | 699 | |
wavenumber | 7:de452fceafc1 | 700 | while(RS232_1.readable()) |
wavenumber | 7:de452fceafc1 | 701 | { |
wavenumber | 7:de452fceafc1 | 702 | Val = RS232_1.getc(); |
wavenumber | 7:de452fceafc1 | 703 | |
wavenumber | 7:de452fceafc1 | 704 | if(Val == 0x03) |
wavenumber | 7:de452fceafc1 | 705 | { |
wavenumber | 7:de452fceafc1 | 706 | if(RS232_Idx[1]>0) |
wavenumber | 7:de452fceafc1 | 707 | { |
wavenumber | 7:de452fceafc1 | 708 | RS232_Buff[1][RS232_Idx[1]++] = 0; |
wavenumber | 7:de452fceafc1 | 709 | PC.printf("P:1:%s\r\n",&RS232_Buff[1][0]); |
wavenumber | 7:de452fceafc1 | 710 | ResetRS232_Response(1); |
wavenumber | 7:de452fceafc1 | 711 | break; |
wavenumber | 7:de452fceafc1 | 712 | } |
wavenumber | 7:de452fceafc1 | 713 | } |
wavenumber | 7:de452fceafc1 | 714 | else |
wavenumber | 7:de452fceafc1 | 715 | { |
wavenumber | 7:de452fceafc1 | 716 | if((Val>0x020) && (Val <0x7F) && (RS232_Idx[1]<(sizeof(RS232_Buff)-1))) |
wavenumber | 7:de452fceafc1 | 717 | { |
wavenumber | 7:de452fceafc1 | 718 | RS232_Buff[1][RS232_Idx[1]++] = Val; |
wavenumber | 7:de452fceafc1 | 719 | } |
wavenumber | 7:de452fceafc1 | 720 | } |
wavenumber | 7:de452fceafc1 | 721 | } |
wavenumber | 7:de452fceafc1 | 722 | } |
wavenumber | 7:de452fceafc1 | 723 | |
wavenumber | 7:de452fceafc1 | 724 | |
wavenumber | 8:0cf1573051e8 | 725 | void TerminalCmd_P0B(char *arg) |
wavenumber | 6:6a870e1e52c1 | 726 | { |
wavenumber | 8:0cf1573051e8 | 727 | int Baud = 0; |
wavenumber | 8:0cf1573051e8 | 728 | if(sscanf(arg,"%d",&Baud) == 1) |
wavenumber | 8:0cf1573051e8 | 729 | { |
wavenumber | 8:0cf1573051e8 | 730 | RS232_0.baud(Baud); |
wavenumber | 8:0cf1573051e8 | 731 | PC.printf("Port 0 baud changed to %d",Baud); |
wavenumber | 8:0cf1573051e8 | 732 | } |
wavenumber | 8:0cf1573051e8 | 733 | } |
wavenumber | 6:6a870e1e52c1 | 734 | |
wavenumber | 8:0cf1573051e8 | 735 | void TerminalCmd_P1B(char *arg) |
wavenumber | 8:0cf1573051e8 | 736 | { |
wavenumber | 8:0cf1573051e8 | 737 | int Baud = 0; |
wavenumber | 8:0cf1573051e8 | 738 | if(sscanf(arg,"%d",&Baud) == 1) |
wavenumber | 8:0cf1573051e8 | 739 | { |
wavenumber | 8:0cf1573051e8 | 740 | RS232_1.baud(Baud); |
wavenumber | 8:0cf1573051e8 | 741 | PC.printf("Port 1 baud changed to %d",Baud); |
wavenumber | 8:0cf1573051e8 | 742 | } |
wavenumber | 8:0cf1573051e8 | 743 | } |
wavenumber | 6:6a870e1e52c1 | 744 | |
emh203 | 0:7798270c1f52 | 745 | void TerminalCmd_MFCI(char *arg) |
emh203 | 0:7798270c1f52 | 746 | { |
emh203 | 0:7798270c1f52 | 747 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 748 | float Data; |
emh203 | 0:7798270c1f52 | 749 | |
emh203 | 0:7798270c1f52 | 750 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 751 | { |
emh203 | 0:7798270c1f52 | 752 | if(Channel>=0 && Channel <=6) |
emh203 | 0:7798270c1f52 | 753 | { |
emh203 | 0:7798270c1f52 | 754 | Data = ReadMFC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 755 | PC.printf("MFCI:%d:%.3f",Channel,Data); |
emh203 | 0:7798270c1f52 | 756 | } |
emh203 | 0:7798270c1f52 | 757 | else |
emh203 | 0:7798270c1f52 | 758 | { |
emh203 | 0:7798270c1f52 | 759 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 6",Channel); |
emh203 | 0:7798270c1f52 | 760 | } |
emh203 | 0:7798270c1f52 | 761 | } |
emh203 | 0:7798270c1f52 | 762 | else |
emh203 | 0:7798270c1f52 | 763 | { |
emh203 | 0:7798270c1f52 | 764 | for(Channel = 0; Channel<=6; Channel++) |
emh203 | 0:7798270c1f52 | 765 | { |
emh203 | 0:7798270c1f52 | 766 | Data = ReadMFC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 767 | PC.printf("MFCI:%d:%.3f\r\n",Channel,Data); |
emh203 | 0:7798270c1f52 | 768 | } |
emh203 | 0:7798270c1f52 | 769 | } |
emh203 | 0:7798270c1f52 | 770 | } |
emh203 | 0:7798270c1f52 | 771 | |
emh203 | 0:7798270c1f52 | 772 | void TerminalCmd_MFCON(char *arg) |
emh203 | 0:7798270c1f52 | 773 | { |
emh203 | 0:7798270c1f52 | 774 | EnableMFC_Power(); |
emh203 | 0:7798270c1f52 | 775 | } |
emh203 | 0:7798270c1f52 | 776 | |
emh203 | 0:7798270c1f52 | 777 | |
emh203 | 0:7798270c1f52 | 778 | void TerminalCmd_MFCOFF(char *arg) |
emh203 | 0:7798270c1f52 | 779 | { |
emh203 | 0:7798270c1f52 | 780 | DisableMFC_Power(); |
emh203 | 0:7798270c1f52 | 781 | } |
emh203 | 0:7798270c1f52 | 782 | |
emh203 | 0:7798270c1f52 | 783 | |
emh203 | 0:7798270c1f52 | 784 | void TerminalCmd_MFCO(char *arg) |
emh203 | 0:7798270c1f52 | 785 | { |
emh203 | 0:7798270c1f52 | 786 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 787 | float Data = 0.0; |
emh203 | 0:7798270c1f52 | 788 | |
emh203 | 0:7798270c1f52 | 789 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) |
emh203 | 0:7798270c1f52 | 790 | { |
emh203 | 0:7798270c1f52 | 791 | if(Channel>=0 && Channel <=7) |
emh203 | 0:7798270c1f52 | 792 | { |
emh203 | 0:7798270c1f52 | 793 | WriteMFC_AnalogOut(Channel,Data); |
emh203 | 0:7798270c1f52 | 794 | } |
emh203 | 0:7798270c1f52 | 795 | else |
emh203 | 0:7798270c1f52 | 796 | { |
emh203 | 0:7798270c1f52 | 797 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); |
emh203 | 0:7798270c1f52 | 798 | } |
emh203 | 0:7798270c1f52 | 799 | } |
emh203 | 0:7798270c1f52 | 800 | else |
emh203 | 0:7798270c1f52 | 801 | { |
emh203 | 0:7798270c1f52 | 802 | PC.printf("Bad argument... %s. Channel should be an integer between 0 and 7 and value should be a float between 0.0 and 5.0. i.e. MFCO 2 4.45",arg); |
emh203 | 0:7798270c1f52 | 803 | } |
emh203 | 0:7798270c1f52 | 804 | } |
emh203 | 0:7798270c1f52 | 805 | |
emh203 | 0:7798270c1f52 | 806 | void TerminalCmd_AOUT(char *arg) |
emh203 | 0:7798270c1f52 | 807 | { |
emh203 | 0:7798270c1f52 | 808 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 809 | float Data = 0.0; |
emh203 | 0:7798270c1f52 | 810 | |
emh203 | 0:7798270c1f52 | 811 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) |
emh203 | 0:7798270c1f52 | 812 | { |
emh203 | 0:7798270c1f52 | 813 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 814 | { |
emh203 | 0:7798270c1f52 | 815 | WriteMISC_AnalogOut(Channel,Data); |
emh203 | 0:7798270c1f52 | 816 | } |
emh203 | 0:7798270c1f52 | 817 | else |
emh203 | 0:7798270c1f52 | 818 | { |
emh203 | 0:7798270c1f52 | 819 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 820 | } |
emh203 | 0:7798270c1f52 | 821 | } |
emh203 | 0:7798270c1f52 | 822 | else |
emh203 | 0:7798270c1f52 | 823 | { |
emh203 | 0:7798270c1f52 | 824 | PC.printf("Bad argument... %s. Channel should be an integer between 0 and 7 and value should be a float between 0.0 and 5.0. i.e. AOUT 1 1.25",arg); |
emh203 | 0:7798270c1f52 | 825 | } |
emh203 | 0:7798270c1f52 | 826 | } |
emh203 | 0:7798270c1f52 | 827 | |
wavenumber | 3:cb48919cd5e8 | 828 | |
wavenumber | 3:cb48919cd5e8 | 829 | void TerminalCmd_BPOUT(char *arg) |
wavenumber | 3:cb48919cd5e8 | 830 | { |
wavenumber | 3:cb48919cd5e8 | 831 | float Data = 0.0; |
wavenumber | 3:cb48919cd5e8 | 832 | |
wavenumber | 3:cb48919cd5e8 | 833 | if(sscanf(arg,"%f",&Data) == 1) |
wavenumber | 3:cb48919cd5e8 | 834 | { |
wavenumber | 3:cb48919cd5e8 | 835 | WriteBP_AnalogOut(Data); |
wavenumber | 3:cb48919cd5e8 | 836 | } |
wavenumber | 3:cb48919cd5e8 | 837 | else |
wavenumber | 3:cb48919cd5e8 | 838 | { |
wavenumber | 3:cb48919cd5e8 | 839 | PC.printf("Bad argument... %s. value should be a float between 0.0 and 10.0. i.e. BPOUT 1.25",arg); |
wavenumber | 3:cb48919cd5e8 | 840 | } |
wavenumber | 3:cb48919cd5e8 | 841 | } |
wavenumber | 3:cb48919cd5e8 | 842 | |
wavenumber | 3:cb48919cd5e8 | 843 | void TerminalCmd_BPIN(char *arg) |
wavenumber | 3:cb48919cd5e8 | 844 | { |
wavenumber | 3:cb48919cd5e8 | 845 | float Data; |
wavenumber | 3:cb48919cd5e8 | 846 | Data = ReadBP_AnalogInput(); |
wavenumber | 3:cb48919cd5e8 | 847 | PC.printf("BPIN:%.3f",Data); |
wavenumber | 3:cb48919cd5e8 | 848 | } |
wavenumber | 3:cb48919cd5e8 | 849 | |
emh203 | 0:7798270c1f52 | 850 | void TerminalCmd_4TO20(char *arg) |
emh203 | 0:7798270c1f52 | 851 | { |
emh203 | 0:7798270c1f52 | 852 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 853 | float Data; |
emh203 | 0:7798270c1f52 | 854 | |
emh203 | 0:7798270c1f52 | 855 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 856 | { |
emh203 | 0:7798270c1f52 | 857 | if(Channel>=0 && Channel <=1) |
emh203 | 0:7798270c1f52 | 858 | { |
emh203 | 0:7798270c1f52 | 859 | Data = Read4to20(Channel); |
emh203 | 0:7798270c1f52 | 860 | PC.printf("4TO20:%d:%.3f",Channel,Data); |
emh203 | 0:7798270c1f52 | 861 | } |
emh203 | 0:7798270c1f52 | 862 | else |
emh203 | 0:7798270c1f52 | 863 | { |
emh203 | 0:7798270c1f52 | 864 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); |
emh203 | 0:7798270c1f52 | 865 | } |
emh203 | 0:7798270c1f52 | 866 | } |
emh203 | 0:7798270c1f52 | 867 | else |
emh203 | 0:7798270c1f52 | 868 | { |
emh203 | 0:7798270c1f52 | 869 | |
emh203 | 0:7798270c1f52 | 870 | for(Channel = 0;Channel<=1;Channel++) |
emh203 | 0:7798270c1f52 | 871 | { |
emh203 | 0:7798270c1f52 | 872 | Data = Read4to20(Channel); |
emh203 | 1:d64ac853223c | 873 | PC.printf("4TO20:%d:%.5f\r\n",Channel,Data); |
emh203 | 0:7798270c1f52 | 874 | } |
emh203 | 0:7798270c1f52 | 875 | |
emh203 | 0:7798270c1f52 | 876 | } |
emh203 | 0:7798270c1f52 | 877 | |
emh203 | 0:7798270c1f52 | 878 | |
emh203 | 0:7798270c1f52 | 879 | } |
emh203 | 0:7798270c1f52 | 880 | |
emh203 | 0:7798270c1f52 | 881 | void TerminalCmd_AIN(char *arg) |
emh203 | 0:7798270c1f52 | 882 | { |
emh203 | 0:7798270c1f52 | 883 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 884 | float Data; |
emh203 | 0:7798270c1f52 | 885 | |
emh203 | 0:7798270c1f52 | 886 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 887 | { |
emh203 | 0:7798270c1f52 | 888 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 889 | { |
emh203 | 0:7798270c1f52 | 890 | Data = ReadMISC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 891 | PC.printf("AIN:%d:%.3f",Channel,Data); |
emh203 | 0:7798270c1f52 | 892 | } |
emh203 | 0:7798270c1f52 | 893 | else |
emh203 | 0:7798270c1f52 | 894 | { |
emh203 | 0:7798270c1f52 | 895 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 896 | } |
emh203 | 0:7798270c1f52 | 897 | } |
emh203 | 0:7798270c1f52 | 898 | else |
emh203 | 0:7798270c1f52 | 899 | { |
emh203 | 0:7798270c1f52 | 900 | for(Channel = 0;Channel<=3;Channel++) |
emh203 | 0:7798270c1f52 | 901 | { |
emh203 | 0:7798270c1f52 | 902 | Data = ReadMISC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 903 | PC.printf("AIN:%d:%.3f\r\n",Channel,Data); |
emh203 | 0:7798270c1f52 | 904 | } |
emh203 | 0:7798270c1f52 | 905 | } |
emh203 | 0:7798270c1f52 | 906 | } |
emh203 | 0:7798270c1f52 | 907 | |
emh203 | 0:7798270c1f52 | 908 | |
emh203 | 0:7798270c1f52 | 909 | |
emh203 | 0:7798270c1f52 | 910 | void TerminalCmd_EnableHeater(char *arg) |
emh203 | 0:7798270c1f52 | 911 | { |
emh203 | 0:7798270c1f52 | 912 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 913 | |
emh203 | 0:7798270c1f52 | 914 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 915 | { |
emh203 | 0:7798270c1f52 | 916 | if(Channel>=0 && Channel <=7) |
emh203 | 0:7798270c1f52 | 917 | { |
emh203 | 0:7798270c1f52 | 918 | EnableHeater(Channel); |
emh203 | 0:7798270c1f52 | 919 | } |
emh203 | 0:7798270c1f52 | 920 | else |
emh203 | 0:7798270c1f52 | 921 | { |
emh203 | 0:7798270c1f52 | 922 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); |
emh203 | 0:7798270c1f52 | 923 | } |
emh203 | 0:7798270c1f52 | 924 | } |
emh203 | 0:7798270c1f52 | 925 | else |
emh203 | 0:7798270c1f52 | 926 | { |
emh203 | 0:7798270c1f52 | 927 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); |
emh203 | 0:7798270c1f52 | 928 | } |
emh203 | 0:7798270c1f52 | 929 | } |
emh203 | 0:7798270c1f52 | 930 | |
emh203 | 0:7798270c1f52 | 931 | void TerminalCmd_DisableHeater(char *arg) |
emh203 | 0:7798270c1f52 | 932 | { |
emh203 | 0:7798270c1f52 | 933 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 934 | |
emh203 | 0:7798270c1f52 | 935 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 936 | { |
emh203 | 0:7798270c1f52 | 937 | if(Channel>=0 && Channel <=7) |
emh203 | 0:7798270c1f52 | 938 | { |
emh203 | 0:7798270c1f52 | 939 | DisableHeater(Channel); |
emh203 | 0:7798270c1f52 | 940 | } |
emh203 | 0:7798270c1f52 | 941 | else |
emh203 | 0:7798270c1f52 | 942 | { |
emh203 | 0:7798270c1f52 | 943 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); |
emh203 | 0:7798270c1f52 | 944 | } |
emh203 | 0:7798270c1f52 | 945 | } |
emh203 | 0:7798270c1f52 | 946 | else |
emh203 | 0:7798270c1f52 | 947 | { |
emh203 | 0:7798270c1f52 | 948 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); |
emh203 | 0:7798270c1f52 | 949 | } |
emh203 | 0:7798270c1f52 | 950 | |
emh203 | 0:7798270c1f52 | 951 | } |
emh203 | 0:7798270c1f52 | 952 | |
emh203 | 0:7798270c1f52 | 953 | void TerminalCmd_EnableSolenoidValve(char *arg) |
emh203 | 0:7798270c1f52 | 954 | { |
emh203 | 0:7798270c1f52 | 955 | |
emh203 | 0:7798270c1f52 | 956 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 957 | |
emh203 | 0:7798270c1f52 | 958 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 959 | { |
emh203 | 0:7798270c1f52 | 960 | if(Channel>=0 && Channel <=11) |
emh203 | 0:7798270c1f52 | 961 | { |
emh203 | 0:7798270c1f52 | 962 | EnableSolenoidValve(Channel); |
emh203 | 0:7798270c1f52 | 963 | } |
emh203 | 0:7798270c1f52 | 964 | else |
emh203 | 0:7798270c1f52 | 965 | { |
emh203 | 0:7798270c1f52 | 966 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); |
emh203 | 0:7798270c1f52 | 967 | } |
emh203 | 0:7798270c1f52 | 968 | } |
emh203 | 0:7798270c1f52 | 969 | else |
emh203 | 0:7798270c1f52 | 970 | { |
emh203 | 0:7798270c1f52 | 971 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); |
emh203 | 0:7798270c1f52 | 972 | } |
emh203 | 0:7798270c1f52 | 973 | } |
emh203 | 0:7798270c1f52 | 974 | |
emh203 | 0:7798270c1f52 | 975 | void TerminalCmd_DisableSolenoidValue(char *arg) |
emh203 | 0:7798270c1f52 | 976 | { |
emh203 | 0:7798270c1f52 | 977 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 978 | |
emh203 | 0:7798270c1f52 | 979 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 980 | { |
emh203 | 0:7798270c1f52 | 981 | if( Channel >= 0 && Channel <= 11) |
emh203 | 0:7798270c1f52 | 982 | { |
emh203 | 0:7798270c1f52 | 983 | DisableSolenoidValue(Channel); |
emh203 | 0:7798270c1f52 | 984 | } |
emh203 | 0:7798270c1f52 | 985 | else |
emh203 | 0:7798270c1f52 | 986 | { |
emh203 | 0:7798270c1f52 | 987 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); |
emh203 | 0:7798270c1f52 | 988 | } |
emh203 | 0:7798270c1f52 | 989 | } |
emh203 | 0:7798270c1f52 | 990 | else |
emh203 | 0:7798270c1f52 | 991 | { |
emh203 | 0:7798270c1f52 | 992 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); |
emh203 | 0:7798270c1f52 | 993 | } |
emh203 | 0:7798270c1f52 | 994 | |
emh203 | 0:7798270c1f52 | 995 | } |
emh203 | 0:7798270c1f52 | 996 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg) |
emh203 | 0:7798270c1f52 | 997 | { |
emh203 | 0:7798270c1f52 | 998 | |
emh203 | 0:7798270c1f52 | 999 | DisableAllHeatersAndSolenoids(); |
emh203 | 0:7798270c1f52 | 1000 | |
emh203 | 0:7798270c1f52 | 1001 | } |
emh203 | 0:7798270c1f52 | 1002 | |
emh203 | 0:7798270c1f52 | 1003 | void TerminalCmd_EnableMiscDigitalOutput(char *arg) |
emh203 | 0:7798270c1f52 | 1004 | { |
emh203 | 0:7798270c1f52 | 1005 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 1006 | |
emh203 | 0:7798270c1f52 | 1007 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 1008 | { |
emh203 | 0:7798270c1f52 | 1009 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 1010 | { |
emh203 | 0:7798270c1f52 | 1011 | EnableMiscDigitalOutput(Channel); |
emh203 | 0:7798270c1f52 | 1012 | } |
emh203 | 0:7798270c1f52 | 1013 | else |
emh203 | 0:7798270c1f52 | 1014 | { |
emh203 | 0:7798270c1f52 | 1015 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 1016 | } |
emh203 | 0:7798270c1f52 | 1017 | } |
emh203 | 0:7798270c1f52 | 1018 | else |
emh203 | 0:7798270c1f52 | 1019 | { |
emh203 | 0:7798270c1f52 | 1020 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); |
emh203 | 0:7798270c1f52 | 1021 | } |
emh203 | 0:7798270c1f52 | 1022 | |
emh203 | 0:7798270c1f52 | 1023 | } |
emh203 | 0:7798270c1f52 | 1024 | |
emh203 | 0:7798270c1f52 | 1025 | void TerminalCmd_DisableMiscDigitalOutput(char *arg) |
emh203 | 0:7798270c1f52 | 1026 | { |
emh203 | 0:7798270c1f52 | 1027 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 1028 | |
emh203 | 0:7798270c1f52 | 1029 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 1030 | { |
emh203 | 0:7798270c1f52 | 1031 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 1032 | { |
emh203 | 0:7798270c1f52 | 1033 | DisableMiscDigitalOutput(Channel); |
emh203 | 0:7798270c1f52 | 1034 | } |
emh203 | 0:7798270c1f52 | 1035 | else |
emh203 | 0:7798270c1f52 | 1036 | { |
emh203 | 0:7798270c1f52 | 1037 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 1038 | } |
emh203 | 0:7798270c1f52 | 1039 | } |
emh203 | 0:7798270c1f52 | 1040 | else |
emh203 | 0:7798270c1f52 | 1041 | { |
emh203 | 0:7798270c1f52 | 1042 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); |
emh203 | 0:7798270c1f52 | 1043 | } |
emh203 | 0:7798270c1f52 | 1044 | |
emh203 | 0:7798270c1f52 | 1045 | } |
emh203 | 0:7798270c1f52 | 1046 | |
emh203 | 0:7798270c1f52 | 1047 | void TerminalCmd_FlushDigitalIO(char *arg) |
emh203 | 0:7798270c1f52 | 1048 | { |
emh203 | 0:7798270c1f52 | 1049 | FlushDigitalIO(); |
emh203 | 0:7798270c1f52 | 1050 | } |
emh203 | 0:7798270c1f52 | 1051 | |
emh203 | 0:7798270c1f52 | 1052 | void TerminalCmd_FanOn(char *arg) |
emh203 | 0:7798270c1f52 | 1053 | { |
emh203 | 0:7798270c1f52 | 1054 | SetFanSpeed(100); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off |
wavenumber | 2:73a028278c5c | 1055 | MBED_LED1 = 1; |
emh203 | 0:7798270c1f52 | 1056 | } |
emh203 | 0:7798270c1f52 | 1057 | |
emh203 | 0:7798270c1f52 | 1058 | void TerminalCmd_FanOff(char *arg) |
emh203 | 0:7798270c1f52 | 1059 | { |
emh203 | 0:7798270c1f52 | 1060 | SetFanSpeed(0); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off |
wavenumber | 2:73a028278c5c | 1061 | MBED_LED1 = 0; |
emh203 | 0:7798270c1f52 | 1062 | } |
emh203 | 0:7798270c1f52 | 1063 | |
emh203 | 0:7798270c1f52 | 1064 | void TerminalCmd_Fan(char *arg) |
emh203 | 0:7798270c1f52 | 1065 | { |
emh203 | 0:7798270c1f52 | 1066 | int Speed = -1; |
emh203 | 0:7798270c1f52 | 1067 | |
emh203 | 0:7798270c1f52 | 1068 | if(sscanf(arg,"%d",&Speed) == 1) |
emh203 | 0:7798270c1f52 | 1069 | { |
emh203 | 0:7798270c1f52 | 1070 | if(Speed>=0 && Speed<=100) |
emh203 | 0:7798270c1f52 | 1071 | { |
emh203 | 0:7798270c1f52 | 1072 | SetFanSpeed(Speed); |
emh203 | 0:7798270c1f52 | 1073 | } |
emh203 | 0:7798270c1f52 | 1074 | else |
emh203 | 0:7798270c1f52 | 1075 | { |
emh203 | 0:7798270c1f52 | 1076 | PC.printf("%d is an invalid speed. Speed should be between 0 and 100",Speed); |
emh203 | 0:7798270c1f52 | 1077 | } |
emh203 | 0:7798270c1f52 | 1078 | } |
emh203 | 0:7798270c1f52 | 1079 | else |
emh203 | 0:7798270c1f52 | 1080 | { |
emh203 | 0:7798270c1f52 | 1081 | PC.printf("Bad argument... %s. Should be integer between 0 and 100",arg); |
emh203 | 0:7798270c1f52 | 1082 | } |
emh203 | 0:7798270c1f52 | 1083 | |
emh203 | 0:7798270c1f52 | 1084 | } |
emh203 | 0:7798270c1f52 | 1085 | |
emh203 | 0:7798270c1f52 | 1086 | |
emh203 | 0:7798270c1f52 | 1087 | void TerminalCmd_T(char *arg) |
emh203 | 0:7798270c1f52 | 1088 | { |
emh203 | 0:7798270c1f52 | 1089 | float Temp = 0; |
emh203 | 0:7798270c1f52 | 1090 | int Channel = -1; |
wavenumber | 5:b56a4592aac0 | 1091 | int Status = 0; |
emh203 | 0:7798270c1f52 | 1092 | |
emh203 | 0:7798270c1f52 | 1093 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 1094 | { |
emh203 | 0:7798270c1f52 | 1095 | Temp = ReadThermocouple(Channel); |
wavenumber | 5:b56a4592aac0 | 1096 | |
wavenumber | 5:b56a4592aac0 | 1097 | if(ReadThermocouple_FAULT() & (1<<Channel)) |
wavenumber | 5:b56a4592aac0 | 1098 | { |
wavenumber | 5:b56a4592aac0 | 1099 | Status = 1; |
wavenumber | 5:b56a4592aac0 | 1100 | } |
wavenumber | 5:b56a4592aac0 | 1101 | else |
wavenumber | 5:b56a4592aac0 | 1102 | { |
wavenumber | 5:b56a4592aac0 | 1103 | Status = 0; |
wavenumber | 5:b56a4592aac0 | 1104 | } |
wavenumber | 5:b56a4592aac0 | 1105 | |
wavenumber | 5:b56a4592aac0 | 1106 | PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Status); |
emh203 | 0:7798270c1f52 | 1107 | } |
emh203 | 0:7798270c1f52 | 1108 | else |
emh203 | 0:7798270c1f52 | 1109 | { |
emh203 | 0:7798270c1f52 | 1110 | for(Channel = 0; Channel<12;Channel++) |
emh203 | 0:7798270c1f52 | 1111 | { |
emh203 | 0:7798270c1f52 | 1112 | Temp = ReadThermocouple(Channel); |
wavenumber | 5:b56a4592aac0 | 1113 | |
wavenumber | 5:b56a4592aac0 | 1114 | if(ReadThermocouple_FAULT() & (1<<Channel)) |
wavenumber | 5:b56a4592aac0 | 1115 | { |
wavenumber | 5:b56a4592aac0 | 1116 | Status = 1; |
wavenumber | 5:b56a4592aac0 | 1117 | } |
wavenumber | 5:b56a4592aac0 | 1118 | else |
wavenumber | 5:b56a4592aac0 | 1119 | { |
wavenumber | 5:b56a4592aac0 | 1120 | Status = 0; |
wavenumber | 5:b56a4592aac0 | 1121 | } |
wavenumber | 5:b56a4592aac0 | 1122 | |
wavenumber | 5:b56a4592aac0 | 1123 | PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Status); |
emh203 | 0:7798270c1f52 | 1124 | } |
emh203 | 0:7798270c1f52 | 1125 | } |
emh203 | 0:7798270c1f52 | 1126 | } |
emh203 | 0:7798270c1f52 | 1127 | |
emh203 | 0:7798270c1f52 | 1128 | void TerminalCmd_Buzz(char *arg) |
emh203 | 0:7798270c1f52 | 1129 | { |
emh203 | 0:7798270c1f52 | 1130 | |
emh203 | 0:7798270c1f52 | 1131 | float T = -1.0; |
emh203 | 0:7798270c1f52 | 1132 | |
emh203 | 0:7798270c1f52 | 1133 | if(sscanf(arg,"%f",&T) == 1) |
emh203 | 0:7798270c1f52 | 1134 | { |
emh203 | 0:7798270c1f52 | 1135 | if(T>=0.0 && T<=5.0) |
emh203 | 0:7798270c1f52 | 1136 | { |
emh203 | 0:7798270c1f52 | 1137 | Buzz(T); |
emh203 | 0:7798270c1f52 | 1138 | } |
emh203 | 0:7798270c1f52 | 1139 | else |
emh203 | 0:7798270c1f52 | 1140 | { |
emh203 | 0:7798270c1f52 | 1141 | PC.printf("%f is an invalid time period for buzz. Time should be between 0.0 and 5.0 seconds",T); |
emh203 | 0:7798270c1f52 | 1142 | } |
emh203 | 0:7798270c1f52 | 1143 | } |
emh203 | 0:7798270c1f52 | 1144 | else |
emh203 | 0:7798270c1f52 | 1145 | { |
emh203 | 0:7798270c1f52 | 1146 | PC.printf("Bad argument... %s. Should be float between 0.0 and 5.0",arg); |
emh203 | 0:7798270c1f52 | 1147 | } |
emh203 | 0:7798270c1f52 | 1148 | |
emh203 | 0:7798270c1f52 | 1149 | } |
emh203 | 0:7798270c1f52 | 1150 | |
emh203 | 0:7798270c1f52 | 1151 | |
emh203 | 0:7798270c1f52 | 1152 | |
emh203 | 0:7798270c1f52 | 1153 | |
emh203 | 0:7798270c1f52 | 1154 | //***************************************************************** |
emh203 | 0:7798270c1f52 | 1155 | //Plumbing..... |
emh203 | 0:7798270c1f52 | 1156 | //***************************************************************** |
emh203 | 0:7798270c1f52 | 1157 | |
emh203 | 0:7798270c1f52 | 1158 | #define NUM_TERMINAL_COMMANDS (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord)) |
emh203 | 0:7798270c1f52 | 1159 | |
emh203 | 0:7798270c1f52 | 1160 | char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS]; |
emh203 | 0:7798270c1f52 | 1161 | uint8_t TerminalPos; |
emh203 | 0:7798270c1f52 | 1162 | char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1]; |
emh203 | 0:7798270c1f52 | 1163 | char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS]; |
emh203 | 0:7798270c1f52 | 1164 | uint8_t NextCharIn; |
emh203 | 0:7798270c1f52 | 1165 | uint8_t CmdFound; |
emh203 | 0:7798270c1f52 | 1166 | |
emh203 | 0:7798270c1f52 | 1167 | void TerminalBootMsg() |
emh203 | 0:7798270c1f52 | 1168 | { |
emh203 | 0:7798270c1f52 | 1169 | |
emh203 | 0:7798270c1f52 | 1170 | PC.printf("\r\n\r\n"); |
emh203 | 0:7798270c1f52 | 1171 | PC.printf("***********************************\r\n"); |
emh203 | 0:7798270c1f52 | 1172 | PC.printf("CHEM Control Box \r\n"); |
emh203 | 0:7798270c1f52 | 1173 | PC.printf("API Version %s \r\n",API_VERSION); |
emh203 | 0:7798270c1f52 | 1174 | PC.printf("Copyright (C) <2013> Eli Hughes\r\n"); |
emh203 | 0:7798270c1f52 | 1175 | PC.printf("Wavenumber LLC\r\n"); |
emh203 | 0:7798270c1f52 | 1176 | PC.printf("***********************************\r\n\r\n>"); |
emh203 | 0:7798270c1f52 | 1177 | |
emh203 | 0:7798270c1f52 | 1178 | } |
emh203 | 0:7798270c1f52 | 1179 | |
emh203 | 0:7798270c1f52 | 1180 | void InitTerminal() |
emh203 | 0:7798270c1f52 | 1181 | { |
emh203 | 0:7798270c1f52 | 1182 | |
emh203 | 0:7798270c1f52 | 1183 | PC.baud(115200); |
emh203 | 0:7798270c1f52 | 1184 | TerminalPos = 0; |
emh203 | 0:7798270c1f52 | 1185 | CmdFound = 0; |
emh203 | 0:7798270c1f52 | 1186 | TerminalBootMsg(); |
emh203 | 0:7798270c1f52 | 1187 | } |
emh203 | 0:7798270c1f52 | 1188 | |
emh203 | 0:7798270c1f52 | 1189 | void TerminalCmd_Help(char *arg) |
emh203 | 0:7798270c1f52 | 1190 | { |
emh203 | 0:7798270c1f52 | 1191 | uint8_t i; |
emh203 | 0:7798270c1f52 | 1192 | |
emh203 | 0:7798270c1f52 | 1193 | PC.printf("\r\n\r\nCommand List:\r\n"); |
emh203 | 0:7798270c1f52 | 1194 | PC.printf("----------------------\r\n"); |
emh203 | 0:7798270c1f52 | 1195 | |
emh203 | 0:7798270c1f52 | 1196 | for(i=0;i<NUM_TERMINAL_COMMANDS;i++) |
emh203 | 0:7798270c1f52 | 1197 | { |
emh203 | 0:7798270c1f52 | 1198 | PC.printf("%s ----> %s\r\n\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString); |
emh203 | 0:7798270c1f52 | 1199 | } |
emh203 | 0:7798270c1f52 | 1200 | |
emh203 | 0:7798270c1f52 | 1201 | PC.printf("\r\n\r\n"); |
emh203 | 0:7798270c1f52 | 1202 | } |
emh203 | 0:7798270c1f52 | 1203 | |
emh203 | 0:7798270c1f52 | 1204 | void TerminalCmd_Reboot(char *arg) |
emh203 | 0:7798270c1f52 | 1205 | { |
emh203 | 0:7798270c1f52 | 1206 | TerminalBootMsg(); |
emh203 | 0:7798270c1f52 | 1207 | } |
emh203 | 0:7798270c1f52 | 1208 | |
emh203 | 0:7798270c1f52 | 1209 | void ProcessTerminal() |
emh203 | 0:7798270c1f52 | 1210 | { |
emh203 | 0:7798270c1f52 | 1211 | uint8_t i,j; |
emh203 | 0:7798270c1f52 | 1212 | uint8_t ArgsFound; |
emh203 | 0:7798270c1f52 | 1213 | |
emh203 | 0:7798270c1f52 | 1214 | if(PC.readable()) |
emh203 | 0:7798270c1f52 | 1215 | { |
emh203 | 0:7798270c1f52 | 1216 | NextCharIn = PC.getc(); |
emh203 | 0:7798270c1f52 | 1217 | |
emh203 | 0:7798270c1f52 | 1218 | switch(NextCharIn) |
emh203 | 0:7798270c1f52 | 1219 | { |
emh203 | 0:7798270c1f52 | 1220 | case '\r': |
emh203 | 0:7798270c1f52 | 1221 | |
emh203 | 0:7798270c1f52 | 1222 | TerminalLineBuf[TerminalPos++] = 0x0; |
wavenumber | 2:73a028278c5c | 1223 | |
wavenumber | 2:73a028278c5c | 1224 | if(TerminalEcho) |
wavenumber | 2:73a028278c5c | 1225 | { |
wavenumber | 2:73a028278c5c | 1226 | PC.putc(NextCharIn); |
wavenumber | 2:73a028278c5c | 1227 | } |
wavenumber | 2:73a028278c5c | 1228 | |
emh203 | 0:7798270c1f52 | 1229 | if(TerminalPos > 1) |
emh203 | 0:7798270c1f52 | 1230 | { |
emh203 | 0:7798270c1f52 | 1231 | //find the command |
emh203 | 0:7798270c1f52 | 1232 | i=0; |
emh203 | 0:7798270c1f52 | 1233 | while(TerminalLineBuf[i]>0x20 && TerminalLineBuf[i]<0x7f) |
emh203 | 0:7798270c1f52 | 1234 | { |
emh203 | 0:7798270c1f52 | 1235 | TerminalCmdBuf[i] = TerminalLineBuf[i]; |
emh203 | 0:7798270c1f52 | 1236 | i++; |
emh203 | 0:7798270c1f52 | 1237 | |
emh203 | 0:7798270c1f52 | 1238 | if(i==MAX_TERMINAL_CMD_CHARS) |
emh203 | 0:7798270c1f52 | 1239 | { |
emh203 | 0:7798270c1f52 | 1240 | break; |
emh203 | 0:7798270c1f52 | 1241 | } |
emh203 | 0:7798270c1f52 | 1242 | } |
emh203 | 0:7798270c1f52 | 1243 | |
emh203 | 0:7798270c1f52 | 1244 | TerminalCmdBuf[i] = 0; |
emh203 | 0:7798270c1f52 | 1245 | TerminalCmdBuf[i+1] = 0; |
emh203 | 0:7798270c1f52 | 1246 | |
emh203 | 0:7798270c1f52 | 1247 | |
emh203 | 0:7798270c1f52 | 1248 | ArgsFound = TRUE; |
emh203 | 0:7798270c1f52 | 1249 | memset(TerminalArgs,0x00,sizeof(TerminalArgs)); |
emh203 | 0:7798270c1f52 | 1250 | //scan for num terminator or next non whitespace |
emh203 | 0:7798270c1f52 | 1251 | while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS)) |
emh203 | 0:7798270c1f52 | 1252 | { |
emh203 | 0:7798270c1f52 | 1253 | if(TerminalLineBuf[i] == 0x00) |
emh203 | 0:7798270c1f52 | 1254 | { |
emh203 | 0:7798270c1f52 | 1255 | |
emh203 | 0:7798270c1f52 | 1256 | //if we find a NULL terminator before a non whitespace character they flag for no arguments |
emh203 | 0:7798270c1f52 | 1257 | ArgsFound = FALSE; |
emh203 | 0:7798270c1f52 | 1258 | break; |
emh203 | 0:7798270c1f52 | 1259 | } |
emh203 | 0:7798270c1f52 | 1260 | i++; |
emh203 | 0:7798270c1f52 | 1261 | } |
emh203 | 0:7798270c1f52 | 1262 | |
emh203 | 0:7798270c1f52 | 1263 | if(ArgsFound == TRUE) |
emh203 | 0:7798270c1f52 | 1264 | { |
emh203 | 0:7798270c1f52 | 1265 | strcpy(TerminalArgs,&TerminalLineBuf[i]); |
emh203 | 0:7798270c1f52 | 1266 | |
emh203 | 0:7798270c1f52 | 1267 | //trim trailing whitespace |
emh203 | 0:7798270c1f52 | 1268 | i = sizeof(TerminalArgs)-1; |
emh203 | 0:7798270c1f52 | 1269 | |
emh203 | 0:7798270c1f52 | 1270 | while((TerminalArgs[i]<0x21) && (i>0)) |
emh203 | 0:7798270c1f52 | 1271 | { |
emh203 | 0:7798270c1f52 | 1272 | TerminalArgs[i]= 0x00; |
emh203 | 0:7798270c1f52 | 1273 | i--; |
emh203 | 0:7798270c1f52 | 1274 | } |
emh203 | 0:7798270c1f52 | 1275 | } |
emh203 | 0:7798270c1f52 | 1276 | |
emh203 | 0:7798270c1f52 | 1277 | CmdFound = FALSE; |
emh203 | 0:7798270c1f52 | 1278 | for(j=0;j<NUM_TERMINAL_COMMANDS;j++) |
emh203 | 0:7798270c1f52 | 1279 | { |
emh203 | 0:7798270c1f52 | 1280 | if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0) |
emh203 | 0:7798270c1f52 | 1281 | { |
emh203 | 0:7798270c1f52 | 1282 | PC.printf("\r\n"); |
emh203 | 0:7798270c1f52 | 1283 | if(MyTerminalCallbackRecords[j].Callback != NULL) |
emh203 | 0:7798270c1f52 | 1284 | MyTerminalCallbackRecords[j].Callback(TerminalArgs); |
emh203 | 0:7798270c1f52 | 1285 | |
emh203 | 0:7798270c1f52 | 1286 | CmdFound = TRUE; |
emh203 | 0:7798270c1f52 | 1287 | break; |
emh203 | 0:7798270c1f52 | 1288 | } |
emh203 | 0:7798270c1f52 | 1289 | } |
emh203 | 0:7798270c1f52 | 1290 | if(CmdFound == FALSE) |
emh203 | 0:7798270c1f52 | 1291 | { |
emh203 | 0:7798270c1f52 | 1292 | PC.printf("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf); |
emh203 | 0:7798270c1f52 | 1293 | TerminalCmd_Help("no arg"); |
emh203 | 0:7798270c1f52 | 1294 | |
emh203 | 0:7798270c1f52 | 1295 | } |
emh203 | 0:7798270c1f52 | 1296 | } |
wavenumber | 2:73a028278c5c | 1297 | PC.printf("\r\n"); |
emh203 | 0:7798270c1f52 | 1298 | TerminalPos = 0; |
emh203 | 0:7798270c1f52 | 1299 | |
emh203 | 0:7798270c1f52 | 1300 | break; |
emh203 | 0:7798270c1f52 | 1301 | |
emh203 | 0:7798270c1f52 | 1302 | case '\b': |
emh203 | 0:7798270c1f52 | 1303 | if(TerminalPos > 0) |
emh203 | 0:7798270c1f52 | 1304 | { |
wavenumber | 2:73a028278c5c | 1305 | TerminalPos--; |
wavenumber | 2:73a028278c5c | 1306 | if(TerminalEcho) |
wavenumber | 2:73a028278c5c | 1307 | { |
wavenumber | 2:73a028278c5c | 1308 | PC.putc(NextCharIn); |
wavenumber | 2:73a028278c5c | 1309 | } |
emh203 | 0:7798270c1f52 | 1310 | } |
emh203 | 0:7798270c1f52 | 1311 | break; |
emh203 | 0:7798270c1f52 | 1312 | |
emh203 | 0:7798270c1f52 | 1313 | default: |
emh203 | 0:7798270c1f52 | 1314 | |
emh203 | 0:7798270c1f52 | 1315 | if(TerminalPos == 0 && NextCharIn == 0x020) |
emh203 | 0:7798270c1f52 | 1316 | { |
emh203 | 0:7798270c1f52 | 1317 | //Do nothing if space bar is pressed at beginning of line |
emh203 | 0:7798270c1f52 | 1318 | } |
emh203 | 0:7798270c1f52 | 1319 | else if(NextCharIn >= 0x20 && NextCharIn<0x7F) |
emh203 | 0:7798270c1f52 | 1320 | { |
emh203 | 0:7798270c1f52 | 1321 | |
emh203 | 0:7798270c1f52 | 1322 | if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1) |
emh203 | 0:7798270c1f52 | 1323 | { |
emh203 | 0:7798270c1f52 | 1324 | TerminalLineBuf[TerminalPos++] = NextCharIn; |
wavenumber | 2:73a028278c5c | 1325 | if(TerminalEcho) |
wavenumber | 2:73a028278c5c | 1326 | { |
wavenumber | 2:73a028278c5c | 1327 | PC.putc(NextCharIn); |
wavenumber | 2:73a028278c5c | 1328 | } |
emh203 | 0:7798270c1f52 | 1329 | } |
emh203 | 0:7798270c1f52 | 1330 | } |
emh203 | 0:7798270c1f52 | 1331 | |
emh203 | 0:7798270c1f52 | 1332 | break; |
emh203 | 0:7798270c1f52 | 1333 | |
emh203 | 0:7798270c1f52 | 1334 | } |
emh203 | 0:7798270c1f52 | 1335 | } |
emh203 | 0:7798270c1f52 | 1336 | |
emh203 | 0:7798270c1f52 | 1337 | } |
emh203 | 0:7798270c1f52 | 1338 | |
emh203 | 0:7798270c1f52 | 1339 | |
emh203 | 0:7798270c1f52 | 1340 | |
emh203 | 0:7798270c1f52 | 1341 |