Merge remote branch 'upstream/master'
This commit is contained in:
@ -28,14 +28,29 @@ static mbus_slave_data slave_data[MBUS_MAX_PRIMARY_SLAVES];
|
||||
//
|
||||
// init event callback
|
||||
//
|
||||
void (*_mbus_recv_event)(u_char src_type) = NULL;
|
||||
void (*_mbus_send_event)(u_char src_type) = NULL;
|
||||
void (*_mbus_recv_event)(u_char src_type, const char *buff, size_t len) = NULL;
|
||||
void (*_mbus_send_event)(u_char src_type, const char *buff, size_t len) = NULL;
|
||||
|
||||
//
|
||||
// trace callbacks
|
||||
//
|
||||
void
|
||||
mbus_dump_recv_event(u_char src_type, const char *buff, size_t len)
|
||||
{
|
||||
mbus_hex_dump("RECV", buff, len);
|
||||
}
|
||||
|
||||
void
|
||||
mbus_dump_send_event(u_char src_type, const char *buff, size_t len)
|
||||
{
|
||||
mbus_hex_dump("SEND", buff, len);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// Register a function for receive events.
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
mbus_register_recv_event(void (*event)(u_char src_type))
|
||||
mbus_register_recv_event(void (*event)(u_char src_type, const char *buff, size_t len))
|
||||
{
|
||||
_mbus_recv_event = event;
|
||||
}
|
||||
@ -44,7 +59,7 @@ mbus_register_recv_event(void (*event)(u_char src_type))
|
||||
/// Register a function for send events.
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
mbus_register_send_event(void (*event)(u_char src_type))
|
||||
mbus_register_send_event(void (*event)(u_char src_type, const char *buff, size_t len))
|
||||
{
|
||||
_mbus_send_event = event;
|
||||
}
|
||||
@ -2942,6 +2957,28 @@ mbus_data_fixed_print(mbus_data_fixed *data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
mbus_hex_dump(const char *label, const char *buff, size_t len)
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char timestamp[21];
|
||||
size_t i;
|
||||
|
||||
time ( &rawtime );
|
||||
timeinfo = gmtime ( &rawtime );
|
||||
|
||||
strftime(timestamp,20,"%Y-%m-%d %H:%M:%S",timeinfo);
|
||||
fprintf(stderr, "[%s] %s (%03d):", timestamp, label, len);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
fprintf(stderr, " %02X", (u_char) buff[i]);
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int
|
||||
mbus_data_error_print(int error)
|
||||
{
|
||||
|
@ -462,14 +462,17 @@ typedef struct _mbus_data_secondary_address {
|
||||
//
|
||||
// Event callback functions
|
||||
//
|
||||
extern void (*_mbus_recv_event)(u_char src_type);
|
||||
extern void (*_mbus_send_event)(u_char src_type);
|
||||
extern void (*_mbus_recv_event)(u_char src_type, const char *buff, size_t len);
|
||||
extern void (*_mbus_send_event)(u_char src_type, const char *buff, size_t len);
|
||||
|
||||
void mbus_dump_recv_event(u_char src_type, const char *buff, size_t len);
|
||||
void mbus_dump_send_event(u_char src_type, const char *buff, size_t len);
|
||||
|
||||
//
|
||||
// Event register functions
|
||||
//
|
||||
void mbus_register_recv_event(void (*event)(u_char src_type));
|
||||
void mbus_register_send_event(void (*event)(u_char src_type));
|
||||
void mbus_register_recv_event(void (*event)(u_char src_type, const char *buff, size_t len));
|
||||
void mbus_register_send_event(void (*event)(u_char src_type, const char *buff, size_t len));
|
||||
|
||||
//
|
||||
// variable length records
|
||||
@ -554,6 +557,7 @@ void mbus_error_str_set(char *message);
|
||||
void mbus_error_reset();
|
||||
|
||||
void mbus_parse_set_debug(int debug);
|
||||
void mbus_hex_dump(const char *label, const char *buff, size_t len);
|
||||
|
||||
//
|
||||
// data encode/decode functions
|
||||
|
Reference in New Issue
Block a user