Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 2147 → Rev 2203

/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/wifly/PKT_WiFlyHQ.c
0,0 → 1,1406
/*-
* Copyright (c) 2012,2013 Darran Hunt (darran [at] hunt dot net dot nz)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/**
* @file WiFly RN-XV Library
*/
 
 
 
//############################################################################
//# HISTORY PKT_WiFlyHQ.c
//#
//# 03.06.2014 OG
//# - fix: find_WiFly() - Benutzer kann Suche nach WiFly jetzt abbrechen
//# (z.b. weil er kein WiFly angesteckt hat)
//# von dieser Aenderungen betroffen sind auch noch einige Codechanges
//# an anderen Funktionen.
//#
//# 15.04.2014 OG
//# - chg: wifly_init() - Logik bei der Versionsverifikation von WIFLY_ADHOC
//# geaendert da v2.38 ansonsten ggf. den Bach runter gegangen waere.
//# AKTUELL UNGETESTET DA KEIN WIFLY ADHOC VORHANDEN!
//# - add: Wifly_update() ein paar Kommentare im Code
//# - add: KOMMENTAR zu define DEBUG_WIFLY ! (lesenswert!)
//#
//# 14.04.2014 Cebra
//# - add: Defines für getestete WiFly Softwareversionen
//# - add: wifly_init bei der Versionsabfrage erweitert
//#
//# 13.04.2014 OG
//# - ggf. Probleme beim Downgrade des WiFly auf v2.38 -> deaktiviert
//# - FAST KOMPLETT NEUER CODE
//#
//# 03.04.2014 OG
//# - add: define DELAY_BEFORE_SAVE
//# - add: define DELAY_BEFORE_REBOOT
//#
//# 02.04.2014 OG
//# WIP: etliche weitere Aenderungen....
//# - chg: getVersion(): Rueckgabe/Logik geaendert
//# - add: define DELAY_AFTER_MODUL_ON
//#
//# 01.04.2014 SH
//# - chg: Nicht benötigte Progmem Strings auskommentiert
//#
//# 11.03.2014 SH
//# - add: neue Funktionen wl_reset() und wl_update()
//# - chg: wl_init() wurde komplett auf den neuen AP Modus geändert, die Init Routine vom Ad Hoc Modus befindet sich ausgeklammert darunter
//# - chg: getVersion wurde angepasst + neuer Wert für resp_Version[] PROGMEM = "RN-171\r\n" anstatt WiFly
//# - chg: setSSID() und setPassphrase() wurden um weiteren Parameter ergänzt
//# - chg: createAdhocNetwork angepasst da Funktion setSSID() enthalten
//# - del: ausgeklammerte Funktionen getConnection, getDHCPMode, getSpaceReplace, getopt_Asc und join
//#
//# 12.02.2014 OG
//# - chg: readTimeout() Auskommentiert: "unused variable 'ind'"
//# - chg: wl_init() Auskommentiert: "unused variable 'dhcpMode'"
//#
//# 02.07.2013 cebra
//# - new: Routinen für WiFly WLAN-Modul
//#
//###########################################################################
 
 
#include <avr/pgmspace.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#include <util/delay.h>
#include <inttypes.h>
#include <string.h>
#include "../main.h"
#include "PKT_WiFlyHQ.h"
#include "../eeprom/eeprom.h"
#include "../uart/uart1.h"
#include "../timer/timer.h"
#include "../lcd/lcd.h"
#include "../messages.h"
#include "../pkt/pkt.h"
#include "../utils/xutils.h"
#include "wifly_setup.h"
 
 
#ifdef USE_WLAN
 
 
//----------------------------------------------------
// DEBUG
//
// Wenn 'DEBUG_WIFLY' eingeschalte wird dann werden die Ausgaben
// des WiFly auf dem PKT-Screen angezeigt - fast wie bei einem
// Terminal Programm!
//
// Man kann dadurch genaueres erkennen wie die Kommunikation
// ablaeuft und mit welchen Strings beispielsweise das WiFly
// ein Ok quittiert.
//----------------------------------------------------
//#define DEBUG_WIFLY
 
//----------------------------------------------------
// unterstützte WiFly Softwareversionen
//----------------------------------------------------
 
#define Adhoc_Version1 232 // getestet Version 2.32
#define Adhoc_Version2 238 // getestet Version 2.38
 
#define Apmode_Version1 441 // getestet Version 4.41
 
 
//----------------------------------------------------
// Einstellungen
//----------------------------------------------------
static const char WIFLY_IP_ADDRESS[] PROGMEM = "169.254.1.1";
static const char WIFLY_IP_PORT[] PROGMEM = "2000";
 
static const char WIFLY_IP_GATEWAY[] PROGMEM = "169.254.1.1";
static const char WIFLY_IP_NETMASK[] PROGMEM = "255.255.0.0";
 
static const char WIFLY_VERSION_ADHOC[] PROGMEM = "2.38.3";
//static const char WIFLY_VERSION_ADHOC[] PROGMEM = "v2.32";
static const char WIFLY_VERSION_APMODE[] PROGMEM = "4.41";
 
 
//----------------------------------------------------
// Einsstellungen fuer Delay's
//----------------------------------------------------
//#define WIFLY_DEFAULT_TIMEOUT 500 /* 500 milliseconds */
#define WIFLY_DEFAULT_TIMEOUT 100 // n milliseconds
 
 
//----------------------------------------------------
//----------------------------------------------------
uint8_t progress_max = 0;
uint8_t progress_act = 0;
char progress_buffer[22];
char buffer[20];
 
 
char wifly_version_string[12];
uint16_t wifly_version;
 
 
//----------------------------------------------------
// Texte
//----------------------------------------------------
static const char STR_WIFLY_NOT_FOUND[] PROGMEM = "WiFly not found";
 
static const char RECEIVE_AOK[] PROGMEM = "AOK";
 
#define REPLACE_SPACE_CHAR '$' // ersetzt Spaces in einem String-Parameter des WiFly - '$' ist WiFly default (0x24) fuer SSID und Pwd
 
//static const char [] PROGMEM = "";
 
