Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2136 - 1
/*-
2
 * Copyright (c) 2012,2013 Darran Hunt (darran [at] hunt dot net dot nz)
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
16
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
17
 * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
 
26
/**
27
 * @file WiFly RN-XV Library
28
 */
29
 
30
 
31
 
32
//############################################################################
33
//# HISTORY  PKT_WiFlyHQ.c
34
//#
35
//# 03.06.2014 OG
36
//# - fix: find_WiFly() - Benutzer kann Suche nach WiFly jetzt abbrechen
37
//#        (z.b. weil er kein WiFly angesteckt hat)
38
//#        von dieser Aenderungen betroffen sind auch noch einige Codechanges
39
//#        an anderen Funktionen.
40
//#
41
//# 15.04.2014 OG
42
//# - chg: wifly_init() - Logik bei der Versionsverifikation von WIFLY_ADHOC
43
//#        geaendert da v2.38 ansonsten ggf. den Bach runter gegangen waere.
44
//#        AKTUELL UNGETESTET DA KEIN WIFLY ADHOC VORHANDEN!
45
//# - add: Wifly_update() ein paar Kommentare im Code
46
//# - add: KOMMENTAR zu define DEBUG_WIFLY ! (lesenswert!)
47
//#
48
//# 14.04.2014 Cebra
49
//# - add: Defines für getestete WiFly Softwareversionen
50
//# - add: wifly_init bei der Versionsabfrage erweitert
51
//#
52
//# 13.04.2014 OG
53
//# - ggf. Probleme beim Downgrade des WiFly auf v2.38 -> deaktiviert
54
//# - FAST KOMPLETT NEUER CODE
55
//#
56
//# 03.04.2014 OG
57
//# - add: define DELAY_BEFORE_SAVE
58
//# - add: define DELAY_BEFORE_REBOOT
59
//#
60
//# 02.04.2014 OG
61
//# WIP: etliche weitere Aenderungen....
62
//# - chg: getVersion(): Rueckgabe/Logik geaendert
63
//# - add: define DELAY_AFTER_MODUL_ON
64
//#
65
//# 01.04.2014 SH
66
//# - chg: Nicht benötigte Progmem Strings auskommentiert
67
//#
68
//# 11.03.2014 SH
69
//# - add: neue Funktionen wl_reset() und wl_update()
70
//# - chg: wl_init() wurde komplett auf den neuen AP Modus geändert, die Init Routine vom Ad Hoc Modus befindet sich ausgeklammert darunter
71
//# - chg: getVersion wurde angepasst + neuer Wert für resp_Version[] PROGMEM = "RN-171\r\n" anstatt WiFly
72
//# - chg: setSSID() und setPassphrase() wurden um weiteren Parameter ergänzt
73
//# - chg: createAdhocNetwork angepasst da Funktion setSSID() enthalten
74
//# - del: ausgeklammerte Funktionen getConnection, getDHCPMode, getSpaceReplace, getopt_Asc und join
75
//#
76
//# 12.02.2014 OG
77
//# - chg: readTimeout() Auskommentiert: "unused variable 'ind'"
78
//# - chg: wl_init() Auskommentiert: "unused variable 'dhcpMode'"
79
//#
80
//# 02.07.2013 cebra
81
//# - new: Routinen für WiFly WLAN-Modul
82
//#
83
//###########################################################################
84
 
85
 
86
#include <avr/pgmspace.h>
87
#include <stdbool.h>
88
#include <stdlib.h>
89
#include <stdarg.h>
90
#include <util/delay.h>
91
#include <inttypes.h>
92
#include <string.h>
93
#include "../main.h"
94
#include "PKT_WiFlyHQ.h"
95
#include "../eeprom/eeprom.h"
96
#include "../uart/uart1.h"
97
#include "../timer/timer.h"
98
#include "../lcd/lcd.h"
99
#include "../messages.h"
100
#include "../pkt/pkt.h"
101
#include "../utils/xutils.h"
102
#include "wifly_setup.h"
103
 
104
 
105
#ifdef USE_WLAN
106
 
107
 
108
//----------------------------------------------------
109
// DEBUG
110
//
111
// Wenn 'DEBUG_WIFLY' eingeschalte wird dann werden die Ausgaben
112
// des WiFly auf dem PKT-Screen angezeigt - fast wie bei einem
113
// Terminal Programm!
114
//
115
// Man kann dadurch genaueres erkennen wie die Kommunikation
116
// ablaeuft und mit welchen Strings beispielsweise das WiFly
117
// ein Ok quittiert.
118
//----------------------------------------------------
119
//#define DEBUG_WIFLY
120
 
121
//----------------------------------------------------
122
// unterstützte WiFly Softwareversionen
123
//----------------------------------------------------
124
 
125
#define  Adhoc_Version1   232           // getestet Version 2.32
126
#define  Adhoc_Version2   238           // getestet Version 2.38
127
 
128
#define  Apmode_Version1  441           // getestet Version 4.41
129
 
130
 
131
//----------------------------------------------------
132
// Einstellungen
133
//----------------------------------------------------
134
static const char WIFLY_IP_ADDRESS[]        PROGMEM = "169.254.1.1";
135
static const char WIFLY_IP_PORT[]           PROGMEM = "2000";
136
 
137
static const char WIFLY_IP_GATEWAY[]        PROGMEM = "169.254.1.1";
138
static const char WIFLY_IP_NETMASK[]        PROGMEM = "255.255.0.0";
139
 
140
static const char WIFLY_VERSION_ADHOC[]     PROGMEM = "2.38.3";
141
//static const char WIFLY_VERSION_ADHOC[]     PROGMEM = "v2.32";
142
static const char WIFLY_VERSION_APMODE[]    PROGMEM = "4.41";
143
 
144
 
145
//----------------------------------------------------
146
// Einsstellungen fuer Delay's
147
//----------------------------------------------------
148
//#define WIFLY_DEFAULT_TIMEOUT       500 /* 500 milliseconds */
149
#define WIFLY_DEFAULT_TIMEOUT       100 // n milliseconds
150
 
151
 
152
//----------------------------------------------------
153
//----------------------------------------------------
154
uint8_t     progress_max = 0;
155
uint8_t     progress_act = 0;
156
char        progress_buffer[22];
157
char        buffer[20];
158
 
159
 
160
char        wifly_version_string[12];
161
uint16_t    wifly_version;
162
 
163
 
