better error handling and logs

preparing for factory-checker firmware
POWER switch disconnects 5V and GND when turned off
methods for factory checker
test script follows main changes
This commit is contained in:
Masakazu OHTSUKA
2013-12-19 12:48:30 +09:00
parent 9f99b0094b
commit bd0e84eacb
24 changed files with 117 additions and 56 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
**/.DS_Store
logs

View File

@@ -67,9 +67,7 @@ int8_t GSwifi::setup(GSEventHandler on_disconnect, GSEventHandler on_reset) {
clear();
// version 2.5.1 firmware starts with 115200 baud rate
// version 2.5.1 (Tue, Dec 10, 2013 at 2:14 PM) firmware starts with 9600 baud rate
// version 2.4.3 firmware starts with 9600 baud rate
// baud rate is written into default profile in factory
serial_->begin(57600);
// how to change baud rate (2.5.1 has only one profile, don't need to send AT&Y0)
@@ -130,6 +128,51 @@ int8_t GSwifi::setupMDNS() {
return 0;
}
#ifdef FACTORY_CHECKER
int8_t GSwifi::factorySetup() {
clear();
// version 2.5.1 firmware starts with 115200 baud rate
// version 2.5.1 (Tue, Dec 10, 2013 at 2:14 PM) firmware starts with 9600 baud rate
// version 2.4.3 firmware starts with 9600 baud rate
serial_->begin(9600);
// need this to ignore invalid response
command(PB("AT",1), GSCOMMANDMODE_NORMAL);
setBaud(57600);
command(PB("ATE0",1), GSCOMMANDMODE_NORMAL);
command(PB("AT&W0",1), GSCOMMANDMODE_NORMAL);
if (did_timeout_) {
return -1;
}
return 0;
}
int8_t GSwifi::checkVersion() {
command(PB("AT+VER=?",1), GSCOMMANDMODE_VERSION);
if (did_timeout_) {
return -1;
}
return 0;
}
const char *GSwifi::appVersion() {
return versions_[ 0 ];
}
const char *GSwifi::gepsVersion() {
return versions_[ 1 ];
}
const char *GSwifi::wlanVersion() {
return versions_[ 2 ];
}
#endif // FACTORY_CHECKER
int8_t GSwifi::close (uint8_t cid) {
char *cmd = PB("AT+NCLOSE=0", 1);
cmd[ 10 ] = i2x(cid);
@@ -801,6 +844,27 @@ void GSwifi::parseCmdResponse (char *buf) {
gs_response_lines_ = RESPONSE_LINES_ENDED;
}
break;
#ifdef FACTORY_CHECKER
case GSCOMMANDMODE_VERSION:
// expects something like:
// S2W APP VERSION=2.4.3
// S2W GEPS VERSION=2.4.3
// S2W WLAN VERSION=2.4.1
if (gs_response_lines_ == 0) {
memset(versions_, 0, sizeof(versions_));
snprintf(versions_[0], 8, buf+16);
gs_response_lines_ ++;
}
else if (gs_response_lines_ == 1) {
snprintf(versions_[1], 8, buf+17);
gs_response_lines_ ++;
}
else if (gs_response_lines_ == 2) {
snprintf(versions_[2], 8, buf+17);
gs_response_lines_ = RESPONSE_LINES_ENDED;
}
break;
#endif
}
return;

View File

@@ -26,6 +26,7 @@
#define DEBUG
#include "Arduino.h"
#include "env.h"
#include "GSwifi_const.h"
#include "ringbuffer.h"
#include "HardwareSerialX.h"
@@ -65,6 +66,9 @@ public:
GSCOMMANDMODE_STATUS,
GSCOMMANDMODE_MDNS,
GSCOMMANDMODE_MAC,
#ifdef FACTORY_CHECKER
GSCOMMANDMODE_VERSION,
#endif
};
enum GSREQUESTSTATE {
@@ -198,6 +202,13 @@ public:
bool bufferEmpty();
char bufferGet();
#ifdef FACTORY_CHECKER
int8_t factorySetup();
int8_t checkVersion();
const char* appVersion();
const char* gepsVersion();
const char* wlanVersion();
#endif
#ifdef DEBUG
void dump ();
@@ -212,6 +223,9 @@ private:
GSCOMMANDMODE gs_commandmode_;
char ipaddr_[16]; // xxx.xxx.xxx.xxx
char mac_[17]; // 00:1d:c9:01:99:99
#ifdef FACTORY_CHECKER
char versions_[3][8]; // APP,GEPS,WLAN
#endif
struct GSRoute routes_[GS_MAX_ROUTES];
uint8_t route_count_;

View File

@@ -487,8 +487,8 @@ void IR_dump (void)
// Serial.print(P(".x:")); Serial.println(IrCtrl.tx_index,HEX);
// Serial.print(P(".r:")); Serial.println(IrCtrl.recv_timer);
// Serial.print(P(".x:")); Serial.println(IrCtrl.xmit_timer);
// Serial.print(P("p.l:")); Serial.println(packer.length(),HEX);
// for (uint16_t i=0; i<packer.length(); i++) {
// Serial.print(P("p.l:")); Serial.println(IR_packedlength(),HEX);
// for (uint16_t i=0; i<IR_packedlength(); i++) {
// Serial.print((uint8_t)sharedbuffer[i], HEX);
// Serial.print(" ");
// }

View File

@@ -31,6 +31,7 @@ extern uint16_t irpacker_length( const volatile struct irpacker_t *state );
extern void irpacker_unpack_start( volatile struct irpacker_t *state );
extern uint16_t irpacker_unpack( volatile struct irpacker_t *state );
extern void irpacker_load( void *offset );
extern void irpacker_save( void *offset );
#ifdef __cplusplus
}

