예제 #1
0
static void fieldAnswerChunkConfirm(NWK_DataReq_t *req) {
  if (hqVerboseOutput) {
    Serial.print(F("  Message confirmation - "));
  }
  if (req->status == NWK_SUCCESS_STATUS) {
    if (hqVerboseOutput) {
      Serial.println(F("success"));
    }
    if (fieldCommandOutput.length() - fieldAnswerChunksAt > 100) {
      fieldAnswerChunksAt += 100;
      fieldAnswerChunk();
      return; // don't free yet
    }
  } else {
    fieldAnswerRetries++;
    if (fieldAnswerRetries > 3) {
      if (hqVerboseOutput) {
        Serial.print(F("error: "));
        Serial.println(req->status);
      }
    } else {
      if (hqVerboseOutput) {
        Serial.println(F("RETRY"));
      }
      NWK_DataReq(req);
      return; // don't free yet
    }
  }
  fieldAnswerTo = 0;
  // Free memory used by Stringbuffer
  fieldCommandOutput = (char*)NULL;
}
예제 #2
0
static void fieldAnswerChunkConfirm(NWK_DataReq_t *req) {
  if (hqVerboseOutput) {
    sp("  Message confirmation - ");
  }
  if (req->status == NWK_SUCCESS_STATUS) {
    if (hqVerboseOutput) {
      speol("success");
    }
    if (strlen(fieldAnswerChunks + fieldAnswerChunksAt) > 100) {
      fieldAnswerChunksAt += 100;
      fieldAnswerChunk();
      return; // don't free yet
    }
  } else {
    fieldAnswerRetries++;
    if (fieldAnswerRetries > 3) {
      if (hqVerboseOutput) {
        sp("error: ");
        speol(req->status);
      }
    } else {
      if (hqVerboseOutput) {
        speol("RETRY");
      }
      NWK_DataReq(req);
      return; // don't free yet
    }
  }
  fieldAnswerTo = 0;
  free(fieldAnswerChunks);
}
예제 #3
0
static bool fieldCommands(NWK_DataInd_t *ind) {
  int ret;
  if (hqVerboseOutput) {
    Serial.print(F("Received command"));
    Serial.print(F("lqi: "));
    Serial.print(ind->lqi);
    Serial.print(F("  "));
    Serial.print(F("rssi: "));
    Serial.println(ind->rssi);
  }

  if (fieldAnswerTo) {
    if (hqVerboseOutput) {
      Serial.println(F("can't receive command while sending answer"));
    }
    return false;
  }

  if (!fieldCommand.concat((const char*)ind->data, ind->size)) {
    return false; // TODO we need to restart or something, no memory
  }

  // when null terminated, do the message
  if (fieldCommand[fieldCommand.length() - 1] != '\0') {
    if (hqVerboseOutput) {
      Serial.println(F("waiting for more"));
    }
    return true;
  }

  if (hqVerboseOutput) {
    Serial.print(F("running command "));
    Serial.println(fieldCommand);
  }

  // run the command and chunk back the results
  setOutputHandler(&printToString<&fieldCommandOutput>);

  // TODO: Once bitlash fixes const-correctness, this and similar casts
  // should be removed.
  ret = (int)doCommand(const_cast<char *>(fieldCommand.c_str()));
  fieldCommand = (char*)NULL;

  resetOutputHandler();

  if (hqVerboseOutput) {
    Serial.print(F("got result "));
    Serial.println(ret);
  }

  // send data back in chunks
  fieldAnswerTo = ind->srcAddr;
  fieldAnswerChunksAt = 0;
  fieldAnswerRetries = 0;
  fieldAnswerChunk();

  return true;
}
예제 #4
0
static bool fieldCommands(NWK_DataInd_t *ind) {
  int total, ret;
//  RgbLed.blinkGreen(200);

  if (hqVerboseOutput) {
    sp("Received command");
    sp("lqi: ");
    sp(ind->lqi);
    sp("  ");
    sp("rssi: ");
    speol(ind->rssi);
  }

  if (fieldAnswerTo) {
    if (hqVerboseOutput) {
      speol("can't receive command while sending answer");
    }
    return false;
  }

  // commands may be larger than one packet, copy and buffer up
  total = fieldCommandLen + ind->size;

  fieldCommand = (char*)realloc(fieldCommand, total);
  if (!fieldCommand) {
    return false; // TODO we need to restart or something, no memory
  }

  memcpy(fieldCommand + fieldCommandLen, ind->data, ind->size);
  fieldCommandLen = total;

  // when null terminated, do the message
  if (fieldCommand[fieldCommandLen-1] != 0) {
    if (hqVerboseOutput) {
      speol("waiting for more");
    }
    return true;
  }

  // run the command and chunk back the results
  setOutputHandler(&bitlashBuffer);
  Shell.bitlashOutput = (char*)malloc(1);
  Shell.bitlashOutput[0] = 0;
  if (hqVerboseOutput) {
    sp("running command ");
    speol(fieldCommand);
  }

  ret = (int)doCommand(fieldCommand);
  if (hqVerboseOutput) {
    sp("got result ");
    speol(ret);
  }

  setOutputHandler(&bitlashFilter);
  fieldCommandLen = 0;

  // send data back in chunks
  fieldAnswerTo = ind->srcAddr;
  fieldAnswerChunks = Shell.bitlashOutput;
  fieldAnswerChunksAt = 0;
  fieldAnswerRetries = 0;
  fieldAnswerChunk();

  return true;
}