Skip to content

Commit

Permalink
Added aircon mode and time setting to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
papawattu committed Jun 2, 2020
1 parent e5ca716 commit 7cdf85a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
10 changes: 8 additions & 2 deletions include/phevargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
#define HEADLIGHTS "headlights"
#define BATTERY "battery"
#define AIRCON "aircon"
#define AIRCON_MODE "acmode"
#define REGISTER "register"
#define MONITOR "monitor"
#define GET "get"
#define ON "on"
#define OFF "off"
#define HEAT "heat"
#define COOL "cool"
#define WINDSCREEN "windscreen"
#define WAIT_FOR_REG_MAX 40

typedef enum phev_args_commands_t { CMD_UNSET, CMD_INVALID, CMD_STATUS, CMD_REGISTER, CMD_HEADLIGHTS, CMD_BATTERY, CMD_AIRCON, CMD_GET_REG_VAL, CMD_DISPLAY_REG } phev_args_commands_t;
typedef enum phev_args_commands_t { CMD_UNSET, CMD_INVALID, CMD_STATUS, CMD_REGISTER, CMD_HEADLIGHTS, CMD_BATTERY, CMD_AIRCON, CMD_AIRCON_MODE, CMD_GET_REG_VAL, CMD_DISPLAY_REG } phev_args_commands_t;

typedef struct phev_args_opts_t {
bool init;
Expand All @@ -32,6 +36,8 @@ typedef struct phev_args_opts_t {
char * command_topic;
bool verbose;
bool operand_on;
uint8_t operand_mode;
uint8_t operand_time;
uint8_t reg_operand;
bool error;
char * error_message;
Expand All @@ -44,7 +50,7 @@ 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]\nheadlights [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]\nmonitor\nget <register>";
static struct argp_option phev_args_options[] = {
{ "mac", 'm', "<MAC ADDRESS>",0, "MAC address."},
{ "host", 'h', "<HOST NAME>",OPTION_HIDDEN, "IP address of car - defaults to 192.168.8.46."},
Expand Down
6 changes: 6 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ static int main_eventHandler(phevEvent_t *event)
phev_airCon(event->ctx, opts->operand_on, operationCallback);
break;
}
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;
}
}
}
return 0;
Expand Down
68 changes: 67 additions & 1 deletion src/phevargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ int phev_args_validate(int arg_num,phev_args_opts_t * opts)
}
break;
}
case CMD_AIRCON_MODE:
{
if(arg_num == 3)
{
return 0;
}
break;
}
case CMD_REGISTER:
{
if(arg_num == 1)
Expand All @@ -40,6 +48,8 @@ int phev_args_validate(int arg_num,phev_args_opts_t * opts)
break;
}
}
opts->error_message = "Incorrect number of operands";
opts->error = true;
return 1;
}
int phev_args_process_operands(char * arg, int arg_num, phev_args_opts_t * opts)
Expand Down Expand Up @@ -74,11 +84,61 @@ 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_MODE:
{
if(arg_num == 1)
{
if(strcmp(arg,HEAT) == 0)
{
opts->operand_mode = 2;
break;
}
if(strcmp(arg,COOL) == 0)
{
opts->operand_mode = 1;
break;
}
if(strcmp(arg,WINDSCREEN) == 0)
{
opts->operand_mode = 3;
break;
}
opts->error = true;
opts->error_message = "Unrecognised operand";
break;
}

if(arg_num == 2)
{
if(strlen(arg) == 2 && isdigit(arg[0]) && isdigit(arg[1]))
{
opts->operand_time = atoi(arg);

if(opts->operand_time != 10 &&
opts->operand_time != 20 &&
opts->operand_time != 30
)
{
opts->error = true;
opts->error_message = "Unrecognised operand";
break;
}
}
else
{
opts->error = true;
opts->error_message = "Unrecognised operand";
}
}
break;
}
case CMD_GET_REG_VAL: {
if(strlen(arg) == 2 && isdigit(arg[0]) && isdigit(arg[1]) && arg_num == 1)
{
opts->reg_operand = atoi(arg);
} else {
}
else
{
opts->error = true;
opts->error_message = "Not a number";
}
Expand Down Expand Up @@ -121,6 +181,10 @@ int phev_args_process_command(char * arg, int arg_num, phev_args_opts_t * opts)
{
opts->command = CMD_DISPLAY_REG;
}
if(strcmp(arg,AIRCON_MODE) == 0 && arg_num == 0)
{
opts->command = CMD_AIRCON_MODE;
}
return 0;
}
static error_t phev_args_parse_opt(int key, char *arg, struct argp_state *state) {
Expand Down Expand Up @@ -193,11 +257,13 @@ static error_t phev_args_parse_opt(int key, char *arg, struct argp_state *state)
if(opts->error)
{
opts->command = CMD_INVALID;
printf("\nERROR : %s\n",opts->error_message);
argp_usage(state);
}
if(phev_args_validate(state->arg_num,opts))
{
opts->command = CMD_INVALID;
printf("\nERROR : %s\n",opts->error_message);
argp_usage(state);
}
break;
Expand Down

0 comments on commit 7cdf85a

Please sign in to comment.