Exemplo n.º 1
0
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);
  }
}
Exemplo n.º 2
0
static void printResetInformation(void)
{
  // Information about the most recent reset is printed during startup to aid
  // in debugging.
  emberAfGuaranteedPrintln("Reset info: 0x%x (%p)",
                           halGetResetInfo(),
                           halGetResetString());
#ifdef EMBER_AF_API_DIAGNOSTIC_CORTEXM3
  emberAfGuaranteedPrintln("Extended reset info: 0x%2x (%p)",
                           halGetExtendedResetInfo(),
                           halGetExtendedResetString());
  if (halResetWasCrash()) {
    halPrintCrashSummary(APP_SERIAL);
    halPrintCrashDetails(APP_SERIAL);
    halPrintCrashData(APP_SERIAL);
  }
#endif // EMBER_AF_API_DIAGNOSTIC_CORTEXM3
}
Exemplo n.º 3
0
void emberInitReturn(EmberStatus status)
{
  // If initialization fails, we have to assert because something is wrong.
  emberAfGuaranteedPrintln("Init: 0x%x", status);
  assert(status == EMBER_SUCCESS);
  init = true;

#ifdef EMBER_AF_API_TFTP_BOOTLOAD_TARGET
  emInitializeTftpServer();
  emInitializeTftpBootloader();
#endif
}
Exemplo n.º 4
0
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(&parameters, 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, &parameters);
    /*
    if(!emberStackIsUp()){
    	emberAfGuaranteedPrintln("stack wasn't up");
    	emberJoinNetwork(EMBER_STAR_END_DEVICE, &parameters);
    }
	*/
    //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, &parameters);
    }



    emberRunTask(emAppTask);
  }
}