Ejemplo n.º 1
0
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);
  }
}
Ejemplo n.º 2
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);
  }
}
Ejemplo n.º 3
0
void initializeEmberStack(void)
{
  EmberStatus status;
  //Initialize the hal
  halInit();
  INTERRUPTS_ON();
  emberDebugInit(0);
  emberSerialInit(serialPort, serialBaudRate, PARITY_NONE, 1);
  status = emberInit();
  if (status != EMBER_SUCCESS) {
    emberSerialGuaranteedPrintf(serialPort,
                                "emberInit status %x\r\n", status);
    assert(false);
  }
}
Ejemplo n.º 4
0
int MAIN(MAIN_FUNCTION_PARAMETERS)
{
  // Let the application and plugins do early initialization.  This function is
  // generated.
  emberAfMain(MAIN_FUNCTION_ARGUMENTS);

  // Initialize the HAL and enable interrupts.
  halInit();
  INTERRUPTS_ON();

  // Initialize the serial ports.
  SERIAL_INIT();

  // Display diagnostic information about the most recent reset.
  PRINT_RESET_INFORMATION();

  // Initialize a task for the application and plugin events and enable idling.
  emAppTask = emberTaskInit(emAppEvents);
  emberTaskEnableIdling(true);

  // Initialize the stack and wait until it finishes.  We do this so that the
  // application doesn't get ahead of the stack.
  emberInit();
  while (!init) {
    halResetWatchdog();
    PROCESS_MANAGEMENT_COMMAND();
  }
  init = false;

  // Initialize the application and plugins.  This function is generated.
  emberAfInit();

  // Run the application loop, which usually never terminates.
  loop();

  return 0;
}
Ejemplo n.º 5
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);
  }
}