Update the 8266 stuff to my newest build.

This commit is contained in:
cnlohr 2015-08-16 00:54:18 -04:00
parent 30648367b7
commit a1a3d94e28
13 changed files with 424 additions and 47 deletions

View file

@ -128,7 +128,7 @@ int ICACHE_FLASH_ATTR issue_command(char * buffer, int retsize, char *pusrdata,
buffend += ets_sprintf( buffend, "!FM%d\r\n", r );
break;
}
case 'w': case 'W': //Flash Write (FW#\n) <- # = byte pos.
case 'w': case 'W': //Flash Write (FW#\n) <- # = byte pos. Reads until end-of-packet.
if( colon )
{
colon++;
@ -149,6 +149,48 @@ int ICACHE_FLASH_ATTR issue_command(char * buffer, int retsize, char *pusrdata,
}
buffend += ets_sprintf(buffend, "!FW\r\n" );
break;
case 'x': case 'X': //Flash Write Hex (FX#\t#\tDATTAAAAA) <- a = byte pos. b = length (in hex-pairs). Generally used for web-browser.
if( colon )
{
int i;
int siz = 0;
colon++;
char * colon2 = (char *) ets_strstr( (char*)colon, "\t" );
if( colon2 )
{
*colon2 = 0;
siz = my_atoi( colon );
}
//nr = place to write.
//siz = size to write.
//colon2 = data start.
if( colon2 && nr >= 524288)
{
colon2++;
int datlen = ((int)len - (colon2 - pusrdata))/2;
if( datlen > siz ) datlen = siz;
for( i = 0; i < datlen; i++ )
{
int8_t r1 = fromhex1( *(colon2++) );
int8_t r2 = fromhex1( *(colon2++) );
if( r1 == -1 || r2 == -1 ) goto failfx;
buffend[i] = (r1 << 4) | r2;
}
//ets_memcpy( buffer, colon2, datlen );
EnterCritical();
spi_flash_write( nr, (uint32*)buffend, (datlen/4)*4 );
ExitCritical();
buffend += ets_sprintf(buffend, "FX%d\t%d\r\n", nr, siz );
break;
}
}
failfx:
buffend += ets_sprintf(buffend, "!FX\r\n" );
break;
case 'r': case 'R': //Flash Read (FR#\n) <- # = sector.
if( colon )
{

View file

@ -45,7 +45,7 @@ void SHA1Transform(uint32 state[5], const uint8 buffer[64]);
//SPI_FLASH_SEC_SIZE 4096
void SPIEraseSector(uint16 sec); //Doesn't work?
void SPIEraseSector(uint16 sec);
void SPIEraseArea(uint32 start,uint32 len); //Doesn't work?
void SPIEraseBlock(uint16 blk);
void SPIWrite(uint32 des_addr, uint32_t *src_addr, uint32_t size);

View file

@ -7,7 +7,7 @@
#include <stdio.h>
#define SRCSIZE 4096
#define BLKSIZE 65536
static const char * key = "";
static int keylen = 0;
@ -211,30 +211,39 @@ static int MyRewriteFlash( char * command, int commandlen )
//Disable all interrupts.
ets_intr_lock();
ipl = (size1/SRCSIZE)+1;
p = to1/SRCSIZE;
uart_tx_one_char( 'A' );
int j;
ipl = (size1/BLKSIZE)+1;
p = to1/BLKSIZE;
for( i = 0; i < ipl; i++ )
{
SPIEraseSector( p++ );
SPIWrite( to1, (uint32_t*)(0x40200000 + from1), SRCSIZE );
to1 += SRCSIZE;
from1 += SRCSIZE;
SPIEraseBlock( p++ );
for( j = 0; j < BLKSIZE/SRCSIZE; j++ )
{
SPIWrite( to1, (uint32_t*)(0x40200000 + from1), SRCSIZE );
to1 += SRCSIZE;
from1 += SRCSIZE;
}
}
uart_tx_one_char( 'B' );
ipl = (size2/SRCSIZE)+1;
p = to2/SRCSIZE;
ipl = (size2/BLKSIZE)+1;
p = to2/BLKSIZE;
for( i = 0; i < ipl; i++ )
{
SPIEraseSector( p++ );
SPIWrite( to2, (uint32_t*)(0x40200000 + from2), SRCSIZE );
to2 += SRCSIZE;
from2 += SRCSIZE;
SPIEraseBlock( p++ );
for( j = 0; j < BLKSIZE/SRCSIZE; j++ )
{
SPIWrite( to2, (uint32_t*)(0x40200000 + from2), SRCSIZE );
to2 += SRCSIZE;
from2 += SRCSIZE;
}
}
uart_tx_one_char( 'R' );
uart_tx_one_char( 'C' );
void(*rebootme)() = (void(*)())0x40000080;

View file

@ -515,12 +515,14 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
break;
case 5: //Established connection.
{
//XXX TODO: Seems to malfunction on large-ish packets. I know it has problems with 140-byte payloads.
if( curlen < 5 ) //Can't interpret packet.
break;
uint8_t fin = c & 1;
uint8_t opcode = c << 4;
uint32_t payloadlen = *(curdata++);
uint16_t payloadlen = *(curdata++);
curlen--;
if( !(payloadlen & 0x80) )
{
@ -529,6 +531,8 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
break;
}
payloadlen &= 0x7f;
if( payloadlen == 127 )
{
//Very long payload.
@ -543,10 +547,6 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
curdata += 2;
curlen -= 2;
}
else
{
payloadlen &= 0x7f;
}
wsmask[0] = curdata[0];
wsmask[1] = curdata[1];
@ -556,10 +556,21 @@ void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c )
curlen -= 4;
wsmaskplace = 0;
//XXX Warning: When packets get larger, they may split the
//websockets packets into multiple parts. We could handle this
//but at the cost of prescious RAM. I am chosing to just drop those
//packets on the floor, and restarting the connection.
if( curlen < payloadlen )
{
HTDEBUG( "Websocket Fragmented. %d %d\n", curlen, payloadlen );
curhttp->state = HTTP_WAIT_CLOSE;
return;
}
WebSocketData( payloadlen );
curlen -= payloadlen;
curlen -= payloadlen;
curdata += payloadlen;
break;
}
default:

View file

@ -68,11 +68,26 @@ char tohex1( uint8_t i )
return (i<10)?('0'+i):('a'-10+i);
}
int8_t fromhex1( char c )
{
if( c >= '0' && c <= '9' )
return c - '0';
else if( c >= 'a' && c <= 'f' )
return c - 'a' + 10;
else if( c >= 'A' && c <= 'F' )
return c - 'A' + 10;
else
return -1;
}
void ICACHE_FLASH_ATTR EndTCPWrite( struct espconn * conn )
{
if(generic_ptr!=generic_buffer)
espconn_sent(conn,generic_buffer,generic_ptr-generic_buffer);
{
int r = espconn_sent(conn,generic_buffer,generic_ptr-generic_buffer);
}
}
@ -93,6 +108,9 @@ void PushBlob( const uint8 * buffer, int len )
int8_t TCPCanSend( struct espconn * conn, int size )
{
#ifdef SAFESEND
return TCPDoneSend( conn );
#else
struct espconn_packet infoarg;
sint8 r = espconn_get_packet_info(conn, &infoarg);
@ -100,6 +118,7 @@ int8_t TCPCanSend( struct espconn * conn, int size )
return 1;
else
return 0;
#endif
}
int8_t ICACHE_FLASH_ATTR TCPDoneSend( struct espconn * conn )

View file

@ -5,6 +5,7 @@
#ifndef _MYSTUFF_H
#define _MYSTUFF_H
#include <mem.h>
#include <c_types.h>
#include <user_interface.h>
@ -12,6 +13,14 @@
#include <espconn.h>
#include <esp8266_rom.h>
//XXX WARNING As of 1.3.0, "cansend" doesn't work.
//the SDK seems to misbehave when trying to send without a full
//response packet.
#define SAFESEND
extern char generic_print_buffer[384];
extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 };
@ -19,6 +28,7 @@ extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2",
#define printf( ... ) ets_sprintf( generic_print_buffer, __VA_ARGS__ ); uart0_sendStr( generic_print_buffer );
char tohex1( uint8_t i );
int8_t fromhex1( char c ); //returns -1 if not hex char.
int32 my_atoi( const char * in );
void Uint32To10Str( char * out, uint32 dat );