Exemplo n.º 1
0
/**	Read 4-byte page.
 *
 *	@param page	Page number
 */
void SL018::readPage(byte page)
{
	data[0] = 2;
	data[1] = CMD_READ4;
	data[2] = page;
	transmitData();
}
Exemplo n.º 2
0
/**	Read 16-byte block.
 *
 *	@param block Block number
 */
void SL018::readBlock(byte block)
{
	data[0] = 2;
	data[1] = CMD_READ16;
	data[2] = block;
	transmitData();
}
Exemplo n.º 3
0
DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, const Action &action)
{

    QList<int> rawData;
    QByteArray binCode;

    int repetitions = 10;

    if (action.actionTypeId() == upActionTypeId) {
        binCode = "10101000";
    } else if (action.actionTypeId() == downActionTypeId) {
        binCode = "10100000";
    } else if (action.actionTypeId() == syncActionTypeId) {
        binCode = "10100000";
        repetitions = 20;
    } else {
        return DeviceManager::DeviceErrorActionTypeNotFound;
    }

    // append ID
    binCode.append("100101010110011000000001");

    //QByteArray remoteId = "100101010110011000000001";
    //    QByteArray motionDetectorId = "100100100101101101101010";
    //QByteArray wallSwitchId = "000001001101000010110110";
    //    QByteArray randomID     = "100010101010111010101010";



    // =======================================
    //create rawData timings list
    int delay = 650;

    // sync signal
    rawData.append(1);
    rawData.append(10);

    // add the code
    foreach (QChar c, binCode) {
        if(c == '0'){
            rawData.append(1);
            rawData.append(2);
        }
        if(c == '1'){
            rawData.append(2);
            rawData.append(1);
        }
    }

    // =======================================
    // send data to driver
    if(transmitData(delay, rawData, repetitions)){
        qCDebug(dcRF433) << "transmitted successfully" << pluginName() << device->name() << action.actionTypeId();
        return DeviceManager::DeviceErrorNoError;
    }else{
        qCWarning(dcRF433) << "could not transmitt" << pluginName() << device->name() << action.actionTypeId();
        return DeviceManager::DeviceErrorHardwareNotAvailable;
    }
}
Exemplo n.º 4
0
void transmitString(const char * pString)
{
    int index = 0;
    while(pString[index])
    {
        transmitData(pString[index++]);
    }
}
Exemplo n.º 5
0
/** Write master key (key A).
 *
 *	@param sector Sector number
 *	@param key Key value (6 bytes)
 */
void SL018::writeKey(byte sector, byte key[6])
{
	data[0] = 8;
	data[1] = CMD_WRITE_KEY;
	data[2] = sector;
	memcpy(data + 3, key, 6);
	transmitData();
}
Exemplo n.º 6
0
/**	Turns on/off the RF field.
 *
 *	@param level 0 is off, anything else is on
 */
void SM130::setAntennaPower(byte level)
{
	antennaPower = level;
	data[0] = 2;
	data[1] = CMD_ANTENNA_POWER;
	data[2] = antennaPower;
	transmitData();
}
Exemplo n.º 7
0
/** Authenticate with transport key (0xFFFFFFFFFFFF).
 *
 *	@param block Block number
 */
void SM130::authenticate(byte block)
{
	data[0] = 3;
	data[1] = CMD_AUTHENTICATE;
	data[2] = block;
	data[3] = 0xff;
	transmitData();
}
Exemplo n.º 8
0
/** Authenticate with transport key (0xFFFFFFFFFFFF).
 *
 *	@param sector Sector number
 */
void SL018::authenticate(byte sector)
{
	data[0] = 9;
	data[1] = CMD_LOGIN;
	data[2] = sector;
	data[3] = 0xAA;
	memset(data + 4, 0xFF, 6);
	transmitData();
}
Exemplo n.º 9
0
/**	Write 16-byte block.
 *
 *	The block will be padded with zeroes if the message is shorter
 *	than 15 characters.
 *
 *	@param block Block number
 *	@param message Null-terminated string of up to 15 characters
 */
void SM130::writeBlock(byte block, const char* message)
{
	data[0] = 18;
	data[1] = CMD_WRITE16;
	data[2] = block;
	strncpy((char*)data + 3, message, 15);
	data[18] = 0;
	transmitData();
}
Exemplo n.º 10
0
/**	Write 4-byte page.
 *
 *	This command is used for Mifare Ultralight tags which have 4 byte pages.
 *
 *	@param page Page number
 *	@param message Null-terminated string of up to 3 characters
 */
void SL018::writePage(byte page, const char* message)
{
	data[0] = 6;
	data[1] = CMD_WRITE4;
	data[2] = page;
	strncpy((char*)data + 3, message, 3);
	data[6] = 0;
	transmitData();
}
Exemplo n.º 11
0
/** Authenticate with specified key A or key B.
 *
 *	@param block Block number
 *	@param keyType Which key to use: 0xAA for key A or 0xBB for key B
 *	@param key Key value (6 bytes)
 */
void SM130::authenticate(byte block, byte keyType, byte key[6])
{
	data[0] = 9;
	data[1] = CMD_AUTHENTICATE;
	data[2] = block;
	data[3] = keyType;
	memcpy(data + 4, key, 6);
	transmitData();
}
Exemplo n.º 12
0
/**	Write 4-byte block.
 *
 *	This command is used for Mifare Ultralight tags which have 4 byte blocks.
 *
 *	@param block Block number
 *	@param message Null-terminated string of up to 3 characters
 */
