コード例 #1
0
void PinoccioScoutHandler::announce(uint16_t group, const String& message) {
  // when lead scout, shortcut
  if (Scout.isLeadScout()) {
    leadAnnouncementSend(group, Scout.getAddress(), message);
    // Don't broadcast HQ commands over the network if we are a lead
    // scout
    if (!group || group == 0xBEEF)
      return;
  }

  if (hqVerboseOutput) {
    // TODO: This writes to Serial directly, but if we use the bitlash
    // sp functions while we're called from inside a command, this debug
    // output is added to the  command output, which isn't quite what we
    // want. There should be a better way to emit this kind of "log"
    // message.
    Serial.print(F("mesh announcing to "));
    Serial.print(group);
    Serial.print(F(" "));
    Serial.println(message);
  }

  // TODO: Allocate the data and request pointers in a single malloc?
  char *data = strdup(message.c_str());
  if (!data) {
    return;
  }

  if(announceQ[0])
  {
    int i = 1;
    while(i < announceQsize && announceQ[i]) i++;
    if(i == announceQsize) return (void)free(data);
    announceQ[i] = data;
    announceQG[i] = group;
    return;
  }
  announceQ[0] = data;
  announceQG[0] = group;
  announceQSend();
}
コード例 #2
0
void PinoccioScoutHandler::announce(uint16_t group, char *message) {
  if (hqVerboseOutput) {
    sp("announcing to ");
    sp(group);
    sp(" ");
    speol(message);
  }

  // when lead scout, shortcut
  if (Scout.isLeadScout()) {
    leadAnnouncementSend(group, Scout.getAddress(), message);
  }

  char *data = strdup(message);
  if (!data) {
    return;
  }

  struct announceQ_t *r = (struct announceQ_t*)malloc(sizeof(struct announceQ_t));
  if (!r) {
    return;
  }

  Scout.meshJoinGroup(group); // must be joined to send
  memset(r, 0, sizeof(struct announceQ_t));
  r->req.dstAddr = group;
  r->req.dstEndpoint = 4;
  r->req.srcEndpoint = Scout.getAddress();
  r->req.options = NWK_OPT_MULTICAST|NWK_OPT_ENABLE_SECURITY;
  r->req.data = (uint8_t*)data;
  r->req.size = strlen(data)+1;
  r->req.confirm = announceConfirm;
  if (!announceQ) {
    announceQ = r;
    NWK_DataReq(&(r->req));
  } else {
    struct announceQ_t *last = announceQ;
    while(last->next) last = last->next;
    last->next = r;
  }
}
コード例 #3
0
static bool fieldAnnouncements(NWK_DataInd_t *ind) {
  char *data = (char*)ind->data;
  // be safe
  if (!ind->options & NWK_IND_OPT_MULTICAST) {
    return true;
  }

  if (hqVerboseOutput) {
    Serial.print(F("multicast in "));
    Serial.println(ind->dstAddr);
  }
  if (Scout.isLeadScout()) {
    leadAnnouncementSend(ind->dstAddr, ind->srcAddr, ConstBuf(data, ind->size-1)); // no null
  }
  if (!ind->dstAddr || ind->dstAddr == 0xBEEF || strlen(data) < 3 || data[0] != '[') {
    return false;
  }

  int keys[10];
  keyLoad((char*)ind->data, keys, millis());

  // run the Bitlash callback function, if defined
  StringBuffer callback(20);
  callback.appendSprintf("on.message.group", ind->dstAddr);
  if (find_user_function(const_cast<char*>(callback.c_str())) || findscript(const_cast<char*>(callback.c_str()))) {
    StringBuffer buf(64, 16);
    buf.appendSprintf("on.message.group(%d,%d", ind->dstAddr, ind->srcAddr);
    for (int i=2; i<=keys[0]; i++) {
      buf.appendSprintf(",%d", keys[i]);
    }
    buf += ")";
    doCommand(const_cast<char*>(buf.c_str()));
  }

  return true;
}
コード例 #4
0
static bool fieldAnnouncements(NWK_DataInd_t *ind) {
  char callback[32], *data = (char*)ind->data;
  // be safe
  if (!ind->options & NWK_IND_OPT_MULTICAST) {
    return true;
  }

  if (hqVerboseOutput) {
    sp("multicast in ");
    sp(ind->dstAddr);
    speol();
  }
  if (Scout.isLeadScout()) {
    leadAnnouncementSend(ind->dstAddr, ind->srcAddr, data);
  }
  if (ind->dstAddr == 0xBEEF || strlen(data) <3 || data[0] != '[') {
    return false;
  }

  int keys[10];
  keyLoad((char*)ind->data, keys, millis());

  // run the Bitlash callback function, if defined
  sprintf(callback, "event.group%d", ind->dstAddr);
  if (findscript(callback)) {
    char buf[128];
    sprintf(buf, "event.group%d(%d", ind->dstAddr, ind->srcAddr);
    for (int i=2; i<=keys[0]; i++) {
      sprintf(buf + strlen(buf), ",%d", keys[i]);
    }
    sprintf(buf + strlen(buf), ")");
    doCommand(buf);
  }

  return true;
}