5
firmware/src/IRKit/env.h Normal file
View File

@@ -0,0 +1,5 @@
#ifndef __ENV_H__
#define __ENV_H__
#endif

View File

@@ -1 +1 @@
../../../src/main/HardwareSerialX.cpp
../../../src/IRKit/HardwareSerialX.cpp

View File

@@ -1 +1 @@
../../../src/main/HardwareSerialX.h
../../../src/IRKit/HardwareSerialX.h

View File

@@ -17,7 +17,7 @@ void setup() {
digitalWrite( LDO33_ENABLE, HIGH );
// gainspan
Serial1X.begin(57600);
Serial1X.begin(9600);
}
void loop() {

View File

@@ -1 +1 @@
../../../src/main/pgmStrToRAM.c
../../../src/IRKit/pgmStrToRAM.c

View File

@@ -1 +1 @@
../../../src/main/pgmStrToRAM.h
../../../src/IRKit/pgmStrToRAM.h

View File

@@ -1 +1 @@
../../../src/main/pins.h
../../../src/IRKit/pins.h

View File

@@ -1 +1 @@
../../../src/main/ringbuffer.c
../../../src/IRKit/ringbuffer.c

View File

@@ -1 +1 @@
../../../src/main/ringbuffer.h
../../../src/IRKit/ringbuffer.h

View File

@@ -0,0 +1 @@
../../../src/IRKit/IrPacker.c

View File

@@ -1 +0,0 @@
../../../src/main/IrPacker.cpp

View File

@@ -1 +1 @@
../../../src/main/IrPacker.h
../../../src/IRKit/IrPacker.h

View File

@@ -1 +1 @@
../../../src/main/MemoryFree.c
../../../src/IRKit/MemoryFree.c

View File

@@ -1 +1 @@
../../../src/main/MemoryFree.h
../../../src/IRKit/MemoryFree.h

View File

@@ -22,36 +22,9 @@ void setup() {
while ( ! Serial ) ; // wait for leonardo
uint8_t buff[100];
IrPacker packer(buff);
/* packer.load( (void*) 177 ); */
packer.save( (void*) 169 );
irpacker_save( (void*) 169 );
Serial.println("saved!");
/* uint8_t packed = packer.pack( 30 ); */
/* uint16_t unpacked = packer.unpack( packed ); */
/* Serial.print("packed: "); Serial.println(packed); */
/* Serial.print("unpacked: "); Serial.println(unpacked); */
/* setBuffer8( buff, 21, */
/* 0xba, 0xa6, */
/* 0x01 /\* marker *\/, */
/* 0x7e /\* val0:815 *\/, */
/* 0x9e /\* val1:2451 *\/, */
/* 0x71 /\* length: 113bits = 15byte *\/, */
/* 0x04, 0x40, 0x50, 0x14, 0x00, 0x00, 0x00, 0x40, */
/* 0x00, 0x40, 0x10, 0x00, 0x45, 0x55, 0x00 */
/* ); */
/* packer.length_ = 21; */
/* unsigned long before = micros(); */
/* packer.unpackStart(); */
/* for (uint8_t i=0; i<115; i++) { */
/* uint16_t unpacked = packer.unpack(); */
/* // Serial.println(unpacked); */
/* } */
/* unsigned long after = micros(); */
/* Serial.print( "after-before[us]: " ); Serial.println(after-before); */
}
void loop() {

View File

@@ -1 +1 @@
../../../src/main/pgmStrToRAM.c
../../../src/IRKit/pgmStrToRAM.c

View File

@@ -1 +1 @@
../../../src/main/pgmStrToRAM.h
../../../src/IRKit/pgmStrToRAM.h

View File

@@ -948,7 +948,6 @@ design rules under a new name.</description>
<contactref element="LED1" pad="K"/>
<contactref element="ICSP" pad="6"/>
<contactref element="CN1" pad="8"/>
<contactref element="SW1" pad="3"/>
<contactref element="JP1" pad="1"/>
<contactref element="LED2" pad="K"/>
<polygon width="0.6096" layer="16">
@@ -1300,6 +1299,9 @@ design rules under a new name.</description>
<wire x1="14.1" y1="13.5" x2="14.14" y2="13.48" width="0.254" layer="1"/>
<wire x1="7.1" y1="13.5" x2="7.05" y2="13.5" width="0.254" layer="1"/>
</signal>
<signal name="N$8">
<contactref element="SW1" pad="3"/>
</signal>
</signals>
<errors>
<approved hash="3,16,6bf2281828126bf8"/>

View File

@@ -1336,7 +1336,6 @@ Distributor Buerklin, 11G810</description>
<part name="+3V3" library="supply1" deviceset="+3V3" device=""/>
<part name="IC1" library="my" deviceset="JAPANINO-SLIM" device=""/>
<part name="SW1" library="my" deviceset="SLIDE-SWITCH1/2" device="" value="SS12D01G4"/>
<part name="GND2" library="supply1" deviceset="GND" device=""/>
<part name="JP1" library="pinhead" deviceset="PINHD-1X6" device="/90" value="TTL-232R-3V3"/>
<part name="GND3" library="supply1" deviceset="GND" device=""/>
<part name="R4" library="my" deviceset="RESISTOR-US" device="2012" value="1k"/>
@@ -1358,6 +1357,7 @@ Distributor Buerklin, 11G810</description>
<part name="X3" library="my" deviceset="PAD-N" device=""/>
<part name="X4" library="my" deviceset="PAD-N" device=""/>
<part name="GND6" library="supply1" deviceset="GND" device=""/>
<part name="X5" library="my" deviceset="PAD-N" device=""/>
</parts>
<sheets>
<sheet>
@@ -1385,7 +1385,6 @@ http://creativecommons.org/license/by-sa/2.5/</text>
<instance part="+3V3" gate="G$1" x="152.4" y="147.32"/>
<instance part="IC1" gate="G$1" x="172.72" y="198.12"/>
<instance part="SW1" gate="1" x="134.62" y="238.76" rot="R270"/>
<instance part="GND2" gate="1" x="139.7" y="220.98"/>
<instance part="JP1" gate="A" x="264.16" y="134.62"/>
<instance part="GND3" gate="1" x="251.46" y="124.46"/>
<instance part="R4" gate="G$1" x="231.14" y="139.7" rot="R90"/>
@@ -1407,6 +1406,7 @@ http://creativecommons.org/license/by-sa/2.5/</text>
<instance part="X3" gate="G$1" x="218.44" y="78.74"/>
<instance part="X4" gate="G$1" x="218.44" y="88.9"/>
<instance part="GND6" gate="1" x="154.94" y="233.68"/>
<instance part="X5" gate="G$1" x="142.24" y="233.68"/>
</instances>
<busses>
</busses>
@@ -1437,11 +1437,6 @@ http://creativecommons.org/license/by-sa/2.5/</text>
<wire x1="175.26" y1="132.08" x2="175.26" y2="129.54" width="0.1524" layer="91"/>
</segment>
<segment>
<pinref part="SW1" gate="1" pin="S"/>
<pinref part="GND2" gate="1" pin="GND"/>
<wire x1="139.7" y1="233.68" x2="139.7" y2="223.52" width="0.1524" layer="91"/>
</segment>
<segment>
<pinref part="GND3" gate="1" pin="GND"/>
<wire x1="251.46" y1="127" x2="251.46" y2="142.24" width="0.1524" layer="91"/>
<pinref part="JP1" gate="A" pin="1"/>
@@ -1716,6 +1711,12 @@ http://creativecommons.org/license/by-sa/2.5/</text>
<label x="266.7" y="139.7" size="1.778" layer="95" xref="yes"/>
</segment>
</net>
<net name="N$8" class="0">
<segment>
<pinref part="SW1" gate="1" pin="S"/>
<wire x1="139.7" y1="233.68" x2="142.24" y2="233.68" width="0.1524" layer="91"/>
</segment>
</net>
</nets>
</sheet>
</sheets>