164
//----------------------------------------------------
165
// Texte
166
//----------------------------------------------------
167
static const char STR_WIFLY_NOT_FOUND[]     PROGMEM = "WiFly not found";
168
 
169
static const char RECEIVE_AOK[]             PROGMEM = "AOK";
170
 
171
#define REPLACE_SPACE_CHAR  '$'     // ersetzt Spaces in einem String-Parameter des WiFly - '$' ist WiFly default (0x24) fuer SSID und Pwd
172
 
173
//static const char []      PROGMEM = "";
174
 
175
//----------------------------------------------------
176
 
177
 
178
//#############################################################################
179
//#
180
//#############################################################################
181
 
182
 
183
//----------------------------------------------------
184
//----------------------------------------------------
185
void debug_begin( void )
186
{
187
    lcd_cls();
188
    lcd_setpos(0,0);
189
}
190
 
191
 
192
//----------------------------------------------------
193
//----------------------------------------------------
194
void debug_wait( void )
195
{
196
    set_beep( 25, 0xffff, BeepNormal );
197
    clear_key_all();
198
    while( !get_key_press(1 << KEY_ESC) && !get_key_press(1 << KEY_ENTER) );
199
    lcd_print_LF();
200
}
201
 
202
 
203
//----------------------------------------------------
204
//----------------------------------------------------
205
void debug_message( uint8_t *text )
206
{
207
    lcd_print_LF();
208
    lcd_print( text, MINVERS );
209
    debug_wait();
210
    lcd_print_LF();
211
}
212
 
213
 
214
 
215
 
216
 
217
 
218
//#############################################################################
219
//#
220
//#############################################################################
221
 
222
 
223
/** Read the next character from the WiFly serial interface.
224
 * Waits up to timeout milliseconds to receive the character.
225
 * @param chp pointer to store the read character in
226
 * @param timeout the number of milliseconds to wait for a character
227
 * @retval true - character read
228
 * @retval false - timeout reached, character not read
229
 */
230
bool readTimeout( char *chp, uint16_t timeout)
231
{
232
    char ch;
233
    timer2 = timeout;
234
 
235
    while( timer2>0 )
236
    {
237
        if( uart1_available() > 0 )
238
        {
239
            ch = uart1_getc();
240
            *chp = ch;
241
 
242
            #ifdef DEBUG_WIFLY
243
            lcd_print_char( ch, MNORMAL);
244
            #endif
245
 
246
            return (true);
247
        }
248
    }
249
 
250
    return (false);
251
}
252
 
253
 
254
 
255
 
256
//--------------------------------------------------------------
257
//--------------------------------------------------------------
258
void flushRx( int timeout )
259
{
260
    char ch;
261
    while( readTimeout( &ch, timeout) );
262
}
263
 
264
 
265
 
266
 
267
/**
268
 * Read characters from the WiFly and match them against the
269
 * progmem string. Ignore any leading characters that don't match. Keep
270
 * reading, discarding the input, until the string is matched
271
 * or until no characters are received for the timeout duration.
272
 * @param str The string to match, in progmem.
273
 * @param timeout fail if no data received for this period (in milliseconds).
274
 * @retval true - a match was found
275
 * @retval false - no match found, timeout reached
276
 */
277
bool match_P( const char *str, uint16_t timeout)
278
{
279
    const char *match = str;
280
    char ch, ch_P;
281
 
282
    ch_P = pgm_read_byte(match);
283
    if( ch_P == '\0' ) return true; /* Null string always matches */
284
 
285
    while( readTimeout( &ch, timeout) )
286
    {
287
        // DEBUG
288
        //lcd_print_char( ch, MNORMAL );
289
 
290
        if( ch == ch_P ) match++;
291
        else
292
        {
293
            match = str; // Restart match
294
            if( ch == pgm_read_byte(match) ) match++;
295
        }
296
 
297
        ch_P = pgm_read_byte( match );
298
        if( ch_P == '\0' ) return (true);
299
    }
300
 
301
    return (false);
302
}
303
 
304
 
305
 
306
 
307
 
308
 
309
//#############################################################################
310
//# progress
311
//#############################################################################
312
 
313
//--------------------------------------------------------------
314
// msg: PROGMEM
315
//--------------------------------------------------------------
316
void progress_begin( uint8_t maxsteps )
317
{
318
    progress_max = maxsteps;
319
    progress_act = 0;
320
}
321
 
322
 
323
//--------------------------------------------------------------
324
// wait4key: true / false
325
//--------------------------------------------------------------
326
void progress_end( uint8_t wait4key )
327
{
328
    progress_max = 0;
329
    progress_act = 0;
330
 
331
    if( wait4key )
332
    {
333
        lcd_printp_at( 12, 7, strGet(ENDE), MNORMAL);                   // Keyline
334
        set_beep( 25, 0xffff, BeepNormal );                             // kurzer Bestaetigungs-Beep
335
        clear_key_all();
336
        while( !get_key_press(1 << KEY_ESC) );                          // warte auf Taste...
337
    }
338
}
339
 
340
 
341
 
342
//--------------------------------------------------------------
343
// msg: PROGMEM
344
//--------------------------------------------------------------
345
void progress_show( const char *msg )
346
{
347
    int8_t  yoffs = 3;
348
 
349
    #ifdef DEBUG_WIFLY
350
    return;
351
    #endif
352
 
353
    if( progress_max )
354
    {
355
        progress_act++;
356
 
357
        lcdx_printf_center_P( 4, MNORMAL, 0,yoffs, PSTR("%d/%d"), progress_act, progress_max );
358
 
359
        if( msg )
360
        {
361
            strncpyat_P( progress_buffer, msg, 20, ' ', 2);
362
 
363
            lcd_frect( 2, (5*8)+yoffs, 124, 7, 0);                                          // Zeile 5 loeschen
364
            lcdx_print_center( 5, (uint8_t *)progress_buffer, MNORMAL, 0,yoffs);            // Text zentriert; String im RAM
365
        }
366
 
367
        lcd_rect_round( 0, 28+yoffs, 127, 22, 1, R2);                                       // Rahmen
368
        _delay_ms(700);                                                                     // fuer Anzeige (Entschleunigung)
369
    }
370
}
371
 
372
 
373
 
374
//--------------------------------------------------------------
375
// gibt zentriert einen Text und loescht vorher die Zeile
376
//--------------------------------------------------------------
377
void MsgCenter_P( uint8_t y, const char *text, uint8_t mode, int8_t yoffs )
378
{
379
    lcdx_cls_row( y, MNORMAL, yoffs );
380
    lcdx_printp_center( y, text, MNORMAL, 0, yoffs );
381
}
382
 
