IoT - Kubus / Mbed 2 deprecated Kubus

Dependencies:   mbed nRF24L01P

common.h

Committer:
pannaannap
Date:
2017-01-05
Revision:
7:e51d0fbb1a25
Parent:
6:98401b545e0c
Child:
8:1861d0eef60a

File content as of revision 7:e51d0fbb1a25:

#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,
};

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_, uint8_t counter_)
        : type(type_), counter(counter_) {}
    
    // TODO correct?
    Data(std::string serialized)
        : type(serialized[0]), counter(serialized[1]) {}
    
    std::string serialize();
    
    uint8_t type;
    uint8_t counter;
};

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

#endif /* JNP3_COMMON */