Hideharu Tsunemoto
/
mbed_11U24_CapacitorDose_V001
LPC11U24USBSerial&ADCMeasure6Ch_Measure_Charge_Discharge
main.cpp@0:568f6e865655, 2019-11-26 (annotated)
- Committer:
- H_Tsunemoto
- Date:
- Tue Nov 26 00:10:16 2019 +0000
- Revision:
- 0:568f6e865655
LPC11U24_CapacitorDose
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
H_Tsunemoto | 0:568f6e865655 | 1 | ///////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 2 | // DCapacitor Dose Meter // |
H_Tsunemoto | 0:568f6e865655 | 3 | // for 6CH Sensor Charge / Discharge / Measure // |
H_Tsunemoto | 0:568f6e865655 | 4 | // Since 2019.11.22 H.Tsunemoto // |
H_Tsunemoto | 0:568f6e865655 | 5 | // Sample Program Import (1) Serial_interrupt // |
H_Tsunemoto | 0:568f6e865655 | 6 | // (2) Timer_Interrupt(100mSec) Sample // |
H_Tsunemoto | 0:568f6e865655 | 7 | // (3) Internal_ADC_with_interrupt // |
H_Tsunemoto | 0:568f6e865655 | 8 | ///////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 9 | |
H_Tsunemoto | 0:568f6e865655 | 10 | #include "mbed.h" |
H_Tsunemoto | 0:568f6e865655 | 11 | #include "stdio.h" |
H_Tsunemoto | 0:568f6e865655 | 12 | #include "math.h" |
H_Tsunemoto | 0:568f6e865655 | 13 | #include "LPC11Uxx.h" |
H_Tsunemoto | 0:568f6e865655 | 14 | |
H_Tsunemoto | 0:568f6e865655 | 15 | // MBED NXP-LPC11U24 Bord I/O Port Status Define |
H_Tsunemoto | 0:568f6e865655 | 16 | Serial device(USBTX, USBRX); |
H_Tsunemoto | 0:568f6e865655 | 17 | // On_Board Debug LED |
H_Tsunemoto | 0:568f6e865655 | 18 | DigitalOut myled1(P1_8); |
H_Tsunemoto | 0:568f6e865655 | 19 | DigitalOut myled2(P1_9); |
H_Tsunemoto | 0:568f6e865655 | 20 | DigitalOut myled3(P1_10); |
H_Tsunemoto | 0:568f6e865655 | 21 | DigitalOut myled4(P1_11); |
H_Tsunemoto | 0:568f6e865655 | 22 | |
H_Tsunemoto | 0:568f6e865655 | 23 | DigitalOut P36_Int1msec(p36); |
H_Tsunemoto | 0:568f6e865655 | 24 | DigitalOut P35_SampleTiming(p35); |
H_Tsunemoto | 0:568f6e865655 | 25 | |
H_Tsunemoto | 0:568f6e865655 | 26 | // Common Relay Connect SW |
H_Tsunemoto | 0:568f6e865655 | 27 | DigitalOut pCOM_Vref_Conn_p5(p5); |
H_Tsunemoto | 0:568f6e865655 | 28 | DigitalOut pCOM_GND_Conn_p6(p6); |
H_Tsunemoto | 0:568f6e865655 | 29 | DigitalOut pCOM_AD_OFF_DRV_p13(p13); |
H_Tsunemoto | 0:568f6e865655 | 30 | |
H_Tsunemoto | 0:568f6e865655 | 31 | // Sensor Relay Connect SW 1 - 6 |
H_Tsunemoto | 0:568f6e865655 | 32 | DigitalOut pS1_Conn_p7(p7); |
H_Tsunemoto | 0:568f6e865655 | 33 | DigitalOut pS2_Conn_p8(p8); |
H_Tsunemoto | 0:568f6e865655 | 34 | DigitalOut pS3_Conn_p9(p9); |
H_Tsunemoto | 0:568f6e865655 | 35 | DigitalOut pS4_Conn_p10(p10); |
H_Tsunemoto | 0:568f6e865655 | 36 | DigitalOut pS5_Conn_p11(p11); |
H_Tsunemoto | 0:568f6e865655 | 37 | DigitalOut pS6_Conn_p12(p12); |
H_Tsunemoto | 0:568f6e865655 | 38 | |
H_Tsunemoto | 0:568f6e865655 | 39 | // Sensor Error LED 1 - 6 |
H_Tsunemoto | 0:568f6e865655 | 40 | DigitalOut pS1_LED_p30(p30); |
H_Tsunemoto | 0:568f6e865655 | 41 | DigitalOut pS2_LED_p29(p29); |
H_Tsunemoto | 0:568f6e865655 | 42 | DigitalOut pS3_LED_p28(p28); |
H_Tsunemoto | 0:568f6e865655 | 43 | DigitalOut pS4_LED_p27(p27); |
H_Tsunemoto | 0:568f6e865655 | 44 | DigitalOut pS5_LED_p26(p26); |
H_Tsunemoto | 0:568f6e865655 | 45 | DigitalOut pS6_LED_p25(p25); |
H_Tsunemoto | 0:568f6e865655 | 46 | |
H_Tsunemoto | 0:568f6e865655 | 47 | //Sensor 6CH AnalogIn input 1 - 6 (p15,p16,p17,p18,p19,p20 ); |
H_Tsunemoto | 0:568f6e865655 | 48 | AnalogIn pS1_AD0__p15(p15); |
H_Tsunemoto | 0:568f6e865655 | 49 | AnalogIn pS2_AD1__p16(p16); |
H_Tsunemoto | 0:568f6e865655 | 50 | AnalogIn pS3_AD2__p17(p17); |
H_Tsunemoto | 0:568f6e865655 | 51 | AnalogIn pS4_AD3__p18(p18); |
H_Tsunemoto | 0:568f6e865655 | 52 | AnalogIn pS5_AD5__p19(p19); |
H_Tsunemoto | 0:568f6e865655 | 53 | AnalogIn pS6_AD6__p20(p20); |
H_Tsunemoto | 0:568f6e865655 | 54 | //DigitalInOut p10_Power(p10,PIN_OUTPUT,PullNone,0); |
H_Tsunemoto | 0:568f6e865655 | 55 | |
H_Tsunemoto | 0:568f6e865655 | 56 | /////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 57 | // Parameter Data ////////////// |
H_Tsunemoto | 0:568f6e865655 | 58 | ///////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 59 | //-------- DosimeterDock Parameter declaration --------// |
H_Tsunemoto | 0:568f6e865655 | 60 | typedef struct st_DosiDock_param{ |
H_Tsunemoto | 0:568f6e865655 | 61 | int i_P10PowerMode; // LPC11U24 P10PowerMode Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 62 | //0:GND 1:Vcc(Charge)(Digital High) 2:OFF(Open) |
H_Tsunemoto | 0:568f6e865655 | 63 | int i_P20ADC_Mode; // P20 ADC Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 64 | //0:P20_Open(No Measure) 1:P20_ADC 2:P20_ADC/Open AutoChange |
H_Tsunemoto | 0:568f6e865655 | 65 | float f_ChargeLimitVolt; // 「V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 66 | float f_ChargeLimitAfter_Delay; // [sec] Power Charge Delay しきい値を超えてからのDelay |
H_Tsunemoto | 0:568f6e865655 | 67 | float f_ChargeOver_Time; //[sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 68 | float f_DisCharge_Time; //「sec] Discharge Time |
H_Tsunemoto | 0:568f6e865655 | 69 | int i_SampleInterval_msec; // [msec] 測定周期 |
H_Tsunemoto | 0:568f6e865655 | 70 | int i_SampleTimes_MAX; // 測定回数 |
H_Tsunemoto | 0:568f6e865655 | 71 | }ST_DOSIDOCK_PARAM; |
H_Tsunemoto | 0:568f6e865655 | 72 | |
H_Tsunemoto | 0:568f6e865655 | 73 | ST_DOSIDOCK_PARAM st_dosimeterDock_param; |
H_Tsunemoto | 0:568f6e865655 | 74 | // Parameter Data Define |
H_Tsunemoto | 0:568f6e865655 | 75 | //i_P10PowerMode; // LPC11U24 P10PowerMode Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 76 | //0:GND 1:Vcc(Charge)(Digital High) 2:OFF(Open) |
H_Tsunemoto | 0:568f6e865655 | 77 | #define Def_P10Power_0_GND 0 |
H_Tsunemoto | 0:568f6e865655 | 78 | #define Def_P10Power_1_Vcc 1 |
H_Tsunemoto | 0:568f6e865655 | 79 | #define Def_P10Power_2_Open 2 |
H_Tsunemoto | 0:568f6e865655 | 80 | #define Def_P10Power_2_MAX Def_P10Power_2_Open |
H_Tsunemoto | 0:568f6e865655 | 81 | |
H_Tsunemoto | 0:568f6e865655 | 82 | #define Def_P20ADC_0_Open 0 |
H_Tsunemoto | 0:568f6e865655 | 83 | #define Def_P20ADC_1_ADC 1 |
H_Tsunemoto | 0:568f6e865655 | 84 | #define Def_P20ADC_2_AutoChange 2 |
H_Tsunemoto | 0:568f6e865655 | 85 | #define Def_P20ADC_4_MAX 4 |
H_Tsunemoto | 0:568f6e865655 | 86 | |
H_Tsunemoto | 0:568f6e865655 | 87 | #define Def_CHARGE_Limit_VoltMIN 1.0f |
H_Tsunemoto | 0:568f6e865655 | 88 | #define Def_CHARGE_Limit_VoltMAX 3.4f |
H_Tsunemoto | 0:568f6e865655 | 89 | |
H_Tsunemoto | 0:568f6e865655 | 90 | #define Def_CHARGE_AfterDelay_MIN 0.0f |
H_Tsunemoto | 0:568f6e865655 | 91 | #define Def_CHARGE_AfterDelay_MAX 3600.0f // 1H |
H_Tsunemoto | 0:568f6e865655 | 92 | |
H_Tsunemoto | 0:568f6e865655 | 93 | #define Def_CHARGE_TIME_MIN 1.0f |
H_Tsunemoto | 0:568f6e865655 | 94 | #define Def_CHARGE_TIME_MAX 3600.0f // 1H |
H_Tsunemoto | 0:568f6e865655 | 95 | |
H_Tsunemoto | 0:568f6e865655 | 96 | #define Def_SAMPLE_INTERVAL_MIN 10 // 10[msec] |
H_Tsunemoto | 0:568f6e865655 | 97 | #define Def_SAMPLE_INTERVAL_MAX 10000 // 10000[msec] |
H_Tsunemoto | 0:568f6e865655 | 98 | |
H_Tsunemoto | 0:568f6e865655 | 99 | //-------- DosimeterDock Parameter Default Set --------// |
H_Tsunemoto | 0:568f6e865655 | 100 | const ST_DOSIDOCK_PARAM const_DosiDock_Param_Default= |
H_Tsunemoto | 0:568f6e865655 | 101 | { |
H_Tsunemoto | 0:568f6e865655 | 102 | 1 //i_P10PowerMode LPC11U24 P10PowerMode Pin Mode |
H_Tsunemoto | 0:568f6e865655 | 103 | ,1 //i_P20ADC_Mode P20 ADC Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 104 | ,3.2f //f_ChargeLimitVolt 「V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 105 | ,5.0f //f_ChargeLimitAfter_Delay [sec] Power Charge Delay しきい値を超えてからのDelay |
H_Tsunemoto | 0:568f6e865655 | 106 | ,15.0f //f_ChargeOver_Time[sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 107 | ,5.0f //f_DisCharge_Time 「sec] Discharge Time |
H_Tsunemoto | 0:568f6e865655 | 108 | ,100 //i_SampleInterval_msec // [msec] 測定周期 |
H_Tsunemoto | 0:568f6e865655 | 109 | ,5 //i_SampleTimes_MAX; // 測定回数 |
H_Tsunemoto | 0:568f6e865655 | 110 | }; |
H_Tsunemoto | 0:568f6e865655 | 111 | |
H_Tsunemoto | 0:568f6e865655 | 112 | #define Def_CHARGE_LImitVolt 3.2f // 「V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 113 | #define Def_CHARGE_LimitAfter_Delay 5.0f // [sec] Power Charge Delay しきい値を超えてからのDelay |
H_Tsunemoto | 0:568f6e865655 | 114 | #define Def_Sample_Interval 0.01f // [sec] ADC Sample Interval |
H_Tsunemoto | 0:568f6e865655 | 115 | #define Def_CHARGE_OverTime 15.0f // [sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 116 | ////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 117 | // |
H_Tsunemoto | 0:568f6e865655 | 118 | ////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 119 | // Timer Interrupt // |
H_Tsunemoto | 0:568f6e865655 | 120 | /////////////// |
H_Tsunemoto | 0:568f6e865655 | 121 | Ticker Int1mSec_Timer; |
H_Tsunemoto | 0:568f6e865655 | 122 | Timer t; |
H_Tsunemoto | 0:568f6e865655 | 123 | |
H_Tsunemoto | 0:568f6e865655 | 124 | ////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 125 | //--------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 126 | // --- Serial Communication --- // |
H_Tsunemoto | 0:568f6e865655 | 127 | //--------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 128 | void Tx_interrupt(); |
H_Tsunemoto | 0:568f6e865655 | 129 | void Rx_interrupt(); |
H_Tsunemoto | 0:568f6e865655 | 130 | void send_line(); |
H_Tsunemoto | 0:568f6e865655 | 131 | int read_line(); // Return Rec CHAR Count 2013.08.08 Tsunemoto Append |
H_Tsunemoto | 0:568f6e865655 | 132 | void Tick_1mSec_Interrupt(); |
H_Tsunemoto | 0:568f6e865655 | 133 | |
H_Tsunemoto | 0:568f6e865655 | 134 | // Circular buffers for serial TX and RX data - used by interrupt routines |
H_Tsunemoto | 0:568f6e865655 | 135 | const int ser_buffer_size = 255; |
H_Tsunemoto | 0:568f6e865655 | 136 | // might need to increase buffer size for high baud rates |
H_Tsunemoto | 0:568f6e865655 | 137 | char tx_buffer[ser_buffer_size]; |
H_Tsunemoto | 0:568f6e865655 | 138 | char rx_buffer[ser_buffer_size]; |
H_Tsunemoto | 0:568f6e865655 | 139 | // Circular buffer pointers |
H_Tsunemoto | 0:568f6e865655 | 140 | // volatile makes read-modify-write atomic |
H_Tsunemoto | 0:568f6e865655 | 141 | volatile int tx_in=0; |
H_Tsunemoto | 0:568f6e865655 | 142 | volatile int tx_out=0; |
H_Tsunemoto | 0:568f6e865655 | 143 | volatile int rx_in=0; |
H_Tsunemoto | 0:568f6e865655 | 144 | volatile int rx_out=0; |
H_Tsunemoto | 0:568f6e865655 | 145 | // Line buffers for sprintf and sscanf |
H_Tsunemoto | 0:568f6e865655 | 146 | char tx_line[80]; |
H_Tsunemoto | 0:568f6e865655 | 147 | char rx_line[80]; |
H_Tsunemoto | 0:568f6e865655 | 148 | //--- 2013.08.08 Tsunemoto ------// |
H_Tsunemoto | 0:568f6e865655 | 149 | //-- rx Data Cr Rec Counter |
H_Tsunemoto | 0:568f6e865655 | 150 | volatile int rx_cr_Rec = 0; |
H_Tsunemoto | 0:568f6e865655 | 151 | //-----------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 152 | //--------- Timer Innterrupt For DAC Control ---------------// |
H_Tsunemoto | 0:568f6e865655 | 153 | //-----------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 154 | int timer_count=0; |
H_Tsunemoto | 0:568f6e865655 | 155 | int timer_1Sec=0; |
H_Tsunemoto | 0:568f6e865655 | 156 | int main_loop_count=0; |
H_Tsunemoto | 0:568f6e865655 | 157 | ////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 158 | //// Measurement Mode ///// |
H_Tsunemoto | 0:568f6e865655 | 159 | ////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 160 | #define SAMPLE_MODE_NotActive 0 |
H_Tsunemoto | 0:568f6e865655 | 161 | #define SAMPLE_MODE_ACTIVE 1 |
H_Tsunemoto | 0:568f6e865655 | 162 | int i_SampleMode=0; |
H_Tsunemoto | 0:568f6e865655 | 163 | #define CHARGE_MODE_NotActive 0 |
H_Tsunemoto | 0:568f6e865655 | 164 | #define CHARGE_MODE_AfterDelay 1 |
H_Tsunemoto | 0:568f6e865655 | 165 | #define CHARGE_MODE_ACTIVE 2 |
H_Tsunemoto | 0:568f6e865655 | 166 | int i_ChargeMode=0; |
H_Tsunemoto | 0:568f6e865655 | 167 | |
H_Tsunemoto | 0:568f6e865655 | 168 | #define DISCHARGE_MODE_NotActive 0 |
H_Tsunemoto | 0:568f6e865655 | 169 | #define DISCHARGE_MODE_ACTIVE 1 |
H_Tsunemoto | 0:568f6e865655 | 170 | int i_DisChargeMode=0; |
H_Tsunemoto | 0:568f6e865655 | 171 | |
H_Tsunemoto | 0:568f6e865655 | 172 | // 100usec Decrement Counter |
H_Tsunemoto | 0:568f6e865655 | 173 | int i_ADC_IntCount =0; |
H_Tsunemoto | 0:568f6e865655 | 174 | int i_ADC_Sample_Count=0; |
H_Tsunemoto | 0:568f6e865655 | 175 | int i_ChargeAfterDelayCount =0; |
H_Tsunemoto | 0:568f6e865655 | 176 | int i_Charge_TermOverCount=0; |
H_Tsunemoto | 0:568f6e865655 | 177 | int i_DisChargeTermCount =0; |
H_Tsunemoto | 0:568f6e865655 | 178 | |
H_Tsunemoto | 0:568f6e865655 | 179 | |
H_Tsunemoto | 0:568f6e865655 | 180 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 181 | //------------ Command Check & Set Function ---------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 182 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 183 | //------------ Command Check & Set Function ---------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 184 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 185 | float ADC_Sample_Send(); |
H_Tsunemoto | 0:568f6e865655 | 186 | void Ser_Command_Input(); |
H_Tsunemoto | 0:568f6e865655 | 187 | void DosiDock_param_init(); |
H_Tsunemoto | 0:568f6e865655 | 188 | void com_Table_Param_Send(); |
H_Tsunemoto | 0:568f6e865655 | 189 | void com_Stat_Table_Param_Send(); |
H_Tsunemoto | 0:568f6e865655 | 190 | // Command No.1 "PW x" P10 PowerMode Pin Status Set // |
H_Tsunemoto | 0:568f6e865655 | 191 | bool com_Check_PW_P10Mode(int i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 192 | // Command No.2 "AD x" P20 ADC Pin Status Set // |
H_Tsunemoto | 0:568f6e865655 | 193 | bool com_Check_AD_P20Mode(int i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 194 | // Command No.3 "LV xx.xx" [V] Power Charge Limit Volt Set // |
H_Tsunemoto | 0:568f6e865655 | 195 | bool com_Check_LV_PW_ChargeLimit_V(int i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 196 | // Command No.4 "LW xx.xx" [sec] Power Charge Delay しきい値を超えてからのDelay // |
H_Tsunemoto | 0:568f6e865655 | 197 | bool com_Check_LW_PW_ChargeAfterDelay(int i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 198 | // Command No.5 "LT xx.xx" [sec] Charge Time Max Set // |
H_Tsunemoto | 0:568f6e865655 | 199 | bool com_Check_LT_ChargeOverTime(int i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 200 | // Command No.6 "LD xx.xx" [「sec] Discharge Time Set // |
H_Tsunemoto | 0:568f6e865655 | 201 | bool com_Check_LD_PW_DisCharge_Time(int i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 202 | void P10_PWR_Pin_0_GND(); |
H_Tsunemoto | 0:568f6e865655 | 203 | void P10_PWR_Pin_1_High(); |
H_Tsunemoto | 0:568f6e865655 | 204 | void P10_PWR_Pin_2_Open(); |
H_Tsunemoto | 0:568f6e865655 | 205 | void P20_ADC_Pin_0_Open(); |
H_Tsunemoto | 0:568f6e865655 | 206 | void P20_ADC_Pin_1_ADCin(); |
H_Tsunemoto | 0:568f6e865655 | 207 | void P20_ADC_Pin_2_AD_Open(); |
H_Tsunemoto | 0:568f6e865655 | 208 | void P20_ADC_Pin_3_ADPin_GNDTest(); |
H_Tsunemoto | 0:568f6e865655 | 209 | void P20_ADC_Pin_4_ADPin_HighTest(); |
H_Tsunemoto | 0:568f6e865655 | 210 | |
H_Tsunemoto | 0:568f6e865655 | 211 | //----------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 212 | |
H_Tsunemoto | 0:568f6e865655 | 213 | ////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 214 | int main(){ |
H_Tsunemoto | 0:568f6e865655 | 215 | float f_ADC_inp =0.0; |
H_Tsunemoto | 0:568f6e865655 | 216 | |
H_Tsunemoto | 0:568f6e865655 | 217 | // Serial Baud 115200 |
H_Tsunemoto | 0:568f6e865655 | 218 | device.baud(115200); |
H_Tsunemoto | 0:568f6e865655 | 219 | timer_count = 0; |
H_Tsunemoto | 0:568f6e865655 | 220 | DosiDock_param_init(); |
H_Tsunemoto | 0:568f6e865655 | 221 | Int1mSec_Timer.attach_us(&Tick_1mSec_Interrupt, (1000)); |
H_Tsunemoto | 0:568f6e865655 | 222 | t.reset(); |
H_Tsunemoto | 0:568f6e865655 | 223 | t.start(); |
H_Tsunemoto | 0:568f6e865655 | 224 | |
H_Tsunemoto | 0:568f6e865655 | 225 | // Setup a serial interrupt function to receive data |
H_Tsunemoto | 0:568f6e865655 | 226 | device.attach(&Rx_interrupt, Serial::RxIrq); |
H_Tsunemoto | 0:568f6e865655 | 227 | // Setup a serial interrupt function to transmit data |
H_Tsunemoto | 0:568f6e865655 | 228 | device.attach(&Tx_interrupt, Serial::TxIrq); |
H_Tsunemoto | 0:568f6e865655 | 229 | timer_count = 0; |
H_Tsunemoto | 0:568f6e865655 | 230 | |
H_Tsunemoto | 0:568f6e865655 | 231 | //--- ADC Measurement Control Parameter Initial Set ---// |
H_Tsunemoto | 0:568f6e865655 | 232 | // adc_param_init(); |
H_Tsunemoto | 0:568f6e865655 | 233 | //--- DAC Control Parameter Init --- // |
H_Tsunemoto | 0:568f6e865655 | 234 | // dac1_param_init(); |
H_Tsunemoto | 0:568f6e865655 | 235 | // -- Main Loop -- // |
H_Tsunemoto | 0:568f6e865655 | 236 | while (1) { |
H_Tsunemoto | 0:568f6e865655 | 237 | if(rx_cr_Rec > 0){ |
H_Tsunemoto | 0:568f6e865655 | 238 | Ser_Command_Input(); |
H_Tsunemoto | 0:568f6e865655 | 239 | } |
H_Tsunemoto | 0:568f6e865655 | 240 | // Sample Measurement Active |
H_Tsunemoto | 0:568f6e865655 | 241 | if(i_SampleMode == SAMPLE_MODE_ACTIVE){ |
H_Tsunemoto | 0:568f6e865655 | 242 | myled4 = 1.0; |
H_Tsunemoto | 0:568f6e865655 | 243 | if(i_ADC_IntCount == 0){ |
H_Tsunemoto | 0:568f6e865655 | 244 | i_ADC_IntCount= (st_dosimeterDock_param.i_SampleInterval_msec)*10; |
H_Tsunemoto | 0:568f6e865655 | 245 | f_ADC_inp =ADC_Sample_Send(); |
H_Tsunemoto | 0:568f6e865655 | 246 | i_ADC_Sample_Count++; |
H_Tsunemoto | 0:568f6e865655 | 247 | if(i_ADC_Sample_Count >= st_dosimeterDock_param.i_SampleTimes_MAX){ |
H_Tsunemoto | 0:568f6e865655 | 248 | i_SampleMode = SAMPLE_MODE_NotActive; // Sample End |
H_Tsunemoto | 0:568f6e865655 | 249 | myled4 = 0; |
H_Tsunemoto | 0:568f6e865655 | 250 | sprintf(tx_line,"SM:END\r\n" ); |
H_Tsunemoto | 0:568f6e865655 | 251 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 252 | } |
H_Tsunemoto | 0:568f6e865655 | 253 | } |
H_Tsunemoto | 0:568f6e865655 | 254 | |
H_Tsunemoto | 0:568f6e865655 | 255 | } |
H_Tsunemoto | 0:568f6e865655 | 256 | // Charge Mode Active |
H_Tsunemoto | 0:568f6e865655 | 257 | if(i_ChargeMode > CHARGE_MODE_NotActive){ |
H_Tsunemoto | 0:568f6e865655 | 258 | myled3 = 1.0; |
H_Tsunemoto | 0:568f6e865655 | 259 | if(i_ADC_IntCount == 0){ |
H_Tsunemoto | 0:568f6e865655 | 260 | i_ADC_IntCount= (st_dosimeterDock_param.i_SampleInterval_msec)*10; |
H_Tsunemoto | 0:568f6e865655 | 261 | f_ADC_inp =ADC_Sample_Send(); |
H_Tsunemoto | 0:568f6e865655 | 262 | i_ADC_Sample_Count++; |
H_Tsunemoto | 0:568f6e865655 | 263 | if(i_Charge_TermOverCount == 0){ // Time Over Check |
H_Tsunemoto | 0:568f6e865655 | 264 | i_ChargeMode = CHARGE_MODE_NotActive; |
H_Tsunemoto | 0:568f6e865655 | 265 | sprintf(tx_line,"SC:END_Over\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 266 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 267 | } |
H_Tsunemoto | 0:568f6e865655 | 268 | else if (i_ChargeMode == CHARGE_MODE_ACTIVE){ // Charge Level Check |
H_Tsunemoto | 0:568f6e865655 | 269 | if(f_ADC_inp >= st_dosimeterDock_param.f_ChargeLimitVolt){ |
H_Tsunemoto | 0:568f6e865655 | 270 | i_ChargeAfterDelayCount = (int)((st_dosimeterDock_param.f_ChargeLimitAfter_Delay)*10000.0f); |
H_Tsunemoto | 0:568f6e865655 | 271 | i_ChargeMode = CHARGE_MODE_AfterDelay; |
H_Tsunemoto | 0:568f6e865655 | 272 | sprintf(tx_line,"CLV,MS%2.3f,LM%2.3f\r\n",f_ADC_inp,st_dosimeterDock_param.f_ChargeLimitVolt ); |
H_Tsunemoto | 0:568f6e865655 | 273 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 274 | } |
H_Tsunemoto | 0:568f6e865655 | 275 | } |
H_Tsunemoto | 0:568f6e865655 | 276 | else if (i_ChargeMode == CHARGE_MODE_AfterDelay){ |
H_Tsunemoto | 0:568f6e865655 | 277 | if(i_ChargeAfterDelayCount ==0) { // Charge After Delay |
H_Tsunemoto | 0:568f6e865655 | 278 | i_ChargeMode = CHARGE_MODE_NotActive; |
H_Tsunemoto | 0:568f6e865655 | 279 | sprintf(tx_line,"SC:END\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 280 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 281 | } |
H_Tsunemoto | 0:568f6e865655 | 282 | } |
H_Tsunemoto | 0:568f6e865655 | 283 | } |
H_Tsunemoto | 0:568f6e865655 | 284 | if(i_ChargeMode == CHARGE_MODE_NotActive){ |
H_Tsunemoto | 0:568f6e865655 | 285 | P10_PWR_Pin_2_Open(); |
H_Tsunemoto | 0:568f6e865655 | 286 | myled3 = 0; |
H_Tsunemoto | 0:568f6e865655 | 287 | } |
H_Tsunemoto | 0:568f6e865655 | 288 | } |
H_Tsunemoto | 0:568f6e865655 | 289 | // DisCharge Mode Active |
H_Tsunemoto | 0:568f6e865655 | 290 | if(i_DisChargeMode == DISCHARGE_MODE_ACTIVE){ |
H_Tsunemoto | 0:568f6e865655 | 291 | myled4 = 1.0; |
H_Tsunemoto | 0:568f6e865655 | 292 | if(i_ADC_IntCount == 0){ |
H_Tsunemoto | 0:568f6e865655 | 293 | i_ADC_IntCount= (st_dosimeterDock_param.i_SampleInterval_msec)*10; |
H_Tsunemoto | 0:568f6e865655 | 294 | f_ADC_inp =ADC_Sample_Send(); |
H_Tsunemoto | 0:568f6e865655 | 295 | i_ADC_Sample_Count++; |
H_Tsunemoto | 0:568f6e865655 | 296 | if(i_DisChargeTermCount == 0){ // Time Over Check |
H_Tsunemoto | 0:568f6e865655 | 297 | i_DisChargeMode = DISCHARGE_MODE_NotActive; |
H_Tsunemoto | 0:568f6e865655 | 298 | P10_PWR_Pin_2_Open(); |
H_Tsunemoto | 0:568f6e865655 | 299 | myled4 = 0; |
H_Tsunemoto | 0:568f6e865655 | 300 | sprintf(tx_line,"SD:END\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 301 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 302 | } |
H_Tsunemoto | 0:568f6e865655 | 303 | } |
H_Tsunemoto | 0:568f6e865655 | 304 | } |
H_Tsunemoto | 0:568f6e865655 | 305 | // MainLoop LED Blink |
H_Tsunemoto | 0:568f6e865655 | 306 | main_loop_count++; |
H_Tsunemoto | 0:568f6e865655 | 307 | if(main_loop_count>=100000){ |
H_Tsunemoto | 0:568f6e865655 | 308 | myled1 = (myled1+1) & 1; |
H_Tsunemoto | 0:568f6e865655 | 309 | main_loop_count = 0; |
H_Tsunemoto | 0:568f6e865655 | 310 | } |
H_Tsunemoto | 0:568f6e865655 | 311 | ///////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 312 | } |
H_Tsunemoto | 0:568f6e865655 | 313 | } |
H_Tsunemoto | 0:568f6e865655 | 314 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 315 | //---------- "SM" レベル測定スタート ---------------------// |
H_Tsunemoto | 0:568f6e865655 | 316 | // 100usec Decrement Counter |
H_Tsunemoto | 0:568f6e865655 | 317 | //int i_ADC_IntCount =0; |
H_Tsunemoto | 0:568f6e865655 | 318 | //int i_ADC_Sample_Count=0; |
H_Tsunemoto | 0:568f6e865655 | 319 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 320 | void Start_SampleMeasure() |
H_Tsunemoto | 0:568f6e865655 | 321 | { |
H_Tsunemoto | 0:568f6e865655 | 322 | sprintf(tx_line,"SM:START\r\n" ); |
H_Tsunemoto | 0:568f6e865655 | 323 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 324 | |
H_Tsunemoto | 0:568f6e865655 | 325 | AnalogIn p20_Adc(p20); |
H_Tsunemoto | 0:568f6e865655 | 326 | i_SampleMode = SAMPLE_MODE_ACTIVE; |
H_Tsunemoto | 0:568f6e865655 | 327 | i_ADC_IntCount= (st_dosimeterDock_param.i_SampleInterval_msec)*10; |
H_Tsunemoto | 0:568f6e865655 | 328 | i_ADC_Sample_Count= 0 ; //st_dosimeterDock_param.i_SampleTimes_MAX; |
H_Tsunemoto | 0:568f6e865655 | 329 | } |
H_Tsunemoto | 0:568f6e865655 | 330 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 331 | //---------- Chargeスタート ---------------------// |
H_Tsunemoto | 0:568f6e865655 | 332 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 333 | void Start_ChargeMode() |
H_Tsunemoto | 0:568f6e865655 | 334 | { |
H_Tsunemoto | 0:568f6e865655 | 335 | sprintf(tx_line,"SC:START\r\n" ); |
H_Tsunemoto | 0:568f6e865655 | 336 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 337 | AnalogIn p20_Adc(p20); |
H_Tsunemoto | 0:568f6e865655 | 338 | i_ChargeMode = CHARGE_MODE_ACTIVE; |
H_Tsunemoto | 0:568f6e865655 | 339 | i_ADC_IntCount= (st_dosimeterDock_param.i_SampleInterval_msec)*10; |
H_Tsunemoto | 0:568f6e865655 | 340 | i_Charge_TermOverCount = (int)( (st_dosimeterDock_param.f_ChargeOver_Time) * 10000.0f); |
H_Tsunemoto | 0:568f6e865655 | 341 | i_ADC_Sample_Count= 0 ; //st_dosimeterDock_param.i_SampleTimes_MAX; |
H_Tsunemoto | 0:568f6e865655 | 342 | P10_PWR_Pin_1_High(); |
H_Tsunemoto | 0:568f6e865655 | 343 | // sprintf(tx_line,"TIMECOUNT %4d\r\n",i_Charge_TermOverCount ); |
H_Tsunemoto | 0:568f6e865655 | 344 | // send_line(); |
H_Tsunemoto | 0:568f6e865655 | 345 | |
H_Tsunemoto | 0:568f6e865655 | 346 | } |
H_Tsunemoto | 0:568f6e865655 | 347 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 348 | //---------- DisChargeスタート ---------------------// |
H_Tsunemoto | 0:568f6e865655 | 349 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 350 | void Start_DisChargeMode() |
H_Tsunemoto | 0:568f6e865655 | 351 | { |
H_Tsunemoto | 0:568f6e865655 | 352 | sprintf(tx_line,"SD:START\r\n" ); |
H_Tsunemoto | 0:568f6e865655 | 353 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 354 | i_DisChargeMode = DISCHARGE_MODE_ACTIVE; |
H_Tsunemoto | 0:568f6e865655 | 355 | i_ADC_IntCount= (st_dosimeterDock_param.i_SampleInterval_msec)*10; |
H_Tsunemoto | 0:568f6e865655 | 356 | i_DisChargeTermCount=(int)( (st_dosimeterDock_param.f_DisCharge_Time) * 10000.0f); |
H_Tsunemoto | 0:568f6e865655 | 357 | i_ADC_Sample_Count= 0 ; //st_dosimeterDock_param.i_SampleTimes_MAX; |
H_Tsunemoto | 0:568f6e865655 | 358 | P10_PWR_Pin_0_GND(); |
H_Tsunemoto | 0:568f6e865655 | 359 | } |
H_Tsunemoto | 0:568f6e865655 | 360 | |
H_Tsunemoto | 0:568f6e865655 | 361 | //////////////////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 362 | //ST_DosimeterDock_PARAM 初期設定 |
H_Tsunemoto | 0:568f6e865655 | 363 | //typedef struct st_DosiDock_param{ |
H_Tsunemoto | 0:568f6e865655 | 364 | // int i_P10PowerMode; // LPC11U24 P10PowerMode Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 365 | // //0:GND 1:Vcc(Charge)(Digital High) 2:OFF(Open) |
H_Tsunemoto | 0:568f6e865655 | 366 | // int i_P20ADC_Mode; // P20 ADC Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 367 | // //0:P20_Open(No Measure) 1:P20_ADC 2:P20_ADC/Open AutoChange |
H_Tsunemoto | 0:568f6e865655 | 368 | // float f_ChargeLimitVolt; // 「V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 369 | // float f_ChargeLimitAfter_Delay; // [sec] Power Charge Delay しきい値を超えてからのDelay |
H_Tsunemoto | 0:568f6e865655 | 370 | // float f_ChargeOver_Time; //[sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 371 | // float f_DisCharge_Time; //「sec] Discharge Time |
H_Tsunemoto | 0:568f6e865655 | 372 | // int i_SampleInterval_msec; // [msec] 測定周期 |
H_Tsunemoto | 0:568f6e865655 | 373 | // int i_SampleTimes_MAX; // 測定回数 |
H_Tsunemoto | 0:568f6e865655 | 374 | // }ST_DOSIDOCK_PARAM; |
H_Tsunemoto | 0:568f6e865655 | 375 | // |
H_Tsunemoto | 0:568f6e865655 | 376 | //ST_DOSIDOCK_PARAM st_dosimeterDock_param; |
H_Tsunemoto | 0:568f6e865655 | 377 | //////////////////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 378 | //-------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 379 | void DosiDock_param_init() |
H_Tsunemoto | 0:568f6e865655 | 380 | { |
H_Tsunemoto | 0:568f6e865655 | 381 | st_dosimeterDock_param.i_P10PowerMode = const_DosiDock_Param_Default.i_P10PowerMode; |
H_Tsunemoto | 0:568f6e865655 | 382 | st_dosimeterDock_param.i_P20ADC_Mode = const_DosiDock_Param_Default.i_P20ADC_Mode; |
H_Tsunemoto | 0:568f6e865655 | 383 | st_dosimeterDock_param.f_ChargeLimitVolt = const_DosiDock_Param_Default.f_ChargeLimitVolt; |
H_Tsunemoto | 0:568f6e865655 | 384 | st_dosimeterDock_param.f_ChargeLimitAfter_Delay = const_DosiDock_Param_Default.f_ChargeLimitAfter_Delay; |
H_Tsunemoto | 0:568f6e865655 | 385 | st_dosimeterDock_param.f_ChargeOver_Time = const_DosiDock_Param_Default.f_ChargeOver_Time; |
H_Tsunemoto | 0:568f6e865655 | 386 | st_dosimeterDock_param.f_DisCharge_Time = const_DosiDock_Param_Default.f_DisCharge_Time; |
H_Tsunemoto | 0:568f6e865655 | 387 | st_dosimeterDock_param.i_SampleInterval_msec = const_DosiDock_Param_Default.i_SampleInterval_msec; |
H_Tsunemoto | 0:568f6e865655 | 388 | st_dosimeterDock_param.i_SampleTimes_MAX = const_DosiDock_Param_Default.i_SampleTimes_MAX; |
H_Tsunemoto | 0:568f6e865655 | 389 | } |
H_Tsunemoto | 0:568f6e865655 | 390 | ////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 391 | ///// ADC 1 Sample Input & Send // |
H_Tsunemoto | 0:568f6e865655 | 392 | ////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 393 | float ADC_Sample_Send() |
H_Tsunemoto | 0:568f6e865655 | 394 | { |
H_Tsunemoto | 0:568f6e865655 | 395 | // int i; |
H_Tsunemoto | 0:568f6e865655 | 396 | float f_ADC_V =0.0; |
H_Tsunemoto | 0:568f6e865655 | 397 | |
H_Tsunemoto | 0:568f6e865655 | 398 | AnalogIn p20_Adc(p20); |
H_Tsunemoto | 0:568f6e865655 | 399 | f_ADC_V = (float)p20_Adc*3.3; |
H_Tsunemoto | 0:568f6e865655 | 400 | sprintf(tx_line,"ADC,%3i,%2.3f\r\n",i_ADC_Sample_Count, f_ADC_V ); |
H_Tsunemoto | 0:568f6e865655 | 401 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 402 | return(f_ADC_V); |
H_Tsunemoto | 0:568f6e865655 | 403 | } |
H_Tsunemoto | 0:568f6e865655 | 404 | |
H_Tsunemoto | 0:568f6e865655 | 405 | //////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 406 | // P10 Power Port Set // |
H_Tsunemoto | 0:568f6e865655 | 407 | //////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 408 | void P10_PWR_Pin_0_GND() |
H_Tsunemoto | 0:568f6e865655 | 409 | { |
H_Tsunemoto | 0:568f6e865655 | 410 | } |
H_Tsunemoto | 0:568f6e865655 | 411 | void P10_PWR_Pin_1_High() |
H_Tsunemoto | 0:568f6e865655 | 412 | { |
H_Tsunemoto | 0:568f6e865655 | 413 | } |
H_Tsunemoto | 0:568f6e865655 | 414 | void P10_PWR_Pin_2_Open() |
H_Tsunemoto | 0:568f6e865655 | 415 | { |
H_Tsunemoto | 0:568f6e865655 | 416 | |
H_Tsunemoto | 0:568f6e865655 | 417 | } |
H_Tsunemoto | 0:568f6e865655 | 418 | |
H_Tsunemoto | 0:568f6e865655 | 419 | void P10_PWR_Pin_Setting(int i_selMode) |
H_Tsunemoto | 0:568f6e865655 | 420 | { |
H_Tsunemoto | 0:568f6e865655 | 421 | switch(i_selMode){ |
H_Tsunemoto | 0:568f6e865655 | 422 | case 0: |
H_Tsunemoto | 0:568f6e865655 | 423 | P10_PWR_Pin_0_GND(); |
H_Tsunemoto | 0:568f6e865655 | 424 | break; |
H_Tsunemoto | 0:568f6e865655 | 425 | case 1: |
H_Tsunemoto | 0:568f6e865655 | 426 | P10_PWR_Pin_1_High(); |
H_Tsunemoto | 0:568f6e865655 | 427 | break; |
H_Tsunemoto | 0:568f6e865655 | 428 | case 2: |
H_Tsunemoto | 0:568f6e865655 | 429 | P10_PWR_Pin_2_Open(); |
H_Tsunemoto | 0:568f6e865655 | 430 | break; |
H_Tsunemoto | 0:568f6e865655 | 431 | default: |
H_Tsunemoto | 0:568f6e865655 | 432 | break; |
H_Tsunemoto | 0:568f6e865655 | 433 | } |
H_Tsunemoto | 0:568f6e865655 | 434 | |
H_Tsunemoto | 0:568f6e865655 | 435 | } |
H_Tsunemoto | 0:568f6e865655 | 436 | //////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 437 | // P20 ADC Port Set // |
H_Tsunemoto | 0:568f6e865655 | 438 | //////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 439 | void P20_ADC_Pin_0_Open() |
H_Tsunemoto | 0:568f6e865655 | 440 | { |
H_Tsunemoto | 0:568f6e865655 | 441 | DigitalInOut p20_GPIO_Open(p20,PIN_OUTPUT,OpenDrain,1); |
H_Tsunemoto | 0:568f6e865655 | 442 | } |
H_Tsunemoto | 0:568f6e865655 | 443 | void P20_ADC_Pin_1_ADCin() |
H_Tsunemoto | 0:568f6e865655 | 444 | { |
H_Tsunemoto | 0:568f6e865655 | 445 | AnalogIn p20_Adc(p20); |
H_Tsunemoto | 0:568f6e865655 | 446 | |
H_Tsunemoto | 0:568f6e865655 | 447 | } |
H_Tsunemoto | 0:568f6e865655 | 448 | void P20_ADC_Pin_2_AD_Open() |
H_Tsunemoto | 0:568f6e865655 | 449 | { |
H_Tsunemoto | 0:568f6e865655 | 450 | DigitalInOut p20_GPIO_Open(p20,PIN_OUTPUT,OpenDrain,1); |
H_Tsunemoto | 0:568f6e865655 | 451 | |
H_Tsunemoto | 0:568f6e865655 | 452 | } |
H_Tsunemoto | 0:568f6e865655 | 453 | void P20_ADC_Pin_3_ADPin_GNDTest() |
H_Tsunemoto | 0:568f6e865655 | 454 | { |
H_Tsunemoto | 0:568f6e865655 | 455 | DigitalInOut p20_GPIO_GND(p20,PIN_OUTPUT,PullNone,0); |
H_Tsunemoto | 0:568f6e865655 | 456 | |
H_Tsunemoto | 0:568f6e865655 | 457 | } |
H_Tsunemoto | 0:568f6e865655 | 458 | void P20_ADC_Pin_4_ADPin_HighTest() |
H_Tsunemoto | 0:568f6e865655 | 459 | { |
H_Tsunemoto | 0:568f6e865655 | 460 | DigitalInOut p20_GPIO_High(p20,PIN_OUTPUT,PullNone,1); |
H_Tsunemoto | 0:568f6e865655 | 461 | |
H_Tsunemoto | 0:568f6e865655 | 462 | } |
H_Tsunemoto | 0:568f6e865655 | 463 | |
H_Tsunemoto | 0:568f6e865655 | 464 | void P20_ADC_Pin_Setting(int i_selMode) |
H_Tsunemoto | 0:568f6e865655 | 465 | { |
H_Tsunemoto | 0:568f6e865655 | 466 | switch(i_selMode){ |
H_Tsunemoto | 0:568f6e865655 | 467 | case 0: |
H_Tsunemoto | 0:568f6e865655 | 468 | P20_ADC_Pin_0_Open(); |
H_Tsunemoto | 0:568f6e865655 | 469 | break; |
H_Tsunemoto | 0:568f6e865655 | 470 | case 1: |
H_Tsunemoto | 0:568f6e865655 | 471 | P20_ADC_Pin_1_ADCin(); |
H_Tsunemoto | 0:568f6e865655 | 472 | break; |
H_Tsunemoto | 0:568f6e865655 | 473 | case 2: |
H_Tsunemoto | 0:568f6e865655 | 474 | P20_ADC_Pin_2_AD_Open(); |
H_Tsunemoto | 0:568f6e865655 | 475 | break; |
H_Tsunemoto | 0:568f6e865655 | 476 | case 3: |
H_Tsunemoto | 0:568f6e865655 | 477 | P20_ADC_Pin_3_ADPin_GNDTest(); |
H_Tsunemoto | 0:568f6e865655 | 478 | break; |
H_Tsunemoto | 0:568f6e865655 | 479 | case 4: |
H_Tsunemoto | 0:568f6e865655 | 480 | P20_ADC_Pin_4_ADPin_HighTest(); |
H_Tsunemoto | 0:568f6e865655 | 481 | break; |
H_Tsunemoto | 0:568f6e865655 | 482 | default: |
H_Tsunemoto | 0:568f6e865655 | 483 | break; |
H_Tsunemoto | 0:568f6e865655 | 484 | } |
H_Tsunemoto | 0:568f6e865655 | 485 | |
H_Tsunemoto | 0:568f6e865655 | 486 | } |
H_Tsunemoto | 0:568f6e865655 | 487 | |
H_Tsunemoto | 0:568f6e865655 | 488 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 489 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 490 | |
H_Tsunemoto | 0:568f6e865655 | 491 | |
H_Tsunemoto | 0:568f6e865655 | 492 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 493 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 494 | //----- Serial tx/rx Communication |
H_Tsunemoto | 0:568f6e865655 | 495 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 496 | // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:568f6e865655 | 497 | void send_line() { |
H_Tsunemoto | 0:568f6e865655 | 498 | int i; |
H_Tsunemoto | 0:568f6e865655 | 499 | char temp_char; |
H_Tsunemoto | 0:568f6e865655 | 500 | bool empty; |
H_Tsunemoto | 0:568f6e865655 | 501 | i = 0; |
H_Tsunemoto | 0:568f6e865655 | 502 | // Start Critical Section - don't interrupt while changing global buffer variables |
H_Tsunemoto | 0:568f6e865655 | 503 | NVIC_DisableIRQ(UART_IRQn); |
H_Tsunemoto | 0:568f6e865655 | 504 | empty = (tx_in == tx_out); |
H_Tsunemoto | 0:568f6e865655 | 505 | while ((i==0) || (tx_line[i-1] != '\n')) { |
H_Tsunemoto | 0:568f6e865655 | 506 | // Wait if buffer full |
H_Tsunemoto | 0:568f6e865655 | 507 | if (((tx_in + 1) % ser_buffer_size) == tx_out) { |
H_Tsunemoto | 0:568f6e865655 | 508 | // End Critical Section - need to let interrupt routine empty buffer by sending |
H_Tsunemoto | 0:568f6e865655 | 509 | NVIC_EnableIRQ(UART_IRQn); |
H_Tsunemoto | 0:568f6e865655 | 510 | while (((tx_in + 1) % ser_buffer_size) == tx_out) { |
H_Tsunemoto | 0:568f6e865655 | 511 | } |
H_Tsunemoto | 0:568f6e865655 | 512 | // Start Critical Section - don't interrupt while changing global buffer variables |
H_Tsunemoto | 0:568f6e865655 | 513 | NVIC_DisableIRQ(UART_IRQn); |
H_Tsunemoto | 0:568f6e865655 | 514 | } |
H_Tsunemoto | 0:568f6e865655 | 515 | tx_buffer[tx_in] = tx_line[i]; |
H_Tsunemoto | 0:568f6e865655 | 516 | i++; |
H_Tsunemoto | 0:568f6e865655 | 517 | tx_in = (tx_in + 1) % ser_buffer_size; |
H_Tsunemoto | 0:568f6e865655 | 518 | } |
H_Tsunemoto | 0:568f6e865655 | 519 | if (device.writeable() && (empty)) { |
H_Tsunemoto | 0:568f6e865655 | 520 | temp_char = tx_buffer[tx_out]; |
H_Tsunemoto | 0:568f6e865655 | 521 | tx_out = (tx_out + 1) % ser_buffer_size; |
H_Tsunemoto | 0:568f6e865655 | 522 | // Send first character to start tx interrupts, if stopped |
H_Tsunemoto | 0:568f6e865655 | 523 | device.putc(temp_char); |
H_Tsunemoto | 0:568f6e865655 | 524 | } |
H_Tsunemoto | 0:568f6e865655 | 525 | // End Critical Section |
H_Tsunemoto | 0:568f6e865655 | 526 | NVIC_EnableIRQ(UART_IRQn); |
H_Tsunemoto | 0:568f6e865655 | 527 | return; |
H_Tsunemoto | 0:568f6e865655 | 528 | } |
H_Tsunemoto | 0:568f6e865655 | 529 | |
H_Tsunemoto | 0:568f6e865655 | 530 | |
H_Tsunemoto | 0:568f6e865655 | 531 | // Read a line from the large rx buffer from rx interrupt routine |
H_Tsunemoto | 0:568f6e865655 | 532 | // 2013.08.08 H.Tsunemoto |
H_Tsunemoto | 0:568f6e865655 | 533 | // Append Return Chear Number |
H_Tsunemoto | 0:568f6e865655 | 534 | int read_line(){ |
H_Tsunemoto | 0:568f6e865655 | 535 | //void read_line() { |
H_Tsunemoto | 0:568f6e865655 | 536 | int i; |
H_Tsunemoto | 0:568f6e865655 | 537 | i = 0; |
H_Tsunemoto | 0:568f6e865655 | 538 | // Start Critical Section - don't interrupt while changing global buffer variables |
H_Tsunemoto | 0:568f6e865655 | 539 | NVIC_DisableIRQ(UART_IRQn); |
H_Tsunemoto | 0:568f6e865655 | 540 | while((rx_in != rx_out) && (rx_buffer[rx_out]<0x20)){ |
H_Tsunemoto | 0:568f6e865655 | 541 | rx_out = (rx_out + 1) % ser_buffer_size; |
H_Tsunemoto | 0:568f6e865655 | 542 | } |
H_Tsunemoto | 0:568f6e865655 | 543 | while(rx_in != rx_out){ |
H_Tsunemoto | 0:568f6e865655 | 544 | rx_line[i] = rx_buffer[rx_out]; |
H_Tsunemoto | 0:568f6e865655 | 545 | rx_out = (rx_out + 1) % ser_buffer_size; |
H_Tsunemoto | 0:568f6e865655 | 546 | if((rx_line[i] == '\r') || (rx_line[i] == '\n')){ |
H_Tsunemoto | 0:568f6e865655 | 547 | break; |
H_Tsunemoto | 0:568f6e865655 | 548 | } |
H_Tsunemoto | 0:568f6e865655 | 549 | i++; |
H_Tsunemoto | 0:568f6e865655 | 550 | |
H_Tsunemoto | 0:568f6e865655 | 551 | } |
H_Tsunemoto | 0:568f6e865655 | 552 | rx_line[i] = 0; |
H_Tsunemoto | 0:568f6e865655 | 553 | // End Critical Section |
H_Tsunemoto | 0:568f6e865655 | 554 | NVIC_EnableIRQ(UART_IRQn); |
H_Tsunemoto | 0:568f6e865655 | 555 | return(i); |
H_Tsunemoto | 0:568f6e865655 | 556 | } |
H_Tsunemoto | 0:568f6e865655 | 557 | // Interupt Routine to read in data from serial port |
H_Tsunemoto | 0:568f6e865655 | 558 | void Rx_interrupt() { |
H_Tsunemoto | 0:568f6e865655 | 559 | //led1=1; |
H_Tsunemoto | 0:568f6e865655 | 560 | // Loop just in case more than one character is in UART's receive FIFO buffer |
H_Tsunemoto | 0:568f6e865655 | 561 | // Stop if buffer full |
H_Tsunemoto | 0:568f6e865655 | 562 | while ((device.readable()) || (((rx_in + 1) % ser_buffer_size) == rx_out)) { |
H_Tsunemoto | 0:568f6e865655 | 563 | rx_buffer[rx_in] = device.getc(); |
H_Tsunemoto | 0:568f6e865655 | 564 | // Uncomment to Echo to USB serial to watch data flow |
H_Tsunemoto | 0:568f6e865655 | 565 | // monitor_device.putc(rx_buffer[rx_in]); |
H_Tsunemoto | 0:568f6e865655 | 566 | //------- 2013.08.08 Tsunemoto ------------// |
H_Tsunemoto | 0:568f6e865655 | 567 | // -- Char CR Rec Counter ----// |
H_Tsunemoto | 0:568f6e865655 | 568 | if(rx_buffer[rx_in]== '\r'){ |
H_Tsunemoto | 0:568f6e865655 | 569 | //led2 = 1; |
H_Tsunemoto | 0:568f6e865655 | 570 | rx_cr_Rec ++; |
H_Tsunemoto | 0:568f6e865655 | 571 | } |
H_Tsunemoto | 0:568f6e865655 | 572 | //----------------------------// |
H_Tsunemoto | 0:568f6e865655 | 573 | rx_in = (rx_in + 1) % ser_buffer_size; |
H_Tsunemoto | 0:568f6e865655 | 574 | } |
H_Tsunemoto | 0:568f6e865655 | 575 | //led1=0; |
H_Tsunemoto | 0:568f6e865655 | 576 | return; |
H_Tsunemoto | 0:568f6e865655 | 577 | } |
H_Tsunemoto | 0:568f6e865655 | 578 | |
H_Tsunemoto | 0:568f6e865655 | 579 | // Interupt Routine to write out data to serial port |
H_Tsunemoto | 0:568f6e865655 | 580 | void Tx_interrupt() { |
H_Tsunemoto | 0:568f6e865655 | 581 | //led2=1; |
H_Tsunemoto | 0:568f6e865655 | 582 | // Loop to fill more than one character in UART's transmit FIFO buffer |
H_Tsunemoto | 0:568f6e865655 | 583 | // Stop if buffer empty |
H_Tsunemoto | 0:568f6e865655 | 584 | while ((device.writeable()) && (tx_in != tx_out)) { |
H_Tsunemoto | 0:568f6e865655 | 585 | device.putc(tx_buffer[tx_out]); |
H_Tsunemoto | 0:568f6e865655 | 586 | tx_out = (tx_out + 1) % ser_buffer_size; |
H_Tsunemoto | 0:568f6e865655 | 587 | } |
H_Tsunemoto | 0:568f6e865655 | 588 | //led2=0; |
H_Tsunemoto | 0:568f6e865655 | 589 | return; |
H_Tsunemoto | 0:568f6e865655 | 590 | } |
H_Tsunemoto | 0:568f6e865655 | 591 | |
H_Tsunemoto | 0:568f6e865655 | 592 | //////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 593 | // 1msec Timer Interrupt |
H_Tsunemoto | 0:568f6e865655 | 594 | // |
H_Tsunemoto | 0:568f6e865655 | 595 | // 1msec Decrement Counter |
H_Tsunemoto | 0:568f6e865655 | 596 | //int i_ADC_IntCount =0; |
H_Tsunemoto | 0:568f6e865655 | 597 | //int i_ADC_Sample_Count=0; |
H_Tsunemoto | 0:568f6e865655 | 598 | //int i_Charge_Term_Count=0; |
H_Tsunemoto | 0:568f6e865655 | 599 | //int i_ChargeAfterDelayCount =0; |
H_Tsunemoto | 0:568f6e865655 | 600 | //int i_Charge_TermOverCount=0; |
H_Tsunemoto | 0:568f6e865655 | 601 | //int i_DisChargeTermCount =0; |
H_Tsunemoto | 0:568f6e865655 | 602 | |
H_Tsunemoto | 0:568f6e865655 | 603 | /////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 604 | void Tick_1mSec_Interrupt() |
H_Tsunemoto | 0:568f6e865655 | 605 | { |
H_Tsunemoto | 0:568f6e865655 | 606 | P36_Int1msec=1; |
H_Tsunemoto | 0:568f6e865655 | 607 | // Sampling Interval |
H_Tsunemoto | 0:568f6e865655 | 608 | if(i_ADC_IntCount >0){ |
H_Tsunemoto | 0:568f6e865655 | 609 | i_ADC_IntCount--; |
H_Tsunemoto | 0:568f6e865655 | 610 | } |
H_Tsunemoto | 0:568f6e865655 | 611 | // i_Charge_Term_Count |
H_Tsunemoto | 0:568f6e865655 | 612 | if(i_ChargeAfterDelayCount >0){ |
H_Tsunemoto | 0:568f6e865655 | 613 | i_ChargeAfterDelayCount--; |
H_Tsunemoto | 0:568f6e865655 | 614 | } |
H_Tsunemoto | 0:568f6e865655 | 615 | if(i_Charge_TermOverCount >0){ |
H_Tsunemoto | 0:568f6e865655 | 616 | i_Charge_TermOverCount--; |
H_Tsunemoto | 0:568f6e865655 | 617 | } |
H_Tsunemoto | 0:568f6e865655 | 618 | |
H_Tsunemoto | 0:568f6e865655 | 619 | // Discharge Term Counter |
H_Tsunemoto | 0:568f6e865655 | 620 | if(i_DisChargeTermCount >0){ |
H_Tsunemoto | 0:568f6e865655 | 621 | i_DisChargeTermCount--; |
H_Tsunemoto | 0:568f6e865655 | 622 | } |
H_Tsunemoto | 0:568f6e865655 | 623 | |
H_Tsunemoto | 0:568f6e865655 | 624 | timer_count++; //increment timer_count |
H_Tsunemoto | 0:568f6e865655 | 625 | if(timer_count >= 10000){ |
H_Tsunemoto | 0:568f6e865655 | 626 | timer_count = 0; |
H_Tsunemoto | 0:568f6e865655 | 627 | timer_1Sec++; |
H_Tsunemoto | 0:568f6e865655 | 628 | } |
H_Tsunemoto | 0:568f6e865655 | 629 | P36_Int1msec=0; |
H_Tsunemoto | 0:568f6e865655 | 630 | |
H_Tsunemoto | 0:568f6e865655 | 631 | } |
H_Tsunemoto | 0:568f6e865655 | 632 | |
H_Tsunemoto | 0:568f6e865655 | 633 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 634 | //------------ Command Check & Set Function ---------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 635 | // Input :i_RecCharCount :Command Stringth Length // |
H_Tsunemoto | 0:568f6e865655 | 636 | // rx_line[80] :(Global) Rec Data Stringth // |
H_Tsunemoto | 0:568f6e865655 | 637 | // Return :bool b_CommadERR 0= ACK // |
H_Tsunemoto | 0:568f6e865655 | 638 | // 1= ERR // |
H_Tsunemoto | 0:568f6e865655 | 639 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 640 | /* |
H_Tsunemoto | 0:568f6e865655 | 641 | //-------- DosimeterDock Parameter declaration --------// |
H_Tsunemoto | 0:568f6e865655 | 642 | typedef struct st_DosiDock_param{ |
H_Tsunemoto | 0:568f6e865655 | 643 | int i_P10PowerMode; // LPC11U24 P10PowerMode Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 644 | //0:GND 1:Vcc(Charge)(Digital High) 2:OFF(Open) |
H_Tsunemoto | 0:568f6e865655 | 645 | int i_P20ADC_Mode; // P20 ADC Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 646 | //0:P20_Open(No Measure) 1:P20_ADC 2:P20_ADC/Open AutoChange |
H_Tsunemoto | 0:568f6e865655 | 647 | float f_ChargeLimitVolt; // 「V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 648 | float f_ChargeLimitAfter_Delay; // [sec] Power Charge Delay しきい値を超えてからのDelay |
H_Tsunemoto | 0:568f6e865655 | 649 | float f_ChargeOver_Time; //[sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 650 | float f_DisCharge_Time; //「sec] Discharge Time |
H_Tsunemoto | 0:568f6e865655 | 651 | int i_SampleInterval_msec; // [msec] 測定周期 |
H_Tsunemoto | 0:568f6e865655 | 652 | int i_SampleTimes_MAX; // 測定回数 |
H_Tsunemoto | 0:568f6e865655 | 653 | }ST_DOSIDOCK_PARAM; |
H_Tsunemoto | 0:568f6e865655 | 654 | |
H_Tsunemoto | 0:568f6e865655 | 655 | ST_DOSIDOCK_PARAM st_dosimeterDock_param; |
H_Tsunemoto | 0:568f6e865655 | 656 | // Parameter Data Define |
H_Tsunemoto | 0:568f6e865655 | 657 | //i_P10PowerMode; // LPC11U24 P10PowerMode Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 658 | //0:GND 1:Vcc(Charge)(Digital High) 2:OFF(Open) |
H_Tsunemoto | 0:568f6e865655 | 659 | #define Def_P10Power_0_GND 0 |
H_Tsunemoto | 0:568f6e865655 | 660 | #define Def_P10Power_1_Vcc 1 |
H_Tsunemoto | 0:568f6e865655 | 661 | #define Def_P10Power_2_Open 2 |
H_Tsunemoto | 0:568f6e865655 | 662 | #define Def_P10Power_2_MAX Def_P10Power_2_Open |
H_Tsunemoto | 0:568f6e865655 | 663 | |
H_Tsunemoto | 0:568f6e865655 | 664 | #define Def_P20ADC_0_Open 0 |
H_Tsunemoto | 0:568f6e865655 | 665 | #define Def_P20ADC_1_ADC 1 |
H_Tsunemoto | 0:568f6e865655 | 666 | #define Def_P20ADC_2_AutoChange 2 |
H_Tsunemoto | 0:568f6e865655 | 667 | #define Def_P20ADC_2_MAX Def_P20ADC_2_AutoChange |
H_Tsunemoto | 0:568f6e865655 | 668 | |
H_Tsunemoto | 0:568f6e865655 | 669 | #define Def_CHARGE_Limit_VoltMIN 1.0f |
H_Tsunemoto | 0:568f6e865655 | 670 | #define Def_CHARGE_Limit_VoltMAX 3.4f |
H_Tsunemoto | 0:568f6e865655 | 671 | |
H_Tsunemoto | 0:568f6e865655 | 672 | #define Def_CHARGE_AfterDelay_MIN 0.0f |
H_Tsunemoto | 0:568f6e865655 | 673 | #define Def_CHARGE_AfterDelay_MAX 3600.0f // 1H |
H_Tsunemoto | 0:568f6e865655 | 674 | |
H_Tsunemoto | 0:568f6e865655 | 675 | #define Def_CHARGE_TIME_MIN 1.0f |
H_Tsunemoto | 0:568f6e865655 | 676 | #define Def_CHARGE_Time_MAX 3600.0f // 1H |
H_Tsunemoto | 0:568f6e865655 | 677 | |
H_Tsunemoto | 0:568f6e865655 | 678 | #define Def_SAMPLE_INTERVAL_MIN 10d // 10[msec] |
H_Tsunemoto | 0:568f6e865655 | 679 | #define Def_SAMPLE_INTERVAL_MAX 10000d // 10000[msec] |
H_Tsunemoto | 0:568f6e865655 | 680 | |
H_Tsunemoto | 0:568f6e865655 | 681 | */ |
H_Tsunemoto | 0:568f6e865655 | 682 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 683 | // Command No.1 "PW x" P10 PowerMode Pin Status Set // |
H_Tsunemoto | 0:568f6e865655 | 684 | //int st_dosimeterDock_param.i_P10PowerMode = 1; // P10PW Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 685 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 686 | bool com_Check_PW_P10Mode(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 687 | { |
H_Tsunemoto | 0:568f6e865655 | 688 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 689 | int i_num=0; |
H_Tsunemoto | 0:568f6e865655 | 690 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 691 | |
H_Tsunemoto | 0:568f6e865655 | 692 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 693 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 694 | } |
H_Tsunemoto | 0:568f6e865655 | 695 | else{ |
H_Tsunemoto | 0:568f6e865655 | 696 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 697 | i_num= atoi(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 698 | if((i_num >= 0 ) && (i_num <= Def_P10Power_2_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 699 | st_dosimeterDock_param.i_P10PowerMode = i_num; |
H_Tsunemoto | 0:568f6e865655 | 700 | P10_PWR_Pin_Setting(i_num); |
H_Tsunemoto | 0:568f6e865655 | 701 | } |
H_Tsunemoto | 0:568f6e865655 | 702 | else{ |
H_Tsunemoto | 0:568f6e865655 | 703 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 704 | } |
H_Tsunemoto | 0:568f6e865655 | 705 | |
H_Tsunemoto | 0:568f6e865655 | 706 | } |
H_Tsunemoto | 0:568f6e865655 | 707 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 708 | } |
H_Tsunemoto | 0:568f6e865655 | 709 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 710 | // Command No.2 "AD x" P20 ADC Pin Status Set // |
H_Tsunemoto | 0:568f6e865655 | 711 | //int st_dosimeterDock_param.i_P20ADC_Mode = 1; // P20 ADC Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 712 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 713 | bool com_Check_AD_P20Mode(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 714 | { |
H_Tsunemoto | 0:568f6e865655 | 715 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 716 | int i_num=0; |
H_Tsunemoto | 0:568f6e865655 | 717 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 718 | |
H_Tsunemoto | 0:568f6e865655 | 719 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 720 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 721 | } |
H_Tsunemoto | 0:568f6e865655 | 722 | else{ |
H_Tsunemoto | 0:568f6e865655 | 723 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 724 | i_num= atoi(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 725 | if((i_num >= 0 ) && (i_num <= Def_P20ADC_4_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 726 | st_dosimeterDock_param.i_P20ADC_Mode = i_num; |
H_Tsunemoto | 0:568f6e865655 | 727 | P20_ADC_Pin_Setting(i_num); |
H_Tsunemoto | 0:568f6e865655 | 728 | } |
H_Tsunemoto | 0:568f6e865655 | 729 | else{ |
H_Tsunemoto | 0:568f6e865655 | 730 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 731 | } |
H_Tsunemoto | 0:568f6e865655 | 732 | |
H_Tsunemoto | 0:568f6e865655 | 733 | } |
H_Tsunemoto | 0:568f6e865655 | 734 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 735 | } |
H_Tsunemoto | 0:568f6e865655 | 736 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 737 | // Command No.3 "LV xx.xx" [V] Power Charge Limit Volt Set // |
H_Tsunemoto | 0:568f6e865655 | 738 | //int st_dosimeterDock_param.f_ChargeLimitVolt = 3.2; // [V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 739 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 740 | bool com_Check_LV_PW_ChargeLimit_V(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 741 | { |
H_Tsunemoto | 0:568f6e865655 | 742 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 743 | float f_num=0.00f; |
H_Tsunemoto | 0:568f6e865655 | 744 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 745 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 746 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 747 | } |
H_Tsunemoto | 0:568f6e865655 | 748 | else{ |
H_Tsunemoto | 0:568f6e865655 | 749 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 750 | f_num = atof(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 751 | if((f_num >= Def_CHARGE_Limit_VoltMIN ) && (f_num <= Def_CHARGE_Limit_VoltMAX)){ |
H_Tsunemoto | 0:568f6e865655 | 752 | st_dosimeterDock_param.f_ChargeLimitVolt = ( f_num ) ; |
H_Tsunemoto | 0:568f6e865655 | 753 | } |
H_Tsunemoto | 0:568f6e865655 | 754 | else{ |
H_Tsunemoto | 0:568f6e865655 | 755 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 756 | } |
H_Tsunemoto | 0:568f6e865655 | 757 | } |
H_Tsunemoto | 0:568f6e865655 | 758 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 759 | } |
H_Tsunemoto | 0:568f6e865655 | 760 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 761 | // Command No.4 "LW xx.xx" [sec] Power Charge Delay しきい値を超えてからのDelay // |
H_Tsunemoto | 0:568f6e865655 | 762 | //int st_dosimeterDock_param.f_ChargeLimitAfter_Delay = 5.0; // [sec] Power Charge Delay |
H_Tsunemoto | 0:568f6e865655 | 763 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 764 | bool com_Check_LW_PW_ChargeAfterDelay(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 765 | { |
H_Tsunemoto | 0:568f6e865655 | 766 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 767 | float f_num=0.00f; |
H_Tsunemoto | 0:568f6e865655 | 768 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 769 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 770 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 771 | } |
H_Tsunemoto | 0:568f6e865655 | 772 | else{ |
H_Tsunemoto | 0:568f6e865655 | 773 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 774 | f_num = atof(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 775 | if((f_num >= Def_CHARGE_AfterDelay_MIN ) && (f_num <= Def_CHARGE_AfterDelay_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 776 | st_dosimeterDock_param.f_ChargeLimitAfter_Delay = ( f_num ) ; |
H_Tsunemoto | 0:568f6e865655 | 777 | } |
H_Tsunemoto | 0:568f6e865655 | 778 | else{ |
H_Tsunemoto | 0:568f6e865655 | 779 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 780 | } |
H_Tsunemoto | 0:568f6e865655 | 781 | } |
H_Tsunemoto | 0:568f6e865655 | 782 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 783 | } |
H_Tsunemoto | 0:568f6e865655 | 784 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 785 | // Command No.5 "LT xx.xx" [sec] Charge Time Max Set // |
H_Tsunemoto | 0:568f6e865655 | 786 | //int st_dosimeterDock_param.f_DisCharge_Time = 5.0; // [sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 787 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 788 | bool com_Check_LT_ChargeOverTime(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 789 | { |
H_Tsunemoto | 0:568f6e865655 | 790 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 791 | float f_num=0.00f; |
H_Tsunemoto | 0:568f6e865655 | 792 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 793 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 794 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 795 | } |
H_Tsunemoto | 0:568f6e865655 | 796 | else{ |
H_Tsunemoto | 0:568f6e865655 | 797 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 798 | f_num = atof(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 799 | if((f_num >= Def_CHARGE_TIME_MIN ) && (f_num <= Def_CHARGE_TIME_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 800 | st_dosimeterDock_param.f_ChargeOver_Time = ( f_num ) ; |
H_Tsunemoto | 0:568f6e865655 | 801 | } |
H_Tsunemoto | 0:568f6e865655 | 802 | else{ |
H_Tsunemoto | 0:568f6e865655 | 803 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 804 | } |
H_Tsunemoto | 0:568f6e865655 | 805 | } |
H_Tsunemoto | 0:568f6e865655 | 806 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 807 | } |
H_Tsunemoto | 0:568f6e865655 | 808 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 809 | // Command No.6 "LD xx.xx" [「sec] Discharge Time Set // |
H_Tsunemoto | 0:568f6e865655 | 810 | //int st_dosimeterDock_param.f_DisCharge_Time = 5.0; // 「sec] Discharge Time |
H_Tsunemoto | 0:568f6e865655 | 811 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 812 | bool com_Check_LD_PW_DisCharge_Time(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 813 | { |
H_Tsunemoto | 0:568f6e865655 | 814 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 815 | float f_num=0.00f; |
H_Tsunemoto | 0:568f6e865655 | 816 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 817 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 818 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 819 | } |
H_Tsunemoto | 0:568f6e865655 | 820 | else{ |
H_Tsunemoto | 0:568f6e865655 | 821 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 822 | f_num = atof(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 823 | if((f_num >= Def_CHARGE_TIME_MIN ) && (f_num <= Def_CHARGE_TIME_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 824 | st_dosimeterDock_param.f_DisCharge_Time = ( f_num ) ; |
H_Tsunemoto | 0:568f6e865655 | 825 | } |
H_Tsunemoto | 0:568f6e865655 | 826 | else{ |
H_Tsunemoto | 0:568f6e865655 | 827 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 828 | } |
H_Tsunemoto | 0:568f6e865655 | 829 | } |
H_Tsunemoto | 0:568f6e865655 | 830 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 831 | } |
H_Tsunemoto | 0:568f6e865655 | 832 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 833 | // Command No.7 "MT xxxx" [[msec] 測定周期 // |
H_Tsunemoto | 0:568f6e865655 | 834 | //int st_dosimeterDock_param.i_SampleInterval_msec = 100msec; // [msec] 測定周期 |
H_Tsunemoto | 0:568f6e865655 | 835 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 836 | bool com_Check_MT_Sampling_Time(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 837 | { |
H_Tsunemoto | 0:568f6e865655 | 838 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 839 | int i_num=0; |
H_Tsunemoto | 0:568f6e865655 | 840 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 841 | |
H_Tsunemoto | 0:568f6e865655 | 842 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 843 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 844 | } |
H_Tsunemoto | 0:568f6e865655 | 845 | else{ |
H_Tsunemoto | 0:568f6e865655 | 846 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 847 | i_num= atoi(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 848 | if((i_num > 0 ) && (i_num <= Def_SAMPLE_INTERVAL_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 849 | st_dosimeterDock_param.i_SampleInterval_msec = i_num; |
H_Tsunemoto | 0:568f6e865655 | 850 | } |
H_Tsunemoto | 0:568f6e865655 | 851 | else{ |
H_Tsunemoto | 0:568f6e865655 | 852 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 853 | } |
H_Tsunemoto | 0:568f6e865655 | 854 | |
H_Tsunemoto | 0:568f6e865655 | 855 | } |
H_Tsunemoto | 0:568f6e865655 | 856 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 857 | } |
H_Tsunemoto | 0:568f6e865655 | 858 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 859 | // Command No.8 "MN xxxx" [[Times] // 測定回数 // |
H_Tsunemoto | 0:568f6e865655 | 860 | //int st_dosimeterDock_param.i_SampleTimes_MAX = 5 Times; // [Times] // 測定回数 |
H_Tsunemoto | 0:568f6e865655 | 861 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 862 | bool com_Check_MN_Sample_CountTime(int i_RecCharCount) |
H_Tsunemoto | 0:568f6e865655 | 863 | { |
H_Tsunemoto | 0:568f6e865655 | 864 | bool b_CommadERR=0; |
H_Tsunemoto | 0:568f6e865655 | 865 | int i_num=0; |
H_Tsunemoto | 0:568f6e865655 | 866 | char *pt_comRec; |
H_Tsunemoto | 0:568f6e865655 | 867 | |
H_Tsunemoto | 0:568f6e865655 | 868 | if(i_RecCharCount < 3){ |
H_Tsunemoto | 0:568f6e865655 | 869 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 870 | } |
H_Tsunemoto | 0:568f6e865655 | 871 | else{ |
H_Tsunemoto | 0:568f6e865655 | 872 | pt_comRec = (char *)&rx_line[2]; |
H_Tsunemoto | 0:568f6e865655 | 873 | i_num= atoi(pt_comRec); |
H_Tsunemoto | 0:568f6e865655 | 874 | if((i_num > 0 ) && (i_num <= Def_SAMPLE_INTERVAL_MAX)){ |
H_Tsunemoto | 0:568f6e865655 | 875 | st_dosimeterDock_param.i_SampleTimes_MAX = i_num; |
H_Tsunemoto | 0:568f6e865655 | 876 | } |
H_Tsunemoto | 0:568f6e865655 | 877 | else{ |
H_Tsunemoto | 0:568f6e865655 | 878 | b_CommadERR = 1; |
H_Tsunemoto | 0:568f6e865655 | 879 | } |
H_Tsunemoto | 0:568f6e865655 | 880 | |
H_Tsunemoto | 0:568f6e865655 | 881 | } |
H_Tsunemoto | 0:568f6e865655 | 882 | return(b_CommadERR); |
H_Tsunemoto | 0:568f6e865655 | 883 | } |
H_Tsunemoto | 0:568f6e865655 | 884 | |
H_Tsunemoto | 0:568f6e865655 | 885 | |
H_Tsunemoto | 0:568f6e865655 | 886 | |
H_Tsunemoto | 0:568f6e865655 | 887 | //------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 888 | //----- Serial rx Commmand Input & Parameter Set Function -----// |
H_Tsunemoto | 0:568f6e865655 | 889 | // Tsunemoto Scince 2013.08.08 // |
H_Tsunemoto | 0:568f6e865655 | 890 | //------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 891 | void Ser_Command_Input() |
H_Tsunemoto | 0:568f6e865655 | 892 | { |
H_Tsunemoto | 0:568f6e865655 | 893 | int i_RecCharCount; |
H_Tsunemoto | 0:568f6e865655 | 894 | bool b_CommadERR = 0; |
H_Tsunemoto | 0:568f6e865655 | 895 | |
H_Tsunemoto | 0:568f6e865655 | 896 | // int i; |
H_Tsunemoto | 0:568f6e865655 | 897 | // while(rx_cr_Rec > 0){ |
H_Tsunemoto | 0:568f6e865655 | 898 | // Read a line from the large rx buffer from rx interrupt routine |
H_Tsunemoto | 0:568f6e865655 | 899 | i_RecCharCount = read_line(); |
H_Tsunemoto | 0:568f6e865655 | 900 | |
H_Tsunemoto | 0:568f6e865655 | 901 | if(i_RecCharCount >0) |
H_Tsunemoto | 0:568f6e865655 | 902 | { |
H_Tsunemoto | 0:568f6e865655 | 903 | switch (rx_line[0]){ |
H_Tsunemoto | 0:568f6e865655 | 904 | case 'P': |
H_Tsunemoto | 0:568f6e865655 | 905 | if(rx_line[1] == 'W'){ |
H_Tsunemoto | 0:568f6e865655 | 906 | com_Check_PW_P10Mode(i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 907 | } |
H_Tsunemoto | 0:568f6e865655 | 908 | break; |
H_Tsunemoto | 0:568f6e865655 | 909 | case 'A': |
H_Tsunemoto | 0:568f6e865655 | 910 | if(rx_line[1] == 'D'){ |
H_Tsunemoto | 0:568f6e865655 | 911 | com_Check_AD_P20Mode(i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 912 | } |
H_Tsunemoto | 0:568f6e865655 | 913 | break; |
H_Tsunemoto | 0:568f6e865655 | 914 | case 'L': |
H_Tsunemoto | 0:568f6e865655 | 915 | switch (rx_line[1]){ |
H_Tsunemoto | 0:568f6e865655 | 916 | case 'V': |
H_Tsunemoto | 0:568f6e865655 | 917 | com_Check_LV_PW_ChargeLimit_V( i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 918 | break; |
H_Tsunemoto | 0:568f6e865655 | 919 | case 'W': |
H_Tsunemoto | 0:568f6e865655 | 920 | com_Check_LW_PW_ChargeAfterDelay( i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 921 | break; |
H_Tsunemoto | 0:568f6e865655 | 922 | case 'T': |
H_Tsunemoto | 0:568f6e865655 | 923 | com_Check_LT_ChargeOverTime(i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 924 | break; |
H_Tsunemoto | 0:568f6e865655 | 925 | case 'D': |
H_Tsunemoto | 0:568f6e865655 | 926 | com_Check_LD_PW_DisCharge_Time(i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 927 | break; |
H_Tsunemoto | 0:568f6e865655 | 928 | default: |
H_Tsunemoto | 0:568f6e865655 | 929 | break; |
H_Tsunemoto | 0:568f6e865655 | 930 | } |
H_Tsunemoto | 0:568f6e865655 | 931 | break; |
H_Tsunemoto | 0:568f6e865655 | 932 | case 'M': |
H_Tsunemoto | 0:568f6e865655 | 933 | switch (rx_line[1]){ |
H_Tsunemoto | 0:568f6e865655 | 934 | case 'T': |
H_Tsunemoto | 0:568f6e865655 | 935 | com_Check_MT_Sampling_Time(i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 936 | break; |
H_Tsunemoto | 0:568f6e865655 | 937 | case 'N': |
H_Tsunemoto | 0:568f6e865655 | 938 | com_Check_MN_Sample_CountTime(i_RecCharCount); |
H_Tsunemoto | 0:568f6e865655 | 939 | break; |
H_Tsunemoto | 0:568f6e865655 | 940 | default: |
H_Tsunemoto | 0:568f6e865655 | 941 | break; |
H_Tsunemoto | 0:568f6e865655 | 942 | } |
H_Tsunemoto | 0:568f6e865655 | 943 | break; |
H_Tsunemoto | 0:568f6e865655 | 944 | case 'S': |
H_Tsunemoto | 0:568f6e865655 | 945 | switch (rx_line[1]){ |
H_Tsunemoto | 0:568f6e865655 | 946 | case 'M': |
H_Tsunemoto | 0:568f6e865655 | 947 | Start_SampleMeasure(); |
H_Tsunemoto | 0:568f6e865655 | 948 | break; |
H_Tsunemoto | 0:568f6e865655 | 949 | case 'C': |
H_Tsunemoto | 0:568f6e865655 | 950 | Start_ChargeMode(); |
H_Tsunemoto | 0:568f6e865655 | 951 | break; |
H_Tsunemoto | 0:568f6e865655 | 952 | case 'D': |
H_Tsunemoto | 0:568f6e865655 | 953 | Start_DisChargeMode(); |
H_Tsunemoto | 0:568f6e865655 | 954 | break; |
H_Tsunemoto | 0:568f6e865655 | 955 | default: |
H_Tsunemoto | 0:568f6e865655 | 956 | break; |
H_Tsunemoto | 0:568f6e865655 | 957 | } |
H_Tsunemoto | 0:568f6e865655 | 958 | break; |
H_Tsunemoto | 0:568f6e865655 | 959 | |
H_Tsunemoto | 0:568f6e865655 | 960 | case '?': |
H_Tsunemoto | 0:568f6e865655 | 961 | com_Stat_Table_Param_Send(); |
H_Tsunemoto | 0:568f6e865655 | 962 | ///////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 963 | // Iwate Pattern |
H_Tsunemoto | 0:568f6e865655 | 964 | break; |
H_Tsunemoto | 0:568f6e865655 | 965 | default: |
H_Tsunemoto | 0:568f6e865655 | 966 | break; |
H_Tsunemoto | 0:568f6e865655 | 967 | } |
H_Tsunemoto | 0:568f6e865655 | 968 | //} |
H_Tsunemoto | 0:568f6e865655 | 969 | } |
H_Tsunemoto | 0:568f6e865655 | 970 | |
H_Tsunemoto | 0:568f6e865655 | 971 | if(b_CommadERR == 0){ |
H_Tsunemoto | 0:568f6e865655 | 972 | sprintf(tx_line,"ACK%d \r\n",rx_cr_Rec); |
H_Tsunemoto | 0:568f6e865655 | 973 | // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:568f6e865655 | 974 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 975 | } |
H_Tsunemoto | 0:568f6e865655 | 976 | else{ |
H_Tsunemoto | 0:568f6e865655 | 977 | sprintf(tx_line,"ERR%d \r\n",rx_cr_Rec); |
H_Tsunemoto | 0:568f6e865655 | 978 | // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:568f6e865655 | 979 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 980 | } |
H_Tsunemoto | 0:568f6e865655 | 981 | |
H_Tsunemoto | 0:568f6e865655 | 982 | rx_cr_Rec--; |
H_Tsunemoto | 0:568f6e865655 | 983 | |
H_Tsunemoto | 0:568f6e865655 | 984 | // } |
H_Tsunemoto | 0:568f6e865655 | 985 | } |
H_Tsunemoto | 0:568f6e865655 | 986 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 987 | //------------ Command Check & Set Function ---------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 988 | // Input :i_RecCharCount :Command Stringth Length // |
H_Tsunemoto | 0:568f6e865655 | 989 | // rx_line[80] :(Global) Rec Data Stringth // |
H_Tsunemoto | 0:568f6e865655 | 990 | // Return :bool b_CommadERR 0= ACK // |
H_Tsunemoto | 0:568f6e865655 | 991 | // 1= ERR // |
H_Tsunemoto | 0:568f6e865655 | 992 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:568f6e865655 | 993 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 994 | // ADC No.5 "A?" DAC Parameter Repry // |
H_Tsunemoto | 0:568f6e865655 | 995 | //-------- DosimeterDock Parameter declaration --------// |
H_Tsunemoto | 0:568f6e865655 | 996 | //typedef struct st_DosiDock_param{ |
H_Tsunemoto | 0:568f6e865655 | 997 | // int i_P10PowerMode; // LPC11U24 P10PowerMode Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 998 | // //0:GND 1:Vcc(Charge)(Digital High) 2:OFF(Open) |
H_Tsunemoto | 0:568f6e865655 | 999 | // int i_P20ADC_Mode; // P20 ADC Pin Mode Set |
H_Tsunemoto | 0:568f6e865655 | 1000 | // //0:P20_Open(No Measure) 1:P20_ADC 2:P20_ADC/Open AutoChange |
H_Tsunemoto | 0:568f6e865655 | 1001 | // float f_ChargeLimitVolt; // 「V] Power Charge Limit Volt |
H_Tsunemoto | 0:568f6e865655 | 1002 | // float f_ChargeLimitAfter_Delay; // [sec] Power Charge Delay しきい値を超えてからのDelay |
H_Tsunemoto | 0:568f6e865655 | 1003 | // float f_ChargeOver_Time; //[sec] Charge Time Max |
H_Tsunemoto | 0:568f6e865655 | 1004 | // float f_DisCharge_Time; //「sec] Discharge Time |
H_Tsunemoto | 0:568f6e865655 | 1005 | // int i_SampleInterval_msec; // [msec] 測定周期 |
H_Tsunemoto | 0:568f6e865655 | 1006 | // int i_SampleTimes_MAX; // 測定回数 |
H_Tsunemoto | 0:568f6e865655 | 1007 | // }ST_DOSIDOCK_PARAM; |
H_Tsunemoto | 0:568f6e865655 | 1008 | // |
H_Tsunemoto | 0:568f6e865655 | 1009 | //ST_DOSIDOCK_PARAM st_dosimeterDock_param; |
H_Tsunemoto | 0:568f6e865655 | 1010 | // |
H_Tsunemoto | 0:568f6e865655 | 1011 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:568f6e865655 | 1012 | void com_Stat_Table_Param_Send() |
H_Tsunemoto | 0:568f6e865655 | 1013 | { |
H_Tsunemoto | 0:568f6e865655 | 1014 | float f_num; |
H_Tsunemoto | 0:568f6e865655 | 1015 | int i_num; |
H_Tsunemoto | 0:568f6e865655 | 1016 | |
H_Tsunemoto | 0:568f6e865655 | 1017 | sprintf(tx_line,"DosimeterDock MBED_LPC11U24 Ver0.95 \r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1018 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1019 | |
H_Tsunemoto | 0:568f6e865655 | 1020 | sprintf(tx_line,"?: Parameter & Status Request \r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1021 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1022 | |
H_Tsunemoto | 0:568f6e865655 | 1023 | f_num = ((float)st_dosimeterDock_param.f_ChargeLimitVolt ); |
H_Tsunemoto | 0:568f6e865655 | 1024 | sprintf(tx_line,"LV:Charge Volt Check Level =%2.3f[V]\r\n",f_num); |
H_Tsunemoto | 0:568f6e865655 | 1025 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1026 | f_num = ((float)st_dosimeterDock_param.f_ChargeLimitAfter_Delay ); |
H_Tsunemoto | 0:568f6e865655 | 1027 | sprintf(tx_line,"LW:Charge Delay Time after Charge =%4.2f[sec]\r\n",f_num); |
H_Tsunemoto | 0:568f6e865655 | 1028 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1029 | f_num = ((float)st_dosimeterDock_param.f_ChargeOver_Time ); |
H_Tsunemoto | 0:568f6e865655 | 1030 | sprintf(tx_line,"LT:Charge Time Limit Max =%4.2f[sec]\r\n",f_num); |
H_Tsunemoto | 0:568f6e865655 | 1031 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1032 | f_num = ((float)st_dosimeterDock_param.f_DisCharge_Time ); |
H_Tsunemoto | 0:568f6e865655 | 1033 | sprintf(tx_line,"LD:DisCharge Time Set =%4.2f[sec]\r\n",f_num); |
H_Tsunemoto | 0:568f6e865655 | 1034 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1035 | |
H_Tsunemoto | 0:568f6e865655 | 1036 | sprintf(tx_line,"Sample:\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1037 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1038 | |
H_Tsunemoto | 0:568f6e865655 | 1039 | i_num = ((int)st_dosimeterDock_param.i_SampleInterval_msec ); |
H_Tsunemoto | 0:568f6e865655 | 1040 | sprintf(tx_line,"MT:Sample Interval Time =%4d[msec]\r\n",i_num); |
H_Tsunemoto | 0:568f6e865655 | 1041 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1042 | i_num = ((int)st_dosimeterDock_param.i_SampleTimes_MAX ); |
H_Tsunemoto | 0:568f6e865655 | 1043 | sprintf(tx_line,"MN:Sample Count Time =%4d[Times]\r\n",i_num); |
H_Tsunemoto | 0:568f6e865655 | 1044 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1045 | |
H_Tsunemoto | 0:568f6e865655 | 1046 | sprintf(tx_line,"Pin Active Mode:\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1047 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1048 | if(st_dosimeterDock_param.i_P10PowerMode == 0){ |
H_Tsunemoto | 0:568f6e865655 | 1049 | sprintf(tx_line,"PW: P10 Power Pin : 0 GND\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1050 | } |
H_Tsunemoto | 0:568f6e865655 | 1051 | else if(st_dosimeterDock_param.i_P10PowerMode == 1){ |
H_Tsunemoto | 0:568f6e865655 | 1052 | sprintf(tx_line,"PW: P10 Power Pin : 1 Vcc(High)\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1053 | } |
H_Tsunemoto | 0:568f6e865655 | 1054 | else if(st_dosimeterDock_param.i_P10PowerMode == 2){ |
H_Tsunemoto | 0:568f6e865655 | 1055 | sprintf(tx_line,"PW: P10 Power Pin : 2 Open\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1056 | } |
H_Tsunemoto | 0:568f6e865655 | 1057 | else{ |
H_Tsunemoto | 0:568f6e865655 | 1058 | sprintf(tx_line,"PW: P10 Power Pin : ??\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1059 | } |
H_Tsunemoto | 0:568f6e865655 | 1060 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1061 | |
H_Tsunemoto | 0:568f6e865655 | 1062 | if(st_dosimeterDock_param.i_P20ADC_Mode == 0){ |
H_Tsunemoto | 0:568f6e865655 | 1063 | sprintf(tx_line,"AD: P20 ADC Inp Pin : 0 Open No Measure\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1064 | } |
H_Tsunemoto | 0:568f6e865655 | 1065 | else if(st_dosimeterDock_param.i_P20ADC_Mode == 1){ |
H_Tsunemoto | 0:568f6e865655 | 1066 | sprintf(tx_line,"AD: P20 ADC Inp Pin : 1 ADC Input\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1067 | } |
H_Tsunemoto | 0:568f6e865655 | 1068 | else if(st_dosimeterDock_param.i_P20ADC_Mode == 2){ |
H_Tsunemoto | 0:568f6e865655 | 1069 | sprintf(tx_line,"AD: P20 ADC Inp Pin : 2 ADC/Open Change\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1070 | } |
H_Tsunemoto | 0:568f6e865655 | 1071 | else if(st_dosimeterDock_param.i_P20ADC_Mode == 3){ |
H_Tsunemoto | 0:568f6e865655 | 1072 | sprintf(tx_line,"AD: P20 ADC Inp Pin : 3 GND(Test)\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1073 | } |
H_Tsunemoto | 0:568f6e865655 | 1074 | else if(st_dosimeterDock_param.i_P20ADC_Mode == 4){ |
H_Tsunemoto | 0:568f6e865655 | 1075 | sprintf(tx_line,"AD: P20 ADC Inp Pin : 4 High(Test)\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1076 | } |
H_Tsunemoto | 0:568f6e865655 | 1077 | else{ |
H_Tsunemoto | 0:568f6e865655 | 1078 | sprintf(tx_line,"AD: P20 ADC Inp Pin : ???\r\n"); |
H_Tsunemoto | 0:568f6e865655 | 1079 | } |
H_Tsunemoto | 0:568f6e865655 | 1080 | send_line(); |
H_Tsunemoto | 0:568f6e865655 | 1081 | |
H_Tsunemoto | 0:568f6e865655 | 1082 | } |
H_Tsunemoto | 0:568f6e865655 | 1083 |