bool emPopulateSockAddr(struct sockaddr_storage *storage, const uint8_t *hostString, int family, int streamType, int protocol) { struct addrinfo *results; struct addrinfo *resultIterator; struct addrinfo hints = {0}; hints.ai_family = AF_UNSPEC; int error = getaddrinfo(hostString, NULL, &hints, &results); if (error != 0) { emberSerialPrintfLine(APP_SERIAL, "error during getaddrinfo"); return false; } for (resultIterator = results; resultIterator != NULL; resultIterator = resultIterator->ai_next) { if (resultIterator->ai_family == family && resultIterator->ai_socktype == streamType && resultIterator->ai_protocol == protocol) { MEMCOPY(storage, resultIterator->ai_addr, resultIterator->ai_addrlen); freeaddrinfo(results); return true; } } freeaddrinfo(results); return false; }
void initAndRunMainLoop(void) { EmberStatus status; emberTaskEnableIdling(true); emAppTask = emberTaskInit(emAppEvents); // Initialize the radio and the stack. If this fails, we have to assert // because something is wrong. status = emberInit(); emberSerialPrintfLine(COM_USART2, "Init: 0x%x", status); assert(status == EMBER_SUCCESS); emberAfInit(); emberAfMainInitCallback(); while (TRUE) { // Let the stack or EZSP layer run periodic tasks. emberTick(); // Let the application and plugins run periodic tasks. emberAfMainTickCallback(); emberAfTick(); emberRunTask(emAppTask); } }
void emberInit(void) { emberTaskEnableIdling(true); emberCommandReaderInit(); emSendBinaryManagementCommand(EMBER_INIT_HOST_COMMAND_IDENTIFIER, ""); emberSerialPrintfLine(APP_SERIAL, "thread-app reset"); }
void emberCommandActionHandler(const CommandAction action) { emberAfPushNetworkIndex(emAfCliNetworkIndex); (*action)(); emberAfPopNetworkIndex(); #if defined(EMBER_QA) emberSerialPrintfLine(APP_SERIAL, "CLI Finished"); #endif }
void initAndRunMainLoop(void) { //is working if doing it manually with cli commands #define SENSOR_SINK_SECURITY_KEY {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ 0xAA, 0xAA, 0xAA, 0xAA} uint8_t duration = 0xFF; //says how long it will allow joining (0xFF means a node can join at any time) /////////////////////////////////////////////////////////////////// EmberStatus status; EmberStatus net_status; emberTaskEnableIdling(true); emAppTask = emberTaskInit(emAppEvents); status = emberInit();// (5) (continued from step 4 at end of emberAfMainInitCallback()) Bring up Stack emberSerialPrintfLine(COM_USART2, "Initialization: 0x%x", status); //ember success 0x00 so emberinit worked; stack is up? assert(status == EMBER_SUCCESS); // Initialize the radio and the stack. If this fails, we have to assert // because something is wrong. emberAfInit(); emberAfMainInitCallback(); emberPermitJoining(duration); if(net_status == EMBER_SUCCESS){ emberAfGuaranteedPrintln("Stack is up?"); } if (emberStackIsUp()){ //this does not come out true despite emberinit() is producing EMBER_SUCCESS so stack isn't really up? emberAfGuaranteedPrintln("Stack is definitely up"); } while (TRUE) { // Let the stack or EZSP layer run periodic tasks. emberTick(); //emberAfGuaranteedPrintln("not stuck"); // Let the application and plugins run periodic tasks. emberAfMainTickCallback(); emberAfTick(); emberRunTask(emAppTask); } }
void initAndRunMainLoop(void) { EmberEventControl dataReportControl; EmberStatus status; int counter_reset = 0; emberTaskEnableIdling(true); emAppTask = emberTaskInit(emAppEvents); // Initialize the radio and the stack. If this fails, we have to assert // because something is wrong. status = emberInit(); emberSerialPrintfLine(COM_USART2, "Inititialization: 0x%x", status); //ember success;0x00 so emberinit worked assert(status == EMBER_SUCCESS); emberAfInit(); emberAfMainInitCallback(); //emberNetworkInit() called here emberResetNetworkState(); /////////////////leave network to join coordinator EmberNetworkStatus net_status; EmberNetworkParameters parameters; emberSetSecurityKey(&securityKey); MEMSET(¶meters, 0, sizeof(EmberNetworkParameters)); parameters.radioTxPower = 0; parameters.radioChannel = 1; parameters.panId = 0x01FF; halStackSeedRandom(halCommonGetInt32uMillisecondTick()); while (TRUE) { // Let the stack or EZSP layer run periodic tasks. emberTick(); // Let the application and plugins run periodic tasks. emberAfMainTickCallback(); emberAfTick(); emberEventControlSetActive(dataReportControl); net_status = emberNetworkState(); //emberResetNetworkState(); //emberJoinNetwork(EMBER_STAR_END_DEVICE, ¶meters); /* if(!emberStackIsUp()){ emberAfGuaranteedPrintln("stack wasn't up"); emberJoinNetwork(EMBER_STAR_END_DEVICE, ¶meters); } */ //emberAfGuaranteedPrintln("net_status is: %d", net_status); if(counter_reset == 10000){ emberResetNetworkState(); counter_reset = 0; } else{ counter_reset++; } if (net_status == EMBER_NO_NETWORK){ //emberPermitJoining(0xFF); //emberResetNetworkState(); emberAfGuaranteedPrintln("Network has been reset"); emberJoinNetwork(EMBER_STAR_END_DEVICE, ¶meters); } emberRunTask(emAppTask); } }
// // 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; }