Last active
August 29, 2015 14:04
-
-
Save dmiddlecamp/7990da65953a1b3214a9 to your computer and use it in GitHub Desktop.
CC3000 failing reads at 256 byte boundaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by middleca on 7/17/14. | |
*/ | |
var when = require('when'); | |
var settings = { | |
ip: "192.168.1.49", | |
port: 80, | |
start_size: 0, | |
end_size: 1024 | |
}; | |
//dies at 256 | |
//open a connection, | |
//contruct a test packet | |
//send packet. | |
//wait for positive confirmation | |
//"OK", "Fine." | |
var net = require('net'); | |
var client = null; | |
var packet_size = settings.start_size; | |
var received = null; | |
var expected_count = 0; | |
var count = 0; | |
var core_buffer_size = 128; | |
var testPacketLength = function() { | |
packet_size++; | |
//how many "oks" do we expect to hear back from the core? | |
expected_count = Math.max(Math.ceil(packet_size / core_buffer_size), 1); | |
if (packet_size > settings.end_size) { | |
return when.reject("All done!"); | |
} | |
received = when.defer(); | |
var buf = new Buffer(packet_size); | |
buf.fill(255, 0, packet_size); | |
client.write(buf); | |
console.log("Sending a packet of size " + packet_size); | |
return received.promise; | |
}; | |
var onFinished = function() { | |
console.log("all done!"); | |
process.exit(0); | |
}; | |
var runTestSequence = function() { | |
var done = testPacketLength(); | |
when(done).then(function() { | |
setTimeout(runTestSequence, 50); | |
}, onFinished); | |
}; | |
var countStr = function(str, ndl) { | |
var startIdx = 0; | |
var idx = str.indexOf(ndl, startIdx); | |
var count = 0; | |
while (idx > 0) { | |
count++; | |
startIdx = idx + 1; | |
idx = str.indexOf(ndl, startIdx); | |
} | |
return count; | |
} | |
client = net.connect(settings.port, settings.ip, function() { | |
//console.log("got connection ", arguments); | |
//console.log("client was ", client); | |
client.on("data", function(data) { | |
data = data.toString(); | |
console.log("heard back " + data); | |
if (received) { | |
count += countStr(data, "Ok"); | |
//console.log("expected ", expected_count, " count: ", count); | |
if (expected_count == count) { | |
count = 0; | |
received.resolve(); | |
} | |
} | |
}); | |
runTestSequence(); | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "application.h" | |
//this doesn't work, you need to edit inc/spark_wiring_tcpclient.h | |
//#undef TCPCLIENT_BUF_MAX_SIZE | |
//#define TCPCLIENT_BUF_MAX_SIZE 128 | |
void setup(); | |
void loop(); | |
TCPServer server = TCPServer(80); | |
TCPClient client; | |
uint8_t buffer[1024]; | |
char myIpAddress[24]; | |
void setup() { | |
Serial.begin(115200); | |
server.begin(); | |
Spark.variable("ipAddress", myIpAddress, STRING); | |
IPAddress myIp = Network.localIP(); | |
sprintf(myIpAddress, "%d.%d.%d.%d", myIp[0], myIp[1], myIp[2], myIp[3]); | |
} | |
void loop() { | |
if (client.connected()) { | |
int count = client.available(); | |
if (count > 0) { | |
Serial.println(String(count) + " bytes available"); | |
client.read(buffer, count); | |
const char *response = String(String(count) + String(" Ok")).c_str(); | |
client.write(response); | |
} | |
} | |
else { | |
client = server.available(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment