X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fbme.c;fp=src%2Fbme.c;h=5815e9918f0cf61526d22de4eaf07f9ba7278c30;hb=5b112f7a5d8ae68de4b52ac93374c4d68602f1b6;hp=ba399f0c0035944db380ae164bc1f3c1d6cb0592;hpb=b951f0f45f60917eea7104e44d0f14c3e0d1f189;p=monky diff --git a/src/bme.c b/src/bme.c index ba399f0..5815e99 100644 --- a/src/bme.c +++ b/src/bme.c @@ -73,14 +73,13 @@ static void dumpBuffer(const void *buf, size_t bufSize) const char* bmeClientGetData(const char *bmeSocketPath, struct bme_reply *bmeReply) { - static int x = 0; - printf("%d\n", x); // outputs the value of x //always crashes on 23 or 24 - x = x + 1; + //static int x = 0; + //printf("%d\n", x); // outputs the value of x //always crashes on 23 or 24 + //x = x + 1; int s = socket(AF_LOCAL, SOCK_STREAM, 0); if (s <= 0) return "socket"; - NORM_ERR("bme a"); struct sockaddr_un name; name.sun_family = AF_LOCAL; strcpy(name.sun_path, bmeSocketPath); @@ -89,29 +88,26 @@ const char* bmeClientGetData(const char *bmeSocketPath, struct bme_reply *bmeRep char foo[256]; size_t rd; - NORM_ERR("bme b"); // TODO: clean up this crap write(s, "SYNC\10\0\0\0BMentity", 16); rd = read(s, foo, sizeof(foo)); - NORM_ERR("read %i bytes",rd); //reads 0 right before it crashes + //NORM_ERR("read %i bytes",rd); //reads 9 every time //fprintf(stderr, "rd=%zu\n", rd); - NORM_ERR("bme c"); write(s, "SYNC\4\0\0\0\3\200\0\0\n", 12);//crashes here - NORM_ERR("bme c.5"); + rd = read(s, foo, 20); - NORM_ERR("bme d"); - NORM_ERR("read %i bytes",rd); //reads 0 right before it crashes + //NORM_ERR("bme socket read %i bytes",rd); //reads -1 right before it crashes //fprintf(stderr, "rd=%zu\n", rd); rd = read(s, bmeReply, sizeof(*bmeReply)); //fprintf(stderr, "rd=%zu\n", rd); - NORM_ERR("bme e"); + // FIXME: sometimes we get extra data in replies - NORM_ERR("read %i bytes",rd); //reads 0 right before it crashes + //NORM_ERR("read %i bytes",rd); //reads 0 right before it crashes if (rd > 128){ memmove( bmeReply, ((char*) bmeReply) + rd - 128, 128); } - dumpBuffer(bmeReply, rd); - + // dumpBuffer(bmeReply, rd); + close(s); return 0; } @@ -131,9 +127,9 @@ struct bme_reply getBattInfoFromBME() struct bme_reply bmeReply; memset(&bmeReply, 0, sizeof bmeReply); - NORM_ERR("bme 1"); + //NORM_ERR("bme 1"); const char *failedOn = bmeClientGetData("/tmp/.bmesrv", &bmeReply); - NORM_ERR("bme 2"); + //NORM_ERR("bme 2"); if (failedOn) { NORM_ERR("bme_client_get_data failed on %s: %s\n", failedOn, strerror(errno)); //try again