Skip to content

Commit

Permalink
add hanparser
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Sep 16, 2024
1 parent b6608b0 commit 85339f9
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _COSEM_H
#define _COSEM_H

#include "lwip/def.h"
//#include "lwip/def.h"

// Blue book, Table 2
enum CosemType {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions tasmota/Plugins/AmsLib/DlmsParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _DLMSPARSER_H
#define _DLMSPARSER_H

//#include "Arduino.h"
#include "DataParser.h"

//class DLMSParser {
//public:
int8_t DLMSParser_parse(uint8_t *buf, DataParserContext &ctx);
//};

#endif
File renamed without changes.
13 changes: 13 additions & 0 deletions tasmota/Plugins/AmsLib/DsmrParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _DSMRPARSER_H
#define _DSMRPARSER_H

//#include "Arduino.h"
#include "DataParser.h"

//class DSMRParser {
//public:
int8_t DSMRParser_parse(uint8_t *buf, DataParserContext &ctx, bool verified);
//private:
//};

#endif
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _GBTPARSER_H
#define _GBTPARSER_H

#include "Arduino.h"
#include "DataParser.h"

#define GBT_TAG 0xE0
Expand All @@ -14,14 +13,14 @@ typedef struct GBTHeader {
uint8_t size;
} __attribute__((packed)) GBTHeader;

class GBTParser {
public:
int8_t parse(uint8_t *buf, DataParserContext &ctx);
~GBTParser(void);
private:
//class GBTParser {
//public:
int8_t GBTParser_parse(uint8_t *buf, DataParserContext &ctx);
// ~GBTParser(void);
//private:
uint8_t lastSequenceNumber = 0;
uint16_t pos = 0;
uint8_t *buf = NULL;
};
//};

#endif
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _GCMPARSER_H
#define _GCMPARSER_H

#include "Arduino.h"
#include "DataParser.h"

#define GCM_TAG 0xDB
Expand All @@ -15,14 +14,15 @@ typedef struct GCMSizeDef {
} __attribute__((packed)) GCMSizeDef;


class GCMParser {
public:
GCMParser(uint8_t *encryption_key, uint8_t *authentication_key);
int8_t parse(uint8_t *buf, DataParserContext &ctx);
private:
//class GCMParser {
//public:
//GCMParser(uint8_t *encryption_key, uint8_t *authentication_key);

int8_t GCMParser_parse(uint8_t *buf, DataParserContext &ctx);
//private:
uint8_t encryption_key[16];
uint8_t authentication_key[16];
uint8_t use_auth = 0;
};
//};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "lwip/def.h"
#include <t_bearssl.h>

GCMParser::GCMParser(uint8_t *encryption_key, uint8_t *authentication_key) {
GCMParser_GCMParser(uint8_t *encryption_key, uint8_t *authentication_key) {
memcpy(this->encryption_key, encryption_key, 16);
memcpy(this->authentication_key, authentication_key, 16);
use_auth = 0;
Expand All @@ -17,7 +17,7 @@ GCMParser::GCMParser(uint8_t *encryption_key, uint8_t *authentication_key) {
}
}

int8_t GCMParser::parse(uint8_t *d, DataParserContext &ctx) {
int8_t GCMParser_parse(uint8_t *d, DataParserContext &ctx) {
if(ctx.length < 12) return DATA_PARSE_INCOMPLETE;

uint8_t* ptr = (uint8_t*) d;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _HDLCPARSER_H
#define _HDLCPARSER_H

#include "Arduino.h"
#include "DataParser.h"

#define HDLC_FLAG 0x7E
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ typedef struct MbusFooter {
uint8_t flag;
} __attribute__((packed)) MbusFooter;

class MBUSParser {
public:
int8_t parse(uint8_t *buf, DataParserContext &ctx);
~MBUSParser(void);
uint16_t write(const uint8_t* d, DataParserContext &ctx);
private:
//class MBUSParser {
//public:
int8_t MBUSParser_parse(uint8_t *buf, DataParserContext &ctx);
// ~MBUSParser(void);
uint16_t MBUSParser_write(const uint8_t* d, DataParserContext &ctx);
//private:
uint8_t lastSequenceNumber = 0;
uint16_t pos = 0;
uint8_t *buf = NULL;
uint8_t checksum(const uint8_t* p, int len);
};
//};

#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef _CRC_H
#define _CRC_H

#include "Arduino.h"
#include <stdint.h>

uint16_t AMS_crc16(const uint8_t* p, int len);
uint16_t AMS_crc16_x25(const uint8_t* p, int len);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#ifndef _HAN_PARSER_H
#define _HAN_PARSER_H
#if defined __cplusplus
#include "Arduino.h"
#include "DataParsers.h"
#include "DataParser.h"
#include "Cosem.h"
Expand All @@ -13,19 +12,19 @@
int16_t serial_available(void);
uint8_t serial_read(void);

class Han_Parser
{
public:
//class Han_Parser
//{
//public:
Han_Parser(uint16_t (*)(uint8_t, uint8_t), uint8_t, uint8_t *, uint8_t *);
~Han_Parser(void);
bool readHanPort(uint8_t **out, uint16_t *size, uint8_t flags);
int16_t unwrapData(uint8_t *buf, DataParserContext &context);
void printHanReadError(int16_t pos);
// ~Han_Parser(void);
bool Han_Parser_readHanPort(uint8_t **out, uint16_t *size, uint8_t flags);
int16_t Han_Parser_unwrapData(uint8_t *buf, DataParserContext &context);
void Han_Parser_printHanReadError(int16_t pos);
uint8_t encryptionKey[16];
uint8_t authenticationKey[16];
uint8_t hanBuffer[BUF_SIZE_HAN];
int len = 0;
private:
//private:
uint16_t (*dispatch)(uint8_t, uint8_t);
int serial_available(void);
int serial_read(void);
Expand All @@ -42,6 +41,6 @@ class Han_Parser
uint8_t meter;
bool serialInit = true;
bool Debug = true;
};
//};
#endif
#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define _HEXUTILS_H

#include <stdint.h>
#include "Arduino.h"

String AMS_toHex(uint8_t* in);
String AMS_toHex(uint8_t* in, uint16_t size);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tasmota/Plugins/module_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,9 @@ typedef struct {
#define ptwai_read_alerts(A,B) jspdispatch(78,(uint32_t)A,(uint32_t)B,0)
#define ptwai__clear_receive_queue() jspdispatch(79,0,0,0)

#define NewHanParser(A) (Han_Parser*)jspdispatch(90,(uint32_t)A,0,0)
#define DelHanParser(A) jspdispatch(91,(uint32_t)A,0,0)
#define ReadHanPort(A,B) jspdispatch(92,(uint32_t)A,(uint32_t)B,0)

#define Replace_Cmd_Vars(A,B,C,D) jReplace_Cmd_Vars((uint32_t)A,B,(uint32_t)C,D)

Expand Down
10 changes: 10 additions & 0 deletions tasmota/Plugins/modules_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ typedef struct {
} PLUGIN_COUNTER;


typedef struct {
uint16_t (*sd)(uint8_t, uint8_t);
uint8_t meter;
uint8_t *key;
uint8_t *auth;
uint8_t **out;
uint16_t *size;
uint8_t flags;
} HP_PARS;

#define MD_TYPE uint32_t

#define MOD_STORE_NAMESIZE 8
Expand Down
12 changes: 0 additions & 12 deletions tasmota/Plugins/plugin_ams/DlmsParser.h

This file was deleted.

13 changes: 0 additions & 13 deletions tasmota/Plugins/plugin_ams/DsmrParser.h

This file was deleted.

17 changes: 0 additions & 17 deletions tasmota/Plugins/plugin_ams/library.json

This file was deleted.

17 changes: 0 additions & 17 deletions tasmota/Plugins/plugin_ams/library.properties

This file was deleted.

Loading

0 comments on commit 85339f9

Please sign in to comment.