Skip to content

Commit

Permalink
Add packet metamodel and first version of packet catalog file. Genera…
Browse files Browse the repository at this point in the history
…te headers and use them in temp sensor.
  • Loading branch information
breaker27 committed Dec 5, 2013
1 parent 903d137 commit e715194
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 6 deletions.
13 changes: 13 additions & 0 deletions firmware/src_common/e2p_access.h
Expand Up @@ -40,6 +40,12 @@ static inline void eeprom_write_UIntValue(uint16_t byte, uint8_t bit, uint16_t l
_eeprom_write_UIntValue(byte, bit, length_bits, val, NULL);
}

static inline void eeprom_write_IntValue(uint16_t byte, uint8_t bit, uint16_t length_bits, int32_t val)
{
_eeprom_write_UIntValue(byte, bit, length_bits,
(uint32_t)(((((uint32_t)val) >> 31) << (length_bits - 1)) | (val & ((1 << length_bits) - 1))),
NULL);
}

// function wrappers for ARRAY access
static inline uint8_t array_read_UIntValue8(uint16_t byte, uint8_t bit, uint16_t length_bits, uint32_t minval, uint32_t maxval, uint8_t * array)
Expand All @@ -62,4 +68,11 @@ static inline void array_write_UIntValue(uint16_t byte, uint8_t bit, uint16_t le
_eeprom_write_UIntValue(byte, bit, length_bits, val, array);
}

static inline void array_write_IntValue(uint16_t byte, uint8_t bit, uint16_t length_bits, int32_t val, uint8_t * array)
{
_eeprom_write_UIntValue(byte, bit, length_bits,
(uint32_t)(((((uint32_t)val) >> 31) << (length_bits - 1)) | (val & ((1 << length_bits) - 1))),
array);
}