//----------------------------------------------------
 
 
//#############################################################################
//#
//#############################################################################
 
 
//----------------------------------------------------
//----------------------------------------------------
void debug_begin( void )
{
lcd_cls();
lcd_setpos(0,0);
}
 
 
//----------------------------------------------------
//----------------------------------------------------
void debug_wait( void )
{
set_beep( 25, 0xffff, BeepNormal );
clear_key_all();
while( !get_key_press(1 << KEY_ESC) && !get_key_press(1 << KEY_ENTER) );
lcd_print_LF();
}
 
 
//----------------------------------------------------
//----------------------------------------------------
void debug_message( uint8_t *text )
{
lcd_print_LF();
lcd_print( text, MINVERS );
debug_wait();
lcd_print_LF();
}
 
 
 
 
 
 
//#############################################################################
//#
//#############################################################################
 
 
/** Read the next character from the WiFly serial interface.
* Waits up to timeout milliseconds to receive the character.
* @param chp pointer to store the read character in
* @param timeout the number of milliseconds to wait for a character
* @retval true - character read
* @retval false - timeout reached, character not read
*/
bool readTimeout( char *chp, uint16_t timeout)
{
char ch;
timer2 = timeout;
 
while( timer2>0 )
{
if( uart1_available() > 0 )
{
ch = uart1_getc();
*chp = ch;
 
#ifdef DEBUG_WIFLY
lcd_print_char( ch, MNORMAL);
#endif
 
return (true);
}
}
 
return (false);
}
 
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void flushRx( int timeout )
{
char ch;
while( readTimeout( &ch, timeout) );
}
 
 
 
 
/**
* Read characters from the WiFly and match them against the
* progmem string. Ignore any leading characters that don't match. Keep
* reading, discarding the input, until the string is matched
* or until no characters are received for the timeout duration.
* @param str The string to match, in progmem.
* @param timeout fail if no data received for this period (in milliseconds).
* @retval true - a match was found
* @retval false - no match found, timeout reached
*/
bool match_P( const char *str, uint16_t timeout)
{
const char *match = str;
char ch, ch_P;
 
ch_P = pgm_read_byte(match);
if( ch_P == '\0' ) return true; /* Null string always matches */
 
while( readTimeout( &ch, timeout) )
{
// DEBUG
//lcd_print_char( ch, MNORMAL );
 
if( ch == ch_P ) match++;
else
{
match = str; // Restart match
if( ch == pgm_read_byte(match) ) match++;
}
 
ch_P = pgm_read_byte( match );
if( ch_P == '\0' ) return (true);
}
 
return (false);
}
 
 
 
 
 
 
//#############################################################################
//# progress
//#############################################################################
 
//--------------------------------------------------------------
// msg: PROGMEM
//--------------------------------------------------------------
void progress_begin( uint8_t maxsteps )
{
progress_max = maxsteps;
progress_act = 0;
}
 
 
//--------------------------------------------------------------
// wait4key: true / false
//--------------------------------------------------------------
void progress_end( uint8_t wait4key )
{
progress_max = 0;
progress_act = 0;
 
if( wait4key )
{
lcd_printp_at( 12, 7, strGet(ENDE), MNORMAL); // Keyline
set_beep( 25, 0xffff, BeepNormal ); // kurzer Bestaetigungs-Beep
clear_key_all();
while( !get_key_press(1 << KEY_ESC) ); // warte auf Taste...
}
}
 
 
 
//--------------------------------------------------------------
// msg: PROGMEM
//--------------------------------------------------------------
void progress_show( const char *msg )
{
int8_t yoffs = 3;
 
#ifdef DEBUG_WIFLY
return;
#endif
 
if( progress_max )
{
progress_act++;
 
lcdx_printf_center_P( 4, MNORMAL, 0,yoffs, PSTR("%d/%d"), progress_act, progress_max );
 
if( msg )
{
strncpyat_P( progress_buffer, msg, 20, ' ', 2);
 
lcd_frect( 2, (5*8)+yoffs, 124, 7, 0); // Zeile 5 loeschen
lcdx_print_center( 5, (uint8_t *)progress_buffer, MNORMAL, 0,yoffs); // Text zentriert; String im RAM
}
 
lcd_rect_round( 0, 28+yoffs, 127, 22, 1, R2); // Rahmen
_delay_ms(700); // fuer Anzeige (Entschleunigung)
}
}
 
 
 
//--------------------------------------------------------------
// gibt zentriert einen Text und loescht vorher die Zeile
//--------------------------------------------------------------
void MsgCenter_P( uint8_t y, const char *text, uint8_t mode, int8_t yoffs )
{
lcdx_cls_row( y, MNORMAL, yoffs );
lcdx_printp_center( y, text, MNORMAL, 0, yoffs );
}
 
 
 
//#############################################################################
//# sendcmd
//#############################################################################
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void cmd_showerror( const char *cmdstr)
{
//void PKT_Message_P( const char *text, uint8_t error, uint16_t timeout, uint8_t beep, uint8_t clearscreen )
PKT_Message_P( cmdstr, true, 3000, true, true ); // max. 30 Sekunden anzeigen
}
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
uint8_t find_Prompt()
{
char c;
uint8_t state = 0;
 
while( readTimeout( &c, WIFLY_DEFAULT_TIMEOUT) )
{
if( state == 0 && (c == '>') ) { state = 1; continue; }
if( state == 1 && (c == ' ') ) return true;
 
if( state == 1 ) break; // Fehler: nicht vorgesehen
}
 
return false;
}
 
 
//--------------------------------------------------------------
// nicht verwendet...
//--------------------------------------------------------------
uint8_t find_Prompt2()
{
char c;
 
timer2 = 800; // 8 Sekunden max. suchen
while( readTimeout( &c, WIFLY_DEFAULT_TIMEOUT) && timer2 )
{
if( c == '>' ) return true;
}
 
return false;
}
 
 
 
//--------------------------------------------------------------
// Das ist erstmal so uebernommen - ob das alles sein muss??
//
// Put the WiFly into command mode
//
// RUECKGABE:
// >0: ok
// =0: Fehler
// -1: Abbruch Benutzer
//--------------------------------------------------------------
int8_t cmd_EnterCommandMode( void )
{
uint8_t retry = 2;
int8_t result = 0; // false
 
while( retry && !result )
{
//_delay_ms(250);
uart1_puts_p( PSTR("$$$") );
//_delay_ms(250);
_delay_ms(100);
uart1_putc('\r');
 
if( get_key_short(1 << KEY_ESC) ) // Abbruch durch Benutzer?
{
return -1; // -1 = Abbruch Benutzer
}
 
result = find_Prompt(); // ggf. result = true
if( !result )
{
retry--;
_delay_ms(250);
}
}
 
return result;
}
 
 
 
//--------------------------------------------------------------
// PARAMETER:
// cmdstr : PROGMEM
// strvalue : RAM
// match_receive: PROGMEM
// findprompt : true/false
//--------------------------------------------------------------
uint8_t cmdsend( const char *cmdstr, const char *strvalue, const char *match_receive, uint8_t findprompt )
{
uint8_t result = true;
const char *p;
char c;
 
progress_show( cmdstr );
 
//--------------------
// Senden...
//--------------------
uart1_puts_p( cmdstr );
 
if( strvalue != NULL )
{
uart1_putc(' ');
 
p = strvalue;
while( *p )
{
c = *p;
if( c == ' ' ) c = REPLACE_SPACE_CHAR;
uart1_putc( c );
p++;
}
}
uart1_putc('\r');
 
 
//--------------------
// Antwort...
//--------------------
if( match_receive )
{
//if( !match_P( p, WIFLY_DEFAULT_TIMEOUT) )
if( !match_P( match_receive, 2000) )
{
cmd_showerror( cmdstr ); // Fehler auf PKT Screen anzeigen und durch Benutzer bestaetigen lassen
result = false;
}
// DEBUG
//lcdx_printf_at_P( 2, 7, MINVERS, 0,0, PSTR("%d"), result );
}
 
#ifdef DEBUG_WIFLY
debug_wait();
#endif
 
// TODO: Kommandos die keinen Prompt zurueckliefern? (evtl. 'reset'?)
//uart1_putc('\r'); // fuer cmd_Join ein extra Return... (bei den anderen Kommandos stoert es nicht)
 
if( result && findprompt)
{
result = find_Prompt();
}
 
return( result );
}
 
 
 