void SM130::writeFourByteBlock(byte block, const char* message)
{
	data[0] = 6;
	data[1] = CMD_WRITE4;
	data[2] = block;
	strncpy((char*)data + 3, message, 3);
	data[6] = 0;
	transmitData();
}
Exemplo n.º 13
0
DeviceManager::DeviceError DevicePluginUnitec::executeAction(Device *device, const Action &action)
{   
    QList<int> rawData;
    QByteArray binCode;

    if (action.actionTypeId() != powerActionTypeId) {
        return DeviceManager::DeviceErrorActionTypeNotFound;
    }

    // Bin codes for buttons
    if (device->paramValue("Channel").toString() == "A" && action.param("power").value().toBool() == true) {
        binCode.append("111011000100111010111111");
    } else if (device->paramValue("Channel").toString() == "A" && action.param("power").value().toBool() == false) {
        binCode.append("111001100110100001011111");
    } else if (device->paramValue("Channel").toString() == "B" && action.param("power").value().toBool() == true) {
        binCode.append("111011000100111010111011");
    } else if (device->paramValue("Channel").toString() == "B" && action.param("power").value().toBool() == false) {
        binCode.append("111000111001100111101011");
    } else if (device->paramValue("Channel").toString() == "C" && action.param("power").value().toBool() == true) {
        binCode.append("111000000011011111000011");
    } else if (device->paramValue("Channel").toString() == "C" && action.param("power").value().toBool() == false) {
        binCode.append("111001100110100001010011");
    } else if (device->paramValue("Channel").toString() == "D" && action.param("power").value().toBool() == true) {
        binCode.append("111001100110100001011101");
    } else if (device->paramValue("Channel").toString() == "D" && action.param("power").value().toBool() == false) {
        binCode.append("111000000011011111001101");
    }

    // =======================================
    //create rawData timings list
    int delay = 500;

    // add sync code
    rawData.append(6);
    rawData.append(14);

    // add the code
    foreach (QChar c, binCode) {
        if(c == '0'){
            rawData.append(2);
            rawData.append(1);
        }else{
            rawData.append(1);
            rawData.append(2);
        }
    }

    // =======================================
    // send data to hardware resource
    if(transmitData(delay, rawData)){
        qCDebug(dcUnitec) << "transmitted" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
        return DeviceManager::DeviceErrorNoError;
    }else{
        qCWarning(dcUnitec) << "could not transmitt" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
        return DeviceManager::DeviceErrorHardwareNotAvailable;
    }
}
Exemplo n.º 14
0
/** Authenticate with specified key A or key B.
 *
 *	@param sector Sector number
 *	@param keyType Which key to use: 0xAA for key A or 0xBB for key B
 *	@param key Key value (6 bytes)
 */
void SL018::authenticate(byte sector, byte keyType, byte key[6])
{
	data[0] = 9;
	data[1] = CMD_LOGIN;
	data[2] = sector;
	data[3] = keyType;
	memcpy(data + 4, key, 6);
	transmitData();
}
Exemplo n.º 15
0
/**	Write 16-byte block.
 *
 *	The block will be padded with zeroes if the message is shorter
 *	than 15 characters.
 *
 *	@param block Block number
 *	@param message string of 16 characters (binary safe)
 */