383
 
384
 
385
//#############################################################################
386
//# sendcmd
387
//#############################################################################
388
 
389
 
390
//--------------------------------------------------------------
391
//--------------------------------------------------------------
392
void cmd_showerror( const char *cmdstr)
393
{
394
    //void PKT_Message_P( const char *text, uint8_t error, uint16_t timeout, uint8_t beep, uint8_t clearscreen )
395
    PKT_Message_P( cmdstr, true, 3000, true, true );        // max. 30 Sekunden anzeigen
396
}
397
 
398
 
399
 
400
//--------------------------------------------------------------
401
//--------------------------------------------------------------
402
uint8_t find_Prompt()
403
{
404
    char c;
405
    uint8_t state = 0;
406
 
407
    while( readTimeout( &c, WIFLY_DEFAULT_TIMEOUT) )
408
    {
409
        if( state == 0 && (c == '>') )  { state = 1; continue; }
410
        if( state == 1 && (c == ' ') )  return true;
411
 
412
        if( state == 1 ) break;     // Fehler: nicht vorgesehen
413
    }
414
 
415
    return false;
416
}
417
 
418
 
419
//--------------------------------------------------------------
420
// nicht verwendet...
421
//--------------------------------------------------------------
422
uint8_t find_Prompt2()
423
{
424
    char c;
425
 
426
    timer2 = 800;  // 8 Sekunden max. suchen
427
    while( readTimeout( &c, WIFLY_DEFAULT_TIMEOUT) && timer2 )
428
    {
429
        if( c == '>' )  return true;
430
    }
431
 
432
    return false;
433
}
434
 
435
 
436
 
437
//--------------------------------------------------------------
438
// Das ist erstmal so uebernommen - ob das alles sein muss??
439
//
440
// Put the WiFly into command mode
441
//
442
// RUECKGABE:
443
//  >0: ok
444
//  =0: Fehler
445
//  -1: Abbruch Benutzer
446
//--------------------------------------------------------------
447
int8_t cmd_EnterCommandMode( void )
448
{
449
    uint8_t retry  = 2;
450
    int8_t  result = 0;     // false
451
 
452
    while( retry && !result )
453
    {
454
        //_delay_ms(250);
455
        uart1_puts_p( PSTR("$$$") );
456
        //_delay_ms(250);
457
        _delay_ms(100);
458
        uart1_putc('\r');
459
 
460
        if( get_key_short(1 << KEY_ESC) )       // Abbruch durch Benutzer?
461
        {
462
            return -1;                          //   -1 = Abbruch Benutzer
463
        }
464
 
465
        result = find_Prompt();                 // ggf. result = true
466
        if( !result )
467
        {
468
            retry--;
469
            _delay_ms(250);
470
        }
471
    }
472
 
473
    return result;
474
}
475
 
476
 
477
 
478
//--------------------------------------------------------------
479
// PARAMETER:
480
//   cmdstr       : PROGMEM
481
//   strvalue     : RAM
482
//   match_receive: PROGMEM
483
//   findprompt   : true/false
484
//--------------------------------------------------------------
485
uint8_t cmdsend( const char *cmdstr, const char *strvalue, const char *match_receive, uint8_t findprompt )
486
{
487
    uint8_t result = true;
488
    const char *p;
489
    char c;
490
 
491
    progress_show( cmdstr );
492
 
493
    //--------------------
494
    // Senden...
495
    //--------------------
496
    uart1_puts_p( cmdstr );
497
 
498
    if( strvalue != NULL )
499
    {
500
        uart1_putc(' ');
501
 
502
        p = strvalue;
503
        while( *p )
504
        {
505
            c = *p;
506
            if( c == ' ' ) c = REPLACE_SPACE_CHAR;
507
            uart1_putc( c );
508
            p++;
509
        }
510
    }
511
    uart1_putc('\r');
512
 
513
 
514
    //--------------------
515
    // Antwort...
516
    //--------------------
517
    if( match_receive )
518
    {
519
        //if( !match_P( p, WIFLY_DEFAULT_TIMEOUT) )
520
        if( !match_P( match_receive, 2000) )
521
        {
522
            cmd_showerror( cmdstr );                // Fehler auf PKT Screen anzeigen und durch Benutzer bestaetigen lassen
523
            result = false;
524
        }
525
        // DEBUG
526
        //lcdx_printf_at_P( 2, 7, MINVERS,  0,0, PSTR("%d"), result );
527
    }
528
 
529
    #ifdef DEBUG_WIFLY
530
    debug_wait();
531
    #endif
532
 
533
    // TODO: Kommandos die keinen Prompt zurueckliefern? (evtl. 'reset'?)
534
    //uart1_putc('\r'); // fuer cmd_Join ein extra Return... (bei den anderen Kommandos stoert es nicht)
535
 
536
    if( result && findprompt)
537
    {
538
        result = find_Prompt();
539
    }
540
 
541
    return( result );
542
}
543
 
544
 
545
 
546
//--------------------------------------------------------------
547
// cmdsend_P()
548
//
549
// PARAMETER:
550
//--------------------------------------------------------------
551
uint8_t cmdsend_P( const char *cmdstr, const char *strvalue, const char *match_receive, uint8_t findprompt )
552
{
553
    strncpy_P( buffer, strvalue, 20);
554
    return cmdsend( cmdstr, buffer, match_receive, findprompt );
555
}
556
 
557
 
558
 