//--------------------------------------------------------------
// cmdsend_P()
//
// PARAMETER:
//--------------------------------------------------------------
uint8_t cmdsend_P( const char *cmdstr, const char *strvalue, const char *match_receive, uint8_t findprompt )
{
strncpy_P( buffer, strvalue, 20);
return cmdsend( cmdstr, buffer, match_receive, findprompt );
}
 
 
 
//--------------------------------------------------------------
// Version wird anhand des Prompt's ermittelt
// Implementiert als State-Machine
//--------------------------------------------------------------
uint8_t cmd_GetVersion( void )
{
char c;
uint8_t state = 0;
char *dst = wifly_version_string;
uint8_t n = 0;
 
wifly_version = 0;
 
uart1_putc('\r'); // erzwinge Prompt
 
while( readTimeout( &c, WIFLY_DEFAULT_TIMEOUT) )
{
if( (state == 0) && (c == '<') )
{
state = 1;
continue;
}
 
if( (state == 1) && (c != '>') )
{
// TODO: Ende vom Prompt im Fehlerfall catchen...
if( n+1 >= sizeof(wifly_version_string) )
break;
*dst = c;
dst++;
n++;
continue;
}
 
if( (state == 1) && (c == '>') ) // Versionsstring-Ende erreicht
{
*dst = 0;
state = 2;
break;
}
 
}
 
 
if( state == 2 )
{
//uint16_t wifly_version;
wifly_version = (wifly_version_string[0]-'0') * 100;
wifly_version += (wifly_version_string[2]-'0') * 10;
wifly_version += (wifly_version_string[3]-'0') * 1;
}
else
{
cmd_showerror( PSTR("get version") ); // Fehler auf PKT Screen anzeigen und durch Benutzer bestaetigen lassen
}
 
return (state == 2);
}
 
 
 
//--------------------------------------------------------------
// cmd_Set()
//
// PARAMETER:
// cmdstr: PROGMEM
//--------------------------------------------------------------
uint8_t cmd_Set( const char *cmdstr )
{
return cmdsend( cmdstr, 0, RECEIVE_AOK, true );
}
 
 
 
//--------------------------------------------------------------
// cmd_SetStr()
//
// PARAMETER:
// cmdstr: PROGMEM
// str : RAM
//--------------------------------------------------------------
uint8_t cmd_SetStr( const char *cmdstr, const char *str )
{
return cmdsend( cmdstr, str, RECEIVE_AOK, true );
}
 
 
 
//--------------------------------------------------------------
// cmd_SetStr()
//
// PARAMETER:
// cmdstr: PROGMEM
// str : PROGMEM
//--------------------------------------------------------------
uint8_t cmd_SetStr_P( const char *cmdstr, const char *str )
{
return cmdsend_P( cmdstr, str, RECEIVE_AOK, true );
}
 
 
 
//--------------------------------------------------------------
// cmd_SetNum()
//
// PARAMETER:
// cmdstr: PROGMEM
// value : Dezimal
//--------------------------------------------------------------
uint8_t cmd_SetNum( const char *cmdstr, const uint16_t value )
{
utoa( value, buffer, 10 );
return cmd_SetStr( cmdstr, buffer);
}
 
 
 
//--------------------------------------------------------------
// cmd_Reset()
//--------------------------------------------------------------
uint8_t cmd_Reset( void )
{
uint8_t result = true;
 
//_delay_ms( 500 );
result = cmdsend( PSTR("factory RESET"), 0, PSTR("Defaults"), false );
_delay_ms( 1000 );
 
return result;
 
// return cmdsend( PSTR("factory RESET"), 0, PSTR("Defaults"), true );
}
 
 
 
//--------------------------------------------------------------
// cmd_Save()
//--------------------------------------------------------------
uint8_t cmd_Save( void )
{
//_delay_ms( DELAY_BEFORE_SAVE );
_delay_ms( 200 );
return cmdsend( PSTR("save"), 0, PSTR("Storing"), true );
}
 
 
//--------------------------------------------------------------
// cmd_Join()
//--------------------------------------------------------------
uint8_t cmd_Join( const char *ssid )
{
uint8_t result = true;
 
result = cmdsend( PSTR("join"), ssid, PSTR("Associated"), false );
if( result ) uart1_putc('\r');;
if( result ) result = find_Prompt();
 
return result;
}
 
 
 
//--------------------------------------------------------------
// cmd_Reboot()
//--------------------------------------------------------------
uint8_t cmd_Reboot( void )
{
//_delay_ms( DELAY_BEFORE_REBOOT );
_delay_ms( 300 );
cmdsend( PSTR("reboot"), 0, 0, false );
_delay_ms( 2000 );
return true;
}
 
 
 
//#############################################################################
//# WiFly suchen
//#############################################################################
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
void find_WiFly_searchmsg( const char *text, uint8_t baud )
{
lcd_frect( 0, 2*8, 126, 7, 0); // Zeile 2 loeschen
lcdx_printf_center_P( 2, MNORMAL, 0,0, PSTR("%S %lu Baud"), text, Baud_to_uint32(baud) ); // Text zentriert
}
 
 
 
//--------------------------------------------------------------
// RUECKGABE:
// >0: ok
// =0: Fehler
// -1: Abbruch Benutzer
//--------------------------------------------------------------
int8_t find_WiFly_baud( uint8_t baud )
{
int8_t result = 1;
 
find_WiFly_searchmsg( strGet(STR_SEARCH), baud );
 
// Anmerkung 06.04.2014 OG:
// SetBaudUart1() (in uart/uart1.c) setzt nur die Baudrate des Uart.
// Config.PKT_Baudrate wird durch SetBaudUart1() NICHT geaendert!
SetBaudUart1( baud );
 
result = cmd_EnterCommandMode();
 
if( result > 0 )
{
return baud; // Baud gefunden, ok!
}
 
return result; // nicht gefunden oder Abbruch durch Benutzer
}
 
 
 
