Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DRIVERS/CHEM_BOX_COMMON.cpp@7:de452fceafc1, 2021-09-20 (annotated)
- Committer:
- wavenumber
- Date:
- Mon Sep 20 01:32:52 2021 +0000
- Revision:
- 7:de452fceafc1
- Parent:
- 6:6a870e1e52c1
- Child:
- 8:0cf1573051e8
Returning data back from the Pump. Reverting to 82 ohm resistor for 4-20
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 | 6:6a870e1e52c1 | 140 | RS232_1.baud(19200); | 
| 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 | |
| emh203 | 0:7798270c1f52 | 322 | if(ThermocoupleData & (0x10000000)) | 
| 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); | 
| emh203 | 0:7798270c1f52 | 560 | |
| emh203 | 0:7798270c1f52 | 561 | //Populate this array with the callback functions and their terminal command string | 
| emh203 | 0:7798270c1f52 | 562 | TerminalCallbackRecord MyTerminalCallbackRecords[] ={ {"reset",TerminalCmd_Reset,"Resets the CHEM box"}, | 
| emh203 | 0:7798270c1f52 | 563 | |
| emh203 | 0:7798270c1f52 | 564 | {"help",TerminalCmd_Help,"Lists available commands"}, | 
| emh203 | 0:7798270c1f52 | 565 | |
| emh203 | 0:7798270c1f52 | 566 | {"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 | 567 | |
| emh203 | 0:7798270c1f52 | 568 | {"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 | 569 | |
| emh203 | 0:7798270c1f52 | 570 | {"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 | 571 | |
| emh203 | 0:7798270c1f52 | 572 | {"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 | 573 | |
| emh203 | 0:7798270c1f52 | 574 | {"DAHAS",TerminalCmd_DisableAllHeatersAndSolenoids,"Disables all heaters and solenoids. Command is immediately executed."}, | 
| emh203 | 0:7798270c1f52 | 575 | |
| emh203 | 0:7798270c1f52 | 576 | {"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 | 577 | |
| emh203 | 0:7798270c1f52 | 578 | {"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 | 579 | |
| emh203 | 0:7798270c1f52 | 580 | {"FDIO",TerminalCmd_FlushDigitalIO,"Updates the all of the digital IO channels"}, | 
| emh203 | 0:7798270c1f52 | 581 | |
| emh203 | 0:7798270c1f52 | 582 | {"FON",TerminalCmd_FanOn,"Turns on the fans"}, | 
| emh203 | 0:7798270c1f52 | 583 | |
| emh203 | 0:7798270c1f52 | 584 | {"FOFF",TerminalCmd_FanOff,"Turns off the fans"}, | 
| emh203 | 0:7798270c1f52 | 585 | |
| emh203 | 0:7798270c1f52 | 586 | {"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 | 587 | |
| emh203 | 0:7798270c1f52 | 588 | {"T",TerminalCmd_T,"Read thermocouple channel"}, | 
| emh203 | 0:7798270c1f52 | 589 | |
| emh203 | 0:7798270c1f52 | 590 | {"MFCI",TerminalCmd_MFCI,"Reads in voltage from MFC channel"}, | 
| emh203 | 0:7798270c1f52 | 591 | |
| emh203 | 0:7798270c1f52 | 592 | {"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 | 593 | |
| emh203 | 0:7798270c1f52 | 594 | {"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 | 595 | |
| emh203 | 0:7798270c1f52 | 596 | {"4TO20",TerminalCmd_4TO20,"Reads a 4 to 20 mA channel"}, | 
| emh203 | 0:7798270c1f52 | 597 | |
| emh203 | 0:7798270c1f52 | 598 | {"AIN",TerminalCmd_AIN,"Reads a general purpose analog in channel"}, | 
| emh203 | 0:7798270c1f52 | 599 | |
| emh203 | 0:7798270c1f52 | 600 | {"MFCON",TerminalCmd_MFCON,"Turns on the MFC power"}, | 
| emh203 | 0:7798270c1f52 | 601 | |
| wavenumber | 2:73a028278c5c | 602 | {"MFCOFF",TerminalCmd_MFCOFF,"Turns off the MFC power"}, | 
| wavenumber | 2:73a028278c5c | 603 | |
| wavenumber | 3:cb48919cd5e8 | 604 | {"BPOUT",TerminalCmd_BPOUT,"Sets a control voltage between 0 and 10 for the backpressure regulator. I.E. BPOUT 1.21"}, | 
| wavenumber | 3:cb48919cd5e8 | 605 | |
| wavenumber | 3:cb48919cd5e8 | 606 | {"BPIN",TerminalCmd_BPIN,"Reads the Back pressure regulator feedback. I.E. BPIN "}, | 
| wavenumber | 3:cb48919cd5e8 | 607 | |
| wavenumber | 6:6a870e1e52c1 | 608 | {"P0",TerminalCmd_P0,"Sends a command over RS232 port 0 to the Pump. A carriage return will be added automatically."}, | 
| wavenumber | 6:6a870e1e52c1 | 609 | |
| wavenumber | 6:6a870e1e52c1 | 610 | {"P1",TerminalCmd_P1,"Sends a command over RS232 port 0 to the Pump. A carriage return will be added automatically."}, | 
| wavenumber | 6:6a870e1e52c1 | 611 | |
| wavenumber | 3:cb48919cd5e8 | 612 | |
| wavenumber | 2:73a028278c5c | 613 | {"ECHO_OFF",TerminalCmd_ECHO_OFF,"Disables echoing of characters"} | 
| emh203 | 0:7798270c1f52 | 614 | }; | 
| emh203 | 0:7798270c1f52 | 615 | |
| emh203 | 0:7798270c1f52 | 616 | |
| emh203 | 0:7798270c1f52 | 617 | extern "C" void mbed_reset(); | 
| emh203 | 0:7798270c1f52 | 618 | |
| emh203 | 0:7798270c1f52 | 619 | void TerminalCmd_Reset(char *arg) | 
| emh203 | 0:7798270c1f52 | 620 | { | 
| emh203 | 0:7798270c1f52 | 621 | mbed_reset(); | 
| emh203 | 0:7798270c1f52 | 622 | } | 
| emh203 | 0:7798270c1f52 | 623 | |
| wavenumber | 2:73a028278c5c | 624 | |
| wavenumber | 2:73a028278c5c | 625 | |
| emh203 | 0:7798270c1f52 | 626 | void TerminalCmd_Stub(char *arg) | 
| emh203 | 0:7798270c1f52 | 627 | { | 
| emh203 | 0:7798270c1f52 | 628 | PC.printf("stub \r\n"); | 
| emh203 | 0:7798270c1f52 | 629 | } | 
| emh203 | 0:7798270c1f52 | 630 | |
| wavenumber | 2:73a028278c5c | 631 | void TerminalCmd_ECHO_OFF(char *arg) | 
| wavenumber | 2:73a028278c5c | 632 | { | 
| wavenumber | 2:73a028278c5c | 633 | TerminalEcho = 0; | 
| wavenumber | 2:73a028278c5c | 634 | } | 
| wavenumber | 2:73a028278c5c | 635 | |
| wavenumber | 7:de452fceafc1 | 636 | uint8_t RS232_Buff[2][256]; | 
| wavenumber | 7:de452fceafc1 | 637 | |
| wavenumber | 7:de452fceafc1 | 638 | uint32_t RS232_Idx[2]; | 
| wavenumber | 7:de452fceafc1 | 639 | |
| wavenumber | 7:de452fceafc1 | 640 | |
| wavenumber | 7:de452fceafc1 | 641 | void ResetRS232_Response(uint32_t Channel) | 
| wavenumber | 7:de452fceafc1 | 642 | { | 
| wavenumber | 7:de452fceafc1 | 643 | if(Channel == 0) | 
| wavenumber | 7:de452fceafc1 | 644 | { | 
| wavenumber | 7:de452fceafc1 | 645 | RS232_Idx[0] = 0; | 
| wavenumber | 7:de452fceafc1 | 646 | } | 
| wavenumber | 7:de452fceafc1 | 647 | else | 
| wavenumber | 7:de452fceafc1 | 648 | { | 
| wavenumber | 7:de452fceafc1 | 649 | RS232_Idx[1] = 0; | 
| wavenumber | 7:de452fceafc1 | 650 | } | 
| wavenumber | 7:de452fceafc1 | 651 | } | 
| wavenumber | 6:6a870e1e52c1 | 652 | |
| wavenumber | 6:6a870e1e52c1 | 653 | void TerminalCmd_P0(char *arg) | 
| wavenumber | 6:6a870e1e52c1 | 654 | { | 
| wavenumber | 7:de452fceafc1 | 655 | ResetRS232_Response(0); | 
| wavenumber | 6:6a870e1e52c1 | 656 | RS232_0.printf("%s\r",arg); | 
| wavenumber | 6:6a870e1e52c1 | 657 | } | 
| wavenumber | 6:6a870e1e52c1 | 658 | |
| wavenumber | 7:de452fceafc1 | 659 | |
| wavenumber | 7:de452fceafc1 | 660 | void ProcessRS232() | 
| wavenumber | 7:de452fceafc1 | 661 | { | 
| wavenumber | 7:de452fceafc1 | 662 | uint8_t Val; | 
| wavenumber | 7:de452fceafc1 | 663 | |
| wavenumber | 7:de452fceafc1 | 664 | while(RS232_0.readable()) | 
| wavenumber | 7:de452fceafc1 | 665 | { | 
| wavenumber | 7:de452fceafc1 | 666 | Val = RS232_0.getc(); | 
| wavenumber | 7:de452fceafc1 | 667 | |
| wavenumber | 7:de452fceafc1 | 668 | if(Val == 0x03) | 
| wavenumber | 7:de452fceafc1 | 669 | { | 
| wavenumber | 7:de452fceafc1 | 670 | |
| wavenumber | 7:de452fceafc1 | 671 | if(RS232_Idx[0]>0) | 
| wavenumber | 7:de452fceafc1 | 672 | { | 
| wavenumber | 7:de452fceafc1 | 673 | RS232_Buff[0][RS232_Idx[0]++] = 0; | 
| wavenumber | 7:de452fceafc1 | 674 | PC.printf("P:0:%s\r\n",&RS232_Buff[0][0]); | 
| wavenumber | 7:de452fceafc1 | 675 | ResetRS232_Response(0); | 
| wavenumber | 7:de452fceafc1 | 676 | break; | 
| wavenumber | 7:de452fceafc1 | 677 | } | 
| wavenumber | 7:de452fceafc1 | 678 | } | 
| wavenumber | 7:de452fceafc1 | 679 | else | 
| wavenumber | 7:de452fceafc1 | 680 | { | 
| wavenumber | 7:de452fceafc1 | 681 | if((Val>0x020) && (Val<0x7F) && (RS232_Idx[0]<(sizeof(RS232_Buff)-1))) | 
| wavenumber | 7:de452fceafc1 | 682 | { | 
| wavenumber | 7:de452fceafc1 | 683 | RS232_Buff[0][RS232_Idx[0]++] = Val; | 
| wavenumber | 7:de452fceafc1 | 684 | } | 
| wavenumber | 7:de452fceafc1 | 685 | } | 
| wavenumber | 7:de452fceafc1 | 686 | } | 
| wavenumber | 7:de452fceafc1 | 687 | |
| wavenumber | 7:de452fceafc1 | 688 | |
| wavenumber | 7:de452fceafc1 | 689 | while(RS232_1.readable()) | 
| wavenumber | 7:de452fceafc1 | 690 | { | 
| wavenumber | 7:de452fceafc1 | 691 | Val = RS232_1.getc(); | 
| wavenumber | 7:de452fceafc1 | 692 | |
| wavenumber | 7:de452fceafc1 | 693 | if(Val == 0x03) | 
| wavenumber | 7:de452fceafc1 | 694 | { | 
| wavenumber | 7:de452fceafc1 | 695 | if(RS232_Idx[1]>0) | 
| wavenumber | 7:de452fceafc1 | 696 | { | 
| wavenumber | 7:de452fceafc1 | 697 | RS232_Buff[1][RS232_Idx[1]++] = 0; | 
| wavenumber | 7:de452fceafc1 | 698 | PC.printf("P:1:%s\r\n",&RS232_Buff[1][0]); | 
| wavenumber | 7:de452fceafc1 | 699 | ResetRS232_Response(1); | 
| wavenumber | 7:de452fceafc1 | 700 | break; | 
| wavenumber | 7:de452fceafc1 | 701 | } | 
| wavenumber | 7:de452fceafc1 | 702 | } | 
| wavenumber | 7:de452fceafc1 | 703 | else | 
| wavenumber | 7:de452fceafc1 | 704 | { | 
| wavenumber | 7:de452fceafc1 | 705 | if((Val>0x020) && (Val <0x7F) && (RS232_Idx[1]<(sizeof(RS232_Buff)-1))) | 
| wavenumber | 7:de452fceafc1 | 706 | { | 
| wavenumber | 7:de452fceafc1 | 707 | RS232_Buff[1][RS232_Idx[1]++] = Val; | 
| wavenumber | 7:de452fceafc1 | 708 | } | 
| wavenumber | 7:de452fceafc1 | 709 | } | 
| wavenumber | 7:de452fceafc1 | 710 | } | 
| wavenumber | 7:de452fceafc1 | 711 | } | 
| wavenumber | 7:de452fceafc1 | 712 | |
| wavenumber | 7:de452fceafc1 | 713 | |
| wavenumber | 6:6a870e1e52c1 | 714 | void TerminalCmd_P1(char *arg) | 
| wavenumber | 6:6a870e1e52c1 | 715 | { | 
| wavenumber | 7:de452fceafc1 | 716 | ResetRS232_Response(1); | 
| wavenumber | 6:6a870e1e52c1 | 717 | RS232_1.printf("%s\r",arg); | 
| wavenumber | 6:6a870e1e52c1 | 718 | } | 
| wavenumber | 6:6a870e1e52c1 | 719 | |
| wavenumber | 6:6a870e1e52c1 | 720 | |
| emh203 | 0:7798270c1f52 | 721 | void TerminalCmd_MFCI(char *arg) | 
| emh203 | 0:7798270c1f52 | 722 | { | 
| emh203 | 0:7798270c1f52 | 723 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 724 | float Data; | 
| emh203 | 0:7798270c1f52 | 725 | |
| emh203 | 0:7798270c1f52 | 726 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 727 | { | 
| emh203 | 0:7798270c1f52 | 728 | if(Channel>=0 && Channel <=6) | 
| emh203 | 0:7798270c1f52 | 729 | { | 
| emh203 | 0:7798270c1f52 | 730 | Data = ReadMFC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 731 | PC.printf("MFCI:%d:%.3f",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 732 | } | 
| emh203 | 0:7798270c1f52 | 733 | else | 
| emh203 | 0:7798270c1f52 | 734 | { | 
| emh203 | 0:7798270c1f52 | 735 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 6",Channel); | 
| emh203 | 0:7798270c1f52 | 736 | } | 
| emh203 | 0:7798270c1f52 | 737 | } | 
| emh203 | 0:7798270c1f52 | 738 | else | 
| emh203 | 0:7798270c1f52 | 739 | { | 
| emh203 | 0:7798270c1f52 | 740 | for(Channel = 0; Channel<=6; Channel++) | 
| emh203 | 0:7798270c1f52 | 741 | { | 
| emh203 | 0:7798270c1f52 | 742 | Data = ReadMFC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 743 | PC.printf("MFCI:%d:%.3f\r\n",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 744 | } | 
| emh203 | 0:7798270c1f52 | 745 | } | 
| emh203 | 0:7798270c1f52 | 746 | } | 
| emh203 | 0:7798270c1f52 | 747 | |
| emh203 | 0:7798270c1f52 | 748 | void TerminalCmd_MFCON(char *arg) | 
| emh203 | 0:7798270c1f52 | 749 | { | 
| emh203 | 0:7798270c1f52 | 750 | EnableMFC_Power(); | 
| emh203 | 0:7798270c1f52 | 751 | } | 
| emh203 | 0:7798270c1f52 | 752 | |
| emh203 | 0:7798270c1f52 | 753 | |
| emh203 | 0:7798270c1f52 | 754 | void TerminalCmd_MFCOFF(char *arg) | 
| emh203 | 0:7798270c1f52 | 755 | { | 
| emh203 | 0:7798270c1f52 | 756 | DisableMFC_Power(); | 
| emh203 | 0:7798270c1f52 | 757 | } | 
| emh203 | 0:7798270c1f52 | 758 | |
| emh203 | 0:7798270c1f52 | 759 | |
| emh203 | 0:7798270c1f52 | 760 | void TerminalCmd_MFCO(char *arg) | 
| emh203 | 0:7798270c1f52 | 761 | { | 
| emh203 | 0:7798270c1f52 | 762 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 763 | float Data = 0.0; | 
| emh203 | 0:7798270c1f52 | 764 | |
| emh203 | 0:7798270c1f52 | 765 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) | 
| emh203 | 0:7798270c1f52 | 766 | { | 
| emh203 | 0:7798270c1f52 | 767 | if(Channel>=0 && Channel <=7) | 
| emh203 | 0:7798270c1f52 | 768 | { | 
| emh203 | 0:7798270c1f52 | 769 | WriteMFC_AnalogOut(Channel,Data); | 
| emh203 | 0:7798270c1f52 | 770 | } | 
| emh203 | 0:7798270c1f52 | 771 | else | 
| emh203 | 0:7798270c1f52 | 772 | { | 
| emh203 | 0:7798270c1f52 | 773 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); | 
| emh203 | 0:7798270c1f52 | 774 | } | 
| emh203 | 0:7798270c1f52 | 775 | } | 
| emh203 | 0:7798270c1f52 | 776 | else | 
| emh203 | 0:7798270c1f52 | 777 | { | 
| emh203 | 0:7798270c1f52 | 778 | 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 | 779 | } | 
| emh203 | 0:7798270c1f52 | 780 | } | 
| emh203 | 0:7798270c1f52 | 781 | |
| emh203 | 0:7798270c1f52 | 782 | void TerminalCmd_AOUT(char *arg) | 
| emh203 | 0:7798270c1f52 | 783 | { | 
| emh203 | 0:7798270c1f52 | 784 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 785 | float Data = 0.0; | 
| emh203 | 0:7798270c1f52 | 786 | |
| emh203 | 0:7798270c1f52 | 787 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) | 
| emh203 | 0:7798270c1f52 | 788 | { | 
| emh203 | 0:7798270c1f52 | 789 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 790 | { | 
| emh203 | 0:7798270c1f52 | 791 | WriteMISC_AnalogOut(Channel,Data); | 
| emh203 | 0:7798270c1f52 | 792 | } | 
| emh203 | 0:7798270c1f52 | 793 | else | 
| emh203 | 0:7798270c1f52 | 794 | { | 
| emh203 | 0:7798270c1f52 | 795 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 796 | } | 
| emh203 | 0:7798270c1f52 | 797 | } | 
| emh203 | 0:7798270c1f52 | 798 | else | 
| emh203 | 0:7798270c1f52 | 799 | { | 
| emh203 | 0:7798270c1f52 | 800 | 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 | 801 | } | 
| emh203 | 0:7798270c1f52 | 802 | } | 
| emh203 | 0:7798270c1f52 | 803 | |
| wavenumber | 3:cb48919cd5e8 | 804 | |
| wavenumber | 3:cb48919cd5e8 | 805 | void TerminalCmd_BPOUT(char *arg) | 
| wavenumber | 3:cb48919cd5e8 | 806 | { | 
| wavenumber | 3:cb48919cd5e8 | 807 | float Data = 0.0; | 
| wavenumber | 3:cb48919cd5e8 | 808 | |
| wavenumber | 3:cb48919cd5e8 | 809 | if(sscanf(arg,"%f",&Data) == 1) | 
| wavenumber | 3:cb48919cd5e8 | 810 | { | 
| wavenumber | 3:cb48919cd5e8 | 811 | WriteBP_AnalogOut(Data); | 
| wavenumber | 3:cb48919cd5e8 | 812 | } | 
| wavenumber | 3:cb48919cd5e8 | 813 | else | 
| wavenumber | 3:cb48919cd5e8 | 814 | { | 
| wavenumber | 3:cb48919cd5e8 | 815 | 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 | 816 | } | 
| wavenumber | 3:cb48919cd5e8 | 817 | } | 
| wavenumber | 3:cb48919cd5e8 | 818 | |
| wavenumber | 3:cb48919cd5e8 | 819 | void TerminalCmd_BPIN(char *arg) | 
| wavenumber | 3:cb48919cd5e8 | 820 | { | 
| wavenumber | 3:cb48919cd5e8 | 821 | float Data; | 
| wavenumber | 3:cb48919cd5e8 | 822 | Data = ReadBP_AnalogInput(); | 
| wavenumber | 3:cb48919cd5e8 | 823 | PC.printf("BPIN:%.3f",Data); | 
| wavenumber | 3:cb48919cd5e8 | 824 | } | 
| wavenumber | 3:cb48919cd5e8 | 825 | |
| emh203 | 0:7798270c1f52 | 826 | void TerminalCmd_4TO20(char *arg) | 
| emh203 | 0:7798270c1f52 | 827 | { | 
| emh203 | 0:7798270c1f52 | 828 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 829 | float Data; | 
| emh203 | 0:7798270c1f52 | 830 | |
| emh203 | 0:7798270c1f52 | 831 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 832 | { | 
| emh203 | 0:7798270c1f52 | 833 | if(Channel>=0 && Channel <=1) | 
| emh203 | 0:7798270c1f52 | 834 | { | 
| emh203 | 0:7798270c1f52 | 835 | Data = Read4to20(Channel); | 
| emh203 | 0:7798270c1f52 | 836 | PC.printf("4TO20:%d:%.3f",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 837 | } | 
| emh203 | 0:7798270c1f52 | 838 | else | 
| emh203 | 0:7798270c1f52 | 839 | { | 
| emh203 | 0:7798270c1f52 | 840 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); | 
| emh203 | 0:7798270c1f52 | 841 | } | 
| emh203 | 0:7798270c1f52 | 842 | } | 
| emh203 | 0:7798270c1f52 | 843 | else | 
| emh203 | 0:7798270c1f52 | 844 | { | 
| emh203 | 0:7798270c1f52 | 845 | |
| emh203 | 0:7798270c1f52 | 846 | for(Channel = 0;Channel<=1;Channel++) | 
| emh203 | 0:7798270c1f52 | 847 | { | 
| emh203 | 0:7798270c1f52 | 848 | Data = Read4to20(Channel); | 
| emh203 | 1:d64ac853223c | 849 | PC.printf("4TO20:%d:%.5f\r\n",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 850 | } | 
| emh203 | 0:7798270c1f52 | 851 | |
| emh203 | 0:7798270c1f52 | 852 | } | 
| emh203 | 0:7798270c1f52 | 853 | |
| emh203 | 0:7798270c1f52 | 854 | |
| emh203 | 0:7798270c1f52 | 855 | } | 
| emh203 | 0:7798270c1f52 | 856 | |
| emh203 | 0:7798270c1f52 | 857 | void TerminalCmd_AIN(char *arg) | 
| emh203 | 0:7798270c1f52 | 858 | { | 
| emh203 | 0:7798270c1f52 | 859 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 860 | float Data; | 
| emh203 | 0:7798270c1f52 | 861 | |
| emh203 | 0:7798270c1f52 | 862 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 863 | { | 
| emh203 | 0:7798270c1f52 | 864 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 865 | { | 
| emh203 | 0:7798270c1f52 | 866 | Data = ReadMISC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 867 | PC.printf("AIN:%d:%.3f",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 868 | } | 
| emh203 | 0:7798270c1f52 | 869 | else | 
| emh203 | 0:7798270c1f52 | 870 | { | 
| emh203 | 0:7798270c1f52 | 871 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 872 | } | 
| emh203 | 0:7798270c1f52 | 873 | } | 
| emh203 | 0:7798270c1f52 | 874 | else | 
| emh203 | 0:7798270c1f52 | 875 | { | 
| emh203 | 0:7798270c1f52 | 876 | for(Channel = 0;Channel<=3;Channel++) | 
| emh203 | 0:7798270c1f52 | 877 | { | 
| emh203 | 0:7798270c1f52 | 878 | Data = ReadMISC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 879 | PC.printf("AIN:%d:%.3f\r\n",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 880 | } | 
| emh203 | 0:7798270c1f52 | 881 | } | 
| emh203 | 0:7798270c1f52 | 882 | } | 
| emh203 | 0:7798270c1f52 | 883 | |
| emh203 | 0:7798270c1f52 | 884 | |
| emh203 | 0:7798270c1f52 | 885 | |
| emh203 | 0:7798270c1f52 | 886 | void TerminalCmd_EnableHeater(char *arg) | 
| emh203 | 0:7798270c1f52 | 887 | { | 
| emh203 | 0:7798270c1f52 | 888 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 889 | |
| emh203 | 0:7798270c1f52 | 890 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 891 | { | 
| emh203 | 0:7798270c1f52 | 892 | if(Channel>=0 && Channel <=7) | 
| emh203 | 0:7798270c1f52 | 893 | { | 
| emh203 | 0:7798270c1f52 | 894 | EnableHeater(Channel); | 
| emh203 | 0:7798270c1f52 | 895 | } | 
| emh203 | 0:7798270c1f52 | 896 | else | 
| emh203 | 0:7798270c1f52 | 897 | { | 
| emh203 | 0:7798270c1f52 | 898 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); | 
| emh203 | 0:7798270c1f52 | 899 | } | 
| emh203 | 0:7798270c1f52 | 900 | } | 
| emh203 | 0:7798270c1f52 | 901 | else | 
| emh203 | 0:7798270c1f52 | 902 | { | 
| emh203 | 0:7798270c1f52 | 903 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); | 
| emh203 | 0:7798270c1f52 | 904 | } | 
| emh203 | 0:7798270c1f52 | 905 | } | 
| emh203 | 0:7798270c1f52 | 906 | |
| emh203 | 0:7798270c1f52 | 907 | void TerminalCmd_DisableHeater(char *arg) | 
| emh203 | 0:7798270c1f52 | 908 | { | 
| emh203 | 0:7798270c1f52 | 909 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 910 | |
| emh203 | 0:7798270c1f52 | 911 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 912 | { | 
| emh203 | 0:7798270c1f52 | 913 | if(Channel>=0 && Channel <=7) | 
| emh203 | 0:7798270c1f52 | 914 | { | 
| emh203 | 0:7798270c1f52 | 915 | DisableHeater(Channel); | 
| emh203 | 0:7798270c1f52 | 916 | } | 
| emh203 | 0:7798270c1f52 | 917 | else | 
| emh203 | 0:7798270c1f52 | 918 | { | 
| emh203 | 0:7798270c1f52 | 919 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); | 
| emh203 | 0:7798270c1f52 | 920 | } | 
| emh203 | 0:7798270c1f52 | 921 | } | 
| emh203 | 0:7798270c1f52 | 922 | else | 
| emh203 | 0:7798270c1f52 | 923 | { | 
| emh203 | 0:7798270c1f52 | 924 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); | 
| emh203 | 0:7798270c1f52 | 925 | } | 
| emh203 | 0:7798270c1f52 | 926 | |
| emh203 | 0:7798270c1f52 | 927 | } | 
| emh203 | 0:7798270c1f52 | 928 | |
| emh203 | 0:7798270c1f52 | 929 | void TerminalCmd_EnableSolenoidValve(char *arg) | 
| emh203 | 0:7798270c1f52 | 930 | { | 
| emh203 | 0:7798270c1f52 | 931 | |
| emh203 | 0:7798270c1f52 | 932 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 933 | |
| emh203 | 0:7798270c1f52 | 934 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 935 | { | 
| emh203 | 0:7798270c1f52 | 936 | if(Channel>=0 && Channel <=11) | 
| emh203 | 0:7798270c1f52 | 937 | { | 
| emh203 | 0:7798270c1f52 | 938 | EnableSolenoidValve(Channel); | 
| emh203 | 0:7798270c1f52 | 939 | } | 
| emh203 | 0:7798270c1f52 | 940 | else | 
| emh203 | 0:7798270c1f52 | 941 | { | 
| emh203 | 0:7798270c1f52 | 942 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); | 
| emh203 | 0:7798270c1f52 | 943 | } | 
| emh203 | 0:7798270c1f52 | 944 | } | 
| emh203 | 0:7798270c1f52 | 945 | else | 
| emh203 | 0:7798270c1f52 | 946 | { | 
| emh203 | 0:7798270c1f52 | 947 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); | 
| emh203 | 0:7798270c1f52 | 948 | } | 
| emh203 | 0:7798270c1f52 | 949 | } | 
| emh203 | 0:7798270c1f52 | 950 | |
| emh203 | 0:7798270c1f52 | 951 | void TerminalCmd_DisableSolenoidValue(char *arg) | 
| emh203 | 0:7798270c1f52 | 952 | { | 
| emh203 | 0:7798270c1f52 | 953 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 954 | |
| emh203 | 0:7798270c1f52 | 955 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 956 | { | 
| emh203 | 0:7798270c1f52 | 957 | if( Channel >= 0 && Channel <= 11) | 
| emh203 | 0:7798270c1f52 | 958 | { | 
| emh203 | 0:7798270c1f52 | 959 | DisableSolenoidValue(Channel); | 
| emh203 | 0:7798270c1f52 | 960 | } | 
| emh203 | 0:7798270c1f52 | 961 | else | 
| emh203 | 0:7798270c1f52 | 962 | { | 
| emh203 | 0:7798270c1f52 | 963 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); | 
| emh203 | 0:7798270c1f52 | 964 | } | 
| emh203 | 0:7798270c1f52 | 965 | } | 
| emh203 | 0:7798270c1f52 | 966 | else | 
| emh203 | 0:7798270c1f52 | 967 | { | 
| emh203 | 0:7798270c1f52 | 968 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); | 
| emh203 | 0:7798270c1f52 | 969 | } | 
| emh203 | 0:7798270c1f52 | 970 | |
| emh203 | 0:7798270c1f52 | 971 | } | 
| emh203 | 0:7798270c1f52 | 972 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg) | 
| emh203 | 0:7798270c1f52 | 973 | { | 
| emh203 | 0:7798270c1f52 | 974 | |
| emh203 | 0:7798270c1f52 | 975 | DisableAllHeatersAndSolenoids(); | 
| emh203 | 0:7798270c1f52 | 976 | |
| emh203 | 0:7798270c1f52 | 977 | } | 
| emh203 | 0:7798270c1f52 | 978 | |
| emh203 | 0:7798270c1f52 | 979 | void TerminalCmd_EnableMiscDigitalOutput(char *arg) | 
| emh203 | 0:7798270c1f52 | 980 | { | 
| emh203 | 0:7798270c1f52 | 981 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 982 | |
| emh203 | 0:7798270c1f52 | 983 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 984 | { | 
| emh203 | 0:7798270c1f52 | 985 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 986 | { | 
| emh203 | 0:7798270c1f52 | 987 | EnableMiscDigitalOutput(Channel); | 
| emh203 | 0:7798270c1f52 | 988 | } | 
| emh203 | 0:7798270c1f52 | 989 | else | 
| emh203 | 0:7798270c1f52 | 990 | { | 
| emh203 | 0:7798270c1f52 | 991 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 992 | } | 
| emh203 | 0:7798270c1f52 | 993 | } | 
| emh203 | 0:7798270c1f52 | 994 | else | 
| emh203 | 0:7798270c1f52 | 995 | { | 
| emh203 | 0:7798270c1f52 | 996 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); | 
| emh203 | 0:7798270c1f52 | 997 | } | 
| emh203 | 0:7798270c1f52 | 998 | |
| emh203 | 0:7798270c1f52 | 999 | } | 
| emh203 | 0:7798270c1f52 | 1000 | |
| emh203 | 0:7798270c1f52 | 1001 | void TerminalCmd_DisableMiscDigitalOutput(char *arg) | 
| emh203 | 0:7798270c1f52 | 1002 | { | 
| emh203 | 0:7798270c1f52 | 1003 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 1004 | |
| emh203 | 0:7798270c1f52 | 1005 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 1006 | { | 
| emh203 | 0:7798270c1f52 | 1007 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 1008 | { | 
| emh203 | 0:7798270c1f52 | 1009 | DisableMiscDigitalOutput(Channel); | 
| emh203 | 0:7798270c1f52 | 1010 | } | 
| emh203 | 0:7798270c1f52 | 1011 | else | 
| emh203 | 0:7798270c1f52 | 1012 | { | 
| emh203 | 0:7798270c1f52 | 1013 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 1014 | } | 
| emh203 | 0:7798270c1f52 | 1015 | } | 
| emh203 | 0:7798270c1f52 | 1016 | else | 
| emh203 | 0:7798270c1f52 | 1017 | { | 
| emh203 | 0:7798270c1f52 | 1018 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); | 
| emh203 | 0:7798270c1f52 | 1019 | } | 
| emh203 | 0:7798270c1f52 | 1020 | |
| emh203 | 0:7798270c1f52 | 1021 | } | 
| emh203 | 0:7798270c1f52 | 1022 | |
| emh203 | 0:7798270c1f52 | 1023 | void TerminalCmd_FlushDigitalIO(char *arg) | 
| emh203 | 0:7798270c1f52 | 1024 | { | 
| emh203 | 0:7798270c1f52 | 1025 | FlushDigitalIO(); | 
| emh203 | 0:7798270c1f52 | 1026 | } | 
| emh203 | 0:7798270c1f52 | 1027 | |
| emh203 | 0:7798270c1f52 | 1028 | void TerminalCmd_FanOn(char *arg) | 
| emh203 | 0:7798270c1f52 | 1029 | { | 
| emh203 | 0:7798270c1f52 | 1030 | SetFanSpeed(100); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off | 
| wavenumber | 2:73a028278c5c | 1031 | MBED_LED1 = 1; | 
| emh203 | 0:7798270c1f52 | 1032 | } | 
| emh203 | 0:7798270c1f52 | 1033 | |
| emh203 | 0:7798270c1f52 | 1034 | void TerminalCmd_FanOff(char *arg) | 
| emh203 | 0:7798270c1f52 | 1035 | { | 
| emh203 | 0:7798270c1f52 | 1036 | SetFanSpeed(0); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off | 
| wavenumber | 2:73a028278c5c | 1037 | MBED_LED1 = 0; | 
| emh203 | 0:7798270c1f52 | 1038 | } | 
| emh203 | 0:7798270c1f52 | 1039 | |
| emh203 | 0:7798270c1f52 | 1040 | void TerminalCmd_Fan(char *arg) | 
| emh203 | 0:7798270c1f52 | 1041 | { | 
| emh203 | 0:7798270c1f52 | 1042 | int Speed = -1; | 
| emh203 | 0:7798270c1f52 | 1043 | |
| emh203 | 0:7798270c1f52 | 1044 | if(sscanf(arg,"%d",&Speed) == 1) | 
| emh203 | 0:7798270c1f52 | 1045 | { | 
| emh203 | 0:7798270c1f52 | 1046 | if(Speed>=0 && Speed<=100) | 
| emh203 | 0:7798270c1f52 | 1047 | { | 
| emh203 | 0:7798270c1f52 | 1048 | SetFanSpeed(Speed); | 
| emh203 | 0:7798270c1f52 | 1049 | } | 
| emh203 | 0:7798270c1f52 | 1050 | else | 
| emh203 | 0:7798270c1f52 | 1051 | { | 
| emh203 | 0:7798270c1f52 | 1052 | PC.printf("%d is an invalid speed. Speed should be between 0 and 100",Speed); | 
| emh203 | 0:7798270c1f52 | 1053 | } | 
| emh203 | 0:7798270c1f52 | 1054 | } | 
| emh203 | 0:7798270c1f52 | 1055 | else | 
| emh203 | 0:7798270c1f52 | 1056 | { | 
| emh203 | 0:7798270c1f52 | 1057 | PC.printf("Bad argument... %s. Should be integer between 0 and 100",arg); | 
| emh203 | 0:7798270c1f52 | 1058 | } | 
| emh203 | 0:7798270c1f52 | 1059 | |
| emh203 | 0:7798270c1f52 | 1060 | } | 
| emh203 | 0:7798270c1f52 | 1061 | |
| emh203 | 0:7798270c1f52 | 1062 | |
| emh203 | 0:7798270c1f52 | 1063 | void TerminalCmd_T(char *arg) | 
| emh203 | 0:7798270c1f52 | 1064 | { | 
| emh203 | 0:7798270c1f52 | 1065 | float Temp = 0; | 
| emh203 | 0:7798270c1f52 | 1066 | int Channel = -1; | 
| wavenumber | 5:b56a4592aac0 | 1067 | int Status = 0; | 
| emh203 | 0:7798270c1f52 | 1068 | |
| emh203 | 0:7798270c1f52 | 1069 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 1070 | { | 
| emh203 | 0:7798270c1f52 | 1071 | Temp = ReadThermocouple(Channel); | 
| wavenumber | 5:b56a4592aac0 | 1072 | |
| wavenumber | 5:b56a4592aac0 | 1073 | if(ReadThermocouple_FAULT() & (1<<Channel)) | 
| wavenumber | 5:b56a4592aac0 | 1074 | { | 
| wavenumber | 5:b56a4592aac0 | 1075 | Status = 1; | 
| wavenumber | 5:b56a4592aac0 | 1076 | } | 
| wavenumber | 5:b56a4592aac0 | 1077 | else | 
| wavenumber | 5:b56a4592aac0 | 1078 | { | 
| wavenumber | 5:b56a4592aac0 | 1079 | Status = 0; | 
| wavenumber | 5:b56a4592aac0 | 1080 | } | 
| wavenumber | 5:b56a4592aac0 | 1081 | |
| wavenumber | 5:b56a4592aac0 | 1082 | PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Status); | 
| emh203 | 0:7798270c1f52 | 1083 | } | 
| emh203 | 0:7798270c1f52 | 1084 | else | 
| emh203 | 0:7798270c1f52 | 1085 | { | 
| emh203 | 0:7798270c1f52 | 1086 | for(Channel = 0; Channel<12;Channel++) | 
| emh203 | 0:7798270c1f52 | 1087 | { | 
| emh203 | 0:7798270c1f52 | 1088 | Temp = ReadThermocouple(Channel); | 
| wavenumber | 5:b56a4592aac0 | 1089 | |
| wavenumber | 5:b56a4592aac0 | 1090 | if(ReadThermocouple_FAULT() & (1<<Channel)) | 
| wavenumber | 5:b56a4592aac0 | 1091 | { | 
| wavenumber | 5:b56a4592aac0 | 1092 | Status = 1; | 
| wavenumber | 5:b56a4592aac0 | 1093 | } | 
| wavenumber | 5:b56a4592aac0 | 1094 | else | 
| wavenumber | 5:b56a4592aac0 | 1095 | { | 
| wavenumber | 5:b56a4592aac0 | 1096 | Status = 0; | 
| wavenumber | 5:b56a4592aac0 | 1097 | } | 
| wavenumber | 5:b56a4592aac0 | 1098 | |
| wavenumber | 5:b56a4592aac0 | 1099 | PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Status); | 
| emh203 | 0:7798270c1f52 | 1100 | } | 
| emh203 | 0:7798270c1f52 | 1101 | } | 
| emh203 | 0:7798270c1f52 | 1102 | } | 
| emh203 | 0:7798270c1f52 | 1103 | |
| emh203 | 0:7798270c1f52 | 1104 | void TerminalCmd_Buzz(char *arg) | 
| emh203 | 0:7798270c1f52 | 1105 | { | 
| emh203 | 0:7798270c1f52 | 1106 | |
| emh203 | 0:7798270c1f52 | 1107 | float T = -1.0; | 
| emh203 | 0:7798270c1f52 | 1108 | |
| emh203 | 0:7798270c1f52 | 1109 | if(sscanf(arg,"%f",&T) == 1) | 
| emh203 | 0:7798270c1f52 | 1110 | { | 
| emh203 | 0:7798270c1f52 | 1111 | if(T>=0.0 && T<=5.0) | 
| emh203 | 0:7798270c1f52 | 1112 | { | 
| emh203 | 0:7798270c1f52 | 1113 | Buzz(T); | 
| emh203 | 0:7798270c1f52 | 1114 | } | 
| emh203 | 0:7798270c1f52 | 1115 | else | 
| emh203 | 0:7798270c1f52 | 1116 | { | 
| emh203 | 0:7798270c1f52 | 1117 | PC.printf("%f is an invalid time period for buzz. Time should be between 0.0 and 5.0 seconds",T); | 
| emh203 | 0:7798270c1f52 | 1118 | } | 
| emh203 | 0:7798270c1f52 | 1119 | } | 
| emh203 | 0:7798270c1f52 | 1120 | else | 
| emh203 | 0:7798270c1f52 | 1121 | { | 
| emh203 | 0:7798270c1f52 | 1122 | PC.printf("Bad argument... %s. Should be float between 0.0 and 5.0",arg); | 
| emh203 | 0:7798270c1f52 | 1123 | } | 
| emh203 | 0:7798270c1f52 | 1124 | |
| emh203 | 0:7798270c1f52 | 1125 | } | 
| emh203 | 0:7798270c1f52 | 1126 | |
| emh203 | 0:7798270c1f52 | 1127 | |
| emh203 | 0:7798270c1f52 | 1128 | |
| emh203 | 0:7798270c1f52 | 1129 | |
| emh203 | 0:7798270c1f52 | 1130 | //***************************************************************** | 
| emh203 | 0:7798270c1f52 | 1131 | //Plumbing..... | 
| emh203 | 0:7798270c1f52 | 1132 | //***************************************************************** | 
| emh203 | 0:7798270c1f52 | 1133 | |
| emh203 | 0:7798270c1f52 | 1134 | #define NUM_TERMINAL_COMMANDS (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord)) | 
| emh203 | 0:7798270c1f52 | 1135 | |
| emh203 | 0:7798270c1f52 | 1136 | char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS]; | 
| emh203 | 0:7798270c1f52 | 1137 | uint8_t TerminalPos; | 
| emh203 | 0:7798270c1f52 | 1138 | char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1]; | 
| emh203 | 0:7798270c1f52 | 1139 | char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS]; | 
| emh203 | 0:7798270c1f52 | 1140 | uint8_t NextCharIn; | 
| emh203 | 0:7798270c1f52 | 1141 | uint8_t CmdFound; | 
| emh203 | 0:7798270c1f52 | 1142 | |
| emh203 | 0:7798270c1f52 | 1143 | void TerminalBootMsg() | 
| emh203 | 0:7798270c1f52 | 1144 | { | 
| emh203 | 0:7798270c1f52 | 1145 | |
| emh203 | 0:7798270c1f52 | 1146 | PC.printf("\r\n\r\n"); | 
| emh203 | 0:7798270c1f52 | 1147 | PC.printf("***********************************\r\n"); | 
| emh203 | 0:7798270c1f52 | 1148 | PC.printf("CHEM Control Box \r\n"); | 
| emh203 | 0:7798270c1f52 | 1149 | PC.printf("API Version %s \r\n",API_VERSION); | 
| emh203 | 0:7798270c1f52 | 1150 | PC.printf("Copyright (C) <2013> Eli Hughes\r\n"); | 
| emh203 | 0:7798270c1f52 | 1151 | PC.printf("Wavenumber LLC\r\n"); | 
| emh203 | 0:7798270c1f52 | 1152 | PC.printf("***********************************\r\n\r\n>"); | 
| emh203 | 0:7798270c1f52 | 1153 | |
| emh203 | 0:7798270c1f52 | 1154 | } | 
| emh203 | 0:7798270c1f52 | 1155 | |
| emh203 | 0:7798270c1f52 | 1156 | void InitTerminal() | 
| emh203 | 0:7798270c1f52 | 1157 | { | 
| emh203 | 0:7798270c1f52 | 1158 | |
| emh203 | 0:7798270c1f52 | 1159 | PC.baud(115200); | 
| emh203 | 0:7798270c1f52 | 1160 | TerminalPos = 0; | 
| emh203 | 0:7798270c1f52 | 1161 | CmdFound = 0; | 
| emh203 | 0:7798270c1f52 | 1162 | TerminalBootMsg(); | 
| emh203 | 0:7798270c1f52 | 1163 | } | 
| emh203 | 0:7798270c1f52 | 1164 | |
| emh203 | 0:7798270c1f52 | 1165 | void TerminalCmd_Help(char *arg) | 
| emh203 | 0:7798270c1f52 | 1166 | { | 
| emh203 | 0:7798270c1f52 | 1167 | uint8_t i; | 
| emh203 | 0:7798270c1f52 | 1168 | |
| emh203 | 0:7798270c1f52 | 1169 | PC.printf("\r\n\r\nCommand List:\r\n"); | 
| emh203 | 0:7798270c1f52 | 1170 | PC.printf("----------------------\r\n"); | 
| emh203 | 0:7798270c1f52 | 1171 | |
| emh203 | 0:7798270c1f52 | 1172 | for(i=0;i<NUM_TERMINAL_COMMANDS;i++) | 
| emh203 | 0:7798270c1f52 | 1173 | { | 
| emh203 | 0:7798270c1f52 | 1174 | PC.printf("%s ----> %s\r\n\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString); | 
| emh203 | 0:7798270c1f52 | 1175 | } | 
| emh203 | 0:7798270c1f52 | 1176 | |
| emh203 | 0:7798270c1f52 | 1177 | PC.printf("\r\n\r\n"); | 
| emh203 | 0:7798270c1f52 | 1178 | } | 
| emh203 | 0:7798270c1f52 | 1179 | |
| emh203 | 0:7798270c1f52 | 1180 | void TerminalCmd_Reboot(char *arg) | 
| emh203 | 0:7798270c1f52 | 1181 | { | 
| emh203 | 0:7798270c1f52 | 1182 | TerminalBootMsg(); | 
| emh203 | 0:7798270c1f52 | 1183 | } | 
| emh203 | 0:7798270c1f52 | 1184 | |
| emh203 | 0:7798270c1f52 | 1185 | void ProcessTerminal() | 
| emh203 | 0:7798270c1f52 | 1186 | { | 
| emh203 | 0:7798270c1f52 | 1187 | uint8_t i,j; | 
| emh203 | 0:7798270c1f52 | 1188 | uint8_t ArgsFound; | 
| emh203 | 0:7798270c1f52 | 1189 | |
| emh203 | 0:7798270c1f52 | 1190 | if(PC.readable()) | 
| emh203 | 0:7798270c1f52 | 1191 | { | 
| emh203 | 0:7798270c1f52 | 1192 | NextCharIn = PC.getc(); | 
| emh203 | 0:7798270c1f52 | 1193 | |
| emh203 | 0:7798270c1f52 | 1194 | switch(NextCharIn) | 
| emh203 | 0:7798270c1f52 | 1195 | { | 
| emh203 | 0:7798270c1f52 | 1196 | case '\r': | 
| emh203 | 0:7798270c1f52 | 1197 | |
| emh203 | 0:7798270c1f52 | 1198 | TerminalLineBuf[TerminalPos++] = 0x0; | 
| wavenumber | 2:73a028278c5c | 1199 | |
| wavenumber | 2:73a028278c5c | 1200 | if(TerminalEcho) | 
| wavenumber | 2:73a028278c5c | 1201 | { | 
| wavenumber | 2:73a028278c5c | 1202 | PC.putc(NextCharIn); | 
| wavenumber | 2:73a028278c5c | 1203 | } | 
| wavenumber | 2:73a028278c5c | 1204 | |
| emh203 | 0:7798270c1f52 | 1205 | if(TerminalPos > 1) | 
| emh203 | 0:7798270c1f52 | 1206 | { | 
| emh203 | 0:7798270c1f52 | 1207 | //find the command | 
| emh203 | 0:7798270c1f52 | 1208 | i=0; | 
| emh203 | 0:7798270c1f52 | 1209 | while(TerminalLineBuf[i]>0x20 && TerminalLineBuf[i]<0x7f) | 
| emh203 | 0:7798270c1f52 | 1210 | { | 
| emh203 | 0:7798270c1f52 | 1211 | TerminalCmdBuf[i] = TerminalLineBuf[i]; | 
| emh203 | 0:7798270c1f52 | 1212 | i++; | 
| emh203 | 0:7798270c1f52 | 1213 | |
| emh203 | 0:7798270c1f52 | 1214 | if(i==MAX_TERMINAL_CMD_CHARS) | 
| emh203 | 0:7798270c1f52 | 1215 | { | 
| emh203 | 0:7798270c1f52 | 1216 | break; | 
| emh203 | 0:7798270c1f52 | 1217 | } | 
| emh203 | 0:7798270c1f52 | 1218 | } | 
| emh203 | 0:7798270c1f52 | 1219 | |
| emh203 | 0:7798270c1f52 | 1220 | TerminalCmdBuf[i] = 0; | 
| emh203 | 0:7798270c1f52 | 1221 | TerminalCmdBuf[i+1] = 0; | 
| emh203 | 0:7798270c1f52 | 1222 | |
| emh203 | 0:7798270c1f52 | 1223 | |
| emh203 | 0:7798270c1f52 | 1224 | ArgsFound = TRUE; | 
| emh203 | 0:7798270c1f52 | 1225 | memset(TerminalArgs,0x00,sizeof(TerminalArgs)); | 
| emh203 | 0:7798270c1f52 | 1226 | //scan for num terminator or next non whitespace | 
| emh203 | 0:7798270c1f52 | 1227 | while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS)) | 
| emh203 | 0:7798270c1f52 | 1228 | { | 
| emh203 | 0:7798270c1f52 | 1229 | if(TerminalLineBuf[i] == 0x00) | 
| emh203 | 0:7798270c1f52 | 1230 | { | 
| emh203 | 0:7798270c1f52 | 1231 | |
| emh203 | 0:7798270c1f52 | 1232 | //if we find a NULL terminator before a non whitespace character they flag for no arguments | 
| emh203 | 0:7798270c1f52 | 1233 | ArgsFound = FALSE; | 
| emh203 | 0:7798270c1f52 | 1234 | break; | 
| emh203 | 0:7798270c1f52 | 1235 | } | 
| emh203 | 0:7798270c1f52 | 1236 | i++; | 
| emh203 | 0:7798270c1f52 | 1237 | } | 
| emh203 | 0:7798270c1f52 | 1238 | |
| emh203 | 0:7798270c1f52 | 1239 | if(ArgsFound == TRUE) | 
| emh203 | 0:7798270c1f52 | 1240 | { | 
| emh203 | 0:7798270c1f52 | 1241 | strcpy(TerminalArgs,&TerminalLineBuf[i]); | 
| emh203 | 0:7798270c1f52 | 1242 | |
| emh203 | 0:7798270c1f52 | 1243 | //trim trailing whitespace | 
| emh203 | 0:7798270c1f52 | 1244 | i = sizeof(TerminalArgs)-1; | 
| emh203 | 0:7798270c1f52 | 1245 | |
| emh203 | 0:7798270c1f52 | 1246 | while((TerminalArgs[i]<0x21) && (i>0)) | 
| emh203 | 0:7798270c1f52 | 1247 | { | 
| emh203 | 0:7798270c1f52 | 1248 | TerminalArgs[i]= 0x00; | 
| emh203 | 0:7798270c1f52 | 1249 | i--; | 
| emh203 | 0:7798270c1f52 | 1250 | } | 
| emh203 | 0:7798270c1f52 | 1251 | } | 
| emh203 | 0:7798270c1f52 | 1252 | |
| emh203 | 0:7798270c1f52 | 1253 | CmdFound = FALSE; | 
| emh203 | 0:7798270c1f52 | 1254 | for(j=0;j<NUM_TERMINAL_COMMANDS;j++) | 
| emh203 | 0:7798270c1f52 | 1255 | { | 
| emh203 | 0:7798270c1f52 | 1256 | if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0) | 
| emh203 | 0:7798270c1f52 | 1257 | { | 
| emh203 | 0:7798270c1f52 | 1258 | PC.printf("\r\n"); | 
| emh203 | 0:7798270c1f52 | 1259 | if(MyTerminalCallbackRecords[j].Callback != NULL) | 
| emh203 | 0:7798270c1f52 | 1260 | MyTerminalCallbackRecords[j].Callback(TerminalArgs); | 
| emh203 | 0:7798270c1f52 | 1261 | |
| emh203 | 0:7798270c1f52 | 1262 | CmdFound = TRUE; | 
| emh203 | 0:7798270c1f52 | 1263 | break; | 
| emh203 | 0:7798270c1f52 | 1264 | } | 
| emh203 | 0:7798270c1f52 | 1265 | } | 
| emh203 | 0:7798270c1f52 | 1266 | if(CmdFound == FALSE) | 
| emh203 | 0:7798270c1f52 | 1267 | { | 
| emh203 | 0:7798270c1f52 | 1268 | PC.printf("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf); | 
| emh203 | 0:7798270c1f52 | 1269 | TerminalCmd_Help("no arg"); | 
| emh203 | 0:7798270c1f52 | 1270 | |
| emh203 | 0:7798270c1f52 | 1271 | } | 
| emh203 | 0:7798270c1f52 | 1272 | } | 
| wavenumber | 2:73a028278c5c | 1273 | PC.printf("\r\n"); | 
| emh203 | 0:7798270c1f52 | 1274 | TerminalPos = 0; | 
| emh203 | 0:7798270c1f52 | 1275 | |
| emh203 | 0:7798270c1f52 | 1276 | break; | 
| emh203 | 0:7798270c1f52 | 1277 | |
| emh203 | 0:7798270c1f52 | 1278 | case '\b': | 
| emh203 | 0:7798270c1f52 | 1279 | if(TerminalPos > 0) | 
| emh203 | 0:7798270c1f52 | 1280 | { | 
| wavenumber | 2:73a028278c5c | 1281 | TerminalPos--; | 
| wavenumber | 2:73a028278c5c | 1282 | if(TerminalEcho) | 
| wavenumber | 2:73a028278c5c | 1283 | { | 
| wavenumber | 2:73a028278c5c | 1284 | PC.putc(NextCharIn); | 
| wavenumber | 2:73a028278c5c | 1285 | } | 
| emh203 | 0:7798270c1f52 | 1286 | } | 
| emh203 | 0:7798270c1f52 | 1287 | break; | 
| emh203 | 0:7798270c1f52 | 1288 | |
| emh203 | 0:7798270c1f52 | 1289 | default: | 
| emh203 | 0:7798270c1f52 | 1290 | |
| emh203 | 0:7798270c1f52 | 1291 | if(TerminalPos == 0 && NextCharIn == 0x020) | 
| emh203 | 0:7798270c1f52 | 1292 | { | 
| emh203 | 0:7798270c1f52 | 1293 | //Do nothing if space bar is pressed at beginning of line | 
| emh203 | 0:7798270c1f52 | 1294 | } | 
| emh203 | 0:7798270c1f52 | 1295 | else if(NextCharIn >= 0x20 && NextCharIn<0x7F) | 
| emh203 | 0:7798270c1f52 | 1296 | { | 
| emh203 | 0:7798270c1f52 | 1297 | |
| emh203 | 0:7798270c1f52 | 1298 | if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1) | 
| emh203 | 0:7798270c1f52 | 1299 | { | 
| emh203 | 0:7798270c1f52 | 1300 | TerminalLineBuf[TerminalPos++] = NextCharIn; | 
| wavenumber | 2:73a028278c5c | 1301 | if(TerminalEcho) | 
| wavenumber | 2:73a028278c5c | 1302 | { | 
| wavenumber | 2:73a028278c5c | 1303 | PC.putc(NextCharIn); | 
| wavenumber | 2:73a028278c5c | 1304 | } | 
| emh203 | 0:7798270c1f52 | 1305 | } | 
| emh203 | 0:7798270c1f52 | 1306 | } | 
| emh203 | 0:7798270c1f52 | 1307 | |
| emh203 | 0:7798270c1f52 | 1308 | break; | 
| emh203 | 0:7798270c1f52 | 1309 | |
| emh203 | 0:7798270c1f52 | 1310 | } | 
| emh203 | 0:7798270c1f52 | 1311 | } | 
| emh203 | 0:7798270c1f52 | 1312 | |
| emh203 | 0:7798270c1f52 | 1313 | } | 
| emh203 | 0:7798270c1f52 | 1314 | |
| emh203 | 0:7798270c1f52 | 1315 | |
| emh203 | 0:7798270c1f52 | 1316 | |
| emh203 | 0:7798270c1f52 | 1317 | 
