#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "LoRaWan_APP.h"


#if 0
/* OTAA para*/
uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 };
uint8_t appEui[] = { 0xa0, 0x57, 0x81, 0x00, 0x01, 0x12, 0xaa, 0xf3 };
uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 };


/* ABP para*/
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 };
uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 };
uint32_t devAddr =  ( uint32_t )0x007e6ae1;

void configInit() {

}

#else

config_t myConfig = { 
    .devEui = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 },
    .appEui = { 0xa0, 0x57, 0x81, 0x00, 0x01, 0x12, 0xaa, 0xf3 },
    .appKey = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 },
    .nwkSKey = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
    .appSKey = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
    .devAddr = 0,
    .overTheAirActivation = true,
    .modbus_poll_slots = {
        { .typ = INPUT_REGISTERS, .id = 7, .address = 0x01 },
        { .typ = INPUT_REGISTERS, .id = 7, .address = 0x02 },
        { .typ = UNASSIGNED, .id = 0, .address = 0 },
    }
};

// these variables are defined as externals in the LoRaWAN stack
uint8_t devEui[sizeof(myConfig.devEui)];
uint8_t appEui[sizeof(myConfig.appEui)];
uint8_t appKey[sizeof(myConfig.appKey)];
uint8_t nwkSKey[sizeof(myConfig.nwkSKey)];
uint8_t appSKey[sizeof(myConfig.appSKey)];
uint32_t devAddr;
LoRaMacRegion_t loraWanRegion;
bool overTheAirActivation;

void configInit() {
    memcpy(devEui, myConfig.devEui, sizeof(devEui));
    memcpy(appEui, myConfig.appEui, sizeof(appEui));
    memcpy(appKey, myConfig.appKey, sizeof(appKey));
    memcpy(nwkSKey, myConfig.nwkSKey, sizeof(nwkSKey));
    memcpy(appSKey, myConfig.appSKey, sizeof(appSKey));
    devAddr = myConfig.devAddr;
    loraWanRegion = LORAMAC_REGION_EU868;
    overTheAirActivation = myConfig.overTheAirActivation;
}
#endif 