//--------------------------------------------------------------
// ok = find_WiFly()
//
// Sucht das WiFly mit verschiedenen Baudraten.
//
// Wenn das WiFly mit von Config.PKT_Baudrate (= 57600) abweichender
// Baudrate gefunden wird (z.B. 9600 Baud) dann wird das WiFly
// automatisch auf 57600 Baud umkonfiguriert damit nachfolgende
// Funktionen das nicht mehr beachten muessen.
//
// RUECKGABE:
// ok = true : WiFly gefunden und ist auf 57600 Baud
// ok = false: kein WiFly gefunden
//
// >0: ok
// =0: Fehler
// -1: Abbruch Benutzer
//
// Anmerkung:
// #define Baud_9600 1
// #define Baud_19200 2
// #define Baud_38400 3
// #define Baud_57600 4
// #define Baud_115200 5
// #define Baud_4800 6
// #define Baud_2400 7
//--------------------------------------------------------------
int8_t find_WiFly( void ) // search Wifly with all Baudrates
{
int8_t result = 1; // 1 == true
int8_t baud = 0;
 
//inCommandMode = false;
//exitCommand = 0;
 
set_Modul_On( Wlan ); // WiFly einschalten
 
timer2 = 60; // Delay damit das WiFly booten kann
while( timer2 );
 
lcd_printp_at(12, 7, strGet(ENDE), MNORMAL); // Keyline: "Ende"
 
//------------------------
// suche WiFly mit versch. Baudraten
//------------------------
if( baud==0 ) baud = find_WiFly_baud( Baud_57600 );
if( baud==0 ) baud = find_WiFly_baud( Baud_9600 );
if( baud==0 ) baud = find_WiFly_baud( Baud_115200 );
if( baud==0 ) baud = find_WiFly_baud( Baud_38400 );
if( baud==0 ) baud = find_WiFly_baud( Baud_19200 );
if( baud==0 ) baud = find_WiFly_baud( Baud_4800 );
if( baud==0 ) baud = find_WiFly_baud( Baud_2400 );
 
lcdx_cls_row( 7, MNORMAL, 0); // Keyline loeschen
 
//------------------------
// Abbruch durch Benutzer?
//------------------------
if( baud < 0 )
{
SetBaudUart1( Config.PKT_Baudrate ); // orginal Baudrate von Uart1 wieder herstellen
set_Modul_On( USB ); // wieder auf USB zurueckschalten
return -1; // -1 = Abbruch Benutzer
}
 
 
//------------------------
// kein WiFly gefunden...
//------------------------
if( baud==0 ) // WiFly nicht gefunden :-(
{
SetBaudUart1( Config.PKT_Baudrate ); // orginal Baudrate von Uart1 wieder herstellen
set_Modul_On( USB ); // wieder auf USB zurueckschalten
 
//PKT_Message_P( *text, error, timeout, beep, clearscreen )
PKT_Message_P( STR_WIFLY_NOT_FOUND, true, 3000, true, true ); // max. 30 Sekunden anzeigen
 
return false; // 0 = nicht gefunden
}
 
 
//------------------------
// WiFly gefunden!
//------------------------
find_WiFly_searchmsg( strGet(STR_FOUND), baud ); // Anzeige: "gefunden..."
 
 
//------------------------
// WiFly Baud ok?
// -> ggf. WiFly Baud umkonfigurieren
//------------------------
if( Config.PKT_Baudrate != baud )
{
find_WiFly_searchmsg( strGet(STR_SET), Config.PKT_Baudrate ); // Anzeige: "setze..."
 
if( result ) result = cmd_Set( PSTR("set u b 57600") ); // -> etwas unsauber hier einfach 57600 zu setzen und nicht Config.PKT_Baudrate
if( result ) result = cmd_Save();
if( result ) result = cmd_Reboot(); // true = uart-baud setzen
 
SetBaudUart1( Config.PKT_Baudrate ); // orginal Baudrate von Uart1 wieder herstellen
if( result ) result = cmd_EnterCommandMode();
}
 
 
return result;
}
 
 
 
//#############################################################################
//#
//#############################################################################
 
 
//--------------------------------------------------------------
// zeigt die WiFly-Version an
//--------------------------------------------------------------
uint8_t wifly_version_show( void )
{
int8_t result = 1; // 1 = true
 
ShowTitle_P( PSTR("WiFly Version"), true );
 
result = find_WiFly();
 
if( result < 0 ) // Abbruch durch Benutzer?
{
clear_key_all();
return result;
}
 
if( result ) result = cmd_GetVersion(); // Ergebnis in 'wifly_version_string'
 
set_Modul_On( USB );
 
if( result )
{
// TODO:
// Anzeige ob WiFly-Version kompatibel zum gewaehlten
// Mode (AP-Mode, AdHoc) ist
//lcd_frect( 0, 2*8, 126, 7, 0); // Zeile 2 loeschen
 
lcd_rect_round( 0, 8*4+3, 127, 8*2, 1, R2); // Anzeige-Rahmen
lcdx_printf_center_P( 5, MNORMAL, 0,0, PSTR("Version: v%s"), wifly_version_string );
 
lcd_printp_at( 12, 7, strGet(ENDE), MNORMAL); // Keyline
set_beep( 25, 0xffff, BeepNormal ); // kurzer Bestaetigungs-Beep
 
clear_key_all();
while( !get_key_press(1 << KEY_ESC) ); // warte auf Taste...
}
else
{
PKT_Message_P( PSTR("Version FAIL!"), true, 3000, true, true ); // max. 30 Sekunden anzeigen
}
 
clear_key_all();
return result;
}
 
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
uint8_t _ask( uint8_t keyline )
{
uint8_t ask = 0;
 
lcd_rect_round( 0, 34, 127, 16, 1, R2); // Rahmen
 
lcd_printp_at( 12, 7, strGet(keyline), MNORMAL); // Keyline
 
if( keyline == ENDE )
set_beep( 1000, 0xffff, BeepNormal ); // langer Error-Beep
else
set_beep( 25, 0xffff, BeepNormal ); // kurzer Bestaetigungs-Beep
 
clear_key_all();
while( !ask ) // warte auf Ja/Nein
{
if( get_key_press(1 << KEY_ENTER) ) ask = 1; // "Ja"
if( get_key_press(1 << KEY_ESC) ) ask = 2; // "Nein"
};
 
return( ask==1 );
}
 
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
uint8_t wifly_init_perform( uint8_t wiflymode ) //AP Mode
{
uint8_t result = true;
 
#ifndef DEBUG_WIFLY
MsgCenter_P( 2, PSTR("INIT"), MNORMAL, 0 );
#endif
 
 
//---------------
// WIFLY_ADHOC
//---------------
if( wiflymode == WIFLY_ADHOC )
{
progress_begin( 9 );
 
//if( result ) result = cmd_Set( PSTR("set u m 1") ); // ist das notwendig? - (turn off echo)
//if( result ) result = cmd_Set( PSTR("set sys printlvl 0") ); // ist das notwendig?
//if( result ) result = cmd_Set( PSTR("set comm remote 0") ); // ist das notwendig?
 
if( result ) result = cmd_Set( PSTR("set wlan join 4") ); // 4 = AdHoc
if( result ) result = cmd_Set( PSTR("set ip dhcp 0") );
 
if( result ) result = cmd_SetStr_P( PSTR("set ip address"), WIFLY_IP_ADDRESS );
if( result ) result = cmd_SetStr_P( PSTR("set ip gateway"), WIFLY_IP_GATEWAY );
if( result ) result = cmd_SetStr_P( PSTR("set ip netmask"), WIFLY_IP_NETMASK );
 
if( result ) result = cmd_SetStr( PSTR("set wlan ssid"), Config.Wlan_SSID );
if( result ) result = cmd_SetNum( PSTR("set wlan chan"), Config.Wlan_Channel );
}
 
 
//---------------
// WIFLY_APMODE
//---------------
if( wiflymode == WIFLY_APMODE )
{
progress_begin( 13 );
 
if( result ) result = cmd_Set( PSTR("set wlan join 7") );
if( result ) result = cmd_Set( PSTR("set ip dhcp 4") );
 
if( result ) result = cmd_SetStr_P( PSTR("set ip address"), WIFLY_IP_ADDRESS );
if( result ) result = cmd_SetStr_P( PSTR("set ip gateway"), WIFLY_IP_GATEWAY );
if( result ) result = cmd_SetStr_P( PSTR("set ip netmask"), WIFLY_IP_NETMASK );
 
if( result ) result = cmd_Set( PSTR("set wlan rate 3") );
if( result ) result = cmd_SetStr( PSTR("set apmode ssid") , Config.Wlan_SSID );
if( result ) result = cmd_SetStr( PSTR("set apmode pass") , Config.Wlan_Password );
if( result ) result = cmd_SetNum( PSTR("set wlan channel"), Config.Wlan_Channel );
if( result ) result = cmd_Set( PSTR("set ip protocol 0x3") );
if( result ) result = cmd_Set( PSTR("set apmode link_monitor 0") );
}
 
if( result ) result = cmd_Save();
if( result ) result = cmd_Reboot();
 
progress_end( false ); // Progress abschalten
 
return( result );
}
 
 
 
 
//--------------------------------------------------------------
// ok = wifly_init( wiflymode )
//
// initialisiert das WiFly fuer AP-Mode oder AdHoc
//
// PARAMETER:
// wiflymode: WIFLY_APMODE = Firmware wifly7-441.img
// WIFLY_ADHOC = Firmware wifly7-2383.img
//--------------------------------------------------------------
uint8_t wifly_init( uint8_t wiflymode ) //AP Mode
{
int8_t result = 1; // 1 = true
uint8_t ask = false;
uint8_t versionerror = false;
char *title = (char *)PSTR("Init WiFly");
char *strMode;
 
if( wiflymode == WIFLY_ADHOC ) strMode = (char *)PSTR("AdHoc");
else strMode = (char *)PSTR("AP-Mode");
 
ShowTitle_P( title, true );
 
result = find_WiFly();
 
if( result < 0 ) // Abbruch durch Benutzer?
{
clear_key_all();
return result;
}
 
 
if( result ) result = cmd_GetVersion();
 
//-----------------------------
// Version pruefen
//-----------------------------
if( result )
{
//--------
// ADHOC
//--------
if( wiflymode == WIFLY_ADHOC )
{
if( (wifly_version != Adhoc_Version1) // 2.32
&& (wifly_version != Adhoc_Version2) // 2.38
)
{
versionerror = true;
}
}
 
//--------
// APMODE
//--------
if( wiflymode == WIFLY_APMODE && wifly_version != Apmode_Version1 ) versionerror = true;
 
if( versionerror )
{
set_Modul_On( USB );
ShowTitle_P( title, true );
lcdx_printf_center_P( 2, MNORMAL, 0, -4, PSTR("WiFly v%s"), wifly_version_string );
lcdx_printf_center_P( 3, MNORMAL, 0, -1, PSTR("ERROR") );
lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("Version no %S!"), strMode ); // "Version no AP-Mode" / "AdHoc"
ask = _ask( ENDE );
 
return false;
}
}
 
 
//-----------------------------
// Benutzer fragen
//-----------------------------
if( result )
{
ShowTitle_P( title, true );
//lcdx_printf_at_P( 0, 1, MINVERS, 0,0, PSTR("%d"), wifly_version );
 
lcdx_printf_center_P( 2, MNORMAL, 0, -4, PSTR("WiFly v%s"), wifly_version_string ); // WiFly Versionsanzeige
lcdx_printf_center_P( 3, MNORMAL, 0, -2, PSTR("%S: OK") , strMode ); // "AP-Mode" oder "AdHoc"
lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("%S?") , title ); // "Init WiFly?"
 
