Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Sep 23, 2017
1 parent dd79dad commit fb26b8a
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 177 deletions.
46 changes: 0 additions & 46 deletions burba/apps/hello-mqtt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,52 +65,6 @@ uint32_t handle_command(uint8_t type, Command *command) {
return sts;
}

int8_t proto_input_handler(channel_reader_t *rd, proto_msg_t command_id,
void *obj) {

proto_msg_t ack_type = {ACK_TYPE, 1};
ack_type.dline = command_id.dline;

Ack ack = ACK__INIT;

ack.id = command_id.type;

DEBUG("executing [%d,%d] message\n", command_id.type, command_id.subtype);

switch (command_id.type) {
case COMMAND_TYPE: {
Command *cmd = (Command *)obj;
printf("command: %ld, seq: %ld\n", cmd->id, cmd->seq);
bocia_command(rd, cmd);
break;
}
case SECRET_TYPE: {
Secret *secret = (Secret *)obj;
set_ap_password(secret->key);
cc3200_reset();
break;
}
case CONFIG_TYPE: {
bocia_set_cfg((Config *)obj);
rd->send(rd, ack_type, &ack);
break;
}
case PROFILE_TYPE: {
Profile *profile;
profile = (Profile *)obj;
DEBUG("ssid: %s - pwd: %s\n", profile->uid, profile->pwd);
sbapp_add_profile(profile->uid, profile->pwd);
rd->send(rd, ack_type, &ack);
break;
}
default:
DEBUG("custom command [%d]\n", command_id.type);
ack.status = handle_command(command_id.type, (Command *)obj);
ack.has_status = 1;
rd->send(rd, ack_type, &ack);
}
return INPUTHANDLER_OK;
}

