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