ask = _ask( NOYES );
 
if( !ask ) // "Nein"
{
set_Modul_On( USB );
return false;
}
}
 
 
//-----------------------------
// Init durchfuehren
//-----------------------------
if( result )
{
ShowTitle_P( title, true );
result = wifly_init_perform( wiflymode );
}
 
set_Modul_On( USB );
 
if( !result )
PKT_Message_P( PSTR("Init FAIL!"), true, 3000, true, true ); // max. 30 Sekunden anzeigen
else
PKT_Message_P( PSTR("Init OK!"), false, 3000, true, true ); // max. 30 Sekunden anzeigen
 
clear_key_all();
return( result );
}
 
 
 
//--------------------------------------------------------------
// PARAMETER:
// wiflymode: WIFLY_APMODE = Firmware wifly7-441.img
// WIFLY_ADHOC = Firmware wifly7-2383.img
//--------------------------------------------------------------
uint8_t wifly_update( uint8_t wiflymode )
{
int8_t result = 1; // 1 = true
uint8_t ask = false;
char *title = (char *)PSTR("Update WiFly");
const char *pStr;
 
 
ShowTitle_P( title, true );
 
result = find_WiFly();
 
if( result < 0 ) // Abbruch durch Benutzer?
{
clear_key_all();
return result;
}
 
 
if( result ) result = cmd_GetVersion();
 
//-----------------------------
// Benutzer fragen
//-----------------------------
if( result )
{
if( wiflymode == WIFLY_ADHOC ) pStr = WIFLY_VERSION_ADHOC;
else pStr = WIFLY_VERSION_APMODE;
 
ShowTitle_P( title, true );
//lcdx_printf_at_P( 0, 1, MINVERS, 0,0, PSTR("%d"), wifly_version );
lcdx_printf_center_P( 2, MNORMAL, 0, -4, PSTR("%S: v%s"), strGet(STR_VON), wifly_version_string );
lcdx_printf_center_P( 3, MNORMAL, 0, -2, PSTR("%S: v%S"), strGet(STR_NACH), pStr );
lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("%S?"), title );
 
ask = _ask( NOYES );
 
if( !ask ) // "Nein"
{
set_Modul_On( USB );
return false;
}
}
 
 
//-----------------------------
// Update durchfuehren
//-----------------------------
if( result )
{
ShowTitle_P( title, true );
progress_begin( 16 );
}
 
//----------------------------
// 1. Reset
//----------------------------
#ifndef DEBUG_WIFLY
if( result ) MsgCenter_P( 2, PSTR("Reset"), MNORMAL, 0 );
#endif
if( result ) result = cmd_Reset();
if( result ) result = cmd_Reboot();
if( result ) result = find_WiFly();
 
//----------------------------
// 2. mit Heimnetz verbinden
//----------------------------
#ifndef DEBUG_WIFLY
if( result ) MsgCenter_P( 2, PSTR("verbinde Heimnetz"), MNORMAL, 0 );
#endif
if( result ) result = cmd_Set( PSTR("set ip dhcp 1") );
if( result ) result = cmd_SetStr( PSTR("set wlan phrase"), Config.Wlan_HomePassword );
if( result ) result = cmd_Set( PSTR("set wlan channel 0") );
 
if( result ) result = cmd_Join( Config.Wlan_HomeSSID );
 
