Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BufferedSerial Servo2 PCT2075 I2CEeprom FastPWM
Diff: cli.cpp
- Revision:
- 1:450090bdb6f4
- Parent:
- 0:77803b3ee157
- Child:
- 2:8e7b51353f32
--- a/cli.cpp Fri Jun 28 19:32:51 2019 +0000 +++ b/cli.cpp Sat Apr 25 15:35:58 2020 +0000 @@ -10,29 +10,30 @@ #include <cctype> using namespace std; -extern eeprom_settings mode ; +extern eeprom_settings user_settings ; //eeprom_settings mode ; -extern int ver, vef, measured_pw_us; +//extern int ver, vef, measured_pw_us; +extern void set_throttle_limit (struct parameters & a) ; +extern void speed_control_factor_set (struct parameters & a) ; +extern void query_system (struct parameters & a) ; extern uint32_t ReadEngineRPM () ; extern double Read_BatteryVolts () ; +extern void Read_Ammeter (double *) ; -const int MAX_PARAMS = 10; -struct parameters { - int32_t times[50]; - int32_t position_in_list, last_time, numof_dbls; - double dbl[MAX_PARAMS]; -} ; - // WithOUT RTOS //extern BufferedSerial pc; + +#ifdef TARGET_NUCLEO_L432KC // extern Serial pc; -//extern BufferedSerial pc; -extern double test_pot; // These used in knifeandfork code testing only +#else +extern BufferedSerial pc; +#endif +//extern double test_pot; // These used in knifeandfork code testing only //extern int numof_eeprom_options2 ; //extern struct optpar const option_list2[] ; @@ -46,6 +47,7 @@ */ void mode19_cmd (struct parameters & a) // With no params, reads eeprom contents. With params sets eeprom contents { + char temps[36]; int i; pc.printf ("\r\nmode - Set system data in EEPROM - Jan 2019\r\nSyntax 'mode' with no parameters lists current state.\r\n"); @@ -59,17 +61,17 @@ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: if (temps[1] >= option_list2[i].min && temps[1] <= option_list2[i].max) - mode.wr(temps[1], RPM0 + i); + user_settings.wr(temps[1], RPM0 + i); break; case 37: // set pwm scale factor if (temps[1] >= option_list2[PWM_SCALE].min && temps[1] <= option_list2[PWM_SCALE].max) - mode.wr(temps[1], PWM_SCALE); + user_settings.wr(temps[1], PWM_SCALE); break; case 83: // set to defaults - mode.set_defaults (); + user_settings.set_defaults (); break; case 9: // 9 Save settings - mode.save (); + user_settings.save (); pc.printf ("Saving settings to EEPROM\r\n"); break; default: @@ -79,31 +81,32 @@ else { pc.printf ("No Changes\r\n"); } - pc.printf ("mode 0\t%s, [%d]\r\n", option_list2[0].t, mode.rd(RPM0)); - pc.printf ("mode 1\t%s, [%d]\r\n", option_list2[1].t, mode.rd(RPM1)); - pc.printf ("mode 2\t%s, [%d]\r\n", option_list2[2].t, mode.rd(RPM2)); - pc.printf ("mode 3\t%s, [%d]\r\n", option_list2[3].t, mode.rd(RPM3)); - pc.printf ("mode 4\t%s, [%d]\r\n", option_list2[4].t, mode.rd(RPM4)); - pc.printf ("mode 5\t%s, [%d]\r\n", option_list2[5].t, mode.rd(RPM5)); - pc.printf ("mode 6\t%s, [%d]\r\n", option_list2[6].t, mode.rd(RPM6)); - pc.printf ("mode 7\t%s, [%d]\r\n", option_list2[7].t, mode.rd(RPM7)); - pc.printf ("mode 8\t%s, [%d]\r\n", option_list2[8].t, mode.rd(RPM8)); + pc.printf ("mode 0\t%s, [%d]\r\n", option_list2[0].t, user_settings.rd(RPM0)); + pc.printf ("mode 1\t%s, [%d]\r\n", option_list2[1].t, user_settings.rd(RPM1)); + pc.printf ("mode 2\t%s, [%d]\r\n", option_list2[2].t, user_settings.rd(RPM2)); + pc.printf ("mode 3\t%s, [%d]\r\n", option_list2[3].t, user_settings.rd(RPM3)); + pc.printf ("mode 4\t%s, [%d]\r\n", option_list2[4].t, user_settings.rd(RPM4)); + pc.printf ("mode 5\t%s, [%d]\r\n", option_list2[5].t, user_settings.rd(RPM5)); + pc.printf ("mode 6\t%s, [%d]\r\n", option_list2[6].t, user_settings.rd(RPM6)); + pc.printf ("mode 7\t%s, [%d]\r\n", option_list2[7].t, user_settings.rd(RPM7)); + pc.printf ("mode 8\t%s, [%d]\r\n", option_list2[8].t, user_settings.rd(RPM8)); - pc.printf ("mode 37\t%s, [%d]\r\n", option_list2[PWM_SCALE].t, mode.rd(PWM_SCALE)); + pc.printf ("mode 37\t%s, [%d]\r\n", option_list2[PWM_SCALE].t, user_settings.rd(PWM_SCALE)); pc.printf ("mode 83\tSet to defaults\r\n"); pc.printf ("mode 9\tSave settings\r\r\n"); } void gpcmd (struct parameters & a) { - pc.printf ("pwm=%d\r\n", mode.get_pwm ((int)a.dbl[0])); + pc.printf ("pwm=%.3f\r\n", user_settings.get_pwm ((int)a.dbl[0])); } +extern VEXT_Data Field; + void rfcmd (struct parameters & a) { - pc.printf ("ver = %d, vef = %d, measured_pw_us = %d\r\n", ver, vef, measured_pw_us); + pc.printf ("Field.measured_period = %d, Field.measured_pw_us = %d, duty_cycle = %.3f\r\n", Field.measured_period, Field.measured_pw_us, Field.duty_cycle()); } -extern double glob_rpm; extern void set_RPM_demand (uint32_t d) ; void set_rpm_cmd (struct parameters & a) { @@ -113,13 +116,20 @@ void speedcmd (struct parameters & a) { int s = ReadEngineRPM (); - pc.printf ("speed %d, %.2f, pwm %d\r\n", s, glob_rpm, mode.get_pwm(s)); + pc.printf ("speed %d, pwm %.3f\r\n", s, user_settings.get_pwm(s)); } void vcmd (struct parameters & a) { pc.printf ("volts %.2f\r\n", Read_BatteryVolts()); } +void icmd (struct parameters & a) { + double results[4]; + //double * ampsptr = + Read_Ammeter(results) ; + pc.printf ("amps %.3f, offset %.3f\r\n", results[0], results[1]); +} + extern void set_servo (double p) ; // Only for test, called from cli void set_servo_cmd (struct parameters & a) { @@ -128,6 +138,13 @@ set_servo (p); } +extern bool set_pwm (double) ; // Range 0.0 to 1.0 +void p_cmd (struct parameters & a) { +// int32_t i = (int32_t)a.dbl[0]; + pc.printf ("Setting PWM to %d percent\r\n", (int)(a.dbl[0] * 100.0)); + set_pwm (a.dbl[0]); +} + void null_cmd (struct parameters & a) { pc.printf ("At null_cmd, parameters : First %.3f, second %.3f\r\n", a.dbl[0], a.dbl[1]); } @@ -142,21 +159,27 @@ struct kb_command const command_list[] = { {"?", "Lists available commands, same as ls", menucmd}, - {"ls", "Lists available commands, same as menu", menucmd}, {"rf", "Check rise and fall on VEXT", rfcmd}, {"s", "Speed, RPM", speedcmd}, {"v", "Read Battery volts", vcmd}, + {"i", "Read Ammeter", icmd}, + {"p", "Set PWM 0 to 2400???", p_cmd}, + {"q", "Query system - toggle message stream on/off", query_system}, {"gp","Get pwm from RPM", gpcmd}, {"mode", "See or set eeprom values", mode19_cmd}, {"nu", "do nothing", null_cmd}, +#ifndef SPEED_CONTROL_ENABLE // Includes engine revs servo control loop {"ser","set throttle servo direct 0 - 99", set_servo_cmd}, - {"sv","set engine RPM demand 3000 - 6000", set_rpm_cmd}, +#endif + {"sf","set speed control factor", speed_control_factor_set}, + {"sv","set engine RPM demand 2500 - 6000", set_rpm_cmd}, + {"tl","set throttle_limit 0.0-1.0", set_throttle_limit}, }; const int numof_menu_items = sizeof(command_list) / sizeof(kb_command); void menucmd (struct parameters & a) { - pc.printf("\r\nIntelligent Alternator Controller - Jon Freeman 2019\r\nAt menucmd function - listing commands:-\r\n"); + pc.printf("\r\nIntelligent Alternator Controller - Jon Freeman 2020\r\nAt menucmd function - listing commands:-\r\n"); for(int i = 0; i < numof_menu_items; i++) pc.printf("[%s]\t\t%s\r\n", command_list[i].cmd_word, command_list[i].explan); pc.printf("End of List of Commands\r\n"); @@ -164,6 +187,7 @@ void command_line_interpreter () { + const int MAX_CMD_LEN = 120; static char cmd_line[MAX_CMD_LEN + 4]; static int cl_index = 0; @@ -221,6 +245,7 @@ cl_index = 0; } // End of else key was CR, may or may not be command to lookup } // End of while (pc.readable()) + }