void client_handler(void) {
Config *cfg;
Expand Down
242 changes: 141 additions & 101 deletions burba/sys/bocia/bocia.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@

#include "bocia.h"

#define ENABLE_DEBUG (1)
#define ENABLE_DEBUG (1)
#include "debug.h"

/**
* @brief return the channels list
*/
channel_reader_t *channels(void);


uint8_t broker_is_connected(void);

void broker_disconnect(kernel_pid_t board_io_pid);


/**
* @brief set how the board will reboot
*
Expand Down Expand Up @@ -91,145 +89,187 @@ int16_t mqtt_receive(int16_t* fd, unsigned char** packet);

static Config *config = 0;

int8_t proto_input_handler(channel_reader_t *rd, proto_msg_t command_id,
void *obj) {

proto_msg_t ack_type = {ACK_TYPE, 1};
ack_type.dline = command_id.dline;

Ack ack = ACK__INIT;

ack.id = command_id.type;

DEBUG("executing [%d,%d] message\n", command_id.type, command_id.subtype);

switch (command_id.type) {
case COMMAND_TYPE: {
Command *cmd = (Command *)obj;
printf("command: %ld, seq: %ld\n", cmd->id, cmd->seq);
bocia_command(rd, cmd);
break;
}
case SECRET_TYPE: {
Secret *secret = (Secret *)obj;
set_ap_password(secret->key);
cc3200_reset();
break;
}
case CONFIG_TYPE: {
bocia_set_cfg((Config *)obj);
rd->send(rd, ack_type, &ack);
break;
}
case PROFILE_TYPE: {
Profile *profile;
profile = (Profile *)obj;
DEBUG("ssid: %s - pwd: %s\n", profile->uid, profile->pwd);
sbapp_add_profile(profile->uid, profile->pwd);
rd->send(rd, ack_type, &ack);
break;
}
default:
DEBUG("custom command [%d]\n", command_id.type);
ack.status = handle_command(command_id.type, (Command *)obj);
ack.has_status = 1;
rd->send(rd, ack_type, &ack);
}
return INPUTHANDLER_OK;
}

uint8_t bocia_remote_console(void) {
channel_reader_t *channel;
channel_reader_t *channel;

channel = channels();
channel = channels();

for (uint8_t i = 0; i < SBAPP_SOCKETS; i++) {
if (channel->debug == 1) {
return 1;
}
}
return 0;
for (uint8_t i = 0; i < SBAPP_SOCKETS; i++) {
if (channel->debug == 1) {
return 1;
}
}
return 0;
}

_ssize_t bocia_remote_write(const void *data, size_t count) {
channel_reader_t *channel;
channel = channels();
channel_reader_t *channel;
channel = channels();

for (uint8_t i = 0; i < SBAPP_SOCKETS; i++) {
if (channel->debug == 1) {
sl_Send(channel->fd, data, count, 0);
}
channel++;
}
for (uint8_t i = 0; i < SBAPP_SOCKETS; i++) {
if (channel->debug == 1) {
sl_Send(channel->fd, data, count, 0);
}
channel++;
}

return count;
return count;
}

void bocia_broadcast(proto_msg_t type, void *data) {
channel_reader_t *channel;
channel = channels();

for (uint8_t i = 0; i < SBAPP_SOCKETS; i++) {
if (channel->send) {
channel->send(channel, type, data);
}
channel++;
}
channel_reader_t *channel;
channel = channels();

for (uint8_t i = 0; i < SBAPP_SOCKETS; i++) {
if (channel->send) {
channel->send(channel, type, data);
}
channel++;
}
}

int8_t bocia_unmarshall(channel_reader_t *rd, unsigned char *data,
int8_t (*handler)(channel_reader_t *, proto_msg_t, void *)) {
void *obj;
proto_msg_t ptype;
int8_t sts;
int8_t (*handler)(channel_reader_t *, proto_msg_t,
void *)) {
void *obj;
proto_msg_t ptype;
int8_t sts;

ptype = nais_unmarshall(data, &obj);
ptype = nais_unmarshall(data, &obj);

if (ptype.subtype & (1 << DEBUG_OPTION_BIT)) {
rd->debug = 1;
}
if (ptype.subtype & (1 << DEBUG_OPTION_BIT)) {
rd->debug = 1;
}

// reuse type slot for status reporting
sts = handler(rd, ptype, obj);
sts = handler(rd, ptype, obj);

nais_free(obj);
nais_free(obj);

return sts;
return sts;
}

void set_reboot_mode(int mode) {
if (mode == 1) {
DEBUG("reset to factory state\n");
simplelink_to_default_state();
bocia_delete_file(BOCIA_CFG_FILE);
PRCMOCRRegisterWrite(0, 0);
} else {
PRCMOCRRegisterWrite(0, 1);
}
if (mode == 1) {
DEBUG("reset to factory state\n");
simplelink_to_default_state();
bocia_delete_file(BOCIA_CFG_FILE);
PRCMOCRRegisterWrite(0, 0);
} else {
PRCMOCRRegisterWrite(0, 1);
}
}



void bocia_set_cfg(Config *new_config) {
if (config) {
nais_free(config);
}
bocia_write_cfg(new_config);
config = new_config;
if (config) {
nais_free(config);
}
bocia_write_cfg(new_config);
config = new_config;
}

Config *bocia_get_config(void) {
if (config) {
return config;
}
config = bocia_read_cfg();
return config;
if (config) {
return config;
}
config = bocia_read_cfg();
return config;
}

Config *bocia_toggle_board_mode(void) {

int16_t nprofiles;
int16_t nprofiles;

nprofiles = sbapp_get_profiles();
nprofiles = sbapp_get_profiles();

// check if provisioned
config = bocia_get_config();
if (config && (nwp.role == ROLE_AP) && nprofiles > 0) {
sbapp_set_mode(ROLE_STA);
} else if ((config == 0) && (nwp.role == ROLE_STA)) {
sbapp_set_mode(ROLE_AP);
}
// check if provisioned
config = bocia_get_config();
if (config && (nwp.role == ROLE_AP) && nprofiles > 0) {
sbapp_set_mode(ROLE_STA);
} else if ((config == 0) && (nwp.role == ROLE_STA)) {
sbapp_set_mode(ROLE_AP);
}

return config;
return config;
}

void delayed_reboot(channel_reader_t *rd) {
msg_t msg;
msg_t msg;

msg.type = REBOOT_REQUEST;
msg_send(&msg, rd->target_pid);
msg.type = REBOOT_REQUEST;
msg_send(&msg, rd->target_pid);
}

void bocia_command(channel_reader_t *rd, Command* cmd) {
switch (cmd->id) {
case REBOOT_CMD:
delayed_reboot(rd);
break;
case TOGGLE_WIFI_MODE_CMD:
set_reboot_mode(0);
delayed_reboot(rd);
break;
case FACTORY_RESET_CMD:
set_reboot_mode(1);
delayed_reboot(rd);
break;
case GET_CONFIG_CMD: {
proto_msg_t type = { CONFIG_TYPE, 0 };

if (!config) {
config = bocia_get_config();
}
rd->send(rd, type, config); // TODO check null pointer arg
break;
}
default:
DEBUG("invalid command id: %ld\n", cmd->id);

}
void bocia_command(channel_reader_t *rd, Command *cmd) {
switch (cmd->id) {
case REBOOT_CMD:
delayed_reboot(rd);
break;
case TOGGLE_WIFI_MODE_CMD:
set_reboot_mode(0);
delayed_reboot(rd);
break;
case FACTORY_RESET_CMD:
set_reboot_mode(1);
delayed_reboot(rd);
break;
case GET_CONFIG_CMD: {
proto_msg_t type = {CONFIG_TYPE, 0};

if (!config) {
config = bocia_get_config();
}
rd->send(rd, type, config); // TODO check null pointer arg
break;
}
default:
DEBUG("invalid command id: %ld\n", cmd->id);
}
}


0 comments on commit fb26b8a

Please sign in to comment.