//----------------------------
// 3. FTP Download & Update
//----------------------------
#ifndef DEBUG_WIFLY
if( result ) MsgCenter_P( 2, PSTR("FTP Update"), MNORMAL, 0 );
#endif
if( result ) result = cmd_Set( PSTR("set ftp address 198.175.253.161") );
if( result ) result = cmd_Set( PSTR("set ftp dir public") );
if( result ) result = cmd_Set( PSTR("set ftp user roving") );
if( result ) result = cmd_Set( PSTR("set ftp pass Pass123") );
if( result ) result = cmd_Set( PSTR("set ftp timeout 800") );
 
//if( result ) result = cmd_Set( PSTR("del config") );
 
if( result )
{
//-----
// das kann einiges gekuerzt werden wenn das denn zuverlaessig laufen wuerde...
//
// hier wird auf v4.40 geprueft da laut Refrenz-Manual erst seit dieser Version
// "cupdate" unterstuetzt wird. Bei einem Downgraden von v4.4 auf eine aeltere
// Version ist ein clean des Dateisystems ('c') erforderlich da sonst das WiFly
// nur via Hardware-Taster an GPIO9 wiedre zum Leben erweckt werden kann.
//
// Anmerkung: evtl. wuer auch ein "del config" reichen - das ist aber nicht
// hinreichend getestet
//-----
if( wifly_version >= 440 )
{
if( wiflymode == WIFLY_ADHOC )
result = cmdsend( PSTR("ftp cupdate wifly7-2383.img"), 0, PSTR("UPDATE OK"), false );
else
result = cmdsend( PSTR("ftp cupdate wifly7-441.img") , 0, PSTR("UPDATE OK"), false );
}
else
{
if( wiflymode == WIFLY_ADHOC )
result = cmdsend( PSTR("ftp update wifly7-2383.img"), 0, PSTR("UPDATE OK"), false );
else
result = cmdsend( PSTR("ftp update wifly7-441.img") , 0, PSTR("UPDATE OK"), false );
}
}
 
if( result ) result = cmd_Reset();
if( result ) { timer2 = 50; while(timer2); };
 
 
/*
//-----
// Baustelle / Experimente bzgl. FTP-Update
//-----
//debug_message("FTP END");
//debug_message("RESET");
//if( result ) result = cmd_Reboot();
if( result ) { timer2 = 100; while(timer2); };
if( result ) { timer2 = 200; while(timer2); };
debug_message("FINDPR");
uart1_putc('\r');
if( result ) result = find_Prompt();
if( result ) debug_message("FINDPR END: 1");
else debug_message("FINDPR END: 0");
*/
 
 
//progress_end( true ); // Progress abschalten & warten
progress_end( false ); // Progress abschalten
 
 
//----------------------------
// 4. Init
//----------------------------
/*
if( result ) { timer2 = 10; while(timer2); };
if( result ) set_Modul_On( USB );
if( result ) { timer2 = 10; while(timer2); };
if( result ) ShowTitle_P( title, true );
if( result ) result = result = find_WiFly();
if( result ) result = wifly_init_perform( wiflymode );
*/
 
set_Modul_On( USB );
 
 
if( !result )
PKT_Message_P( PSTR("Update FAIL!"), true, 3000, true, true ); // max. 30 Sekunden anzeigen
else
PKT_Message_P( PSTR("Update OK!"), false, 3000, true, true ); // max. 30 Sekunden anzeigen
 
 
clear_key_all();
return result;
}
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
uint8_t wifly_reset( void )
{
int8_t result = 1; // 1 = true
uint8_t ask = false;
char *title = (char *)PSTR("Reset WiFly");
 
ShowTitle_P( title, true );
 
result = find_WiFly();
 
if( result < 0 ) // Abbruch durch Benutzer?
{
clear_key_all();
return result;
}
 
 
//-----------------------------
// Benutzer fragen
//-----------------------------
if( result )
{
ShowTitle_P( title, true );
lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("%S?"), title );
 
ask = _ask( NOYES );
 
if( !ask ) // "Nein"
{
set_Modul_On( USB );
return false;
}
}
 
ShowTitle_P( title, true );
 
if( result ) progress_begin( 2 );
 
if( result ) result = cmd_Reset();
if( result ) result = cmd_Reboot();
 
progress_end( false ); // Progress abschalten
 
set_Modul_On( USB );
 
if( result )
{
//PKT_Message_P( *text, error, timeout, beep, clearscreen )
PKT_Message_P( PSTR("Reset OK!"), false, 3000, true, true ); // max. 30 Sekunden anzeigen
}
else
{
PKT_Message_P( PSTR("Reset FAIL!"), true, 3000, true, true ); // max. 30 Sekunden anzeigen
}
 
clear_key_all();
return result;
}
 
 
 
//#############################################################################
//# TEST / DEBUG
//#############################################################################
 
 
//--------------------------------------------------------------
// nur zum testen!
//--------------------------------------------------------------
uint8_t wifly_test( void )
{
uint8_t result = true;
 
return result;
}
 
#endif
 
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/wifly/PKT_WiFlyHQ.h
0,0 → 1,89
/*-
* Copyright (c) 2012,2013 Darran Hunt (darran [at] hunt dot net dot nz)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/* Release history
*
* Version Date Description
* 0.1 25-Mar-2012 First release.
* 0.2 09-Apr-2012 Added features to support http servers.
* - added an httpserver.ino example.
* - added sendChunk() and sendChunkln() to send chunked HTTP bodies.
* - added terminal() method for simple terminal access via debug stream
* - replaced getFreeMemory() with simpler version that works with 0 bytes
* - turned peek buffer into a circular buffer to fix bug with detecting
* *CLOS* and *OPEN* after a partial match.
* - Added new TCP connection detection via *OPEN* match from available().
* isConnected() can now be polled until a client connects.
* - made the match() function public, handy for matching text in a stream.
* - Added a getProtocol() function to get current set of protocols.
* 0.3 21-Apr-2012 Added createAdhocNetwork() to create an Ad Hoc WiFi network.
* Optimised the setopt() and getopt() function so they handle
* integer conversions and refactored all of the set and get functions.
* Added a multMatch_P() function to match serial data against multiple
* progmem strings.
* Added failure detection to the join() function to quickly detect
* a failure rather than relying on a timeout.
* Added setJoin() and getJoin() function for access to the wlan join parameter.
* Refactored getres() to use the new multiMatch_P() function.
*
*/
 
/**
* @mainpage WiFlyHQ WiFly RN-XV Arduino library
*
* This library provides functions for setting up and managing the WiFly module,
* sending UDP packets, opening TCP connections and sending and receiving data
* over the TCP connection.
*
* @author Harlequin-Tech
*/
 
//############################################################################
//# HISTORY PKT_WiFlyHQ.h
//#
//# 13.04.2014 OG
//# - FAST KOMPLETT NEUER CODE
//#
//# 02.04.2014 OG
//# - add: Versionshistorie ergaenzt
//###########################################################################
 
 
#ifndef _WIFLYHQ_H_
#define _WIFLYHQ_H_
 
