From cd336cab1a82044138eb0ba22ed1013e0ae5b9ba Mon Sep 17 00:00:00 2001 From: 033zhek <033zhek@gmail.com> Date: Sun, 8 Oct 2023 03:16:38 +0300 Subject: [PATCH] sensor refactor --- .../lib/TransmissionModule/TransmissionModule.cpp | 13 +++++-------- .../lib/TransmissionModule/TransmissionModule.h | 1 - cybergarden-sensor/src/main.cpp | 1 - 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp b/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp index 2e4e09f..96191b5 100644 --- a/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp +++ b/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp @@ -8,9 +8,11 @@ #define ECC_LENGTH 4 #define TOTAL_LENGTH (MSG_LENGTH + ECC_LENGTH) -void TransmissionModule::encrypt(uint8_t * input_data, size_t data_size, uint8_t* output_data) +void TransmissionModule::transmit(MeasureData &data) { + size_t posn, len, inc = 5; + size_t data_size = 4; cipher->clear(); cipher->setKey(encryptionKey, key_size); cipher->setIV(iv, iv_size); @@ -27,7 +29,7 @@ void TransmissionModule::encrypt(uint8_t * input_data, size_t data_size, uint8_t len = data_size - posn; if (len > inc) len = inc; - cipher->encrypt(buffer + posn, input_data + posn, len); + cipher->encrypt(buffer + posn, (uint8_t*)&data + 1 + posn, len); } //************************* @@ -47,17 +49,12 @@ void TransmissionModule::encrypt(uint8_t * input_data, size_t data_size, uint8_t // cipher->decrypt(buffer2 + posn, buffer + posn, len); // } - // if (memcmp(buffer2, input_data, data_size) != 0) { + // if (memcmp(buffer2, (uint8_t*)&data + 1, data_size) != 0) { // Serial.println("doesn't work"); // } else{ // Serial.println("works"); // } - memcpy(output_data, buffer, data_size); -} - -void TransmissionModule::transmit(MeasureData &data) -{ uint8_t msg[MSG_LENGTH]; msg[0] = data.sensor_id; memcpy(msg + 1, (void *) &data, 4); diff --git a/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.h b/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.h index 247b77d..2ac2156 100644 --- a/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.h +++ b/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.h @@ -37,7 +37,6 @@ public: reedSolomonModule(&reedSolomonModule) { cipher = new ChaChaPoly(); } - void encrypt(uint8_t * data, size_t data_size, uint8_t* output_data); void transmit(MeasureData &data); }; diff --git a/cybergarden-sensor/src/main.cpp b/cybergarden-sensor/src/main.cpp index 508530b..d2c64f8 100644 --- a/cybergarden-sensor/src/main.cpp +++ b/cybergarden-sensor/src/main.cpp @@ -21,7 +21,6 @@ void loop() { measureData.sensor_id = 0xA5; measureData.sensor_type = 0x01; measureData.payload = getMockSensorData(); - transmissionModule.encrypt((uint8_t*)&measureData+1, 4, (uint8_t*)&measureData+1); transmissionModule.transmit(measureData); delay(1000); } \ No newline at end of file