559
//--------------------------------------------------------------
560
// Version wird anhand des Prompt's ermittelt
561
// Implementiert als State-Machine
562
//--------------------------------------------------------------
563
uint8_t cmd_GetVersion( void )
564
{
565
    char    c;
566
    uint8_t state = 0;
567
    char    *dst = wifly_version_string;
568
    uint8_t n = 0;
569
 
570
    wifly_version = 0;
571
 
572
    uart1_putc('\r');                                       // erzwinge Prompt
573
 
574
    while( readTimeout( &c, WIFLY_DEFAULT_TIMEOUT) )
575
    {
576
        if( (state == 0) && (c == '<') )
577
        {
578
            state = 1;
579
            continue;
580
        }
581
 
582
        if( (state == 1) && (c != '>') )
583
        {
584
            // TODO: Ende vom Prompt im Fehlerfall catchen...
585
            if( n+1 >= sizeof(wifly_version_string) )
586
                break;
587
            *dst = c;
588
            dst++;
589
            n++;
590
            continue;
591
        }
592
 
593
        if( (state == 1) && (c == '>') )                    //  Versionsstring-Ende erreicht
594
        {
595
            *dst = 0;
596
            state = 2;
597
            break;
598
        }
599
 
600
    }
601
 
602
 
603
    if( state == 2 )
604
    {
605
        //uint16_t  wifly_version;
606
        wifly_version  = (wifly_version_string[0]-'0') * 100;
607
        wifly_version += (wifly_version_string[2]-'0') * 10;
608
        wifly_version += (wifly_version_string[3]-'0') * 1;
609
    }
610
    else
611
    {
612
        cmd_showerror( PSTR("get version") );               // Fehler auf PKT Screen anzeigen und durch Benutzer bestaetigen lassen
613
    }
614
 
615
    return (state == 2);
616
}
617
 
618
 
619
 
620
//--------------------------------------------------------------
621
// cmd_Set()
622
//
623
// PARAMETER:
624
//   cmdstr: PROGMEM
625
//--------------------------------------------------------------
626
uint8_t cmd_Set( const char *cmdstr )
627
{
628
    return cmdsend( cmdstr, 0, RECEIVE_AOK, true );
629
}
630
 
631
 
632
 
633
//--------------------------------------------------------------
634
// cmd_SetStr()
635
//
636
// PARAMETER:
637
//   cmdstr: PROGMEM
638
//   str   : RAM
639
//--------------------------------------------------------------
640
uint8_t cmd_SetStr( const char *cmdstr, const char *str )
641
{
642
    return cmdsend( cmdstr, str, RECEIVE_AOK, true );
643
}
644
 
645
 
646
 
647
//--------------------------------------------------------------
648
// cmd_SetStr()
649
//
650
// PARAMETER:
651
//   cmdstr: PROGMEM
652
//   str   : PROGMEM
653
//--------------------------------------------------------------
654
uint8_t cmd_SetStr_P( const char *cmdstr, const char *str )
655
{
656
    return cmdsend_P( cmdstr, str, RECEIVE_AOK, true );
657
}
658
 
659
 
660
 
661
//--------------------------------------------------------------
662
// cmd_SetNum()
663
//
664
// PARAMETER:
665
//   cmdstr: PROGMEM
666
//   value : Dezimal
667
//--------------------------------------------------------------
668
uint8_t cmd_SetNum( const char *cmdstr, const uint16_t value )
669
{
670
    utoa( value, buffer, 10 );
671
    return cmd_SetStr( cmdstr, buffer);
672
}
673
 
674
 
675
 
676
//--------------------------------------------------------------
677
// cmd_Reset()
678
//--------------------------------------------------------------
679
uint8_t cmd_Reset( void )
680
{
681
    uint8_t result = true;
682
 
683
    //_delay_ms( 500 );
684
    result = cmdsend( PSTR("factory RESET"), 0, PSTR("Defaults"), false );
685
    _delay_ms( 1000 );
686
 
687
    return result;
688
 
689
//  return cmdsend( PSTR("factory RESET"), 0, PSTR("Defaults"), true );
690
}
691
 
692
 
693
 
694
//--------------------------------------------------------------
695
// cmd_Save()
696
//--------------------------------------------------------------
697
uint8_t cmd_Save( void )
698
{
699
    //_delay_ms( DELAY_BEFORE_SAVE );
700
    _delay_ms( 200 );
701
    return cmdsend( PSTR("save"), 0, PSTR("Storing"), true );
702
}
703
 
704
 
705
//--------------------------------------------------------------
706
// cmd_Join()
707
//--------------------------------------------------------------
708
uint8_t cmd_Join( const char *ssid )
709
{
710
    uint8_t result = true;
711
 
712
    result = cmdsend( PSTR("join"), ssid, PSTR("Associated"), false );
713
    if( result )    uart1_putc('\r');;
714
    if( result )    result = find_Prompt();
715
 
716
    return result;
717
}
718
 
719
 
720
 
721
//--------------------------------------------------------------
722
// cmd_Reboot()
723
//--------------------------------------------------------------
724
uint8_t cmd_Reboot( void )
725
{
726
    //_delay_ms( DELAY_BEFORE_REBOOT );
727
    _delay_ms( 300 );
728
    cmdsend( PSTR("reboot"), 0, 0, false );
729
    _delay_ms( 2000 );
730
    return true;
731
}
732
 
733
 
734
 
735
//#############################################################################
736
//# WiFly suchen
737
//#############################################################################
738
 
739
 
740
//--------------------------------------------------------------
741
//--------------------------------------------------------------
742
void find_WiFly_searchmsg( const char *text, uint8_t baud )
743
{
744
    lcd_frect( 0, 2*8, 126, 7, 0);                                                              // Zeile 2 loeschen
745
    lcdx_printf_center_P( 2, MNORMAL, 0,0, PSTR("%S %lu Baud"), text, Baud_to_uint32(baud) );   // Text zentriert
746
}
747
 
748
 
749
 
750
//--------------------------------------------------------------
751
// RUECKGABE:
752
//  >0: ok
753
//  =0: Fehler
754
//  -1: Abbruch Benutzer
755
//--------------------------------------------------------------
756
int8_t find_WiFly_baud( uint8_t baud )
757
{
758
    int8_t result = 1;
759
 
760
    find_WiFly_searchmsg( strGet(STR_SEARCH), baud );
761
 
762
    // Anmerkung 06.04.2014 OG:
763
    // SetBaudUart1() (in uart/uart1.c) setzt nur die Baudrate des Uart.
764
    // Config.PKT_Baudrate wird durch SetBaudUart1() NICHT geaendert!
765
    SetBaudUart1( baud );
766
 
767
    result = cmd_EnterCommandMode();
768
 
769
    if( result > 0 )
770
    {
771
        return baud;                        // Baud gefunden, ok!
772
    }
773
 
774
    return result;                          // nicht gefunden oder Abbruch durch Benutzer
775
}
776
 
777
 
778
 
