Merge pull request #48 from mapnull/feature

get custom string from msg that isn't a stream type
This commit is contained in:
Henrik Ekblad
2015-02-03 22:05:29 +01:00
2 changed files with 15 additions and 16 deletions
+12 -16
View File
@@ -13,12 +13,10 @@ MyMessage::MyMessage(uint8_t _sensor, uint8_t _type) {
type = _type;
}
bool MyMessage::isAck() const {
return miGetAck();
}
/* Getters for payload converted to desired form */
void* MyMessage::getCustom() const {
return (void *)data;
@@ -42,16 +40,20 @@ char MyMessage::i2h(uint8_t i) const {
return 'A' + k - 10;
}
char* MyMessage::getCustomString(char *buffer) const {
for (uint8_t i = 0; i < miGetLength(); i++)
{
buffer[i * 2] = i2h(data[i] >> 4);
buffer[(i * 2) + 1] = i2h(data[i]);
}
buffer[miGetLength() * 2] = '\0';
return buffer;
}
char* MyMessage::getStream(char *buffer) const {
uint8_t cmd = miGetCommand();
if ((cmd == C_STREAM) && (buffer != NULL)) {
for (uint8_t i = 0; i < miGetLength(); i++)
{
buffer[i * 2] = i2h(data[i] >> 4);
buffer[(i * 2) + 1] = i2h(data[i]);
}
buffer[miGetLength() * 2] = '\0';
return buffer;
return getCustomString(buffer);
} else {
return NULL;
}
@@ -73,12 +75,11 @@ char* MyMessage::getString(char *buffer) const {
} else if (payloadType == P_LONG32) {
ltoa(lValue, buffer, 10);
} else if (payloadType == P_ULONG32) {
ultoa(ulValue, buffer, 10);
} else if (payloadType == P_FLOAT32) {
dtostrf(fValue,2,fPrecision,buffer);
} else if (payloadType == P_CUSTOM) {
return getStream(buffer);
return getCustomString(buffer);
}
return buffer;
} else {
@@ -151,7 +152,6 @@ unsigned int MyMessage::getUInt() const {
}
MyMessage& MyMessage::setType(uint8_t _type) {
type = _type;
return *this;
@@ -175,7 +175,6 @@ MyMessage& MyMessage::set(void* value, uint8_t length) {
return *this;
}
MyMessage& MyMessage::set(const char* value) {
uint8_t length = min(strlen(value), MAX_PAYLOAD);
miSetLength(length);
@@ -191,7 +190,6 @@ MyMessage& MyMessage::set(uint8_t value) {
return *this;
}
MyMessage& MyMessage::set(float value, uint8_t decimals) {
miSetLength(5); // 32 bit float + persi
miSetPayloadType(P_FLOAT32);
@@ -227,5 +225,3 @@ MyMessage& MyMessage::set(int value) {
iValue = value;
return *this;
}
+3
View File
@@ -122,6 +122,9 @@ typedef enum {
#ifdef __cplusplus
class MyMessage
{
private:
char* getCustomString(char *buffer) const;
public:
// Constructors
MyMessage();