// Todo: Strings verfuegbar machen für connect.c
//extern const char WIFLY_IP_ADDRESS[];
//extern const char WIFLY_IP_PORT[];
 
 
uint8_t wifly_update( uint8_t wiflymode );
uint8_t wifly_reset(void);
uint8_t wifly_version_show( void );
uint8_t wifly_init( uint8_t wiflymode );
 
uint8_t wifly_test( void );
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/wifly/wifly_setup.c
0,0 → 1,424
/*
* wifly_setup.c
*
* Created on: 02.07.2013
* Author: cebra
*/
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
 
//############################################################################
//# HISTORY wifly_setup.c
//#
//# 08.06.2014 OG
//# - chg: Setup_WiFly() - Tipptext fuer Module-Installed ergaenzt
//#
//# 04.06.2014 OG
//# - chg: Menuetext angepasst; Menue-Separator hinzugefuegt
//#
//# 31.05.2014 OG
//# - chg: Setup's auf geaendertes Edit_String() umgestellt (Param 'Text' entfernt)
//#
//# 28.05.2014 OG
//# - chg: Setup's auf das neue Edit_generic() umgestellt
//#
//# 13.04.2014 OG
//# - ggf. Probleme beim Downgrade des WiFly auf v2.38 -> deaktiviert
//# - FAST KOMPLETT NEUER CODE
//#
//# 03.04.2014 OG
//# - add: #include "../pkt/pkt.h"
//#
//# 30.03.2014 OG
//# - chg: Text von WL_INSTALLED geaendert von "Modul eingebaut?" auf "Modul vorhanden?"
//# -> das Modul wird aufgesteckt und nicht eingebaut...
//# - chg: ein paar englische Texte geaendert
//# - chg: Sprache Hollaendisch vollstaendig entfernt
//# - chg: MenuCtrl_PushML_P() umgestellt auf MenuCtrl_PushML2_P()
//#
//# 11.03.2014 SH
//# - add: neue Menüpunkte Reset, Version und Update
//# - chg: Menüpunkt Passwort wurde wieder aktiviert
//# - chg: beim Menüpunkt Kanal fängt die Auswahl jetzt bei 0 an (Modul sucht sich automatisch den besten Kanal)
//#
//# 12.02.2014 OG
//# - chg: Setup_WiFly() Auskommentiert: "unused variable 'z'"
//# - chg: Setup_WiFly() Auskommentiert: "unused variable 'i'"
//#
//# 02.07.2013 cebra
//# - new: wifly_setup(): Setup für WiFly WLAN-Modul
//###########################################################################
 
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/interrupt.h>
//#include <avr/pgmspace.h>
//#include <string.h>
//#include <util/delay.h>
//#include <string.h>
 
#include <avr/pgmspace.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#include <util/delay.h>
#include <inttypes.h>
#include <string.h>
 
#include "../main.h"
#include "../messages.h"
#include "../lcd/lcd.h"
#include "../pkt/pkt.h"
#include "../utils/menuctrl.h"
#include "../utils/xutils.h"
#include "../eeprom/eeprom.h"
#include "../uart/uart1.h"
#include "../setup/setup.h"
#include "../wifly/PKT_WiFlyHQ.h"
#include "wifly_setup.h"
 
 
#ifdef USE_WLAN
 
 
//char buffer[20]; // fuer Versionsabfrage
 
 
 
//-----------------------------
// Setup_WiFly() (WLAN)
//-----------------------------
#define WL_INSTALLED 1
#define WL_SSID 2
#define WL_PASSWORD 3
#define WL_CHANNEL 4
#define WL_INIT 5
#define WL_RESET 6
#define WL_VERSION 7
#define WL_UPDATE 8
#define WL_PCCONFIG 9
#define WL_WPA 10
 
#define WL_HOMESSID 11
#define WL_HOMEPASSWORD 12
#define WL_TEST 99
 
 
static const char WL_INSTALLED_de[] PROGMEM = "WiFly Modus";
static const char WL_INSTALLED_en[] PROGMEM = "WiFly mode";
 
static const char WL_SSID_de[] PROGMEM = "SSID";
#define WL_SSID_en WL_SSID_de
 
static const char WL_PASSWORD_de[] PROGMEM = "Passwort";
static const char WL_PASSWORD_en[] PROGMEM = "Password";
 
static const char WL_HOMESSID_de[] PROGMEM = "Home SSID";
#define WL_HOMESSID_en WL_HOMESSID_de
 
static const char WL_HOMEPASSWORD_de[] PROGMEM = "Home Passwort";
static const char WL_HOMEPASSWORD_en[] PROGMEM = "Home Password";
 
static const char WL_CHANNEL_de[] PROGMEM = "Kanal";
static const char WL_CHANNEL_en[] PROGMEM = "Channel";
 
static const char WL_VERSION_de[] PROGMEM = "zeige Version";
static const char WL_VERSION_en[] PROGMEM = "show version";
 
static const char WL_UPDATE_de[] PROGMEM = "Update";
#define WL_UPDATE_en WL_UPDATE_de
 
static const char WL_PCCONFIG_de[] PROGMEM = "WiFly einschalten";
static const char WL_PCCONFIG_en[] PROGMEM = "WiFly power on";
 
static const char WL_WPA_de[] PROGMEM = "Sicherheit";
static const char WL_WPA_en[] PROGMEM = "Security";
 
 
//############################################################################
 
 
//--------------------------------------------------------------
// Setup_WiFly_MenuCreate()
//
// das Menue aendert sich je nachdem ob WiFly ein- oder
// ausgeschaltet ist
//--------------------------------------------------------------
void Setup_WiFly_MenuCreate( void )
{
 
//---------------
// Create
//---------------
MenuCtrl_Create();
 
if( Config.UseWL == WIFLY_APMODE ) MenuCtrl_SetTitle_P( PSTR("WiFly AP-Mode"));
else if( Config.UseWL == WIFLY_ADHOC ) MenuCtrl_SetTitle_P( PSTR("WiFly AdHoc"));
else MenuCtrl_SetTitle_P( PSTR("WiFly"));
 
 
//---------------
// Menuitems
//---------------
MenuCtrl_PushML2_P( WL_INSTALLED , MENU_ITEM, NOFUNC , WL_INSTALLED_de , WL_INSTALLED_en );
 
if( Config.UseWL )
{
//MenuCtrl_Push_P( WL_TEST , MENU_ITEM, NOFUNC , PSTR("TEST") );
 
MenuCtrl_PushML2_P( WL_VERSION , MENU_ITEM, NOFUNC , WL_VERSION_de , WL_VERSION_en );
 
MenuCtrl_PushSeparator();
 
MenuCtrl_PushML2_P( WL_SSID , MENU_ITEM, NOFUNC , WL_SSID_de , WL_SSID_en );
 
if( Config.UseWL == WIFLY_APMODE )
MenuCtrl_PushML2_P( WL_PASSWORD, MENU_ITEM, NOFUNC , WL_PASSWORD_de , WL_PASSWORD_en );
 
MenuCtrl_PushML2_P( WL_CHANNEL , MENU_ITEM, NOFUNC , WL_CHANNEL_de , WL_CHANNEL_en );
 
 
if( Config.UseWL == WIFLY_APMODE )
MenuCtrl_Push_P( WL_INIT , MENU_ITEM, NOFUNC , PSTR("INIT: AP-Mode") );
else
MenuCtrl_Push_P( WL_INIT , MENU_ITEM, NOFUNC , PSTR("INIT: AdHoc") );
 
MenuCtrl_PushSeparator();
 
MenuCtrl_PushML2_P( WL_HOMESSID , MENU_ITEM, NOFUNC , WL_HOMESSID_de , WL_HOMESSID_en );
MenuCtrl_PushML2_P( WL_HOMEPASSWORD, MENU_ITEM, NOFUNC , WL_HOMEPASSWORD_de , WL_HOMEPASSWORD_en );
MenuCtrl_Push_P( WL_UPDATE , MENU_ITEM, NOFUNC , PSTR("UPDATE: WiFly") );
 
MenuCtrl_PushSeparator();
 
MenuCtrl_Push_P( WL_RESET , MENU_ITEM, NOFUNC , PSTR("RESET: WiFly") );
MenuCtrl_PushML2_P( WL_PCCONFIG , MENU_ITEM, &Port_WiFly2Wi , WL_PCCONFIG_de , WL_PCCONFIG_en );
//MenuCtrl_PushML2_P( WL_WPA , MENU_ITEM, NOFUNC , WL_WPA_de , WL_WPA_en );
 
 
if( Config.UseWL == WIFLY_ADHOC )
{
// aktuell kann es zu Problemen kommen wenn das WiFly
// auf v2.38 gedowngraded wird (WiFly nicht mehr ansprechbar)
// -> deshalb: deaktiviert
MenuCtrl_ItemActive( WL_UPDATE, false );
}
}
}
 
 
 