779
//--------------------------------------------------------------
780
// ok = find_WiFly()
781
//
782
// Sucht das WiFly mit verschiedenen Baudraten.
783
//
784
// Wenn das WiFly mit von Config.PKT_Baudrate (= 57600) abweichender
785
// Baudrate gefunden wird (z.B. 9600 Baud) dann wird das WiFly
786
// automatisch auf 57600 Baud umkonfiguriert damit nachfolgende
787
// Funktionen das nicht mehr beachten muessen.
788
//
789
// RUECKGABE:
790
//  ok = true : WiFly gefunden und ist auf 57600 Baud
791
//  ok = false: kein WiFly gefunden
792
//
793
//  >0: ok
794
//  =0: Fehler
795
//  -1: Abbruch Benutzer
796
//
797
// Anmerkung:
798
//  #define Baud_9600       1
799
//  #define Baud_19200      2
800
//  #define Baud_38400      3
801
//  #define Baud_57600      4
802
//  #define Baud_115200     5
803
//  #define Baud_4800       6
804
//  #define Baud_2400       7
805
//--------------------------------------------------------------
806
int8_t find_WiFly( void )  // search Wifly with all Baudrates
807
{
808
    int8_t result = 1;                                                          // 1 == true
809
    int8_t baud   = 0;
810
 
811
    //inCommandMode = false;
812
    //exitCommand   = 0;
813
 
814
    set_Modul_On( Wlan );                                                       // WiFly einschalten
815
 
816
    timer2 = 60;                                                                // Delay damit das WiFly booten kann
817
    while( timer2 );
818
 
819
    lcd_printp_at(12, 7, strGet(ENDE), MNORMAL);                                // Keyline: "Ende"
820
 
821
    //------------------------
822
    // suche WiFly mit versch. Baudraten
823
    //------------------------
824
    if( baud==0 ) baud = find_WiFly_baud( Baud_57600  );
825
    if( baud==0 ) baud = find_WiFly_baud( Baud_9600   );
826
    if( baud==0 ) baud = find_WiFly_baud( Baud_115200 );
827
    if( baud==0 ) baud = find_WiFly_baud( Baud_38400  );
828
    if( baud==0 ) baud = find_WiFly_baud( Baud_19200  );
829
    if( baud==0 ) baud = find_WiFly_baud( Baud_4800   );
830
    if( baud==0 ) baud = find_WiFly_baud( Baud_2400   );
831
 
832
    lcdx_cls_row( 7, MNORMAL, 0);                                               // Keyline loeschen
833
 
834
    //------------------------
835
    // Abbruch durch Benutzer?
836
    //------------------------
837
    if( baud < 0 )
838
    {
839
        SetBaudUart1( Config.PKT_Baudrate );                                    // orginal Baudrate von Uart1 wieder herstellen
840
        set_Modul_On( USB );                                                    // wieder auf USB zurueckschalten
841
        return -1;                                                              // -1 = Abbruch Benutzer
842
    }
843
 
844
 
845
    //------------------------
846
    // kein WiFly gefunden...
847
    //------------------------
848
    if( baud==0 )                                                               // WiFly nicht gefunden :-(
849
    {
850
        SetBaudUart1( Config.PKT_Baudrate );                                    // orginal Baudrate von Uart1 wieder herstellen
851
        set_Modul_On( USB );                                                    // wieder auf USB zurueckschalten
852
 
853
        //PKT_Message_P( *text, error, timeout, beep, clearscreen )
854
        PKT_Message_P( STR_WIFLY_NOT_FOUND, true, 3000, true, true );           // max. 30 Sekunden anzeigen
855
 
856
        return false;                                                           // 0 = nicht gefunden
857
    }
858
 
859
 
860
    //------------------------
861
    // WiFly gefunden!
862
    //------------------------
863
    find_WiFly_searchmsg( strGet(STR_FOUND), baud );                            // Anzeige: "gefunden..."
864
 
865
 
866
    //------------------------
867
    // WiFly Baud ok?
868
    // -> ggf. WiFly Baud umkonfigurieren
869
    //------------------------
870
    if( Config.PKT_Baudrate != baud )
871
    {
872
        find_WiFly_searchmsg( strGet(STR_SET), Config.PKT_Baudrate );           // Anzeige: "setze..."
873
 
874
        if( result )    result = cmd_Set( PSTR("set u b 57600") );              // -> etwas unsauber hier einfach 57600 zu setzen und nicht Config.PKT_Baudrate
875
        if( result )    result = cmd_Save();
876
        if( result )    result = cmd_Reboot();                                  // true = uart-baud setzen
877
 
878
        SetBaudUart1( Config.PKT_Baudrate );                                    // orginal Baudrate von Uart1 wieder herstellen
879
        if( result )    result = cmd_EnterCommandMode();
880
    }
881
 
882
 
883
    return result;
884
}
885
 
886
 
887
 
888
//#############################################################################
889
//#
890
//#############################################################################
891
 
892
 
893
//--------------------------------------------------------------
894
// zeigt die WiFly-Version an
895
//--------------------------------------------------------------
896
uint8_t wifly_version_show( void )
897
{
898
    int8_t result = 1;                                                  // 1 = true
899
 
900
    ShowTitle_P( PSTR("WiFly Version"), true );
901
 
902
    result = find_WiFly();
903
 
904
    if( result < 0 )                                                    // Abbruch durch Benutzer?
905
    {
906
        clear_key_all();
907
        return result;
908
    }
909
 
910
    if( result ) result = cmd_GetVersion();                             // Ergebnis in 'wifly_version_string'
911
 
912
    set_Modul_On( USB );
913
 
914
    if( result )
915
    {
916
        // TODO:
917
        // Anzeige ob WiFly-Version kompatibel zum gewaehlten
918
        // Mode (AP-Mode, AdHoc) ist
919
        //lcd_frect( 0, 2*8, 126, 7, 0);                                // Zeile 2 loeschen
920
 
921
        lcd_rect_round( 0, 8*4+3, 127, 8*2, 1, R2);                     // Anzeige-Rahmen
922
        lcdx_printf_center_P( 5, MNORMAL, 0,0, PSTR("Version: v%s"), wifly_version_string );
923
 
924
        lcd_printp_at( 12, 7, strGet(ENDE), MNORMAL);                   // Keyline
925
        set_beep( 25, 0xffff, BeepNormal );                             // kurzer Bestaetigungs-Beep
926
 
927
        clear_key_all();
928
        while( !get_key_press(1 << KEY_ESC) );                          // warte auf Taste...
929
    }
930
    else
931
    {
932
        PKT_Message_P( PSTR("Version FAIL!"), true, 3000, true, true );     // max. 30 Sekunden anzeigen
933
    }
934
 
935
    clear_key_all();
936
    return result;
937
}
938
 
