Skip to content

Commit

Permalink
added car-model parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
vzakharchenko committed Mar 4, 2021
1 parent 8438030 commit 5d877c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions include/phevargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#define BATTERY "battery"
#define AIRCON "aircon"
#define AIRCON_MODE "acmode"
#define AIRCON_MY19 "airconmode"
#define REGISTER "register"
#define MONITOR "monitor"
#define GET "get"
Expand All @@ -37,7 +36,6 @@ typedef enum phev_args_commands_t {
CMD_BATTERY,
CMD_AIRCON,
CMD_AIRCON_MODE,
CMD_AIRCON_MY19,
CMD_GET_REG_VAL,
CMD_DISPLAY_REG,
} phev_args_commands_t;
Expand All @@ -51,6 +49,7 @@ typedef struct phev_args_opts_t {
char * topic;
char * command_topic;
bool verbose;
int carModel;
bool operand_on;
uint8_t operand_mode;
uint8_t operand_time;
Expand All @@ -66,9 +65,10 @@ static uint8_t PHEV_ARGS_DEFAULT_MAC[] = {0,0,0,0,0,0};
static const char * phev_args_argp_program_version = "Version\t" VERSION;
static const char * phev_args_argp_program_bug_address = "[email protected]";
static char phev_args_doc[] = "\n\nProgram to control the car via the remote WiFi interface. Requires this device to be connected to the REMOTE**** access point with a valid IP address, which is on the 192.168.8.x subnet.\n\nTHIS PROGRAM COMES WITH NO WARRANTY ANY DAMAGE TO THE CAR OR ANY OTHER EQUIPMENT IS AT THE USERS OWN RISK.";
static char phev_args_args_doc[] = "register\nbattery\naircon [on|off]\nacmode [heat|cool|windscreen] [10|20|30]\nairconmode [heat|cool|windscreen] [10|20|30]\nheadlights [on|off]\nparkinglights [on|off]\nmonitor\nget <register>";
static char phev_args_args_doc[] = "register\nbattery\naircon [on|off]\nacmode [heat|cool|windscreen] [10|20|30]\nheadlights [on|off]\nparkinglights [on|off]\nmonitor\nget <register>";
static struct argp_option phev_args_options[] = {
{ "mac", 'm', "<MAC ADDRESS>",0, "MAC address."},
{ "car-model", 'c', "<YEAR>",0, "Model Year."},
{ "host", 'h', "<HOST NAME>",OPTION_HIDDEN, "IP address of car - defaults to 192.168.8.46."},
{ "port", 'p', "<PORT NUMBER>",OPTION_HIDDEN, "Port to use - defaults to 8080"},
{ "verbose",'v',0,0,"Verbose output"},
Expand Down
17 changes: 10 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,16 @@ static int main_eventHandler(phevEvent_t *event)
case CMD_AIRCON_MODE:
{
printf("Switching air conditioning mode to %d for %d mins\n", opts->operand_mode, opts->operand_time);
phev_airConMode(event->ctx, opts->operand_mode, opts->operand_time, operationCallback);
break;
}
case CMD_AIRCON_MY19:
{
printf("Switching air conditioning mode to %d for %d mins\n", opts->operand_mode, opts->operand_time);
phev_airConMY19(event->ctx, opts->operand_mode, opts->operand_time, operationCallback);
if (opts->verbose)
{
printf("Car Model: %d\n", opts->carModel);
}
if ( opts->carModel == 2019){
phev_airConMY19(event->ctx, opts->operand_mode, opts->operand_time, operationCallback);
} else {
phev_airConMode(event->ctx, opts->operand_mode, opts->operand_time, operationCallback);
}

break;
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/phevargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ int phev_args_validate(int arg_num,phev_args_opts_t * opts)
}
break;
}
case CMD_AIRCON_MY19:
{
if(arg_num == 3)
{
return 0;
}
break;
}
case CMD_REGISTER:
{
if(arg_num == 1)
Expand Down Expand Up @@ -102,7 +94,6 @@ int phev_args_process_operands(char * arg, int arg_num, phev_args_opts_t * opts)
opts->error_message = "Too many operands";
break;
}
case CMD_AIRCON_MY19:
case CMD_AIRCON_MODE:
{
if(arg_num == 1)
Expand Down Expand Up @@ -193,10 +184,6 @@ int phev_args_process_command(char * arg, int arg_num, phev_args_opts_t * opts)
{
opts->command = CMD_AIRCON;
}
if(strcmp(arg,AIRCON_MY19) == 0 && arg_num == 0)
{
opts->command = CMD_AIRCON_MY19;
}
if(strcmp(arg,GET) == 0 && arg_num == 0)
{
opts->command = CMD_GET_REG_VAL;
Expand Down Expand Up @@ -276,6 +263,10 @@ static error_t phev_args_parse_opt(int key, char *arg, struct argp_state *state)
opts->verbose = true;
break;
}
case 'c': {
opts->carModel = atoi(arg);
break;
}
case ARGP_KEY_END:
{
if(opts->error)
Expand Down

0 comments on commit 5d877c0

Please sign in to comment.