Skip to content

Commit

Permalink
Orion Intelliscope mode with SkySafari Pro 4.0 works!
Browse files Browse the repository at this point in the history
- Tested AP mode
- Able to configure WiFly board & save settings
- Switched from WiFlySerial to WiFly library
  • Loading branch information
synfinatic committed Nov 17, 2014
1 parent aa4e927 commit 1c4c6b0
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 192 deletions.
171 changes: 138 additions & 33 deletions src/teensy_dsc/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "cli.h"
#include "utils.h"
#include "defaults.h"
#include "wifly.h"
#include "network.h"

void setup_commands(cli_ctx *ctx);

/*
* Initalizer for a CLI context
*/
cli_ctx *
cli_init_cmd(AnySerial *aserial, common_cli_ctx *common, WiFlySerial *wifly) {
cli_init_cmd(AnySerial *aserial, common_cli_ctx *common, WiFly *wifly) {
cli_ctx *ctx;

ctx = (cli_ctx *)malloc(sizeof(cli_ctx));
Expand All @@ -22,6 +22,11 @@ cli_init_cmd(AnySerial *aserial, common_cli_ctx *common, WiFlySerial *wifly) {
ctx->prev_state = NONE;
ctx->serial = aserial;
ctx->wifly = wifly;
if (wifly == NULL) {
ctx->eat_errors = true;
} else {
ctx->eat_errors = false;
}
setup_commands(ctx);

return ctx;
Expand Down Expand Up @@ -257,7 +262,9 @@ wifi_interactive(cli_ctx *ctx) {
if (pos == READBUFF_SIZE) {
line[0] = NULL;
pos = 0;
ctx->serial->printf("ERR: command too long\n");
if (! ctx->eat_errors) {
ctx->serial->printf("ERR: command too long\n");
}
}
}
}
Expand Down Expand Up @@ -302,13 +309,15 @@ setup_commands(cli_ctx *ctx) {
*/
cmd_status
wifi_ap_commands(cli_ctx *ctx, const char *args) {
if (strcmp(args, "ON") == 0) {
wifi_initial_setup(ctx->wifly, ctx->common->network);
} else if (strcmp(args, "OFF") == 0) {
// TODO: do something
ctx->serial->printf("Doh, this command doesn't do anything yet!\n");
if (strcmp(args, "SAVE") == 0) {
wifi_configure(ctx->wifly, ctx->common->network);
ctx->serial->printf("OK\n");
} else if (strcmp(args, "SHOW") == 0) {
wifi_get_config(ctx->wifly, ctx->serial);
ctx->serial->printf("OK\n");
} else if (strcmp(args, "RESET") == 0) {
ctx->wifly->reset();
ctx->serial->printf("OK\n");
} else {
return E_CMD_NOT_FOUND;
}
Expand All @@ -321,18 +330,26 @@ wifi_ap_commands(cli_ctx *ctx, const char *args) {
cmd_status
wifi_get_help(cli_ctx *ctx, const char *args) {
ctx->serial->printf(
F("AP ON => Turn on the WiFi access point\n" \
"AP OFF => Turn off the WiFi access point\n" \
F("AP SAVE => Save WiFi access point config\n" \
"AP SHOW => Shows the WiFi configuration\n" \
"AP RESET => Reset WiFi to factory defaults\n" \
"SET SSID <ssid> => Set the WiFi SSID\n" \
"SET PASS <pass> => Set the WiFi passphrase\n" \
"SET IP <x.x.x.x> => Set the WiFi IP address\n" \
"SET MASK <x.x.x.x> => Set the WiFi netmask\n" \
"SET CHAN <x> => Set the WiFi channel [0-12]\n" \
"SET PORT <x> => Set the TCP PORT [1-65535]\n" \
"SET RATE <x> => Set the WiFi rate [0-15]\n" \
"SET TXP <x> => Set the WiFi TX Power [0-12]\n" \
"SET AUTH [WPA2|OPEN] => Enable WPA2-PSK or no security\n" \
"SET MODE [AP|CLIENT] => Enable AP or client mode\n" \
"SET ALT xxxx => set ALT encoder resolution\n" \
"SET AZ xxxx => set AZ encoder resolution\n" \
"GET <OPTION> => Get a config option\n" \
"SAVE => Save Wifi settings to flash\n" \
"GET IPA => Get IP of WiFi AP\n" \
"GET ALL => Get all saved EEPROM settings\n" \
"SAVE => Save settings to EEPROM\n" \
"CLEAR => Clear all EEPROM settings\n" \
"? => Help\n" \
"MODE [DSC|WIFI] => Change CLI mode\n")
);
Expand Down Expand Up @@ -368,22 +385,16 @@ wifi_set_option(cli_ctx *ctx, const char *args) {
}
}
value[j] = '\0';

if (strcmp("SSID", option) == 0) {
ctx->wifly->setSSID(value);
strncpy(network->ssid, value, 30);
ctx->serial->printf("OK: %s\n", value);
} else if (strcmp("PASS", option) == 0) {
ctx->wifly->setPassphrase(value);
strncpy(network->passphrase, value, 64);
ctx->serial->printf("OK: %s\n", value);
} else if (strcmp("IP", option) == 0) {
ctx->wifly->setIP(value);
ctx->wifly->setGateway(value);
strncpy(network->ip_address, value, 15);
ctx->serial->printf("OK: %s\n", value);
} else if (strcmp("MASK", option) == 0) {
ctx->wifly->setNetMask(value);
strncpy(network->netmask, value, 15);
ctx->serial->printf("OK: %s\n", value);
} else if (strcmp("CHAN", option) == 0) {
Expand All @@ -392,7 +403,6 @@ wifi_set_option(cli_ctx *ctx, const char *args) {
ctx->serial->printf("Invalid channel: %d\n", i);
return E_CMD_BAD_ARGS;
}
ctx->wifly->setChannel(value);
network->channel = (uint8_t)i;
ctx->serial->printf("OK: %d\n", i);
} else if (strcmp("PORT", option) == 0) {
Expand All @@ -401,24 +411,57 @@ wifi_set_option(cli_ctx *ctx, const char *args) {
ctx->serial->printf("Invalid port: %d\n", i);
return E_CMD_BAD_ARGS;
}
ctx->wifly->setLocalPort(i);
network->port = (uint16_t)i;
ctx->serial->printf("OK: %d\n", i);
} else if (strcmp("AUTH", option) == 0) {
if (strcmp("OPEN", value) == 0) {
ctx->wifly->setAuthMode(0);
network->enable_wpa = 0;
ctx->serial->printf("OK: %d\n", 0);
} else if (strcmp("WPA2", value) == 0) {
ctx->wifly->setAuthMode(4);
network->enable_wpa = 4;
ctx->serial->printf("OK: %d\n", 4);
} else {
ctx->serial->printf("Invalid auth mode: %s\n", value);
return E_CMD_BAD_ARGS;
}
} else if (strcmp("MODE", option) == 0) {
if (strcmp("AP", value) == 0) {
network->enable_ap = 7;
ctx->serial->printf("OK: %d\n", 7);
} else if (strcmp("CLIENT", value) == 0) {
network->enable_ap = 1;
ctx->serial->printf("OK: %d\n", 1);
} else {
ctx->serial->printf("Invalid Wifi mode: %d\n", value);
return E_CMD_BAD_ARGS;
}
} else if (strcmp("RATE", option) == 0) {
i = atoi(value);
if (i < 0 || i > 15) {
ctx->serial-printf("Invalid rate: %d\n", i);
return E_CMD_BAD_ARGS;
}
network->rate = i;
ctx->serial->printf("OK: %d\n", i);
} else if (strcmp("TXP", option) == 0) {
i = atoi(value);
if (i < 0 || 0 > 12) {
ctx->serial-printf("Invalid TX Power: %d\n", i);
return E_CMD_BAD_ARGS;
}
network->tx_power = i;
ctx->serial->printf("OK: %d\n", i);
} else if (strcmp("ALT", option) == 0) {
i = atoi(value);
ctx->common->dec_value = i;
ctx->serial->printf("OK: %d\n", i);
} else if (strcmp("AZ", option) == 0) {
i = atoi(value);
ctx->common->ra_value = i;
ctx->serial->printf("OK: %d\n", i);
} else {
ctx->serial->printf("Unknown command: %s\n", option);
return E_CMD_NOT_FOUND;
}

return E_CMD_OK;
}

Expand All @@ -429,37 +472,99 @@ cmd_status
wifi_get_option(cli_ctx *ctx, const char *args) {
AnySerial *serial = ctx->serial;
network_settings_t *network = ctx->common->network;
char c, *value;

if (strcmp("SSID", args) == 0) {
serial->printf("%s\n", network->ssid);
serial->printf("SSID: %s\n", network->ssid);
} else if (strcmp("PASS", args) == 0) {
serial->printf("%s\n", network->passphrase);
serial->printf("PASS: %s\n", network->passphrase);
} else if (strcmp("IP", args) == 0) {
serial->printf("%s\n", network->ip_address);
serial->printf("IP: %s\n", network->ip_address);
} else if (strcmp("MASK", args) == 0) {
serial->printf("%s\n", network->netmask);
serial->printf("MASK: %s\n", network->netmask);
} else if (strcmp("CHAN", args) == 0) {
serial->printf("%d\n", network->channel);
serial->printf("CHAN: %d\n", network->channel);
} else if (strcmp("PORT", args) == 0) {
serial->printf("%d\n", network->port);
serial->printf("PORT: %d\n", network->port);
} else if (strcmp("AUTH", args) == 0) {
switch (network->enable_wpa) {
case 0:
serial->printf(F("OPEN\n"));
serial->printf(F("AUTH: OPEN\n"));
break;
case 4:
serial->printf(F("AUTH: WPA2\n"));
break;
default:
serial->printf(F("AUTH: Unknown value: %d\n"), network->enable_wpa);
}
} else if (strcmp("MODE", args) == 0) {
switch (network->enable_ap) {
case 7:
serial->printf("MODE: AP\n");
break;
case 1:
serial->printf("MODE: WiFi Client\n");
break;
default:
serial->printf("Mode: Unknown: %d\n", network->enable_ap);
}
} else if (strcmp("RATE", args) == 0) {
serial->printf("RATE: %d\n", network->rate);
} else if (strcmp("TXP", args) == 0) {
serial->printf("TXP: %d\n", network->tx_power);
} else if (strcmp("IPA", args) == 0) {
ctx->wifly->sendCommand("get ip a\r");
serial->print("IPA: ");
while (ctx->wifly->receive((uint8_t *)&c, 1, 300)) {
serial->print((char)c);
}
ctx->wifly->dataMode();
} else if (strcmp("ALT", args) == 0) {
value = EncoderValue(ctx->common->dec_value, true);
serial->printf("ALT: %s\n", value);
} else if (strcmp("AZ", args) == 0) {
value = EncoderValue(ctx->common->ra_value, true);
serial->printf("AZ: %s\n", value);
} else if (strcmp("ALL", args) == 0) {
serial->printf("SSID: %s\n", network->ssid);
serial->printf("PASS: %s\n", network->passphrase);
serial->printf("IP: %s\n", network->ip_address);
serial->printf("MASK: %s\n", network->netmask);
serial->printf("CHAN: %d\n", network->channel);
serial->printf("PORT: %d\n", network->port);
switch (network->enable_wpa) {
case 0:
serial->printf(F("AUTH: OPEN\n"));
break;
case 4:
serial->printf(F("WPA2\n"));
serial->printf(F("AUTH: WPA2\n"));
break;
default:
serial->printf(F("AUTH: Unknown value: %d\n"), network->enable_wpa);
}
switch (network->enable_ap) {
case 7:
serial->printf("MODE: AP\n");
break;
case 1:
serial->printf("MODE: WiFi Client\n");
break;
default:
serial->printf(F("Unknown value: %d\n"), network->enable_wpa);
serial->printf("Mode: Unknown: %d\n", network->enable_ap);
}
serial->printf("RATE: %d\n", network->rate);
serial->printf("TXP: %d\n", network->tx_power);
value = EncoderValue(ctx->common->dec_value, true);
serial->printf("ALT: %s\n", value);
value = EncoderValue(ctx->common->ra_value, true);
serial->printf("AZ: %s\n", value);
}

return E_CMD_OK;
}

/*
* Save Wifi Settings
* Save Wifi Settings to EEPROM
*/
cmd_status
wifi_save_settings(cli_ctx *ctx, const char *args) {
Expand Down
7 changes: 4 additions & 3 deletions src/teensy_dsc/cli.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "wifly.h"
#include "network.h"

#ifndef __CLI_H__
#define __CLI_H__
Expand Down Expand Up @@ -47,15 +47,16 @@ typedef struct cli_ctx_s {
cli_state state;
cli_state prev_state;
AnySerial *serial;
WiFlySerial *wifly;
WiFly *wifly;
// must be big enough to hold max one char commands for a given state
char one_char_cmds[20];
int longest_cmd;
bool eat_errors;
common_cli_ctx *common;
} cli_ctx;

/* init & entrance */
cli_ctx *cli_init_cmd(AnySerial *, common_cli_ctx *, WiFlySerial *);
cli_ctx *cli_init_cmd(AnySerial *, common_cli_ctx *, WiFly *);
cmd_status cli_proc_cmd(cli_ctx *, char *, size_t);

/* dsc commands */
Expand Down
2 changes: 2 additions & 0 deletions src/teensy_dsc/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define WIFLY_CHANNEL 1
#define TX_POWER 1
#define ENABLE_WPA 0
#define ENABLE_AP 1


/*
Expand Down Expand Up @@ -55,6 +56,7 @@ typedef struct {
uint8_t tx_power;
uint8_t rate;
uint8_t enable_wpa;
uint8_t enable_ap;
} network_settings_t;

typedef enum {
Expand Down
24 changes: 24 additions & 0 deletions src/teensy_dsc/network.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef __NETWORK_H__
#define __NETWORK_H__

#include <Flash.h>
#include <AnySerial.h>
#include <WiFly.h>
#include "defaults.h"

#define PAUSE_DURATION 100
#define LONG_PAUSE_DURATION 500

#define PORT_OPEN "*port opened*"
#define PORT_CLOSE "*port closed*"
#define COMM_SIZE 1420
#define COMM_TIME_MS 5

void wifi_initial_setup(WiFly *, network_settings_t *);
void wifi_configure(WiFly *, network_settings_t *);
void wifi_setup_comms(WiFly *);
void wifi_setup_network(WiFly *, network_settings_t *);
void wifi_setup_wireless(WiFly *, network_settings_t *);
void wifi_get_config(WiFly *, AnySerial *);

#endif
Loading

0 comments on commit 1c4c6b0

Please sign in to comment.