EmberStatus emberSerialPrintfLine(uint8_t port, PGM_P formatString, ...)
{
  EmberStatus stat;
  va_list ap;
  va_start (ap, formatString);
  stat = emberSerialPrintfVarArg(port, formatString, ap);
  va_end (ap);
  emberSerialPrintf(port, "\r\n");
  return stat;
}
void printRouteTable(uint8_t serialPort)
{
  EmberRouteTableEntry r;
  uint8_t i;
  bool hit = false;
  for (i = 0; i < EMBER_ROUTE_TABLE_SIZE; i++) {
    if (emberGetRouteTableEntry(i, &r) == EMBER_SUCCESS) {
      hit = true;
      emberSerialPrintf(serialPort,
                        "id:%2X next:%2X status:%p age:%d\r\n",
                        r.destination,
                        r.nextHop,
                        zigbeeRouteStatusNames[r.status],
                        r.age);
      emberSerialWaitSend(serialPort);
    }
  }
  if (! hit)
    emberSerialPrintf(serialPort, "empty route table\r\n");
}
void printNeighborTable(uint8_t serialPort)
{
  EmberNeighborTableEntry n;
  uint8_t i;

  for (i = 0; i < emberNeighborCount(); i++) {
    emberGetNeighbor(i, &n);
    emberSerialPrintf(serialPort, 
            "id:%2X lqi:%d in:%d out:%d age:%d eui:(>)%X%X%X%X%X%X%X%X\r\n",
                      n.shortId,
                      n.averageLqi,
                      n.inCost,
                      n.outCost,
                      n.age,
                      n.longId[7], n.longId[6], n.longId[5], n.longId[4], 
                      n.longId[3], n.longId[2], n.longId[1], n.longId[0]);
    emberSerialWaitSend(serialPort);
    emberSerialBufferTick();
  }
  if (emberNeighborCount() == 0) {
    emberSerialPrintf(serialPort, "empty neighbor table\r\n");
  }
}
Exemple #4
0
EmberStatus halStackInitTokens(void)
{
  #if !defined(BOOTLOADER) && !defined(EMBER_TEST)
    tokTypeMfgFibVersion tokMfg;
    EmberStatus status=EMBER_ERR_FATAL;
    tokTypeStackNvdataVersion tokStack;
    bool mfgTokenVersionValid = false;
    tokTypeMfgFibVersion validMfgTokens[] = VALID_MFG_TOKEN_VERSIONS;
  #endif
  tokensActive = true;



























  if(halInternalSimEeInit()!=EMBER_SUCCESS) {
    TOKENDBG(emberSerialPrintf(SER232,"halInternalSimEeInit Attempt 1 fail\r\n");)
    if(halInternalSimEeInit()!=EMBER_SUCCESS) {
//
// emChooseInterface -- choose an interface for subsequent calls to
// emberUdpListen() or emTcpListen().
//
// When interfaceChoice is 0xFF or prefixChoice is NULL,
// they are ignored. If neither interfaceChoice nor prefixChoice
// are given, an interface menu is printed so the user can decide which
// interface to choose.
//
bool emChooseInterface(uint8_t interfaceChoice,
                       const uint8_t *prefixChoice,
                       bool produceOutput)
{
  struct ifaddrs *addresses[10] = {0};
  struct in6_addr prefix = {0};
  struct in6_addr *ipv6Addresses[10] = {0};
  struct ifaddrs *fullIfAddrs = NULL;

  if (prefixChoice != NULL) {
    if (inet_pton(AF_INET6, prefixChoice, (void*)&prefix) != 1) {
      emberSerialPrintfLine(APP_SERIAL,
                            "Invalid IP address: %s "
                            "(can't change it to network format)",
                            prefixChoice);
      return false;
    }
  }

  int foundCount = emGetIpv6Addresses(addresses, 10, &fullIfAddrs);
  int i;

  if (foundCount == 0) {
    fprintf(stderr, "No global IPv6 interfaces found!\n");
    exit(1);
  }

  if (interfaceChoice == 0xFF) {
    emberSerialPrintfLine(APP_SERIAL, "Choose an interface from below:");
  }

  const char *loopbackAddress = "::1";

  //
  // print out the interfaces
  //
  for (i = 0; i < foundCount; i++) {
    uint8_t addressString[INET6_ADDRSTRLEN] = {0};
    ipv6Addresses[i] =
      &((struct sockaddr_in6*)addresses[i]->ifa_addr)->sin6_addr;

    if (inet_ntop(AF_INET6,
                  ipv6Addresses[i],
                  addressString,
                  sizeof(addressString))
        == NULL) {
      perror("inet_ntop");
      exit(1);
    }

    bool prefixMatch = false;

    if (MEMCOMPARE(&prefix, ipv6Addresses[i], 8) == 0
        || MEMCOMPARE(&prefix, ipv6Addresses[i], 16) == 0) {
      interfaceChoice = i;
    }

    if ((interfaceChoice == 0xFF
         || interfaceChoice == i)
        && produceOutput) {
      emberSerialPrintfLine(APP_SERIAL,
                            "[%u]: %s on interface %s",
                            i,
                            addressString,
                            addresses[i]->ifa_name);
    }
  }

  if (! produceOutput) {
    assert(interfaceChoice != 0xFF);
  } else {
    while (interfaceChoice >= foundCount) {
      emberSerialPrintf(APP_SERIAL, "Choice: ");
      char *line = malloc(1000);
      size_t lineSize = sizeof(line);
      ssize_t bytesRead = getline(&line, &lineSize, stdin);
      interfaceChoice = (bytesRead > 0
                         ? atoi(line)
                         : 0xFF);
      free(line);
    }
  }

  // free later?
  emUnixInterface = strdup(addresses[interfaceChoice]->ifa_name);
  MEMCOPY(emMyIpAddress.bytes, ipv6Addresses[interfaceChoice], 16);
  freeifaddrs(fullIfAddrs);
  return true;
}
EmberStatus emberSerialPrintCarriageReturn(uint8_t port)
{
  return emberSerialPrintf(port, "\r\n");
}
EmberStatus emberSerialWriteByte(uint8_t port, uint8_t byte)
{
  return emberSerialPrintf(port, "%c", byte);
}