//--------------------------------------------------------------
// Setup_WiFly()
//--------------------------------------------------------------
void Setup_WiFly( void )
{
uint8_t itemid;
uint8_t UseWL;
char string[20];
 
Setup_WiFly_MenuCreate();
 
//---------------
// Control
//---------------
while( true )
{
MenuCtrl_Control( MENUCTRL_EVENT );
 
if( MenuCtrl_GetKey() == KEY_ESC ) break; // ENDE
 
itemid = MenuCtrl_GetItemId(); // welcher Menu-Punkt (ID)
edit = 0;
 
 
//--------------------
// TEST
//--------------------
/*
if( itemid == WL_TEST )
{
lcd_cls();
ShowTitle_P( PSTR("TEST"), true );
wifly_test();
}
*/
 
 
 
//--------------------
// Wlan_INSTALLED
//--------------------
if( itemid == WL_INSTALLED )
{
UseWL = Config.UseWL;
 
Config.UseWL = Edit_generic( Config.UseWL, 0, 2, WlanMode, 1, strGet(STR_EXTSV2MODULE),NULL);
 
if( UseWL != Config.UseWL ) // hat Benutzer Einstellung geaendert?
{
MenuCtrl_Destroy(); // Menue aendern wegen wechsel Wlan vorhanden / nicht vorhanden
Setup_WiFly_MenuCreate();
continue;
}
}
 
 
//--------------------
// WL_VERSION
//--------------------
if( itemid == WL_VERSION )
{
wifly_version_show();
}
 
 
//--------------------
// WL_SSID
//--------------------
if( itemid == WL_SSID )
{
strncpyfill( string, Config.Wlan_SSID, wlan_ssid_length+1 ); // wlan_ssid_length
Edit_String( string, wlan_ssid_length , EDIT_SSID );
 
if( edit == 1 )
{
strrtrim( EditString ); // Leerzeichen rechts entfernen
strncpy( Config.Wlan_SSID, EditString, wlan_ssid_length+1 );
}
}
 
 
//--------------------
// WL_PASSWORD
//--------------------
if( itemid == WL_PASSWORD)
{
strncpyfill( string, Config.Wlan_Password, wlan_password_length+1 ); //
Edit_String( string, wlan_password_length , EDIT_WL_PASSWORD );
 
if( edit == 1 )
{
strrtrim( EditString ); // Leerzeichen rechts entfernen
strncpy( Config.Wlan_Password, EditString, wlan_password_length+1 );
}
}
 
 
//--------------------
// WL_HOMESSID
//--------------------
if( itemid == WL_HOMESSID )
{
strncpyfill( string, Config.Wlan_HomeSSID, wlan_ssid_length+1 ); // wlan_ssid_length
Edit_String( string, wlan_ssid_length , EDIT_SSID );
 
if( edit == 1 )
{
strrtrim( EditString); // Leerzeichen rechts entfernen
strncpy( Config.Wlan_HomeSSID, EditString, wlan_ssid_length+1 );
}
}
 
 
//--------------------
// WL_HOMEPASSWORD
//--------------------
if( itemid == WL_HOMEPASSWORD)
{
strncpyfill( string, Config.Wlan_HomePassword, wlan_password_length+1 ); //
Edit_String( string, wlan_password_length , EDIT_WL_PASSWORD );
 
if( edit == 1 )
{
strrtrim( EditString ); // Leerzeichen rechts entfernen
strncpy( Config.Wlan_HomePassword, EditString, wlan_password_length+1 );
}
}
 
 
 
//--------------------
// WL_CHANNEL
//--------------------
if( itemid == WL_CHANNEL )
{
Config.Wlan_Channel = Edit_generic( Config.Wlan_Channel, 0,13,Show_uint3,1 ,NULL,NULL);
}
 
 
//--------------------
// WL_INIT
//--------------------
if( itemid == WL_INIT )
{
wifly_init( Config.UseWL ); // Config.UseWL = WIFLY_APMODE oder WIFLY_ADHOC
}
 
 
//--------------------
// Wlan_RESET
//--------------------
if( itemid == WL_RESET )
{
wifly_reset();
}
 
 
//--------------------
// Wlan_UPDATE
//--------------------
if( itemid == WL_UPDATE )
{
wifly_update( Config.UseWL ); // Config.UseWL = WIFLY_APMODE oder WIFLY_ADHOC
}
 
//--------------------
// Wlan_WPA
//--------------------
//if( itemid == WL_WPA )
//{
// Config.Wlan_WPA = Edit_generic(Config.Wlan_WPA,0,1,WL3,WlanSecurity,1);
//}
 
} // end: while( true )
 
//---------------
// Destroy
//---------------
MenuCtrl_Destroy();
 
} // end: Setup_WiFly()
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/wifly/wifly_setup.h
0,0 → 1,18
/*
* wifly_setup.h
*
* Created on: 02.07.2013
* Author: cebra
*/
 
#ifndef WIFLY_SETUP_H_
#define WIFLY_SETUP_H_
 
 
#define WIFLY_APMODE 1
#define WIFLY_ADHOC 2
 
 
void Setup_WiFly( void );
 
#endif /* WIFLY_SETUP_H_ */
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/PKT/branches/branch_FollowMeStep2/wifly/.
Property changes:
Added: svn:ignore
+_old_source
+
+_doc