939
 
940
 
941
 
942
//--------------------------------------------------------------
943
//--------------------------------------------------------------
944
uint8_t _ask( uint8_t keyline )
945
{
946
    uint8_t     ask = 0;
947
 
948
    lcd_rect_round( 0, 34, 127, 16, 1, R2);                         // Rahmen
949
 
950
    lcd_printp_at( 12, 7, strGet(keyline), MNORMAL);                // Keyline
951
 
952
    if( keyline == ENDE )
953
        set_beep( 1000, 0xffff, BeepNormal );                       // langer Error-Beep
954
    else
955
        set_beep( 25, 0xffff, BeepNormal );                         // kurzer Bestaetigungs-Beep
956
 
957
    clear_key_all();
958
    while( !ask )                                                   // warte auf Ja/Nein
959
    {
960
        if( get_key_press(1 << KEY_ENTER) ) ask = 1;                // "Ja"
961
        if( get_key_press(1 << KEY_ESC) )   ask = 2;                // "Nein"
962
    };
963
 
964
    return( ask==1 );
965
}
966
 
967
 
968
 
969
 
970
//--------------------------------------------------------------
971
//--------------------------------------------------------------
972
uint8_t wifly_init_perform( uint8_t wiflymode ) //AP Mode
973
{
974
    uint8_t     result = true;
975
 
976
    #ifndef DEBUG_WIFLY
977
    MsgCenter_P( 2, PSTR("INIT"), MNORMAL, 0 );
978
    #endif
979
 
980
 
981
    //---------------
982
    // WIFLY_ADHOC
983
    //---------------
984
    if( wiflymode == WIFLY_ADHOC )
985
    {
986
        progress_begin( 9 );
987
 
988
        //if( result ) result = cmd_Set(    PSTR("set u m 1") );                        // ist das notwendig? - (turn off echo)
989
        //if( result ) result = cmd_Set(    PSTR("set sys printlvl 0") );               // ist das notwendig?
990
        //if( result ) result = cmd_Set(    PSTR("set comm remote 0") );                // ist das notwendig?
991
 
992
        if( result ) result = cmd_Set(      PSTR("set wlan join 4") );                  // 4 = AdHoc
993
        if( result ) result = cmd_Set(      PSTR("set ip dhcp 0") );
994
 
995
        if( result ) result = cmd_SetStr_P( PSTR("set ip address"), WIFLY_IP_ADDRESS );
996
        if( result ) result = cmd_SetStr_P( PSTR("set ip gateway"), WIFLY_IP_GATEWAY );
997
        if( result ) result = cmd_SetStr_P( PSTR("set ip netmask"), WIFLY_IP_NETMASK );
998
 
999
        if( result ) result = cmd_SetStr(   PSTR("set wlan ssid"), Config.Wlan_SSID );
1000
        if( result ) result = cmd_SetNum(   PSTR("set wlan chan"), Config.Wlan_Channel );
1001
    }
1002
 
1003
 
1004
    //---------------
1005
    // WIFLY_APMODE
1006
    //---------------
1007
    if( wiflymode == WIFLY_APMODE )
1008
    {
1009
        progress_begin( 13 );
1010
 
1011
        if( result ) result = cmd_Set(      PSTR("set wlan join 7") );
1012
        if( result ) result = cmd_Set(      PSTR("set ip dhcp 4") );
1013
 
1014
        if( result ) result = cmd_SetStr_P( PSTR("set ip address"), WIFLY_IP_ADDRESS );
1015
        if( result ) result = cmd_SetStr_P( PSTR("set ip gateway"), WIFLY_IP_GATEWAY );
1016
        if( result ) result = cmd_SetStr_P( PSTR("set ip netmask"), WIFLY_IP_NETMASK );
1017
 
1018
        if( result ) result = cmd_Set(      PSTR("set wlan rate 3") );
1019
        if( result ) result = cmd_SetStr(   PSTR("set apmode ssid") , Config.Wlan_SSID );
1020
        if( result ) result = cmd_SetStr(   PSTR("set apmode pass") , Config.Wlan_Password );
1021
        if( result ) result = cmd_SetNum(   PSTR("set wlan channel"), Config.Wlan_Channel );
1022
        if( result ) result = cmd_Set(      PSTR("set ip protocol 0x3") );
1023
        if( result ) result = cmd_Set(      PSTR("set apmode link_monitor 0") );
1024
    }
1025
 
1026
    if( result ) result = cmd_Save();
1027
    if( result ) result = cmd_Reboot();
1028
 
1029
    progress_end( false );                              // Progress abschalten
1030
 
1031
    return( result );
1032
}
1033
 
1034
 
1035
 
1036
 
1037
//--------------------------------------------------------------
1038
// ok = wifly_init( wiflymode )
1039
//
1040
// initialisiert das WiFly fuer AP-Mode oder AdHoc
1041
//
1042
// PARAMETER:
1043
//   wiflymode: WIFLY_APMODE = Firmware wifly7-441.img
1044
//              WIFLY_ADHOC  = Firmware wifly7-2383.img
1045
//--------------------------------------------------------------
1046
uint8_t wifly_init( uint8_t wiflymode ) //AP Mode
1047
{
1048
    int8_t      result = 1;                                             // 1 = true
1049
    uint8_t     ask = false;
1050
    uint8_t     versionerror = false;
1051
    char        *title = (char *)PSTR("Init WiFly");
1052
    char        *strMode;
1053
 
1054
    if( wiflymode == WIFLY_ADHOC )  strMode = (char *)PSTR("AdHoc");
1055
    else                            strMode = (char *)PSTR("AP-Mode");
1056
 
1057
    ShowTitle_P( title, true );
1058
 
1059
    result = find_WiFly();
1060
 
1061
    if( result < 0 )                                                    // Abbruch durch Benutzer?
1062
    {
1063
        clear_key_all();
1064
        return result;
1065
    }
1066
 
1067
 
1068
    if( result ) result = cmd_GetVersion();
1069
 
1070
    //-----------------------------
1071
    // Version pruefen
1072
    //-----------------------------
1073
    if( result )
1074
    {
1075
        //--------
1076
        // ADHOC
1077
        //--------
1078
        if( wiflymode == WIFLY_ADHOC )
1079
        {
1080
            if(    (wifly_version != Adhoc_Version1)    // 2.32
1081
                && (wifly_version != Adhoc_Version2)    // 2.38
1082
              )
1083
            {
1084
                versionerror = true;
1085
            }
1086
        }
1087
 
1088
        //--------
1089
        // APMODE
1090
        //--------
1091
        if( wiflymode == WIFLY_APMODE && wifly_version != Apmode_Version1 ) versionerror = true;
1092
 
1093
        if( versionerror )
1094
        {
1095
            set_Modul_On( USB );
1096
            ShowTitle_P( title, true );
1097
            lcdx_printf_center_P( 2, MNORMAL, 0, -4, PSTR("WiFly v%s"), wifly_version_string );
1098
            lcdx_printf_center_P( 3, MNORMAL, 0, -1, PSTR("ERROR") );
1099
            lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("Version no %S!"), strMode );         // "Version no AP-Mode" / "AdHoc"
1100
            ask = _ask( ENDE );
1101
 
1102
            return false;
1103
        }
1104
    }