void SL018::writeBlock(byte block, const char* message)
{
	data[0] = 18;
	data[1] = CMD_WRITE16;
	data[2] = block;
	//strncpy((char*)data + 3, message, 15); // not binary safe
	memcpy( (char*)data + 3, message, 16 );
	data[18] = 0;
	transmitData();
}
Exemplo n.º 16
0
//send some data on an fd, for a special slot and connection_id
eData sendData(tSlot* slot, unsigned char* data, int len)
{
	// only poll connection if we are not awaiting an answer
	slot->pollConnection = false;

	//send data_last and data
	if (len < 127) {
		unsigned char *d = (unsigned char*) malloc(len + 5);
		memcpy(d + 5, data, len);
		d[0] = slot->slot;
		d[1] = slot->connection_id;
		d[2] = T_DATA_LAST;
		d[3] = len + 1;
		d[4] = slot->connection_id;
		len += 5;
		transmitData(slot, d, len);
	}
	else if (len > 126 && len < 255) {
		unsigned char *d = (unsigned char*) malloc(len + 6);
		memcpy(d + 6, data, len);
		d[0] = slot->slot;
		d[1] = slot->connection_id;
		d[2] = T_DATA_LAST;
		d[3] = 0x81;
		d[4] = len + 1;
		d[5] = slot->connection_id;
		len += 6;
		transmitData(slot, d, len);
	}
	else if (len > 254) {
		unsigned char *d = (unsigned char*) malloc(len + 7);
		memcpy(d + 7, data, len);
		d[0] = slot->slot;
		d[1] = slot->connection_id;
		d[2] = T_DATA_LAST;
		d[3] = 0x82;
		d[4] = len >> 8;
		d[5] = len + 1;
		d[6] = slot->connection_id;
		len += 7;
		transmitData(slot, d, len);
	}
Exemplo n.º 17
0
/**
 * This function is called when a packet is received by the radio. It will
 * process the packet.
 */
inline void processData(uint32_t len) {
    uint8_t i, packet_len;

    for(i=0; i<len; i++) {
        //finds the end of the packet
        if(data_temp[i] != ']')
            continue;

        //then terminates the string, ignore everything afterwards
        data_temp[i+1] = '\0';

        //Check validity of string
        // 1) is the first position in array a number
        //printf("%d\r\n", data_temp[0]);
        if((int)data_temp[0] <= 48 || (int)data_temp[0] > 57) {
            //printf("Error1\r\n");
            break;
        }

        // 2) is the second position in array a letter
        //      < 'a' or > 'z' then break
        //printf("%d\r\n", data_temp[1]);
        if((int)data_temp[1] < 97 || (int)data_temp[1] > 122) {
            //printf("Error2\r\n");
            break;
        }

#ifdef GATEWAY
        printf("rx: %s|%d\r\n",data_temp, RFM69_lastRssi());
#endif
        //Reduce the repeat value
        data_temp[0] = data_temp[0] - 1;
        //Now add , and end line and let string functions do the rest
        data_temp[i] = ',';
        data_temp[i+1] = '\0';

        if(strstr(data_temp, NODE_ID) != 0)
            break;

        strcat(data_temp, NODE_ID); // Add ID
        strcat(data_temp, "]"); // Add ending

        packet_len = strlen(data_temp);
        mrtDelay(random_output); // Random delay to try and avoid packet collision

        rx_packets++;

        transmitData(packet_len);
        break;
    }
}
Exemplo n.º 18
0
int HacDeviceManager::searchDevices()
{
	int retry = 3;
	bool found = false;
	while (retry --) {
		QByteArray data(8, 0);
		data[0] = 0x00;
		data[1] = 0x03;
		data[2] = 0x00;
		data[3] = 0x00;
		data[4] = 0x00;
		data[5] = 32;
		crc.crc_16bit=0xffff;
		calccrc(data[0]);
		calccrc(data[1]);
		calccrc(data[2]);
		calccrc(data[3]);
		calccrc(data[4]);
		calccrc(data[5]);
		data[6] = crc.crc_8bit[0];
		data[7] = crc.crc_8bit[1];
		transmitData(data);
		data = receiveData();
		qDebug() << data.toHex();
		if (data.at(0)== 0x00 && data.at(1) == 0x03 &&data.at(2)== 32
			&& data.at(3) == 0x0E && data.at(4) == 0xAA && data.at(5) == 0x11 && data.at(6) == 0xA0) {
			found = true;
			break;
		}
	}

	if (found) {
		d_devices.append(new HacSwitchDevice(this, this));
#ifdef HAC_SWITCH_TEST
		for (int i = 0; i < 18; i++) {
			HacSwitchDevice *swtDev = qobject_cast<HacSwitchDevice *>(d_devices.at(0));
			swtDev->switchControl(i, true);
			HacHelp::MSleep(100);
		}

		for (int i = 0; i < 18; i++) {
			HacSwitchDevice *swtDev = qobject_cast<HacSwitchDevice *>(d_devices.at(0));
			swtDev->switchControl(i, false);
			HacHelp::MSleep(100);
		}
#endif
	}
}
Exemplo n.º 19
0
int main(void)
{
#ifdef ZOMBIE_MODE
    LPC_SYSCON->BODCTRL = 0x11;  //Should be set to Level 1 (Assertion 2.3V, De-assertion 2.4V) reset
#endif

#if defined(GATEWAY) || defined(DEBUG)
    // Initialise the UART0 block for printf output
    uart0Init(115200);
#endif

    // Configure the multi-rate timer for 1ms ticks
    mrtInit(__SYSTEM_CLOCK/1000);

    /* Enable AHB clock to the Switch Matrix , UART0 , GPIO , IOCON, MRT , ACMP */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7) | (1 << 14) /*| (1 << 6)*//* | (1 << 18)*/
                                 | (1 << 10) | (1 << 19);

    // Configure the switch matrix (setup pins for UART0 and SPI)
    configurePins();



#ifdef DEBUG
    mrtDelay(100);
    printf("Node Booted\r\n");
    mrtDelay(100);
#endif

    RFM69_init();

#ifdef ZOMBIE_MODE
    //This is to allow the setup to recover from the initial boot and
    // avoid a loop
    RFM69_setMode(RFM69_MODE_SLEEP);
    init_sleep();
    sleepMicro(20000);
#endif

#ifdef DEBUG
    printf("Node initialized, version %s\r\n",GIT_VER);
#endif

    //Seed random number generator, we can use our 'unique' ID
    random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2];


    while(1) {

        /*
        #ifdef ZOMBIE_MODE
        adc_result = acmpVccEstimate();
        // Before transmitting if the input V is too low we could sleep again
        if (adc_result < 3100 || adc_result > 10000) {
            sleepRadio();
        }
        #endif
        */



        incrementPacketCount();

        //Clear buffer
        data_temp[0] = '\0';
        uint8_t n;

        //Create the packet
        int int_temp;
#ifdef ZOMBIE_MODE
        //This is to allow the setup to recover from the initial boot and
        // avoid a loop
        RFM69_setMode(RFM69_MODE_SLEEP);
        init_sleep();
        sleepMicro(10000);
#endif

        int_temp = RFM69_readTemp(); // Read transmitter temperature


        rx_rssi = RFM69_lastRssi();
        // read the rssi threshold before re-sampling noise floor which will change it
        rssi_threshold = RFM69_lastRssiThreshold();
        floor_rssi = RFM69_sampleRssi();

#ifdef ZOMBIE_MODE
        //This is to allow the setup to recover from the initial boot and
        // avoid a loop
        RFM69_setMode(RFM69_MODE_SLEEP);
        init_sleep();
        sleepMicro(10000);
#endif

#ifdef ZOMBIE_MODE
        adc_result = acmpVccEstimate();
        //sleepMicro(20000);
#endif

#ifdef DEBUG
        printf("ADC: %d\r\n", adc_result);

#endif
#ifdef ZOMBIE_MODE
        //This is to allow the setup to recover from the initial boot and
        // avoid a loop
        RFM69_setMode(RFM69_MODE_SLEEP);
        init_sleep();
        sleepMicro(10000);
#endif

        if(data_count == 97) {
            n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID);
        }
        else {

#ifdef DEBUG
            //n = sprintf(data_temp, "%d%cT%dR%d,%dC%dX%d,%dV%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, rx_restarts, rssi_threshold, adc_result, NODE_ID);
            n = sprintf(data_temp, "%d%cT%dV%d[%s]", NUM_REPEATS, data_count, int_temp, adc_result, NODE_ID);
#elif defined(ZOMBIE_MODE)
            n = sprintf(data_temp, "%d%cT%dV%d[%s]", NUM_REPEATS, data_count, int_temp, adc_result, NODE_ID);
#else
            n = sprintf(data_temp, "%d%cT%dR%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, NODE_ID);
#endif
        }

        transmitData(n);

#ifdef ZOMBIE_MODE
        sleepRadio();
#else
        awaitData(TX_GAP);
#endif

    }

}
Exemplo n.º 20
0
int32_t main(void)
{

#ifndef PIC32_STARTER_KIT
    /*The JTAG is on by default on POR.  A PIC32 Starter Kit uses the JTAG, but
    for other debug tool use, like ICD 3 and Real ICE, the JTAG should be off
    to free up the JTAG I/O */
    DDPCONbits.JTAGEN = 0;
#endif

    /*Refer to the C32 peripheral library documentation for more
    information on the SYTEMConfig function.
    
    This function sets the PB divider, the Flash Wait States, and the DRM
    /wait states to the optimum value.  It also enables the cacheability for
    the K0 segment.  It could has side effects of possibly alter the pre-fetch
    buffer and cache.  It sets the RAM wait states to 0.  Other than
    the SYS_FREQ, this takes these parameters.  The top 3 may be '|'ed
    together:
    
    SYS_CFG_WAIT_STATES (configures flash wait states from system clock)
    SYS_CFG_PB_BUS (configures the PB bus from the system clock)
    SYS_CFG_PCACHE (configures the pCache if used)
    SYS_CFG_ALL (configures the flash wait states, PB bus, and pCache)*/

    /* TODO Add user clock/system configuration code if appropriate.  */
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL); 

    /* Initialize I/O and Peripherals for application */
    InitApp();

    /*Configure Multivector Interrupt Mode.  Using Single Vector Mode
    is expensive from a timing perspective, so most applications
    should probably not use a Single Vector Mode*/
    // Configure UART2 RX Interrupt
    INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);

    // configure for multi-vectored mode
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

    // enable interrupts
    INTEnableInterrupts();


    /* TODO <INSERT USER APPLICATION CODE HERE> */
    //Open UART2
    OpenUART2(UART_EN, UART_BRGH_FOUR|UART_RX_ENABLE | UART_TX_ENABLE, 21);

    //Open SPI 1 channel
    PORTBbits.RB11 = 1;
    OpenSPI1( SPI_MODE8_ON | MASTER_ENABLE_ON | SEC_PRESCAL_1_1 | PRI_PRESCAL_1_1 | FRAME_ENABLE_OFF | CLK_POL_ACTIVE_HIGH | ENABLE_SDO_PIN , SPI_ENABLE );
    SPI1BRG=39;
    initRadio();
    setTXAddress("UNIT2");
    setRXAddress(0,"UNIT1");
    char temp;
    char text[6];
    text[0]='H';
    text[1]='e';
    text[2]='l';
    text[3]='l';
    text[4]='o';
    text[5]='!';
    while(1)
    {
        setTransmitter();
        PORTBbits.RB11 = 0;
        DelayMs(20);
        transmitData(&text[0],6);
        printf("Hello world! \r\n");
        PORTBbits.RB11 = 1;
        DelayMs(20);
    }
}
Exemplo n.º 21
0
DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device, const Action &action)
{

    QList<int> rawData;
    QByteArray binCode;

    QString familyCode = device->paramValue("familyCode").toString();

    // =======================================
    // generate bin from family code
    if(familyCode == "A"){
        binCode.append("00000000");
    }else if(familyCode == "B"){
        binCode.append("01000000");
    }else if(familyCode == "C"){
        binCode.append("00010000");
    }else if(familyCode == "D"){
        binCode.append("01010000");
    }else if(familyCode == "E"){
        binCode.append("00000100");
    }else if(familyCode == "F"){
        binCode.append("01000100");
    }else if(familyCode == "G"){
        binCode.append("01000000");
    }else if(familyCode == "H"){
        binCode.append("01010100");
    }else if(familyCode == "I"){
        binCode.append("00000001");
    }else if(familyCode == "J"){
        binCode.append("01000001");
    }else if(familyCode == "K"){
        binCode.append("00010001");
    }else if(familyCode == "L"){
        binCode.append("01010001");
    }else if(familyCode == "M"){
        binCode.append("00000101");
    }else if(familyCode == "N"){
        binCode.append("01000101");
    }else if(familyCode == "O"){
        binCode.append("00010101");
    }else if(familyCode == "P"){
        binCode.append("01010101");
    }else{
        return DeviceManager::DeviceErrorNoError;
    }

    QString buttonCode = device->paramValue("buttonCode").toString();

    // =======================================
    // generate bin from button code
    if(familyCode == "1"){
        binCode.append("00000000");
    }else if(familyCode == "2"){
        binCode.append("01000000");
    }else if(familyCode == "3"){
        binCode.append("00010000");
    }else if(familyCode == "4"){
        binCode.append("01010000");
    }else if(familyCode == "5"){
        binCode.append("00000100");
    }else if(familyCode == "6"){
        binCode.append("01000100");
    }else if(familyCode == "7"){
        binCode.append("01000000");
    }else if(familyCode == "8"){
        binCode.append("01010100");
    }else if(familyCode == "9"){
        binCode.append("00000001");
    }else if(familyCode == "10"){
        binCode.append("01000001");
    }else if(familyCode == "11"){
        binCode.append("00010001");
    }else if(familyCode == "12"){
        binCode.append("01010001");
    }else if(familyCode == "13"){
        binCode.append("00000101");
    }else if(familyCode == "14"){
        binCode.append("01000101");
    }else if(familyCode == "15"){
        binCode.append("00010101");
    }else if(familyCode == "16"){
        binCode.append("01010101");
    }else{
        return DeviceManager::DeviceErrorNoError;
    }

    // =======================================
    // add fix nibble (0F)
    binCode.append("0001");

    // =======================================
    // add power nibble
    if(action.param("power").value().toBool()){
        binCode.append("0101");
    }else{
        binCode.append("0100");
    }
    //qDebug() << "bin code:" << binCode;

    // =======================================
    //create rawData timings list
    int delay = 350;

    // sync signal
    rawData.append(1);
    rawData.append(31);

    // add the code
    foreach (QChar c, binCode) {
        if(c == '0'){
            rawData.append(1);
            rawData.append(3);
        }else{
            rawData.append(3);
            rawData.append(1);
        }
    }

    // =======================================
    // send data to hardware resource
    if(transmitData(delay, rawData)){
        qDebug() << "transmitted" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
        return DeviceManager::DeviceErrorNoError;
    }else{
        qWarning() << "ERROR: could not transmitt" << pluginName() << device->name() << "power: " << action.param("power").value().toBool();
        return DeviceManager::DeviceErrorHardwareNotAvailable;
    }
}
Exemplo n.º 22
0
int main(void)
{
    // Initialise the GPIO block
    gpioInit();
    
	#ifdef GPS
		// Initialise the UART0 block for printf output
		uart0Init(9600);
	#else
		// Initialise the UART0 block for printf output
		uart0Init(115200);
	#endif
    
    // Configure the multi-rate timer for 1ms ticks
    mrtInit(__SYSTEM_CLOCK/1000);
    
    // Configure the switch matrix (setup pins for UART0 and SPI)
    configurePins();
    
    //Seed random number generator, we can use our 'unique' ID
    random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2];
    //printf("random: %d\r\n", random_output);
    
    RFM69_init();
    
    #ifdef GPS
		int navmode = 9;
		setupGPS();
    #endif

	#ifdef DEBUG
		printf("Node initialized, version %s\r\n",GIT_VER);
	#endif
    
    while(1) {
        
        #ifdef GPS
			mrtDelay(5000);
			navmode = gps_check_nav();
            if (navmode != 6){
                setupGPS();
            }
        
			mrtDelay(500);
			gps_get_position();
			mrtDelay(500);
			gps_check_lock();
			mrtDelay(500);

			//printf("Data: %d,%d,%d,%d,%d,%d\r\n", lat, lon, alt, navmode, lock, sats);
			//printf("Errors: %d,%d\r\n", GPSerror, serialBuffer_write);
        #endif
        
        incrementPacketCount();
        
        //Clear buffer
        data_temp[0] = '\0';
        uint8_t n;
        
        //Create the packet
        int int_temp = RFM69_readTemp(); // Read transmitter temperature
        rx_rssi = RFM69_lastRssi();
        floor_rssi = RFM69_sampleRssi();
        
        #ifdef GPS
			n = sprintf(data_temp, "%d%cL%d,%d,%dT%dR%d[%s]", NUM_REPEATS, data_count, lat, lon, alt, int_temp, rx_rssi, NODE_ID);
		#else
			if(data_count == 97) {
				n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID);
			} else {
				n = sprintf(data_temp, "%d%cT%dR%d,%dC%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, NODE_ID);
			}
        #endif
        
        transmitData(n);
        
        awaitData(TX_GAP);
    }
    
}
Exemplo n.º 23
0
DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const Action &action)
{   

    if (action.actionTypeId() != powerActionTypeId)
        return DeviceManager::DeviceErrorActionTypeNotFound;

    QList<int> rawData;
    QByteArray binCode;

    // create the bincode
    // channels
    if (device->paramValue(chan1ParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(chan2ParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(chan3ParamTypeId).toBool()) {
        binCode.append("00");
    }else{
        binCode.append("01");
    }
    if(device->paramValue(chan4ParamTypeId).toBool()){
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(chan5ParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }

    // Buttons
    if (device->paramValue(aParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(bParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(cParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(dParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }
    if (device->paramValue(eParamTypeId).toBool()) {
        binCode.append("00");
    } else {
        binCode.append("01");
    }

    // Power
    if (action.param(powerParamTypeId).value().toBool()) {
        binCode.append("0001");
    } else {
        binCode.append("0100");
    }

    //create rawData timings list
    int delay = 350;

    // sync signal
    rawData.append(1);
    rawData.append(31);

    // add the code
    foreach (QChar c, binCode) {
        if (c == '0') {
            rawData.append(1);
            rawData.append(3);
        } else {
            rawData.append(3);
            rawData.append(1);
        }
    }

    // send data to hardware resource
    if (transmitData(delay, rawData)) {
        qCDebug(dcElro) << "Transmitted" << pluginName() << device->name() << "power: " << action.param(powerParamTypeId).value().toBool();
        return DeviceManager::DeviceErrorNoError;
    } else {
        qCWarning(dcElro) << "Could not transmitt" << pluginName() << device->name() << "power: " << action.param(powerParamTypeId).value().toBool();
        return DeviceManager::DeviceErrorHardwareNotAvailable;
    }
}
void main (void)
{
  addr_t lAddr;
  bspIState_t intState;
  char *Flash_Addr;                         // Initialize radio address location
  Flash_Addr = (char *)0x10F0;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  // delay loop to ensure proper startup before SimpliciTI increases DCO
  // This is typically tailored to the power supply used, and in this case
  // is overkill for safety due to wide distribution.
  __delay_cycles(65000);

  if( CALBC1_8MHZ == 0xFF && CALDCO_8MHZ == 0xFF )// Do not run if cal values
  {
    P1DIR |= 0x03;
    BSP_TURN_ON_LED1();
    BSP_TURN_OFF_LED2();
    while(1)
    {
      __delay_cycles(65000);
      BSP_TOGGLE_LED2();
      BSP_TOGGLE_LED1();
    }
  }

  BSP_Init();

  if( Flash_Addr[0] == 0xFF &&
      Flash_Addr[1] == 0xFF &&
      Flash_Addr[2] == 0xFF &&
      Flash_Addr[3] == 0xFF )
    {
      createRandomAddress();                // Create Random device address at
    }                                       // initial startup if missing
  lAddr.addr[0]=Flash_Addr[0];
  lAddr.addr[1]=Flash_Addr[1];
  lAddr.addr[2]=Flash_Addr[2];
  lAddr.addr[3]=Flash_Addr[3];

  //SMPL_Init();
  SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);

  MCU_Init();
  //Transmit splash screen and network init notification
  TXString( (char*)splash, sizeof splash);
  TXString( "\r\nInitializing Network....", 26 );

  SMPL_Init(sCB);

  // network initialized
  TXString( "Done\r\n", 6);

  // main work loop
  while(1)
  {
    // Wait for the Join semaphore to be set by the receipt of a Join frame from a
    // device that supports and End Device.

    if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS))
    {
      // listen for a new connection
      SMPL_LinkListen(&sLID[sNumCurrentPeers]);
      sNumCurrentPeers++;
      BSP_ENTER_CRITICAL_SECTION(intState);
      if (sJoinSem)
      {
        sJoinSem--;
      }
      BSP_EXIT_CRITICAL_SECTION(intState);
    }

    // if it is time to measure our own temperature...
    if(sSelfMeasureSem)
    {
//    	TXString("\r\n...", 5);
      BSP_TOGGLE_LED1();
      sSelfMeasureSem = 0;
    }

    // Have we received a frame on one of the ED connections?
    // No critical section -- it doesn't really matter much if we miss a poll
    if (sPeerFrameSem)
    {
    	  uint8_t  msg[MESSAGE_LENGTH], len, i;

      // process all frames waiting
      for (i=0; i<sNumCurrentPeers; ++i)
      {
        if (SMPL_Receive(sLID[i], msg, &len) == SMPL_SUCCESS)
        {
          ioctlRadioSiginfo_t sigInfo;
          sigInfo.lid = sLID[i];
          SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo);
          transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg );
          BSP_TURN_ON_LED2();               // Toggle LED2 when received packet
          BSP_ENTER_CRITICAL_SECTION(intState);
          sPeerFrameSem--;
          BSP_EXIT_CRITICAL_SECTION(intState);
          __delay_cycles(10000);
          BSP_TURN_OFF_LED2();
        }
      }
    }
  }
}
Exemplo n.º 25
0
void readSerialData() {
	uint8_t len;
	uint8_t data;
	uint8_t fifoSize = 0;
	static uint8_t plus = 0;
	static uint8_t pos = 0;
	uint8_t rfBeeMode;
	int i;

	// insert any plusses from last round
	for (i = pos; i < plus; i++) { //be careful, i should start from pos, -changed by Icing
		serialData[i] = '+';
	}

	len = serial_available() + plus + pos;
	if (len > BUFFLEN) {
		len = BUFFLEN;    //only process at most BUFFLEN chars
	}

	// check how much space we have in the TX fifo
	fifoSize = txFifoFree(); // the fifoSize should be the number of bytes in TX FIFO

	if (fifoSize <= 0) {
		serial_flush();
		//ccx_strobe(CCx_SFTX);
		plus = 0;
		pos = 0;
		return;
	}

	if (len > fifoSize) {
		len = fifoSize;    // don't overflow the TX fifo
	}

	for (i = plus + pos; i < len; i++) {
		data = serial_read();
		serialData[i] = data;  //serialData is our global serial buffer
		if (data == '+') {
			plus++;
		} else {
			plus = 0;
		}

		if (plus == 3) {
			len = i - 2; // do not send the last 2 plusses
			plus = 0;
			serialMode = SERIALCMDMODE;
			ccx_strobe(CCx_SIDLE);
			printf("ok, starting cmd mode\r\n");
			break; // jump out of the loop, but still send the remaining chars in the buffer
		}
	}

	if (plus > 0) {
		// save any trailing plusses for the next round
		len -= plus;
	}

	// check if we have more input than the transmitThreshold, if we have just switched to commandmode send  the current buffer anyway.
	if ((serialMode != SERIALCMDMODE)
			&& (len < config_get(CONFIG_TX_THRESHOLD))) {
		pos = len; // keep the current bytes in the buffer and wait till next round.
		return;
	}

	if (len > 0) {
		rfBeeMode = config_get(CONFIG_RFBEE_MODE);
		//only when TRANSMIT_MODE or TRANSCEIVE,transmit the buffer data,otherwise ignore
		if ((rfBeeMode == TRANSMIT_MODE) || (rfBeeMode == TRANSCEIVE_MODE)) {
			tx_packet.len = len + PAYLOAD_OFFSET;
			transmitData(&tx_packet);
			//transmitData(serialData, len, config_get(CONFIG_MY_ADDR), config_get(CONFIG_DEST_ADDR));
		}
		pos = 0; // serial databuffer is free again.
	}
}
Exemplo n.º 26
0
void transmitDigit(unsigned char val)
{
    val &= 0xF;
    val += (val < 10) ? '0' : 'A' - 10;
    transmitData(val);
}
Exemplo n.º 27
0
DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, const Action &action)
{   

    if (device->deviceClassId() != rfControllerDeviceClassId) {
        return DeviceManager::DeviceErrorDeviceClassNotFound;
    }

    QList<int> rawData;
    QByteArray binCode;


    // TODO: find out how the id will be calculated to bin code or make it discoverable
    // =======================================
    // bincode depending on the id
    if (device->paramValue("id") == "0115"){
        binCode.append("001101000001");
    } else if (device->paramValue("id") == "0014") {
        binCode.append("110000010101");
    } else if (device->paramValue("id") == "0008") {
        binCode.append("111101010101");
    } else {
        qCWarning(dcLeynew) << "Could not get id of device: invalid parameter" << device->paramValue("id");
        return DeviceManager::DeviceErrorInvalidParameter;
    }

    int repetitions = 12;
    // =======================================
    // bincode depending on the action
    if (action.actionTypeId() == brightnessUpActionTypeId) {
        binCode.append("000000000011");
        repetitions = 8;
    } else if (action.actionTypeId() == brightnessDownActionTypeId) {
        binCode.append("000000001100");
        repetitions = 8;
    } else if (action.actionTypeId() == powerActionTypeId) {
        binCode.append("000011000000");
    } else if (action.actionTypeId() == redActionTypeId) {
        binCode.append("000000001111");
    } else if (action.actionTypeId() == greenActionTypeId) {
        binCode.append("000000110011");
    } else if (action.actionTypeId() == blueActionTypeId) {
        binCode.append("000011000011");
    } else if (action.actionTypeId() == whiteActionTypeId) {
        binCode.append("000000111100");
    } else if (action.actionTypeId() == orangeActionTypeId) {
        binCode.append("000011001100");
    } else if (action.actionTypeId() == yellowActionTypeId) {
        binCode.append("000011110000");
    } else if (action.actionTypeId() == cyanActionTypeId) {
        binCode.append("001100000011");
    } else if (action.actionTypeId() == purpleActionTypeId) {
        binCode.append("110000000011");
    } else if (action.actionTypeId() == playPauseActionTypeId) {
        binCode.append("000000110000");
    } else if (action.actionTypeId() == speedUpActionTypeId) {
        binCode.append("001100110000");
        repetitions = 8;
    } else if (action.actionTypeId() == speedDownActionTypeId) {
        binCode.append("110000000000");
        repetitions = 8;
    } else if (action.actionTypeId() == autoActionTypeId) {
        binCode.append("001100001100");
    } else if (action.actionTypeId() == flashActionTypeId) {
        binCode.append("110011000000");
    } else if (action.actionTypeId() == jump3ActionTypeId) {
        binCode.append("111100001100");
    } else if (action.actionTypeId() == jump7ActionTypeId) {
        binCode.append("001111000000");
    } else if (action.actionTypeId() == fade3ActionTypeId) {
        binCode.append("110000110000");
    } else if (action.actionTypeId() == fade7ActionTypeId) {
        binCode.append("001100000000");
    } else {
        return DeviceManager::DeviceErrorActionTypeNotFound;
    }

    // =======================================
    //create rawData timings list
    int delay = 50;

    // sync signal (starting with ON)
    rawData.append(3);
    rawData.append(90);

    // add the code
    foreach (QChar c, binCode) {
        if(c == '0'){
            //   _
            //  | |_ _
            rawData.append(3);
            rawData.append(9);
        }else{
            //   _ _
            //  |   |_
            rawData.append(9);
            rawData.append(3);
        }
    }

    // =======================================
    // send data to hardware resource
    if(transmitData(delay, rawData, repetitions)){
        qCDebug(dcLeynew) << "Transmitted" << pluginName() << device->name() << action.id();
        return DeviceManager::DeviceErrorNoError;
    }else{
        qCWarning(dcLeynew) << "Could not transmitt" << pluginName() << device->name() << action.id();
        return DeviceManager::DeviceErrorHardwareNotAvailable;
    }
}
Exemplo n.º 28
0
int main(void)
{
    init_lcd();
    writecommand(0x01);
    updateScreen();

    DDRD |= (1 << PD2);//output for green LED
    DDRD |= (1 << PD3);//output for red LED

    //button pullup resistors:
    PORTB |= (1 << PB3) | (1 << PB4);

    //rotary encoder initializations:
    initialize_rotary();
    sei();

    PORTC |= (1 << PC4) | (1 << PC5);//i2c pullup resistors

    //enable line
    PORTC |= (1 << PC3);
    DDRC |= (1 << PC3); //set as output

    //DS1631
    ds1631_init();
    ds1631_conv();
    unsigned char temp[2];
    //serial communication
    init_serial();

    while (1) {
        PORTC &= ~(1 << PC3);//set enable to 0
        ds1631_temp(temp);
        int tempCelsius = temp[0];
        //convert from celsius to fahrenheit:
        if(temp[1] == 0){
            tempF = (tempCelsius*9)/5 + 32;
        }
        else{
            tempF = tempCelsius * 10 + 5;
            tempF = (tempF*9)/5 + 320;
            tempF /= 10;
        }

        if(oldTempF != tempF){//if temperature changes, update + transmit data
            //update temp
            updateTop();
            char temp[5];
            snprintf(temp, 5, "%d", tempF);
            transmitData(temp, &tempF);
        }

        oldTempF = tempF;//update old temp

        if((PINB & (1 << PB3)) == 0){//if high button is pressed
            buttonState = 1;//high
        }
        if((PINB & (1 << PB4)) == 0){//if low button is pressed
            buttonState = 0;//low
        }

        if(bufferValidFlag == 1){//valid data received
            //convert to int stored inside remoteVal
            int hundreds = (receivedDataBuffer[1]-0x30)*100;
            int tens = (receivedDataBuffer[2]-0x30)*10;
            int ones = receivedDataBuffer[3]-0x30;
            remoteVal = hundreds + tens + ones;
            if(receivedDataBuffer[0] == '-'){
                remoteVal = 0 - remoteVal;
            }
            updateTop();
            bufferValidFlag = 0;//reset
        }

        if(change == 1){
            updateScreen();
            change = 0;//reset
        }

        updateLED();
    }
    return 0;   /* never reached */
}
Exemplo n.º 29
0
/**	Send 1-byte command.
 *
 *	@param cmd Command
 */
void SM130::sendCommand(byte cmd)
{
	data[0] = 1;
	data[1] = cmd;
	transmitData();
}
Exemplo n.º 30
0
int main(void)
{

#if defined(GATEWAY) || defined(DEBUG) || defined(GPS)
    // Initialise the UART0 block for printf output
    uart0Init(115200);
#endif

    // Configure the multi-rate timer for 1ms ticks
    mrtInit(__SYSTEM_CLOCK/1000);

    /* Enable AHB clock to the Switch Matrix , UART0 , GPIO , IOCON, MRT , ACMP */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7) | (1 << 14) /*| (1 << 6)*//* | (1 << 18)*/
                                 | (1 << 10) | (1 << 19);

    // Configure the switch matrix (setup pins for UART0 and SPI)
    configurePins();

    LPC_GPIO_PORT->DIR0 |= (1 << GSM_PWR);

    RFM69_init();

#if defined(GATEWAY) || defined(DEBUG) || defined(GPS)
    mrtDelay(100);
    printf("Node Booted\r\n");
    mrtDelay(100);
#endif

    uart1Init(115200);

    GSM_On();

    //GSM_AT();


#if defined(GATEWAY) || defined(DEBUG) || defined(GPS)
    printf("Node initialized, version %s\r\n",GIT_VER);
#endif

    //Seed random number generator, we can use our 'unique' ID
    random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2];

    mrtDelay(5000);

    GSM_AT();
    mrtDelay(5000);

    GSM_upload();

    while(1) {



        GSM_AT();

        incrementPacketCount();

        //Clear buffer
        data_temp[0] = '\0';
        uint8_t n;

        //Create the packet
        int int_temp;

        int_temp = RFM69_readTemp(); // Read transmitter temperature
        rx_rssi = RFM69_lastRssi();
        // read the rssi threshold before re-sampling noise floor which will change it
        rssi_threshold = RFM69_lastRssiThreshold();
        floor_rssi = RFM69_sampleRssi();

        if(data_count == 97) {
            n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID);
        }
        else {

#ifdef DEBUG
            n = sprintf(data_temp, "%d%cT%dR%d,%dC%dX%d,%dV%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, rx_restarts, rssi_threshold, adc_result, NODE_ID);
#else
            n = sprintf(data_temp, "%d%cT%dR%dX%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, rx_packets, NODE_ID);
#endif
        }

        transmitData(n);
        GSM_upload();

        awaitData(TX_GAP);

    }

}