UKHAS: Don't insert nulls when skipped is called

pull/1/merge
Daniel Richman 2012-07-29 13:49:25 +01:00
rodzic 276e0702d2
commit 7752c8341f
5 zmienionych plików z 30 dodań i 25 usunięć

Wyświetl plik

@ -10,8 +10,15 @@ You will need these dependencies:
- [libcURL](http://curl.haxx.se/)
Both build from source fairly easily, but the easiest way to acquire them for
Ubuntu lucid is:
Ubuntu is:
- [JsonCpp (PPA)](https://launchpad.net/~danieljonathanrichman/+archive/ppa)
- [libcURL (apt)](http://packages.ubuntu.com/lucid/libcurl4-openssl-dev)
for Ubuntu oneiric (11.10) and older
- [libjsoncpp-dev (apt)](http://packages.ubuntu.com/precise/libjsoncpp-dev)
- [libcurl4-openssl-dev (apt)](http://packages.ubuntu.com/precise/libcurl4-openssl-dev)
Or Debian:
- libjsoncpp-dev in wheezy and newer (the wheezy package also works fine on squeeze)
- libcurl4-openssl-dev

Wyświetl plik

@ -22,11 +22,19 @@ void UKHASExtractor::reset_buffer()
void UKHASExtractor::skipped(int n)
{
if (n > 20)
n = 20;
if (extracting)
{
skipped_count += n;
for (int i = 0; i < n; i++)
push('\0', PUSH_NONE);
/* If radio goes silent for too long (~10s at 50baud,
* ~1.5s at 300baud) */
if (skipped_count > 50)
{
mgr->status("UKHAS Extractor: giving up (silence)");
reset_buffer();
extracting = false;
}
}
}
void UKHASExtractor::push(char b, enum push_flags flags)
@ -41,6 +49,7 @@ void UKHASExtractor::push(char b, enum push_flags flags)
buffer.push_back(b);
garbage_count = 0;
skipped_count = 0;
extracting = true;
mgr->status("UKHAS Extractor: found start delimiter");
@ -82,7 +91,7 @@ void UKHASExtractor::push(char b, enum push_flags flags)
garbage_count++;
/* Sane limits to avoid uploading tonnes of garbage */
if (buffer.length() > 1000 || garbage_count > 16)
if (buffer.length() > 1000 || garbage_count > 32)
{
mgr->status("UKHAS Extractor: giving up");

Wyświetl plik

@ -12,6 +12,7 @@ class UKHASExtractor : public Extractor
int extracting;
char last;
string buffer;
int skipped_count;
int garbage_count;
void reset_buffer();

Wyświetl plik

@ -178,21 +178,21 @@ class TestUKHASExtractor:
self.test_extracts()
def test_gives_up_after_16skipped(self):
def test_gives_up_after_50_skipped(self):
self.extr.push("$$")
self.extr.check_status("start delim")
self.extr.skipped(10000)
self.extr.skipped(51)
self.extr.check_status("giving up")
self.extr.check_quiet()
self.extr.push("\n")
self.extr.check_quiet()
def test_gives_up_after_16garbage(self):
def test_gives_up_after_32_garbage(self):
self.extr.push("$$")
self.extr.check_status("start delim")
self.extr.push("some,legit,data")
self.extr.push("\t some printable data" * 17)
self.extr.push("\t some printable data" * 33)
self.extr.check_status("giving up")
self.extr.check_quiet()
@ -207,9 +207,7 @@ class TestUKHASExtractor:
self.extr.check_status("start delim")
self.extr.skipped(5)
self.extr.push("data\n")
# JsonCPP doesn't support \0 in strings, so the mock UploaderThread
# replaces it with \1s
self.extr.check_upload("$$some\1\1\1\1\1data\n")
self.extr.check_upload("$$somedata\n")
self.extr.check_status("extracted")
self.extr.check_status("parse failed")
self.extr.check_data()

Wyświetl plik

@ -42,13 +42,6 @@ public:
namespace habitat {
static void inplace_nonulls(char &c)
{
/* JsonCPP doesn't support '\0' in strings :'-( */
if (c == '\0')
c = '\1';
}
class UploaderThread
{
public:
@ -56,12 +49,9 @@ public:
const Json::Value &metadata=Json::Value::null,
int time_created=-1)
{
std::string data_copy(data);
std::for_each(data_copy.begin(), data_copy.end(), inplace_nonulls);
Json::Value root(Json::arrayValue);
root.append("upload");
root.append(data_copy);
root.append(data);
root.append(metadata);
root.append(time_created);