1105
 
1106
 
1107
    //-----------------------------
1108
    // Benutzer fragen
1109
    //-----------------------------
1110
    if( result )
1111
    {
1112
        ShowTitle_P( title, true );
1113
        //lcdx_printf_at_P( 0, 1, MINVERS,  0,0, PSTR("%d"), wifly_version );
1114
 
1115
        lcdx_printf_center_P( 2, MNORMAL, 0, -4, PSTR("WiFly v%s"), wifly_version_string );     // WiFly Versionsanzeige
1116
        lcdx_printf_center_P( 3, MNORMAL, 0, -2, PSTR("%S: OK")   , strMode );                  // "AP-Mode" oder "AdHoc"
1117
        lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("%S?")      , title );                    // "Init WiFly?"
1118
 
1119
        ask = _ask( NOYES );
1120
 
1121
        if( !ask )  // "Nein"
1122
        {
1123
            set_Modul_On( USB );
1124
            return false;
1125
        }
1126
    }
1127
 
1128
 
1129
    //-----------------------------
1130
    // Init durchfuehren
1131
    //-----------------------------
1132
    if( result )
1133
    {
1134
        ShowTitle_P( title, true );
1135
        result = wifly_init_perform( wiflymode );
1136
    }
1137
 
1138
    set_Modul_On( USB );
1139
 
1140
    if( !result )
1141
        PKT_Message_P( PSTR("Init FAIL!"), true, 3000, true, true );        // max. 30 Sekunden anzeigen
1142
    else
1143
        PKT_Message_P( PSTR("Init OK!"), false, 3000, true, true );     // max. 30 Sekunden anzeigen
1144
 
1145
    clear_key_all();
1146
    return( result );
1147
}
1148
 
1149
 
1150
 
1151
//--------------------------------------------------------------
1152
// PARAMETER:
1153
//   wiflymode: WIFLY_APMODE = Firmware wifly7-441.img
1154
//              WIFLY_ADHOC  = Firmware wifly7-2383.img
1155
//--------------------------------------------------------------
1156
uint8_t wifly_update( uint8_t wiflymode )
1157
{
1158
    int8_t      result = 1;                                             // 1 = true
1159
    uint8_t     ask    = false;
1160
    char        *title = (char *)PSTR("Update WiFly");
1161
    const char  *pStr;
1162
 
1163
 
1164
    ShowTitle_P( title, true );
1165
 
1166
    result = find_WiFly();
1167
 
1168
    if( result < 0 )                                                    // Abbruch durch Benutzer?
1169
    {
1170
        clear_key_all();
1171
        return result;
1172
    }
1173
 
1174
 
1175
    if( result ) result = cmd_GetVersion();
1176
 
1177
    //-----------------------------
1178
    // Benutzer fragen
1179
    //-----------------------------
1180
    if( result )
1181
    {
1182
        if( wiflymode == WIFLY_ADHOC )  pStr = WIFLY_VERSION_ADHOC;
1183
        else                            pStr = WIFLY_VERSION_APMODE;
1184
 
1185
        ShowTitle_P( title, true );
1186
        //lcdx_printf_at_P( 0, 1, MINVERS,  0,0, PSTR("%d"), wifly_version );
1187
        lcdx_printf_center_P( 2, MNORMAL, 0, -4, PSTR("%S: v%s"), strGet(STR_VON), wifly_version_string );
1188
        lcdx_printf_center_P( 3, MNORMAL, 0, -2, PSTR("%S: v%S"), strGet(STR_NACH), pStr );
1189
        lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("%S?"), title );
1190
 
1191
        ask = _ask( NOYES );
1192
 
1193
        if( !ask )  // "Nein"
1194
        {
1195
            set_Modul_On( USB );
1196
            return false;
1197
        }
1198
    }
1199
 
1200
 
1201
    //-----------------------------
1202
    // Update durchfuehren
1203
    //-----------------------------
1204
    if( result )
1205
    {
1206
        ShowTitle_P( title, true );
1207
        progress_begin( 16 );
1208
    }
1209
 
1210
    //----------------------------
1211
    // 1. Reset
1212
    //----------------------------
1213
    #ifndef DEBUG_WIFLY
1214
    if( result ) MsgCenter_P( 2, PSTR("Reset"), MNORMAL, 0 );
1215
    #endif
1216
    if( result ) result = cmd_Reset();
1217
    if( result ) result = cmd_Reboot();
1218
    if( result ) result = find_WiFly();
1219
 
1220
    //----------------------------
1221
    // 2. mit Heimnetz verbinden
1222
    //----------------------------
1223
    #ifndef DEBUG_WIFLY
1224
    if( result ) MsgCenter_P( 2, PSTR("verbinde Heimnetz"), MNORMAL, 0 );
1225
    #endif
1226
    if( result ) result = cmd_Set(      PSTR("set ip dhcp 1") );
1227
    if( result ) result = cmd_SetStr(   PSTR("set wlan phrase"), Config.Wlan_HomePassword );
1228
    if( result ) result = cmd_Set(      PSTR("set wlan channel 0") );
1229
 
1230
    if( result ) result = cmd_Join( Config.Wlan_HomeSSID );
1231
 
1232
    //----------------------------
1233
    // 3. FTP Download & Update
1234
    //----------------------------
1235
    #ifndef DEBUG_WIFLY
1236
    if( result ) MsgCenter_P( 2, PSTR("FTP Update"), MNORMAL, 0 );
1237
    #endif
1238
    if( result ) result = cmd_Set( PSTR("set ftp address 198.175.253.161") );
