IoT - Kubus / Mbed 2 deprecated Kubus

Dependencies:   mbed nRF24L01P

common.h

Committer:
sbarzowski
Date:
2017-01-05
Revision:
10:869163c7929d
Parent:
8:1861d0eef60a
Child:
27:27cffdb2e9d3

File content as of revision 10:869163c7929d:

#ifndef JNP3_COMMON_H
#define JNP3_COMMON_H

#include <stdint.h>
#include <string>
#include "nRF24L01P.h"
#include "mbed.h"

#define DATA_RATE       NRF24L01P_DATARATE_250_KBPS    
#define POWER           NRF24L01P_TX_PWR_ZERO_DB
#define CHANNEL         2
#define TRANSFER_SIZE   32

const unsigned long long MASTER_ADDRESS = 0xABCDEF00;
const unsigned long long PIR1_ADDRESS = 0xABCDEF01;
const unsigned long long PIR2_ADDRESS = 0xABCDEF02;
const unsigned long long DISTANCE_SENSOR_ADDRESS = 0xABCDEF02;
const unsigned long long SOUND_SENSOR_ADDRESS = 0xABCDEF03;

enum SENSOR_TYPE {
    PIR1 = 1,
    PIR2 = 2,
    DISTANCE = 3,
    SOUND = 4,
};

inline bool is_sensor_float(SENSOR_TYPE t) {
    return t == SOUND;
}

struct SensorDescription {
    SensorDescription(int _sensor_id, unsigned long long _rx_address, unsigned long long _tx_address)
        : sensor_id(_sensor_id), rx_address(_rx_address), tx_address(_tx_address) {}
    int sensor_id;
    unsigned long long rx_address;
    unsigned long long tx_address;
};

struct Data {
    Data(uint8_t type_, int32_t i_val)
        : type(type_) {
            value.i = i_val;
        }

    Data(uint8_t type_, float f_val)
        : type(type_) {
            value.f = f_val;
        }
    
    std::string serialize();
    bool deserialize(std::string str);
    
    uint8_t type;
    union {
        int32_t i;
        float f;
    } value;
};

void radio_init(nRF24L01P* radio, unsigned long long rx_address,
        unsigned long long tx_address);

#endif /* JNP3_COMMON */