#endif // E2P_ACCESS
100 changes: 100 additions & 0 deletions firmware/src_common/msggrp_generic.h
@@ -0,0 +1,100 @@
/*
* This file is part of smarthomatic, http://www.smarthomatic.org.
* Copyright (c) 2013 Uwe Freese
*
* smarthomatic is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* smarthomatic is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with smarthomatic. If not, see <http://www.gnu.org/licenses/>.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* ! WARNING: This file is generated by the SHC EEPROM editor and should !
* ! never be modified manually. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/

#include "packet_header.h"
#include "e2p_access.h"

// Message Group "generic"
// =======================
// MessageGroupID: 0
// Description: This group contains messages useful for different devices.


// Message "generic_genericack"
// ----------------------------
// MessageGroupID: 0
// MessageID: 0
// MessageType: 0
// Data fields: SenderID, PacketCounter
// length: 116 bits (needs 15 bytes)

// Function to initialize header for the message.
static inline void pkg_header_init_generic_genericack(void)
{
memset(&bufx[0], 0, sizeof(bufx));
pkg_header_set_messagegroupid(0);
pkg_header_set_messageid(0);
pkg_header_set_messagetype(0);
}

// Function to set CRC value after all data fields are set.
static inline void pkg_header_crc32_generic_genericack(void)
{
pkg_header_set_crc32(crc32(bufx + 4, 12));
}

// Set SenderID (UIntValue)
// byte 10, bit 0, length bits 12, min val 0, max val 4095
static inline void msg_generic_genericack_set_senderid(uint32_t val)
{
array_write_UIntValue(10, 0, 12, val, bufx);
}

// Set PacketCounter (UIntValue)
// byte 11, bit 4, length bits 24, min val 0, max val 16777215
static inline void msg_generic_genericack_set_packetcounter(uint32_t val)
{
array_write_UIntValue(11, 4, 24, val, bufx);
}


// Message "generic_batterystatus"
// -------------------------------
// MessageGroupID: 0
// MessageID: 5
// MessageType: 0
// Data fields: Percentage
// length: 87 bits (needs 11 bytes)

// Function to initialize header for the message.
static inline void pkg_header_init_generic_batterystatus(void)
{
memset(&bufx[0], 0, sizeof(bufx));
pkg_header_set_messagegroupid(0);
pkg_header_set_messageid(5);
pkg_header_set_messagetype(0);
}

// Function to set CRC value after all data fields are set.
static inline void pkg_header_crc32_generic_batterystatus(void)
{
pkg_header_set_crc32(crc32(bufx + 4, 12));
}

// Set Percentage (UIntValue)
// byte 10, bit 0, length bits 7, min val 0, max val 100
static inline void msg_generic_batterystatus_set_percentage(uint32_t val)
{
array_write_UIntValue(10, 0, 7, val, bufx);
}

75 changes: 75 additions & 0 deletions firmware/src_common/msggrp_tempsensor.h
@@ -0,0 +1,75 @@
/*
* This file is part of smarthomatic, http://www.smarthomatic.org.
* Copyright (c) 2013 Uwe Freese
*
* smarthomatic is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* smarthomatic is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with smarthomatic. If not, see <http://www.gnu.org/licenses/>.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* ! WARNING: This file is generated by the SHC EEPROM editor and should !
* ! never be modified manually. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/

#include "packet_header.h"
#include "e2p_access.h"

// Message Group "tempsensor"
// ==========================
// MessageGroupID: 10


// Message "tempsensor_tempstatus"
// -------------------------------
// MessageGroupID: 10
// MessageID: 1
// MessageType: 0
// Data fields: Temperature, Humidity, Brightness
// length: 113 bits (needs 15 bytes)

// Function to initialize header for the message.
static inline void pkg_header_init_tempsensor_tempstatus(void)
{
memset(&bufx[0], 0, sizeof(bufx));
pkg_header_set_messagegroupid(10);
pkg_header_set_messageid(1);
pkg_header_set_messagetype(0);
}

// Function to set CRC value after all data fields are set.
static inline void pkg_header_crc32_tempsensor_tempstatus(void)
{
pkg_header_set_crc32(crc32(bufx + 4, 12));
}

// Set Temperature (IntValue)
// byte 10, bit 0, length bits 16, min val -32768, max val 32767
static inline void msg_tempsensor_tempstatus_set_temperature(int32_t val)
{
array_write_IntValue(10, 0, 16, val, bufx);
}

// Set Humidity (UIntValue)
// byte 12, bit 0, length bits 10, min val 0, max val 1000
static inline void msg_tempsensor_tempstatus_set_humidity(uint32_t val)
{
array_write_UIntValue(12, 0, 10, val, bufx);
}

// Set Brightness (UIntValue)
// byte 13, bit 2, length bits 7, min val 0, max val 100
static inline void msg_tempsensor_tempstatus_set_brightness(uint32_t val)
{
array_write_UIntValue(13, 2, 7, val, bufx);
}

80 changes: 80 additions & 0 deletions firmware/src_common/packet_header.h
@@ -0,0 +1,80 @@
/*
* This file is part of smarthomatic, http://www.smarthomatic.org.
* Copyright (c) 2013 Uwe Freese
*
* smarthomatic is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* smarthomatic is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with smarthomatic. If not, see <http://www.gnu.org/licenses/>.
*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* ! WARNING: This file is generated by the SHC EEPROM editor and should !
* ! never be modified manually. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/

#ifndef _PACKET_HEADER_H
#define _PACKET_HEADER_H

#include "util.h"
#include "e2p_access.h"

// Set CRC32 (UIntValue)
// byte 0, bit 0, length bits 32, min val 0, max val 4294967295
static inline void pkg_header_set_crc32(uint32_t val)
{
array_write_UIntValue(0, 0, 32, val, bufx);
}

// Set SenderID (UIntValue)
// byte 4, bit 0, length bits 12, min val 0, max val 4095
static inline void pkg_header_set_senderid(uint32_t val)
{
array_write_UIntValue(4, 0, 12, val, bufx);
}

// Set PacketCounter (UIntValue)
// byte 5, bit 4, length bits 24, min val 0, max val 16777215
static inline void pkg_header_set_packetcounter(uint32_t val)
{
array_write_UIntValue(5, 4, 24, val, bufx);
}

// Set MessageGroupID (UIntValue)
// byte 8, bit 4, length bits 4, min val 0, max val 15
static inline void pkg_header_set_messagegroupid(uint32_t val)
{
array_write_UIntValue(8, 4, 4, val, bufx);
}

// Set MessageID (UIntValue)
// byte 9, bit 0, length bits 7, min val 0, max val 127
static inline void pkg_header_set_messageid(uint32_t val)
{
array_write_UIntValue(9, 0, 7, val, bufx);
}

// Set MessageType (EnumValue)
// byte 9, bit 7, length bits 1

typedef enum {
MESSAGETYPE_STATUS = 0,
MESSAGETYPE_REQUEST = 1
} MessageTypeEnum;
static inline void pkg_header_set_messagetype(MessageTypeEnum val)
{
array_write_UIntValue(9, 7, 1, val, bufx);
}


// overall length: 80 bits

#endif /* _PACKET_HEADER_H */
2 changes: 1 addition & 1 deletion firmware/src_common/src_common.pnproj
@@ -1 +1 @@
<Project name="src_common"><File path="uart.c"></File><File path="uart.h"></File><File path="util.c"></File><File path="util.h"></File><File path="aes256.c"></File><File path="aes256.h"></File><File path="e2p_access.c"></File><File path="e2p_access.h"></File></Project>
<Project name="src_common"><File path="uart.c"></File><File path="uart.h"></File><File path="util.h"></File><File path="aes256.c"></File><File path="aes256.h"></File><File path="e2p_access.c"></File><File path="e2p_access.h"></File><File path="util.c"></File><File path="msggrp_tempsensor.h"></File><File path="msggrp_generic.h"></File><File path="packet_header.h"></File></Project>
2 changes: 0 additions & 2 deletions firmware/src_common/util.c
Expand Up @@ -37,8 +37,6 @@

#include "e2p_access.h"

uint8_t bufx[65];

#define LED_PIN 7
#define LED_PORT PORTD
#define LED_DDR DDRD
Expand Down
2 changes: 1 addition & 1 deletion firmware/src_common/util.h
Expand Up @@ -30,7 +30,7 @@
#include "e2p_layout.h" // device specific (!) version of e2p layout in the device's directory

// used as buffer for sending data to SHT
extern uint8_t bufx[];
uint8_t bufx[65];
unsigned int adc_data;

void printSigned(int16_t i);
Expand Down

0 comments on commit e715194

Please sign in to comment.