1239
    if( result ) result = cmd_Set( PSTR("set ftp dir public") );
1240
    if( result ) result = cmd_Set( PSTR("set ftp user roving") );
1241
    if( result ) result = cmd_Set( PSTR("set ftp pass Pass123") );
1242
    if( result ) result = cmd_Set( PSTR("set ftp timeout 800") );
1243
 
1244
    //if( result ) result = cmd_Set( PSTR("del config") );
1245
 
1246
    if( result )
1247
    {
1248
        //-----
1249
        // das kann einiges gekuerzt werden wenn das denn zuverlaessig laufen wuerde...
1250
        //
1251
        // hier wird auf v4.40 geprueft da laut Refrenz-Manual erst seit dieser Version
1252
        // "cupdate" unterstuetzt wird. Bei einem Downgraden von v4.4 auf eine aeltere
1253
        // Version ist ein clean des Dateisystems ('c') erforderlich da sonst das WiFly
1254
        // nur via Hardware-Taster an GPIO9 wiedre zum Leben erweckt werden kann.
1255
        //
1256
        // Anmerkung: evtl. wuer auch ein "del config" reichen - das ist aber nicht
1257
        // hinreichend getestet
1258
        //-----
1259
        if( wifly_version >= 440 )
1260
        {
1261
        if( wiflymode == WIFLY_ADHOC )
1262
            result = cmdsend( PSTR("ftp cupdate wifly7-2383.img"), 0, PSTR("UPDATE OK"), false );
1263
        else
1264
            result = cmdsend( PSTR("ftp cupdate wifly7-441.img") , 0, PSTR("UPDATE OK"), false );
1265
        }
1266
        else
1267
        {
1268
        if( wiflymode == WIFLY_ADHOC )
1269
            result = cmdsend( PSTR("ftp update wifly7-2383.img"), 0, PSTR("UPDATE OK"), false );
1270
        else
1271
            result = cmdsend( PSTR("ftp update wifly7-441.img") , 0, PSTR("UPDATE OK"), false );
1272
        }
1273
    }
1274
 
1275
    if( result ) result = cmd_Reset();
1276
    if( result ) { timer2 = 50; while(timer2); };
1277
 
1278
 
1279
/*
1280
    //-----
1281
    // Baustelle / Experimente bzgl. FTP-Update
1282
    //-----
1283
    //debug_message("FTP END");
1284
    //debug_message("RESET");
1285
    //if( result ) result = cmd_Reboot();
1286
    if( result ) { timer2 = 100; while(timer2); };
1287
    if( result ) { timer2 = 200; while(timer2); };
1288
    debug_message("FINDPR");
1289
    uart1_putc('\r');
1290
    if( result ) result = find_Prompt();
1291
    if( result )    debug_message("FINDPR END: 1");
1292
    else            debug_message("FINDPR END: 0");
1293
*/
1294
 
1295
 
1296
    //progress_end( true );                             // Progress abschalten & warten
1297
    progress_end( false );                              // Progress abschalten
1298
 
1299
 
1300
    //----------------------------
1301
    // 4. Init
1302
    //----------------------------
1303
    /*
1304
    if( result ) { timer2 = 10; while(timer2); };
1305
    if( result ) set_Modul_On( USB );
1306
    if( result ) { timer2 = 10; while(timer2); };
1307
    if( result ) ShowTitle_P( title, true );
1308
    if( result ) result = result = find_WiFly();
1309
    if( result ) result = wifly_init_perform( wiflymode );
1310
    */
1311
 
1312
    set_Modul_On( USB );
1313
 
1314
 
1315
    if( !result )
1316
        PKT_Message_P( PSTR("Update FAIL!"), true, 3000, true, true );      // max. 30 Sekunden anzeigen
1317
    else
1318
        PKT_Message_P( PSTR("Update OK!"), false, 3000, true, true );       // max. 30 Sekunden anzeigen
1319
 
1320
 
1321
    clear_key_all();
1322
    return result;
1323
}
1324
 
1325
 
1326
 
1327
//--------------------------------------------------------------
1328
//--------------------------------------------------------------
1329
uint8_t wifly_reset( void )
1330
{
1331
    int8_t      result = 1;                                             // 1 = true
1332
    uint8_t     ask    = false;
1333
    char        *title = (char *)PSTR("Reset WiFly");
1334
 
1335
    ShowTitle_P( title, true );
1336
 
1337
    result = find_WiFly();
1338
 
1339
    if( result < 0 )                                                    // Abbruch durch Benutzer?
1340
    {
1341
        clear_key_all();
1342
        return result;
1343
    }
1344
 
1345
 
1346
    //-----------------------------
1347
    // Benutzer fragen
1348
    //-----------------------------
1349
    if( result )
1350
    {
1351
        ShowTitle_P( title, true );
1352
        lcdx_printf_center_P( 5, MNORMAL, 0, -1, PSTR("%S?"), title );
1353
 
1354
        ask = _ask( NOYES );
1355
 
1356
        if( !ask )  // "Nein"
1357
        {
1358
            set_Modul_On( USB );
1359
            return false;
1360
        }
1361
    }
1362
 
1363
    ShowTitle_P( title, true );
1364
 
1365
    if( result ) progress_begin( 2 );
1366
 
1367
    if( result ) result = cmd_Reset();
1368
    if( result ) result = cmd_Reboot();
1369
 
1370
    progress_end( false );                              // Progress abschalten
1371
 
1372
    set_Modul_On( USB );
1373
 
1374
    if( result )
1375
    {
1376
        //PKT_Message_P( *text, error, timeout, beep, clearscreen )
1377
        PKT_Message_P( PSTR("Reset OK!"), false, 3000, true, true );        // max. 30 Sekunden anzeigen
1378
    }
1379
    else
1380
    {
1381
        PKT_Message_P( PSTR("Reset FAIL!"), true, 3000, true, true );       // max. 30 Sekunden anzeigen
1382
    }
1383
 
1384
    clear_key_all();
1385
    return result;
1386
}
1387
 
1388
 
1389
 
1390
//#############################################################################
1391
//# TEST / DEBUG
1392
//#############################################################################
1393
 
1394
 
1395
//--------------------------------------------------------------
1396
// nur zum testen!
1397
//--------------------------------------------------------------
1398
uint8_t wifly_test( void )
1399
{
1400
    uint8_t result = true;
1401
 
1402
    return result;
1403
}
1404
 
1405
#endif
1406