unify m-bus slave init
This commit is contained in:
parent
1a538e73aa
commit
501b105d01
@ -19,6 +19,35 @@
|
|||||||
|
|
||||||
static int debug = 0;
|
static int debug = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// init slave to get really the beginning of the records
|
||||||
|
//
|
||||||
|
int
|
||||||
|
init_slaves(mbus_handle *handle)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
printf("%s: debug: sending init frame #1\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_NETWORK_LAYER, 1) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// resend SND_NKE, maybe the first get lost
|
||||||
|
//
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
printf("%s: debug: sending init frame #2\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_NETWORK_LAYER, 1) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Scan for devices using secondary addressing.
|
// Scan for devices using secondary addressing.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -91,52 +120,11 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
if (init_slaves(handle) == 0)
|
||||||
// init slave to get really the beginning of the records
|
|
||||||
//
|
|
||||||
|
|
||||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
|
||||||
|
|
||||||
if (frame == NULL)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to allocate mbus frame.\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
|
||||||
frame->address = MBUS_ADDRESS_NETWORK_LAYER;
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
printf("%s: debug: sending init frame #1\n", __PRETTY_FUNCTION__);
|
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to send mbus frame.\n");
|
|
||||||
mbus_frame_free(frame);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mbus_purge_frames(handle);
|
|
||||||
|
|
||||||
//
|
|
||||||
// resend SND_NKE, maybe the first get lost
|
|
||||||
//
|
|
||||||
|
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
|
||||||
frame->address = MBUS_ADDRESS_NETWORK_LAYER;
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
printf("%s: debug: sending init frame #2\n", __PRETTY_FUNCTION__);
|
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to send mbus frame.\n");
|
|
||||||
mbus_frame_free(frame);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mbus_purge_frames(handle);
|
|
||||||
|
|
||||||
if (strlen(addr_str) == 16)
|
if (strlen(addr_str) == 16)
|
||||||
{
|
{
|
||||||
// secondary addressing
|
// secondary addressing
|
||||||
|
@ -19,6 +19,36 @@
|
|||||||
|
|
||||||
static int debug = 0;
|
static int debug = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// init slave to get really the beginning of the records
|
||||||
|
//
|
||||||
|
int
|
||||||
|
init_slaves(mbus_handle *handle)
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
printf("%s: debug: sending init frame #1\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_NETWORK_LAYER, 1) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// resend SND_NKE, maybe the first get lost
|
||||||
|
//
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
printf("%s: debug: sending init frame #2\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_BROADCAST_NOREPLY, 1) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Scan for devices using secondary addressing.
|
// Scan for devices using secondary addressing.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -140,33 +170,12 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
if (init_slaves(handle) == 0)
|
||||||
// init slaves
|
|
||||||
//
|
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
|
||||||
frame->address = MBUS_ADDRESS_NETWORK_LAYER;
|
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to send SND_NKE #1.\n");
|
free(addr_mask);
|
||||||
mbus_frame_free(frame);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) mbus_recv_frame(handle, &reply);
|
|
||||||
|
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
|
||||||
frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
|
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to send SND_NKE #2.\n");
|
|
||||||
mbus_frame_free(frame);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) mbus_recv_frame(handle, &reply);
|
|
||||||
|
|
||||||
mbus_scan_2nd_address_range(handle, 0, addr_mask);
|
mbus_scan_2nd_address_range(handle, 0, addr_mask);
|
||||||
|
|
||||||
mbus_disconnect(handle);
|
mbus_disconnect(handle);
|
||||||
|
@ -77,30 +77,14 @@ main(int argc, char **argv)
|
|||||||
//
|
//
|
||||||
// init slave to get really the beginning of the records
|
// init slave to get really the beginning of the records
|
||||||
//
|
//
|
||||||
|
|
||||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
|
||||||
|
|
||||||
if (frame == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to allocate mbus frame.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
|
||||||
frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
|
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__);
|
printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_BROADCAST_NOREPLY, 1) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to send mbus frame.\n");
|
|
||||||
mbus_frame_free(frame);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbus_recv_frame(handle, &reply);
|
|
||||||
|
|
||||||
if (strlen(addr_str) == 16)
|
if (strlen(addr_str) == 16)
|
||||||
{
|
{
|
||||||
// secondary addressing
|
// secondary addressing
|
||||||
|
@ -75,39 +75,29 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
|
||||||
|
|
||||||
if (frame == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to allocate mbus frame.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// init slaves
|
// init slaves
|
||||||
//
|
//
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
if (debug)
|
||||||
frame->address = MBUS_ADDRESS_NETWORK_LAYER;
|
printf("%s: debug: sending init frame #1\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_NETWORK_LAYER, 1) == -1)
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to send SND_NKE #1.\n");
|
|
||||||
mbus_frame_free(frame);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) mbus_recv_frame(handle, &reply);
|
|
||||||
|
|
||||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
|
||||||
frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
|
|
||||||
|
|
||||||
if (mbus_send_frame(handle, frame) == -1)
|
|
||||||
{
|
{
|
||||||
free(addr_mask);
|
free(addr_mask);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) mbus_recv_frame(handle, &reply);
|
//
|
||||||
|
// resend SND_NKE, maybe the first get lost
|
||||||
|
//
|
||||||
|
if (debug)
|
||||||
|
printf("%s: debug: sending init frame #2\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
if (mbus_send_ping_frame(handle, MBUS_ADDRESS_BROADCAST_NOREPLY, 1) == -1)
|
||||||
|
{
|
||||||
|
free(addr_mask);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
mbus_scan_2nd_address_range(handle, 0, addr_mask);
|
mbus_scan_2nd_address_range(handle, 0, addr_mask);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user