commit
86a7305f5e
@ -121,7 +121,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
if (mbus_is_secondary_address(addr_str))
|
||||
{
|
||||
// secondary addressing
|
||||
|
||||
|
@ -88,7 +88,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
if (mbus_is_secondary_address(addr_str))
|
||||
{
|
||||
// secondary addressing
|
||||
|
||||
|
@ -128,7 +128,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr_mask) != 16)
|
||||
if (mbus_is_secondary_address(addr_mask) == 0)
|
||||
{
|
||||
fprintf(stderr, "Misformatted secondary address mask. Must be 16 character HEX number.\n");
|
||||
free(addr_mask);
|
||||
|
@ -49,7 +49,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr) != 16)
|
||||
if (mbus_is_secondary_address(addr) == 0)
|
||||
{
|
||||
printf("Misformatted secondary address. Must be 16 character HEX number.\n");
|
||||
return 1;
|
||||
|
@ -90,7 +90,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
if (mbus_is_secondary_address(addr_str))
|
||||
{
|
||||
// secondary addressing
|
||||
int ret;
|
||||
|
@ -81,7 +81,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
if (mbus_is_secondary_address(addr_str))
|
||||
{
|
||||
// secondary addressing
|
||||
|
||||
|
@ -70,7 +70,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
if (mbus_is_secondary_address(addr_str))
|
||||
{
|
||||
// secondary addressing
|
||||
|
||||
|
@ -53,7 +53,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr_mask) != 16)
|
||||
if (mbus_is_secondary_address(addr_mask) == 0)
|
||||
{
|
||||
fprintf(stderr, "Misformatted secondary address mask. Must be 16 character HEX number.\n");
|
||||
return 1;
|
||||
|
@ -40,7 +40,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(addr) != 16)
|
||||
if (mbus_is_secondary_address(addr) == 0)
|
||||
{
|
||||
printf("Misformatted secondary address. Must be 16 character HEX number.\n");
|
||||
return 1;
|
||||
|
@ -1629,6 +1629,12 @@ mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, int baudrate)
|
||||
int control_information = 0;
|
||||
mbus_frame *frame;
|
||||
|
||||
if (mbus_is_primary_address(address) == 0)
|
||||
{
|
||||
MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, address);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (baudrate)
|
||||
{
|
||||
case 300:
|
||||
@ -1690,6 +1696,12 @@ mbus_send_request_frame(mbus_handle * handle, int address)
|
||||
{
|
||||
int retval = 0;
|
||||
mbus_frame *frame;
|
||||
|
||||
if (mbus_is_primary_address(address) == 0)
|
||||
{
|
||||
MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, address);
|
||||
return -1;
|
||||
}
|
||||
|
||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
||||
|
||||
@ -1729,6 +1741,12 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int m
|
||||
MBUS_ERROR("%s: Invalid M-Bus handle for request.\n", __PRETTY_FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_is_primary_address(address) == 0)
|
||||
{
|
||||
MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, address);
|
||||
return 1;
|
||||
}
|
||||
|
||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
||||
|
||||
@ -1880,6 +1898,12 @@ mbus_send_ping_frame(mbus_handle *handle, int address, char purge_response)
|
||||
{
|
||||
int retval = 0;
|
||||
mbus_frame *frame;
|
||||
|
||||
if (mbus_is_primary_address(address) == 0)
|
||||
{
|
||||
MBUS_ERROR("%s: invalid address %d\n", __PRETTY_FUNCTION__, address);
|
||||
return 1;
|
||||
}
|
||||
|
||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
||||
|
||||
|
@ -3957,9 +3957,15 @@ mbus_frame_select_secondary_pack(mbus_frame *frame, char *address)
|
||||
int val, i, j, k;
|
||||
char tmp[16];
|
||||
|
||||
if (frame == NULL || address == NULL || strlen(address) != 16)
|
||||
if (frame == NULL || address == NULL)
|
||||
{
|
||||
snprintf(error_str, sizeof(error_str), "%s: frame or address arguments are NULL or invalid.", __PRETTY_FUNCTION__);
|
||||
snprintf(error_str, sizeof(error_str), "%s: frame or address arguments are NULL.", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mbus_is_secondary_address(address) == 0)
|
||||
{
|
||||
snprintf(error_str, sizeof(error_str), "%s: address is invalid.", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -4011,3 +4017,35 @@ mbus_frame_select_secondary_pack(mbus_frame *frame, char *address)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Checks if an integer is a valid primary address.
|
||||
//---------------------------------------------------------
|
||||
int
|
||||
mbus_is_primary_address(int value)
|
||||
{
|
||||
return ((value >= 0x00) && (value <= 0xFF));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Checks if an string is a valid secondary address.
|
||||
//---------------------------------------------------------
|
||||
int
|
||||
mbus_is_secondary_address(const char * value)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (value == NULL)
|
||||
return 0;
|
||||
|
||||
if (strlen(value) != 16)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (!isxdigit(value[i]))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -636,6 +636,9 @@ u_char mbus_dif_datalength_lookup(u_char dif);
|
||||
char *mbus_frame_get_secondary_address(mbus_frame *frame);
|
||||
int mbus_frame_select_secondary_pack(mbus_frame *frame, char *address);
|
||||
|
||||
int mbus_is_primary_address(int value);
|
||||
int mbus_is_secondary_address(const char * value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user