Example project for the Rioux Chem control box

Dependencies:   mbed MODSERIAL

Dependents:   screentest

Rioux Chem Control Box

/media/uploads/emh203/ccb.jpg

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

Committer:
wavenumber
Date:
Thu Aug 05 02:16:11 2021 +0000
Revision:
4:e3eda81c97ae
Parent:
3:cb48919cd5e8
Child:
5:b56a4592aac0
Change the 4 to 20mA computation to use 240 resistor that is on Rev B.  We may need to investigated if this still needs to be the old value of 82

Who changed what in which revision?

UserRevisionLine numberNew 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 3:cb48919cd5e8 137
emh203 0:7798270c1f52 138 }
emh203 0:7798270c1f52 139
emh203 0:7798270c1f52 140
emh203 0:7798270c1f52 141 void SetFanSpeed(uint8_t S)
emh203 0:7798270c1f52 142 {
emh203 0:7798270c1f52 143 if(S>100)
emh203 0:7798270c1f52 144 S = 100;
emh203 0:7798270c1f52 145
emh203 0:7798270c1f52 146 FAN_CONTROL = (float)(S)/100.0;
emh203 0:7798270c1f52 147
emh203 0:7798270c1f52 148 }
emh203 0:7798270c1f52 149
emh203 0:7798270c1f52 150 void EnableFan()
emh203 0:7798270c1f52 151 {
emh203 0:7798270c1f52 152 SetFanSpeed(100);
emh203 0:7798270c1f52 153 }
emh203 0:7798270c1f52 154
emh203 0:7798270c1f52 155 void DisableFan()
emh203 0:7798270c1f52 156 {
emh203 0:7798270c1f52 157 SetFanSpeed(0);
emh203 0:7798270c1f52 158 }
emh203 0:7798270c1f52 159
emh203 0:7798270c1f52 160 void BuzzOff()
emh203 0:7798270c1f52 161 {
emh203 0:7798270c1f52 162 BUZZER_CONTROL = 0;
emh203 0:7798270c1f52 163 }
emh203 0:7798270c1f52 164
emh203 0:7798270c1f52 165 void Buzz(float Time)
emh203 0:7798270c1f52 166 {
emh203 0:7798270c1f52 167 BUZZER_CONTROL = 0.5;
emh203 0:7798270c1f52 168 BuzzTimeout.attach(&BuzzOff, Time);
emh203 0:7798270c1f52 169
emh203 0:7798270c1f52 170 }
emh203 0:7798270c1f52 171
emh203 0:7798270c1f52 172
emh203 0:7798270c1f52 173 void EnableHeater(uint8_t RelayIndex)
emh203 0:7798270c1f52 174 {
emh203 0:7798270c1f52 175 HeaterBits |= (1<<RelayIndex);
emh203 0:7798270c1f52 176 }
emh203 0:7798270c1f52 177
emh203 0:7798270c1f52 178 void DisableHeater(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 EnableSolenoidValve(uint8_t SolenoidIndex)
emh203 0:7798270c1f52 184 {
emh203 0:7798270c1f52 185 SolenoidBits |= (1<<SolenoidIndex);
emh203 0:7798270c1f52 186 }
emh203 0:7798270c1f52 187
emh203 0:7798270c1f52 188 void DisableSolenoidValue(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 DisableAllHeatersAndSolenoids()
emh203 0:7798270c1f52 194 {
emh203 0:7798270c1f52 195
emh203 0:7798270c1f52 196 SolenoidBits = 0;
emh203 0:7798270c1f52 197 HeaterBits = 0;
emh203 0:7798270c1f52 198
emh203 0:7798270c1f52 199 MCU_SR_CLEAR = 1;
emh203 0:7798270c1f52 200
emh203 0:7798270c1f52 201 MCU_SR_CLEAR = 0;
emh203 0:7798270c1f52 202
emh203 0:7798270c1f52 203 MCU_SR_CLEAR = 1;
emh203 0:7798270c1f52 204
emh203 0:7798270c1f52 205 MCU_SR_LOAD = 1;
emh203 0:7798270c1f52 206
emh203 0:7798270c1f52 207 MCU_SR_LOAD = 0;
emh203 0:7798270c1f52 208 }
emh203 0:7798270c1f52 209
emh203 0:7798270c1f52 210 void EnableMiscDigitalOutput(uint8_t DigitalOutIndex)
emh203 0:7798270c1f52 211 {
emh203 0:7798270c1f52 212 DigitalOutputBits |= (1<<DigitalOutIndex);
emh203 0:7798270c1f52 213 }
emh203 0:7798270c1f52 214
emh203 0:7798270c1f52 215 void DisableMiscDigitalOutput(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 FlushDigitalIO()
emh203 0:7798270c1f52 221 {
emh203 0:7798270c1f52 222 SPI1.format(8,0);
emh203 0:7798270c1f52 223
emh203 0:7798270c1f52 224 SPI1.write((SolenoidBits >> 8) & 0xFF);
emh203 0:7798270c1f52 225 SPI1.write(SolenoidBits & 0xFF);
emh203 0:7798270c1f52 226 SPI1.write(HeaterBits & 0xFF);
emh203 0:7798270c1f52 227 SPI1.write(DigitalOutputBits & 0xFF);
emh203 0:7798270c1f52 228
emh203 0:7798270c1f52 229 MCU_SR_LOAD = 1;
emh203 0:7798270c1f52 230 MCU_SR_LOAD = 0;
emh203 0:7798270c1f52 231 }
emh203 0:7798270c1f52 232
wavenumber 2:73a028278c5c 233 //Make sure to call ReadThermocouple before you call this so internal variables are updated
emh203 0:7798270c1f52 234 uint16_t ReadThermocouple_OC()
emh203 0:7798270c1f52 235 {
emh203 0:7798270c1f52 236 return Thermocouple_OC;
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_SCG()
emh203 0:7798270c1f52 240 {
emh203 0:7798270c1f52 241 return Thermocouple_SCG;
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_SCV()
emh203 0:7798270c1f52 245 {
emh203 0:7798270c1f52 246 return Thermocouple_SCV;
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_FAULT()
emh203 0:7798270c1f52 250 {
emh203 0:7798270c1f52 251 return Thermocouple_FAULT;
emh203 0:7798270c1f52 252 }
emh203 0:7798270c1f52 253
emh203 0:7798270c1f52 254
emh203 0:7798270c1f52 255 float ReadInternalTemperature(uint8_t ThermocoupleIndex)
emh203 0:7798270c1f52 256 {
emh203 0:7798270c1f52 257 ReadThermocouple(ThermocoupleIndex); //this will yank out the Data
emh203 0:7798270c1f52 258 return InternalTemperature[ThermocoupleIndex];
emh203 0:7798270c1f52 259 }
emh203 0:7798270c1f52 260
emh203 0:7798270c1f52 261
emh203 0:7798270c1f52 262
emh203 0:7798270c1f52 263 float ReadThermocouple(uint8_t ThermocoupleIndex)
emh203 0:7798270c1f52 264 {
emh203 0:7798270c1f52 265 uint8_t i=0;
emh203 0:7798270c1f52 266 uint32_t ThermocoupleData = 0;
emh203 0:7798270c1f52 267 uint8_t TempData[4];
emh203 0:7798270c1f52 268
emh203 0:7798270c1f52 269 int16_t InternalTemp = 0;
emh203 0:7798270c1f52 270 int16_t ThermocoupleTemp = 0;
emh203 0:7798270c1f52 271
emh203 0:7798270c1f52 272 //reset SPi format
emh203 0:7798270c1f52 273 SPI1.format(8,0);
emh203 0:7798270c1f52 274
emh203 0:7798270c1f52 275 TEMP_SENSE_ADDRESS = ThermocoupleIndex & 0x1f;
emh203 0:7798270c1f52 276
emh203 0:7798270c1f52 277 TEMP_SENSE_CS = 0;
emh203 0:7798270c1f52 278
emh203 0:7798270c1f52 279 for(i=0;i<4;i++)
emh203 0:7798270c1f52 280 TempData[i] = SPI1.write(0);
emh203 0:7798270c1f52 281
emh203 0:7798270c1f52 282 TEMP_SENSE_CS = 1;
emh203 0:7798270c1f52 283
emh203 0:7798270c1f52 284
emh203 0:7798270c1f52 285 ThermocoupleData = (uint32_t)(TempData[3]) |
emh203 0:7798270c1f52 286 (((uint32_t)(TempData[2]))<<8) |
emh203 0:7798270c1f52 287 (((uint32_t)(TempData[1]))<<16) |
emh203 0:7798270c1f52 288 (((uint32_t)(TempData[0]))<<24);
emh203 0:7798270c1f52 289
emh203 0:7798270c1f52 290
emh203 0:7798270c1f52 291 if(ThermocoupleData & 0x01)
emh203 0:7798270c1f52 292 Thermocouple_OC |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 293 else
emh203 0:7798270c1f52 294 Thermocouple_OC &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 295
emh203 0:7798270c1f52 296 if(ThermocoupleData & 0x02)
emh203 0:7798270c1f52 297 Thermocouple_SCG |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 298 else
emh203 0:7798270c1f52 299 Thermocouple_SCG &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 300
emh203 0:7798270c1f52 301 if(ThermocoupleData & 0x04)
emh203 0:7798270c1f52 302 Thermocouple_SCV |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 303 else
emh203 0:7798270c1f52 304 Thermocouple_SCV &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 305
emh203 0:7798270c1f52 306 if(ThermocoupleData & (1<<16))
emh203 0:7798270c1f52 307 Thermocouple_FAULT |= (1<<ThermocoupleIndex);
emh203 0:7798270c1f52 308 else
emh203 0:7798270c1f52 309 Thermocouple_FAULT &= ~(1<<ThermocoupleIndex);
emh203 0:7798270c1f52 310
emh203 0:7798270c1f52 311 if(ThermocoupleData & (1<<15))
emh203 0:7798270c1f52 312 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 313 else
emh203 0:7798270c1f52 314 InternalTemp = (int16_t)( ( (ThermocoupleData>>4) & 0xFFF));
emh203 0:7798270c1f52 315
emh203 0:7798270c1f52 316
emh203 0:7798270c1f52 317 if(ThermocoupleData & (0x10000000))
emh203 0:7798270c1f52 318 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 319 else
emh203 0:7798270c1f52 320 ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF));
emh203 0:7798270c1f52 321
emh203 0:7798270c1f52 322 Temperature[ThermocoupleIndex] = (float)ThermocoupleTemp/4.0;
emh203 0:7798270c1f52 323
emh203 0:7798270c1f52 324 InternalTemperature[ThermocoupleIndex] = (float)InternalTemp/16.0;;
emh203 0:7798270c1f52 325
emh203 0:7798270c1f52 326 return Temperature[ThermocoupleIndex];
emh203 0:7798270c1f52 327 }
emh203 0:7798270c1f52 328
emh203 0:7798270c1f52 329 float ReadMFC_AnalogInput(uint8_t Channel)
emh203 0:7798270c1f52 330 {
emh203 0:7798270c1f52 331 if(Channel > 7)
emh203 0:7798270c1f52 332 Channel = 7;
emh203 0:7798270c1f52 333
emh203 0:7798270c1f52 334 return ((float)(ReadRawADC(Channel)) /4095.0) * 5.0;
emh203 0:7798270c1f52 335
emh203 0:7798270c1f52 336 }
emh203 0:7798270c1f52 337
emh203 0:7798270c1f52 338 void EnableMFC_Power()
emh203 0:7798270c1f52 339 {
emh203 0:7798270c1f52 340 MFC_POWER_CONTROL = 1;
emh203 0:7798270c1f52 341 }
emh203 0:7798270c1f52 342
emh203 0:7798270c1f52 343 void DisableMFC_Power()
emh203 0:7798270c1f52 344 {
emh203 0:7798270c1f52 345 MFC_POWER_CONTROL = 0;
emh203 0:7798270c1f52 346 }
emh203 0:7798270c1f52 347
emh203 0:7798270c1f52 348
emh203 0:7798270c1f52 349 float ReadMISC_AnalogInput(uint8_t Channel)
emh203 0:7798270c1f52 350 {
emh203 0:7798270c1f52 351
emh203 0:7798270c1f52 352 if(Channel > 3)
emh203 0:7798270c1f52 353 Channel = 3;
emh203 0:7798270c1f52 354
emh203 0:7798270c1f52 355 return ((float)(ReadRawADC(Channel + 9)) /4095.0) * 5.0;
emh203 0:7798270c1f52 356
emh203 0:7798270c1f52 357 }
emh203 0:7798270c1f52 358
wavenumber 3:cb48919cd5e8 359
wavenumber 3:cb48919cd5e8 360
emh203 0:7798270c1f52 361 float Read4to20(uint8_t Channel)
emh203 0:7798270c1f52 362 {
emh203 0:7798270c1f52 363
emh203 0:7798270c1f52 364 if(Channel > 1)
emh203 0:7798270c1f52 365 Channel = 1;
emh203 0:7798270c1f52 366
wavenumber 4:e3eda81c97ae 367 return (((float)(ReadRawADC(Channel + 7)) /4095.0) * 5.0) / 240;
emh203 0:7798270c1f52 368
emh203 0:7798270c1f52 369 }
emh203 0:7798270c1f52 370
emh203 0:7798270c1f52 371
wavenumber 3:cb48919cd5e8 372 float ReadBP_AnalogInput()
wavenumber 3:cb48919cd5e8 373 {
wavenumber 3:cb48919cd5e8 374
wavenumber 3:cb48919cd5e8 375 return ((float)(ReadRawADC(15)) /4095.0) * 10.0;
wavenumber 3:cb48919cd5e8 376
wavenumber 3:cb48919cd5e8 377 }
wavenumber 3:cb48919cd5e8 378
wavenumber 3:cb48919cd5e8 379
wavenumber 3:cb48919cd5e8 380
wavenumber 3:cb48919cd5e8 381
wavenumber 3:cb48919cd5e8 382 static uint16_t ReadRawADC_Single(uint8_t Channel)
emh203 0:7798270c1f52 383 {
emh203 0:7798270c1f52 384 uint8_t ControlByte[3];
emh203 0:7798270c1f52 385 uint8_t ADC_Data[3];
emh203 0:7798270c1f52 386 uint16_t V;
emh203 0:7798270c1f52 387
emh203 0:7798270c1f52 388 SPI0.format(8,0); //The ADC requires mode 0,0
emh203 0:7798270c1f52 389
emh203 0:7798270c1f52 390 /*See Microchip manual DS21298E-page 21*/
emh203 0:7798270c1f52 391
emh203 0:7798270c1f52 392 ControlByte[0] = (((Channel&0x07)>>2) & 0x01) | (3<<1);
emh203 0:7798270c1f52 393 ControlByte[1] = Channel<<6;
emh203 0:7798270c1f52 394 ControlByte[2] = 0;
emh203 0:7798270c1f52 395
emh203 0:7798270c1f52 396
emh203 0:7798270c1f52 397 if(Channel<8)
emh203 0:7798270c1f52 398 AIO_ADC1_CS = 0;
emh203 0:7798270c1f52 399 else
emh203 0:7798270c1f52 400 AIO_ADC2_CS = 0;
emh203 0:7798270c1f52 401
emh203 0:7798270c1f52 402 //unroll the loop
emh203 0:7798270c1f52 403 ADC_Data[0] = SPI0.write(ControlByte[0]);
emh203 0:7798270c1f52 404 ADC_Data[1] = SPI0.write(ControlByte[1]);
emh203 0:7798270c1f52 405 ADC_Data[2] = SPI0.write(ControlByte[2]);
emh203 0:7798270c1f52 406
emh203 0:7798270c1f52 407 AIO_ADC1_CS = 1;
emh203 0:7798270c1f52 408 AIO_ADC2_CS = 1;
emh203 0:7798270c1f52 409
emh203 0:7798270c1f52 410
emh203 0:7798270c1f52 411 V = ((uint16_t)(ADC_Data[1])<<8 | (uint16_t)(ADC_Data[2])) & 0xFFF;
emh203 0:7798270c1f52 412
emh203 0:7798270c1f52 413 return (V);
emh203 0:7798270c1f52 414
emh203 0:7798270c1f52 415 }
emh203 0:7798270c1f52 416
wavenumber 3:cb48919cd5e8 417 #define FILTER_SIZE 64
wavenumber 3:cb48919cd5e8 418
wavenumber 3:cb48919cd5e8 419 static uint16_t ReadRawADC(uint8_t Channel)
wavenumber 3:cb48919cd5e8 420 {
wavenumber 3:cb48919cd5e8 421 uint32_t Value = 0;
wavenumber 3:cb48919cd5e8 422
wavenumber 3:cb48919cd5e8 423 for(int i=0;i<FILTER_SIZE;i++)
wavenumber 3:cb48919cd5e8 424 {
wavenumber 3:cb48919cd5e8 425 Value+=ReadRawADC_Single(Channel);
wavenumber 3:cb48919cd5e8 426 }
wavenumber 3:cb48919cd5e8 427
wavenumber 3:cb48919cd5e8 428 Value = Value / FILTER_SIZE;
wavenumber 3:cb48919cd5e8 429
wavenumber 3:cb48919cd5e8 430 return Value;
wavenumber 3:cb48919cd5e8 431
wavenumber 3:cb48919cd5e8 432 }
emh203 0:7798270c1f52 433
emh203 0:7798270c1f52 434 void WriteMFC_AnalogOut(uint8_t Channel,float Value)
emh203 0:7798270c1f52 435 {
emh203 0:7798270c1f52 436
emh203 0:7798270c1f52 437 if(Channel>7)
emh203 0:7798270c1f52 438 Channel = 7;
emh203 0:7798270c1f52 439
emh203 0:7798270c1f52 440 if(Value >5.0)
emh203 0:7798270c1f52 441 Value = 5.0;
emh203 0:7798270c1f52 442
emh203 0:7798270c1f52 443 if(Value<0.0)
emh203 0:7798270c1f52 444 Value = 0.0;
emh203 0:7798270c1f52 445
emh203 0:7798270c1f52 446 WriteRAW_DAC_Value(Channel,(uint16_t)((Value/5.0) * 4095));
emh203 0:7798270c1f52 447
emh203 0:7798270c1f52 448 }
emh203 0:7798270c1f52 449
emh203 0:7798270c1f52 450 void WriteMISC_AnalogOut(uint8_t Channel,float Value)
emh203 0:7798270c1f52 451 {
emh203 0:7798270c1f52 452 if(Channel>3)
emh203 0:7798270c1f52 453 Channel = 3;
emh203 0:7798270c1f52 454
emh203 0:7798270c1f52 455 if(Value >5.0)
emh203 0:7798270c1f52 456 Value = 5.0;
emh203 0:7798270c1f52 457
emh203 0:7798270c1f52 458 if(Value<0.0)
emh203 0:7798270c1f52 459 Value = 0.0;
emh203 0:7798270c1f52 460
emh203 0:7798270c1f52 461 WriteRAW_DAC_Value(8+Channel,(uint16_t)((Value/5.0)*4095));
emh203 0:7798270c1f52 462 }
emh203 0:7798270c1f52 463
wavenumber 3:cb48919cd5e8 464 void WriteBP_AnalogOut(float Value)
wavenumber 3:cb48919cd5e8 465 {
wavenumber 3:cb48919cd5e8 466
wavenumber 3:cb48919cd5e8 467 if(Value >10.0)
wavenumber 3:cb48919cd5e8 468 Value = 10.0;
wavenumber 3:cb48919cd5e8 469
wavenumber 3:cb48919cd5e8 470 if(Value<0.0)
wavenumber 3:cb48919cd5e8 471 Value = 0.0;
wavenumber 3:cb48919cd5e8 472
wavenumber 3:cb48919cd5e8 473 WriteRAW_DAC_Value(12,(uint16_t)((Value/10.0)*4095));
wavenumber 3:cb48919cd5e8 474 }
wavenumber 3:cb48919cd5e8 475
emh203 0:7798270c1f52 476
emh203 0:7798270c1f52 477 void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data)
emh203 0:7798270c1f52 478 {
emh203 0:7798270c1f52 479
emh203 0:7798270c1f52 480 uint16_t DataOut;
emh203 0:7798270c1f52 481
emh203 0:7798270c1f52 482 if(Channel<8)
emh203 0:7798270c1f52 483 AIO_DAC1_CS = 0;
emh203 0:7798270c1f52 484 else
wavenumber 3:cb48919cd5e8 485 {
emh203 0:7798270c1f52 486 AIO_DAC2_CS = 0;
wavenumber 3:cb48919cd5e8 487 Channel -= 8;
wavenumber 3:cb48919cd5e8 488 }
emh203 0:7798270c1f52 489
emh203 0:7798270c1f52 490 SPI0.format(8,1); //The DAC requires mode 0,1
emh203 0:7798270c1f52 491
emh203 0:7798270c1f52 492 DataOut = ((uint16_t)(Channel) & 0x7)<<12 | (Data & 0xFFF);
emh203 0:7798270c1f52 493
emh203 0:7798270c1f52 494 SPI0.write((DataOut>>8)&0xFF);
emh203 0:7798270c1f52 495 SPI0.write(DataOut&0xFF);
emh203 0:7798270c1f52 496
emh203 0:7798270c1f52 497 AIO_DAC1_CS = 1;
emh203 0:7798270c1f52 498 AIO_DAC2_CS = 1;
emh203 0:7798270c1f52 499
emh203 0:7798270c1f52 500 }
emh203 0:7798270c1f52 501
emh203 0:7798270c1f52 502
emh203 0:7798270c1f52 503
emh203 0:7798270c1f52 504
emh203 0:7798270c1f52 505 #define MAX_TERMINAL_LINE_CHARS 128
emh203 0:7798270c1f52 506 #define MAX_TERMINAL_CMD_CHARS 64
emh203 0:7798270c1f52 507
emh203 0:7798270c1f52 508 #ifndef TRUE
emh203 0:7798270c1f52 509 #define TRUE 1
emh203 0:7798270c1f52 510 #endif
emh203 0:7798270c1f52 511
emh203 0:7798270c1f52 512 #ifndef FALSE
emh203 0:7798270c1f52 513 #define FALSE 0
emh203 0:7798270c1f52 514 #endif
emh203 0:7798270c1f52 515
emh203 0:7798270c1f52 516 typedef void (*TerminalCallback)(char *);
emh203 0:7798270c1f52 517
emh203 0:7798270c1f52 518
emh203 0:7798270c1f52 519 typedef struct
emh203 0:7798270c1f52 520 {
emh203 0:7798270c1f52 521 const char *CommandString;
emh203 0:7798270c1f52 522 TerminalCallback Callback;
emh203 0:7798270c1f52 523 const char *HelpString;
emh203 0:7798270c1f52 524
emh203 0:7798270c1f52 525 } TerminalCallbackRecord;
emh203 0:7798270c1f52 526
emh203 0:7798270c1f52 527 //Callback function prototypes
emh203 0:7798270c1f52 528 void TerminalCmd_Help(char *arg);
emh203 0:7798270c1f52 529 void TerminalCmd_Stub(char *arg);
emh203 0:7798270c1f52 530 void TerminalCmd_EnableHeater(char *arg);
emh203 0:7798270c1f52 531 void TerminalCmd_DisableHeater(char *arg);
emh203 0:7798270c1f52 532 void TerminalCmd_EnableSolenoidValve(char *arg);
emh203 0:7798270c1f52 533 void TerminalCmd_DisableSolenoidValue(char *arg);
emh203 0:7798270c1f52 534 void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg);
emh203 0:7798270c1f52 535 void TerminalCmd_EnableMiscDigitalOutput(char *arg);
emh203 0:7798270c1f52 536 void TerminalCmd_DisableMiscDigitalOutput(char *arg);
emh203 0:7798270c1f52 537 void TerminalCmd_FlushDigitalIO(char *arg);
emh203 0:7798270c1f52 538 void TerminalCmd_FanOn(char *arg);
emh203 0:7798270c1f52 539 void TerminalCmd_FanOff(char *arg);
emh203 0:7798270c1f52 540 void TerminalCmd_Buzz(char *arg);
emh203 0:7798270c1f52 541 void TerminalCmd_T(char *arg);
emh203 0:7798270c1f52 542 void TerminalCmd_MFCI(char *arg);
emh203 0:7798270c1f52 543 void TerminalCmd_MFCO(char *arg);
emh203 0:7798270c1f52 544 void TerminalCmd_4TO20(char *arg);
emh203 0:7798270c1f52 545 void TerminalCmd_AIN(char *arg);
emh203 0:7798270c1f52 546 void TerminalCmd_MFCON(char *arg);
emh203 0:7798270c1f52 547 void TerminalCmd_MFCOFF(char *arg);
emh203 0:7798270c1f52 548 void TerminalCmd_AOUT(char *arg);
emh203 0:7798270c1f52 549 void TerminalCmd_Reset(char *arg);
wavenumber 2:73a028278c5c 550 void TerminalCmd_ECHO_OFF(char *arg);
wavenumber 3:cb48919cd5e8 551 void TerminalCmd_BPOUT(char *arg);
wavenumber 3:cb48919cd5e8 552 void TerminalCmd_BPIN(char *arg);
emh203 0:7798270c1f52 553
emh203 0:7798270c1f52 554 //Populate this array with the callback functions and their terminal command string
emh203 0:7798270c1f52 555 TerminalCallbackRecord MyTerminalCallbackRecords[] ={ {"reset",TerminalCmd_Reset,"Resets the CHEM box"},
emh203 0:7798270c1f52 556
emh203 0:7798270c1f52 557 {"help",TerminalCmd_Help,"Lists available commands"},
emh203 0:7798270c1f52 558
emh203 0:7798270c1f52 559 {"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 560
emh203 0:7798270c1f52 561 {"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 562
emh203 0:7798270c1f52 563 {"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 564
emh203 0:7798270c1f52 565 {"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 566
emh203 0:7798270c1f52 567 {"DAHAS",TerminalCmd_DisableAllHeatersAndSolenoids,"Disables all heaters and solenoids. Command is immediately executed."},
emh203 0:7798270c1f52 568
emh203 0:7798270c1f52 569 {"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 570
emh203 0:7798270c1f52 571 {"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 572
emh203 0:7798270c1f52 573 {"FDIO",TerminalCmd_FlushDigitalIO,"Updates the all of the digital IO channels"},
emh203 0:7798270c1f52 574
emh203 0:7798270c1f52 575 {"FON",TerminalCmd_FanOn,"Turns on the fans"},
emh203 0:7798270c1f52 576
emh203 0:7798270c1f52 577 {"FOFF",TerminalCmd_FanOff,"Turns off the fans"},
emh203 0:7798270c1f52 578
emh203 0:7798270c1f52 579 {"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 580
emh203 0:7798270c1f52 581 {"T",TerminalCmd_T,"Read thermocouple channel"},
emh203 0:7798270c1f52 582
emh203 0:7798270c1f52 583 {"MFCI",TerminalCmd_MFCI,"Reads in voltage from MFC channel"},
emh203 0:7798270c1f52 584
emh203 0:7798270c1f52 585 {"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 586
emh203 0:7798270c1f52 587 {"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 588
emh203 0:7798270c1f52 589 {"4TO20",TerminalCmd_4TO20,"Reads a 4 to 20 mA channel"},
emh203 0:7798270c1f52 590
emh203 0:7798270c1f52 591 {"AIN",TerminalCmd_AIN,"Reads a general purpose analog in channel"},
emh203 0:7798270c1f52 592
emh203 0:7798270c1f52 593 {"MFCON",TerminalCmd_MFCON,"Turns on the MFC power"},
emh203 0:7798270c1f52 594
wavenumber 2:73a028278c5c 595 {"MFCOFF",TerminalCmd_MFCOFF,"Turns off the MFC power"},
wavenumber 2:73a028278c5c 596
wavenumber 3:cb48919cd5e8 597 {"BPOUT",TerminalCmd_BPOUT,"Sets a control voltage between 0 and 10 for the backpressure regulator. I.E. BPOUT 1.21"},
wavenumber 3:cb48919cd5e8 598
wavenumber 3:cb48919cd5e8 599 {"BPIN",TerminalCmd_BPIN,"Reads the Back pressure regulator feedback. I.E. BPIN "},
wavenumber 3:cb48919cd5e8 600
wavenumber 3:cb48919cd5e8 601
wavenumber 2:73a028278c5c 602 {"ECHO_OFF",TerminalCmd_ECHO_OFF,"Disables echoing of characters"}
emh203 0:7798270c1f52 603 };
emh203 0:7798270c1f52 604
emh203 0:7798270c1f52 605
emh203 0:7798270c1f52 606 extern "C" void mbed_reset();
emh203 0:7798270c1f52 607
emh203 0:7798270c1f52 608 void TerminalCmd_Reset(char *arg)
emh203 0:7798270c1f52 609 {
emh203 0:7798270c1f52 610 mbed_reset();
emh203 0:7798270c1f52 611 }
emh203 0:7798270c1f52 612
wavenumber 2:73a028278c5c 613
wavenumber 2:73a028278c5c 614
emh203 0:7798270c1f52 615 void TerminalCmd_Stub(char *arg)
emh203 0:7798270c1f52 616 {
emh203 0:7798270c1f52 617 PC.printf("stub \r\n");
emh203 0:7798270c1f52 618 }
emh203 0:7798270c1f52 619
wavenumber 2:73a028278c5c 620 void TerminalCmd_ECHO_OFF(char *arg)
wavenumber 2:73a028278c5c 621 {
wavenumber 2:73a028278c5c 622 TerminalEcho = 0;
wavenumber 2:73a028278c5c 623 }
wavenumber 2:73a028278c5c 624
emh203 0:7798270c1f52 625 void TerminalCmd_MFCI(char *arg)
emh203 0:7798270c1f52 626 {
emh203 0:7798270c1f52 627 int Channel = -1;
emh203 0:7798270c1f52 628 float Data;
emh203 0:7798270c1f52 629
emh203 0:7798270c1f52 630 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 631 {
emh203 0:7798270c1f52 632 if(Channel>=0 && Channel <=6)
emh203 0:7798270c1f52 633 {
emh203 0:7798270c1f52 634 Data = ReadMFC_AnalogInput(Channel);
emh203 0:7798270c1f52 635 PC.printf("MFCI:%d:%.3f",Channel,Data);
emh203 0:7798270c1f52 636 }
emh203 0:7798270c1f52 637 else
emh203 0:7798270c1f52 638 {
emh203 0:7798270c1f52 639 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 6",Channel);
emh203 0:7798270c1f52 640 }
emh203 0:7798270c1f52 641 }
emh203 0:7798270c1f52 642 else
emh203 0:7798270c1f52 643 {
emh203 0:7798270c1f52 644 for(Channel = 0; Channel<=6; Channel++)
emh203 0:7798270c1f52 645 {
emh203 0:7798270c1f52 646 Data = ReadMFC_AnalogInput(Channel);
emh203 0:7798270c1f52 647 PC.printf("MFCI:%d:%.3f\r\n",Channel,Data);
emh203 0:7798270c1f52 648 }
emh203 0:7798270c1f52 649 }
emh203 0:7798270c1f52 650 }
emh203 0:7798270c1f52 651
emh203 0:7798270c1f52 652 void TerminalCmd_MFCON(char *arg)
emh203 0:7798270c1f52 653 {
emh203 0:7798270c1f52 654 EnableMFC_Power();
emh203 0:7798270c1f52 655 }
emh203 0:7798270c1f52 656
emh203 0:7798270c1f52 657
emh203 0:7798270c1f52 658 void TerminalCmd_MFCOFF(char *arg)
emh203 0:7798270c1f52 659 {
emh203 0:7798270c1f52 660 DisableMFC_Power();
emh203 0:7798270c1f52 661 }
emh203 0:7798270c1f52 662
emh203 0:7798270c1f52 663
emh203 0:7798270c1f52 664 void TerminalCmd_MFCO(char *arg)
emh203 0:7798270c1f52 665 {
emh203 0:7798270c1f52 666 int Channel = -1;
emh203 0:7798270c1f52 667 float Data = 0.0;
emh203 0:7798270c1f52 668
emh203 0:7798270c1f52 669 if(sscanf(arg,"%d %f",&Channel,&Data) == 2)
emh203 0:7798270c1f52 670 {
emh203 0:7798270c1f52 671 if(Channel>=0 && Channel <=7)
emh203 0:7798270c1f52 672 {
emh203 0:7798270c1f52 673 WriteMFC_AnalogOut(Channel,Data);
emh203 0:7798270c1f52 674 }
emh203 0:7798270c1f52 675 else
emh203 0:7798270c1f52 676 {
emh203 0:7798270c1f52 677 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel);
emh203 0:7798270c1f52 678 }
emh203 0:7798270c1f52 679 }
emh203 0:7798270c1f52 680 else
emh203 0:7798270c1f52 681 {
emh203 0:7798270c1f52 682 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 683 }
emh203 0:7798270c1f52 684 }
emh203 0:7798270c1f52 685
emh203 0:7798270c1f52 686 void TerminalCmd_AOUT(char *arg)
emh203 0:7798270c1f52 687 {
emh203 0:7798270c1f52 688 int Channel = -1;
emh203 0:7798270c1f52 689 float Data = 0.0;
emh203 0:7798270c1f52 690
emh203 0:7798270c1f52 691 if(sscanf(arg,"%d %f",&Channel,&Data) == 2)
emh203 0:7798270c1f52 692 {
emh203 0:7798270c1f52 693 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 694 {
emh203 0:7798270c1f52 695 WriteMISC_AnalogOut(Channel,Data);
emh203 0:7798270c1f52 696 }
emh203 0:7798270c1f52 697 else
emh203 0:7798270c1f52 698 {
emh203 0:7798270c1f52 699 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 700 }
emh203 0:7798270c1f52 701 }
emh203 0:7798270c1f52 702 else
emh203 0:7798270c1f52 703 {
emh203 0:7798270c1f52 704 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 705 }
emh203 0:7798270c1f52 706 }
emh203 0:7798270c1f52 707
wavenumber 3:cb48919cd5e8 708
wavenumber 3:cb48919cd5e8 709 void TerminalCmd_BPOUT(char *arg)
wavenumber 3:cb48919cd5e8 710 {
wavenumber 3:cb48919cd5e8 711 float Data = 0.0;
wavenumber 3:cb48919cd5e8 712
wavenumber 3:cb48919cd5e8 713 if(sscanf(arg,"%f",&Data) == 1)
wavenumber 3:cb48919cd5e8 714 {
wavenumber 3:cb48919cd5e8 715 WriteBP_AnalogOut(Data);
wavenumber 3:cb48919cd5e8 716 }
wavenumber 3:cb48919cd5e8 717 else
wavenumber 3:cb48919cd5e8 718 {
wavenumber 3:cb48919cd5e8 719 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 720 }
wavenumber 3:cb48919cd5e8 721 }
wavenumber 3:cb48919cd5e8 722
wavenumber 3:cb48919cd5e8 723 void TerminalCmd_BPIN(char *arg)
wavenumber 3:cb48919cd5e8 724 {
wavenumber 3:cb48919cd5e8 725 float Data;
wavenumber 3:cb48919cd5e8 726 Data = ReadBP_AnalogInput();
wavenumber 3:cb48919cd5e8 727 PC.printf("BPIN:%.3f",Data);
wavenumber 3:cb48919cd5e8 728 }
wavenumber 3:cb48919cd5e8 729
emh203 0:7798270c1f52 730 void TerminalCmd_4TO20(char *arg)
emh203 0:7798270c1f52 731 {
emh203 0:7798270c1f52 732 int Channel = -1;
emh203 0:7798270c1f52 733 float Data;
emh203 0:7798270c1f52 734
emh203 0:7798270c1f52 735 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 736 {
emh203 0:7798270c1f52 737 if(Channel>=0 && Channel <=1)
emh203 0:7798270c1f52 738 {
emh203 0:7798270c1f52 739 Data = Read4to20(Channel);
emh203 0:7798270c1f52 740 PC.printf("4TO20:%d:%.3f",Channel,Data);
emh203 0:7798270c1f52 741 }
emh203 0:7798270c1f52 742 else
emh203 0:7798270c1f52 743 {
emh203 0:7798270c1f52 744 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel);
emh203 0:7798270c1f52 745 }
emh203 0:7798270c1f52 746 }
emh203 0:7798270c1f52 747 else
emh203 0:7798270c1f52 748 {
emh203 0:7798270c1f52 749
emh203 0:7798270c1f52 750 for(Channel = 0;Channel<=1;Channel++)
emh203 0:7798270c1f52 751 {
emh203 0:7798270c1f52 752 Data = Read4to20(Channel);
emh203 1:d64ac853223c 753 PC.printf("4TO20:%d:%.5f\r\n",Channel,Data);
emh203 0:7798270c1f52 754 }
emh203 0:7798270c1f52 755
emh203 0:7798270c1f52 756 }
emh203 0:7798270c1f52 757
emh203 0:7798270c1f52 758
emh203 0:7798270c1f52 759 }
emh203 0:7798270c1f52 760
emh203 0:7798270c1f52 761 void TerminalCmd_AIN(char *arg)
emh203 0:7798270c1f52 762 {
emh203 0:7798270c1f52 763 int Channel = -1;
emh203 0:7798270c1f52 764 float Data;
emh203 0:7798270c1f52 765
emh203 0:7798270c1f52 766 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 767 {
emh203 0:7798270c1f52 768 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 769 {
emh203 0:7798270c1f52 770 Data = ReadMISC_AnalogInput(Channel);
emh203 0:7798270c1f52 771 PC.printf("AIN:%d:%.3f",Channel,Data);
emh203 0:7798270c1f52 772 }
emh203 0:7798270c1f52 773 else
emh203 0:7798270c1f52 774 {
emh203 0:7798270c1f52 775 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 776 }
emh203 0:7798270c1f52 777 }
emh203 0:7798270c1f52 778 else
emh203 0:7798270c1f52 779 {
emh203 0:7798270c1f52 780 for(Channel = 0;Channel<=3;Channel++)
emh203 0:7798270c1f52 781 {
emh203 0:7798270c1f52 782 Data = ReadMISC_AnalogInput(Channel);
emh203 0:7798270c1f52 783 PC.printf("AIN:%d:%.3f\r\n",Channel,Data);
emh203 0:7798270c1f52 784 }
emh203 0:7798270c1f52 785 }
emh203 0:7798270c1f52 786 }
emh203 0:7798270c1f52 787
emh203 0:7798270c1f52 788
emh203 0:7798270c1f52 789
emh203 0:7798270c1f52 790 void TerminalCmd_EnableHeater(char *arg)
emh203 0:7798270c1f52 791 {
emh203 0:7798270c1f52 792 int Channel = -1;
emh203 0:7798270c1f52 793
emh203 0:7798270c1f52 794 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 795 {
emh203 0:7798270c1f52 796 if(Channel>=0 && Channel <=7)
emh203 0:7798270c1f52 797 {
emh203 0:7798270c1f52 798 EnableHeater(Channel);
emh203 0:7798270c1f52 799 }
emh203 0:7798270c1f52 800 else
emh203 0:7798270c1f52 801 {
emh203 0:7798270c1f52 802 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel);
emh203 0:7798270c1f52 803 }
emh203 0:7798270c1f52 804 }
emh203 0:7798270c1f52 805 else
emh203 0:7798270c1f52 806 {
emh203 0:7798270c1f52 807 PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg);
emh203 0:7798270c1f52 808 }
emh203 0:7798270c1f52 809 }
emh203 0:7798270c1f52 810
emh203 0:7798270c1f52 811 void TerminalCmd_DisableHeater(char *arg)
emh203 0:7798270c1f52 812 {
emh203 0:7798270c1f52 813 int Channel = -1;
emh203 0:7798270c1f52 814
emh203 0:7798270c1f52 815 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 816 {
emh203 0:7798270c1f52 817 if(Channel>=0 && Channel <=7)
emh203 0:7798270c1f52 818 {
emh203 0:7798270c1f52 819 DisableHeater(Channel);
emh203 0:7798270c1f52 820 }
emh203 0:7798270c1f52 821 else
emh203 0:7798270c1f52 822 {
emh203 0:7798270c1f52 823 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel);
emh203 0:7798270c1f52 824 }
emh203 0:7798270c1f52 825 }
emh203 0:7798270c1f52 826 else
emh203 0:7798270c1f52 827 {
emh203 0:7798270c1f52 828 PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg);
emh203 0:7798270c1f52 829 }
emh203 0:7798270c1f52 830
emh203 0:7798270c1f52 831 }
emh203 0:7798270c1f52 832
emh203 0:7798270c1f52 833 void TerminalCmd_EnableSolenoidValve(char *arg)
emh203 0:7798270c1f52 834 {
emh203 0:7798270c1f52 835
emh203 0:7798270c1f52 836 int Channel = -1;
emh203 0:7798270c1f52 837
emh203 0:7798270c1f52 838 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 839 {
emh203 0:7798270c1f52 840 if(Channel>=0 && Channel <=11)
emh203 0:7798270c1f52 841 {
emh203 0:7798270c1f52 842 EnableSolenoidValve(Channel);
emh203 0:7798270c1f52 843 }
emh203 0:7798270c1f52 844 else
emh203 0:7798270c1f52 845 {
emh203 0:7798270c1f52 846 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel);
emh203 0:7798270c1f52 847 }
emh203 0:7798270c1f52 848 }
emh203 0:7798270c1f52 849 else
emh203 0:7798270c1f52 850 {
emh203 0:7798270c1f52 851 PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg);
emh203 0:7798270c1f52 852 }
emh203 0:7798270c1f52 853 }
emh203 0:7798270c1f52 854
emh203 0:7798270c1f52 855 void TerminalCmd_DisableSolenoidValue(char *arg)
emh203 0:7798270c1f52 856 {
emh203 0:7798270c1f52 857 int Channel = -1;
emh203 0:7798270c1f52 858
emh203 0:7798270c1f52 859 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 860 {
emh203 0:7798270c1f52 861 if( Channel >= 0 && Channel <= 11)
emh203 0:7798270c1f52 862 {
emh203 0:7798270c1f52 863 DisableSolenoidValue(Channel);
emh203 0:7798270c1f52 864 }
emh203 0:7798270c1f52 865 else
emh203 0:7798270c1f52 866 {
emh203 0:7798270c1f52 867 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel);
emh203 0:7798270c1f52 868 }
emh203 0:7798270c1f52 869 }
emh203 0:7798270c1f52 870 else
emh203 0:7798270c1f52 871 {
emh203 0:7798270c1f52 872 PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg);
emh203 0:7798270c1f52 873 }
emh203 0:7798270c1f52 874
emh203 0:7798270c1f52 875 }
emh203 0:7798270c1f52 876 void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg)
emh203 0:7798270c1f52 877 {
emh203 0:7798270c1f52 878
emh203 0:7798270c1f52 879 DisableAllHeatersAndSolenoids();
emh203 0:7798270c1f52 880
emh203 0:7798270c1f52 881 }
emh203 0:7798270c1f52 882
emh203 0:7798270c1f52 883 void TerminalCmd_EnableMiscDigitalOutput(char *arg)
emh203 0:7798270c1f52 884 {
emh203 0:7798270c1f52 885 int Channel = -1;
emh203 0:7798270c1f52 886
emh203 0:7798270c1f52 887 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 888 {
emh203 0:7798270c1f52 889 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 890 {
emh203 0:7798270c1f52 891 EnableMiscDigitalOutput(Channel);
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 PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg);
emh203 0:7798270c1f52 901 }
emh203 0:7798270c1f52 902
emh203 0:7798270c1f52 903 }
emh203 0:7798270c1f52 904
emh203 0:7798270c1f52 905 void TerminalCmd_DisableMiscDigitalOutput(char *arg)
emh203 0:7798270c1f52 906 {
emh203 0:7798270c1f52 907 int Channel = -1;
emh203 0:7798270c1f52 908
emh203 0:7798270c1f52 909 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 910 {
emh203 0:7798270c1f52 911 if(Channel>=0 && Channel <=3)
emh203 0:7798270c1f52 912 {
emh203 0:7798270c1f52 913 DisableMiscDigitalOutput(Channel);
emh203 0:7798270c1f52 914 }
emh203 0:7798270c1f52 915 else
emh203 0:7798270c1f52 916 {
emh203 0:7798270c1f52 917 PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel);
emh203 0:7798270c1f52 918 }
emh203 0:7798270c1f52 919 }
emh203 0:7798270c1f52 920 else
emh203 0:7798270c1f52 921 {
emh203 0:7798270c1f52 922 PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg);
emh203 0:7798270c1f52 923 }
emh203 0:7798270c1f52 924
emh203 0:7798270c1f52 925 }
emh203 0:7798270c1f52 926
emh203 0:7798270c1f52 927 void TerminalCmd_FlushDigitalIO(char *arg)
emh203 0:7798270c1f52 928 {
emh203 0:7798270c1f52 929 FlushDigitalIO();
emh203 0:7798270c1f52 930 }
emh203 0:7798270c1f52 931
emh203 0:7798270c1f52 932 void TerminalCmd_FanOn(char *arg)
emh203 0:7798270c1f52 933 {
emh203 0:7798270c1f52 934 SetFanSpeed(100); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off
wavenumber 2:73a028278c5c 935 MBED_LED1 = 1;
emh203 0:7798270c1f52 936 }
emh203 0:7798270c1f52 937
emh203 0:7798270c1f52 938 void TerminalCmd_FanOff(char *arg)
emh203 0:7798270c1f52 939 {
emh203 0:7798270c1f52 940 SetFanSpeed(0); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off
wavenumber 2:73a028278c5c 941 MBED_LED1 = 0;
emh203 0:7798270c1f52 942 }
emh203 0:7798270c1f52 943
emh203 0:7798270c1f52 944 void TerminalCmd_Fan(char *arg)
emh203 0:7798270c1f52 945 {
emh203 0:7798270c1f52 946 int Speed = -1;
emh203 0:7798270c1f52 947
emh203 0:7798270c1f52 948 if(sscanf(arg,"%d",&Speed) == 1)
emh203 0:7798270c1f52 949 {
emh203 0:7798270c1f52 950 if(Speed>=0 && Speed<=100)
emh203 0:7798270c1f52 951 {
emh203 0:7798270c1f52 952 SetFanSpeed(Speed);
emh203 0:7798270c1f52 953 }
emh203 0:7798270c1f52 954 else
emh203 0:7798270c1f52 955 {
emh203 0:7798270c1f52 956 PC.printf("%d is an invalid speed. Speed should be between 0 and 100",Speed);
emh203 0:7798270c1f52 957 }
emh203 0:7798270c1f52 958 }
emh203 0:7798270c1f52 959 else
emh203 0:7798270c1f52 960 {
emh203 0:7798270c1f52 961 PC.printf("Bad argument... %s. Should be integer between 0 and 100",arg);
emh203 0:7798270c1f52 962 }
emh203 0:7798270c1f52 963
emh203 0:7798270c1f52 964 }
emh203 0:7798270c1f52 965
emh203 0:7798270c1f52 966
emh203 0:7798270c1f52 967 void TerminalCmd_T(char *arg)
emh203 0:7798270c1f52 968 {
emh203 0:7798270c1f52 969 float Temp = 0;
emh203 0:7798270c1f52 970 int Channel = -1;
emh203 0:7798270c1f52 971
emh203 0:7798270c1f52 972 if(sscanf(arg,"%d",&Channel) == 1)
emh203 0:7798270c1f52 973 {
emh203 0:7798270c1f52 974 Temp = ReadThermocouple(Channel);
wavenumber 3:cb48919cd5e8 975 PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Thermocouple_OC);
emh203 0:7798270c1f52 976 }
emh203 0:7798270c1f52 977 else
emh203 0:7798270c1f52 978 {
emh203 0:7798270c1f52 979 for(Channel = 0; Channel<12;Channel++)
emh203 0:7798270c1f52 980 {
emh203 0:7798270c1f52 981 Temp = ReadThermocouple(Channel);
wavenumber 3:cb48919cd5e8 982 PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Thermocouple_OC);
emh203 0:7798270c1f52 983 }
emh203 0:7798270c1f52 984 }
emh203 0:7798270c1f52 985 }
emh203 0:7798270c1f52 986
emh203 0:7798270c1f52 987 void TerminalCmd_Buzz(char *arg)
emh203 0:7798270c1f52 988 {
emh203 0:7798270c1f52 989
emh203 0:7798270c1f52 990 float T = -1.0;
emh203 0:7798270c1f52 991
emh203 0:7798270c1f52 992 if(sscanf(arg,"%f",&T) == 1)
emh203 0:7798270c1f52 993 {
emh203 0:7798270c1f52 994 if(T>=0.0 && T<=5.0)
emh203 0:7798270c1f52 995 {
emh203 0:7798270c1f52 996 Buzz(T);
emh203 0:7798270c1f52 997 }
emh203 0:7798270c1f52 998 else
emh203 0:7798270c1f52 999 {
emh203 0:7798270c1f52 1000 PC.printf("%f is an invalid time period for buzz. Time should be between 0.0 and 5.0 seconds",T);
emh203 0:7798270c1f52 1001 }
emh203 0:7798270c1f52 1002 }
emh203 0:7798270c1f52 1003 else
emh203 0:7798270c1f52 1004 {
emh203 0:7798270c1f52 1005 PC.printf("Bad argument... %s. Should be float between 0.0 and 5.0",arg);
emh203 0:7798270c1f52 1006 }
emh203 0:7798270c1f52 1007
emh203 0:7798270c1f52 1008 }
emh203 0:7798270c1f52 1009
emh203 0:7798270c1f52 1010
emh203 0:7798270c1f52 1011
emh203 0:7798270c1f52 1012
emh203 0:7798270c1f52 1013 //*****************************************************************
emh203 0:7798270c1f52 1014 //Plumbing.....
emh203 0:7798270c1f52 1015 //*****************************************************************
emh203 0:7798270c1f52 1016
emh203 0:7798270c1f52 1017 #define NUM_TERMINAL_COMMANDS (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord))
emh203 0:7798270c1f52 1018
emh203 0:7798270c1f52 1019 char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS];
emh203 0:7798270c1f52 1020 uint8_t TerminalPos;
emh203 0:7798270c1f52 1021 char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1];
emh203 0:7798270c1f52 1022 char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS];
emh203 0:7798270c1f52 1023 uint8_t NextCharIn;
emh203 0:7798270c1f52 1024 uint8_t CmdFound;
emh203 0:7798270c1f52 1025
emh203 0:7798270c1f52 1026 void TerminalBootMsg()
emh203 0:7798270c1f52 1027 {
emh203 0:7798270c1f52 1028
emh203 0:7798270c1f52 1029 PC.printf("\r\n\r\n");
emh203 0:7798270c1f52 1030 PC.printf("***********************************\r\n");
emh203 0:7798270c1f52 1031 PC.printf("CHEM Control Box \r\n");
emh203 0:7798270c1f52 1032 PC.printf("API Version %s \r\n",API_VERSION);
emh203 0:7798270c1f52 1033 PC.printf("Copyright (C) <2013> Eli Hughes\r\n");
emh203 0:7798270c1f52 1034 PC.printf("Wavenumber LLC\r\n");
emh203 0:7798270c1f52 1035 PC.printf("***********************************\r\n\r\n>");
emh203 0:7798270c1f52 1036
emh203 0:7798270c1f52 1037 }
emh203 0:7798270c1f52 1038
emh203 0:7798270c1f52 1039 void InitTerminal()
emh203 0:7798270c1f52 1040 {
emh203 0:7798270c1f52 1041
emh203 0:7798270c1f52 1042 PC.baud(115200);
emh203 0:7798270c1f52 1043 TerminalPos = 0;
emh203 0:7798270c1f52 1044 CmdFound = 0;
emh203 0:7798270c1f52 1045 TerminalBootMsg();
emh203 0:7798270c1f52 1046 }
emh203 0:7798270c1f52 1047
emh203 0:7798270c1f52 1048 void TerminalCmd_Help(char *arg)
emh203 0:7798270c1f52 1049 {
emh203 0:7798270c1f52 1050 uint8_t i;
emh203 0:7798270c1f52 1051
emh203 0:7798270c1f52 1052 PC.printf("\r\n\r\nCommand List:\r\n");
emh203 0:7798270c1f52 1053 PC.printf("----------------------\r\n");
emh203 0:7798270c1f52 1054
emh203 0:7798270c1f52 1055 for(i=0;i<NUM_TERMINAL_COMMANDS;i++)
emh203 0:7798270c1f52 1056 {
emh203 0:7798270c1f52 1057 PC.printf("%s ----> %s\r\n\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString);
emh203 0:7798270c1f52 1058 }
emh203 0:7798270c1f52 1059
emh203 0:7798270c1f52 1060 PC.printf("\r\n\r\n");
emh203 0:7798270c1f52 1061 }
emh203 0:7798270c1f52 1062
emh203 0:7798270c1f52 1063 void TerminalCmd_Reboot(char *arg)
emh203 0:7798270c1f52 1064 {
emh203 0:7798270c1f52 1065 TerminalBootMsg();
emh203 0:7798270c1f52 1066 }
emh203 0:7798270c1f52 1067
emh203 0:7798270c1f52 1068 void ProcessTerminal()
emh203 0:7798270c1f52 1069 {
emh203 0:7798270c1f52 1070 uint8_t i,j;
emh203 0:7798270c1f52 1071 uint8_t ArgsFound;
emh203 0:7798270c1f52 1072
emh203 0:7798270c1f52 1073 if(PC.readable())
emh203 0:7798270c1f52 1074 {
emh203 0:7798270c1f52 1075 NextCharIn = PC.getc();
emh203 0:7798270c1f52 1076
emh203 0:7798270c1f52 1077 switch(NextCharIn)
emh203 0:7798270c1f52 1078 {
emh203 0:7798270c1f52 1079 case '\r':
emh203 0:7798270c1f52 1080
emh203 0:7798270c1f52 1081 TerminalLineBuf[TerminalPos++] = 0x0;
wavenumber 2:73a028278c5c 1082
wavenumber 2:73a028278c5c 1083 if(TerminalEcho)
wavenumber 2:73a028278c5c 1084 {
wavenumber 2:73a028278c5c 1085 PC.putc(NextCharIn);
wavenumber 2:73a028278c5c 1086 }
wavenumber 2:73a028278c5c 1087
emh203 0:7798270c1f52 1088 if(TerminalPos > 1)
emh203 0:7798270c1f52 1089 {
emh203 0:7798270c1f52 1090 //find the command
emh203 0:7798270c1f52 1091 i=0;
emh203 0:7798270c1f52 1092 while(TerminalLineBuf[i]>0x20 && TerminalLineBuf[i]<0x7f)
emh203 0:7798270c1f52 1093 {
emh203 0:7798270c1f52 1094 TerminalCmdBuf[i] = TerminalLineBuf[i];
emh203 0:7798270c1f52 1095 i++;
emh203 0:7798270c1f52 1096
emh203 0:7798270c1f52 1097 if(i==MAX_TERMINAL_CMD_CHARS)
emh203 0:7798270c1f52 1098 {
emh203 0:7798270c1f52 1099 break;
emh203 0:7798270c1f52 1100 }
emh203 0:7798270c1f52 1101 }
emh203 0:7798270c1f52 1102
emh203 0:7798270c1f52 1103 TerminalCmdBuf[i] = 0;
emh203 0:7798270c1f52 1104 TerminalCmdBuf[i+1] = 0;
emh203 0:7798270c1f52 1105
emh203 0:7798270c1f52 1106
emh203 0:7798270c1f52 1107 ArgsFound = TRUE;
emh203 0:7798270c1f52 1108 memset(TerminalArgs,0x00,sizeof(TerminalArgs));
emh203 0:7798270c1f52 1109 //scan for num terminator or next non whitespace
emh203 0:7798270c1f52 1110 while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS))
emh203 0:7798270c1f52 1111 {
emh203 0:7798270c1f52 1112 if(TerminalLineBuf[i] == 0x00)
emh203 0:7798270c1f52 1113 {
emh203 0:7798270c1f52 1114
emh203 0:7798270c1f52 1115 //if we find a NULL terminator before a non whitespace character they flag for no arguments
emh203 0:7798270c1f52 1116 ArgsFound = FALSE;
emh203 0:7798270c1f52 1117 break;
emh203 0:7798270c1f52 1118 }
emh203 0:7798270c1f52 1119 i++;
emh203 0:7798270c1f52 1120 }
emh203 0:7798270c1f52 1121
emh203 0:7798270c1f52 1122 if(ArgsFound == TRUE)
emh203 0:7798270c1f52 1123 {
emh203 0:7798270c1f52 1124 strcpy(TerminalArgs,&TerminalLineBuf[i]);
emh203 0:7798270c1f52 1125
emh203 0:7798270c1f52 1126 //trim trailing whitespace
emh203 0:7798270c1f52 1127 i = sizeof(TerminalArgs)-1;
emh203 0:7798270c1f52 1128
emh203 0:7798270c1f52 1129 while((TerminalArgs[i]<0x21) && (i>0))
emh203 0:7798270c1f52 1130 {
emh203 0:7798270c1f52 1131 TerminalArgs[i]= 0x00;
emh203 0:7798270c1f52 1132 i--;
emh203 0:7798270c1f52 1133 }
emh203 0:7798270c1f52 1134 }
emh203 0:7798270c1f52 1135
emh203 0:7798270c1f52 1136 CmdFound = FALSE;
emh203 0:7798270c1f52 1137 for(j=0;j<NUM_TERMINAL_COMMANDS;j++)
emh203 0:7798270c1f52 1138 {
emh203 0:7798270c1f52 1139 if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0)
emh203 0:7798270c1f52 1140 {
emh203 0:7798270c1f52 1141 PC.printf("\r\n");
emh203 0:7798270c1f52 1142 if(MyTerminalCallbackRecords[j].Callback != NULL)
emh203 0:7798270c1f52 1143 MyTerminalCallbackRecords[j].Callback(TerminalArgs);
emh203 0:7798270c1f52 1144
emh203 0:7798270c1f52 1145 CmdFound = TRUE;
emh203 0:7798270c1f52 1146 break;
emh203 0:7798270c1f52 1147 }
emh203 0:7798270c1f52 1148 }
emh203 0:7798270c1f52 1149 if(CmdFound == FALSE)
emh203 0:7798270c1f52 1150 {
emh203 0:7798270c1f52 1151 PC.printf("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf);
emh203 0:7798270c1f52 1152 TerminalCmd_Help("no arg");
emh203 0:7798270c1f52 1153
emh203 0:7798270c1f52 1154 }
emh203 0:7798270c1f52 1155 }
wavenumber 2:73a028278c5c 1156 PC.printf("\r\n");
emh203 0:7798270c1f52 1157 TerminalPos = 0;
emh203 0:7798270c1f52 1158
emh203 0:7798270c1f52 1159 break;
emh203 0:7798270c1f52 1160
emh203 0:7798270c1f52 1161 case '\b':
emh203 0:7798270c1f52 1162 if(TerminalPos > 0)
emh203 0:7798270c1f52 1163 {
wavenumber 2:73a028278c5c 1164 TerminalPos--;
wavenumber 2:73a028278c5c 1165 if(TerminalEcho)
wavenumber 2:73a028278c5c 1166 {
wavenumber 2:73a028278c5c 1167 PC.putc(NextCharIn);
wavenumber 2:73a028278c5c 1168 }
emh203 0:7798270c1f52 1169 }
emh203 0:7798270c1f52 1170 break;
emh203 0:7798270c1f52 1171
emh203 0:7798270c1f52 1172 default:
emh203 0:7798270c1f52 1173
emh203 0:7798270c1f52 1174 if(TerminalPos == 0 && NextCharIn == 0x020)
emh203 0:7798270c1f52 1175 {
emh203 0:7798270c1f52 1176 //Do nothing if space bar is pressed at beginning of line
emh203 0:7798270c1f52 1177 }
emh203 0:7798270c1f52 1178 else if(NextCharIn >= 0x20 && NextCharIn<0x7F)
emh203 0:7798270c1f52 1179 {
emh203 0:7798270c1f52 1180
emh203 0:7798270c1f52 1181 if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1)
emh203 0:7798270c1f52 1182 {
emh203 0:7798270c1f52 1183 TerminalLineBuf[TerminalPos++] = NextCharIn;
wavenumber 2:73a028278c5c 1184 if(TerminalEcho)
wavenumber 2:73a028278c5c 1185 {
wavenumber 2:73a028278c5c 1186 PC.putc(NextCharIn);
wavenumber 2:73a028278c5c 1187 }
emh203 0:7798270c1f52 1188 }
emh203 0:7798270c1f52 1189 }
emh203 0:7798270c1f52 1190
emh203 0:7798270c1f52 1191 break;
emh203 0:7798270c1f52 1192
emh203 0:7798270c1f52 1193 }
emh203 0:7798270c1f52 1194 }
emh203 0:7798270c1f52 1195
emh203 0:7798270c1f52 1196 }
emh203 0:7798270c1f52 1197
emh203 0:7798270c1f52 1198
emh203 0:7798270c1f52 1199
emh203 0:7798270c1f52 1200