Power line carrier communication protocol data link layer simulation method

By building a high-priority task process and a dynamic delay compensation mechanism, combined with a ring queue cache, the problems of timing misalignment and processing delay in power line carrier communication simulation are solved, efficient data frame processing and dual-mode collaborative simulation are achieved, and the stability and compatibility of the simulation system are improved.

CN120729361AActive Publication Date: 2025-09-30BEIJING ZHONGCHEN MICROELECTRONICS CO LTD

Patent Information

Application Number
CN202510870767.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-09-30
Estimated Expiration
2045-06-26

AI Technical Summary

Technical Problem

Existing power line carrier communication simulation methods lack refined simulation of data link layer timing synchronization and dynamic compensation mechanisms, resulting in deviations between simulation results and real scenarios. This makes it difficult to meet the needs of rapid parsing and response to large numbers of data packets in high-real-time scenarios, and fails to effectively solve the problems of low frame processing efficiency and synchronization error accumulation in scenarios such as multi-node collaboration and burst data transmission that are unique to power line carrier communication.

Method used

Build a high-priority task process to achieve time slot-level timing synchronization, combine dynamic delay compensation with a ring queue caching mechanism, synchronize the local clock through the beacon frame timestamp, use the ring queue to cache TCP message data, add delay compensation before sending, and delay the start of the physical layer receiving action when receiving to ensure that the data frame is demodulated and parsed within the physical layer time slot.

Benefits of technology

It improves the protocol stack simulation accuracy of the simulation system, reduces frame conflicts and retransmissions, improves the stability and throughput of data link layer simulation, supports the simulation of RF and PLC dual-mode collaborative scenarios, and meets the State Grid's verification requirements for dual-mode compatibility of terminal equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120729361A_ABST
    Figure CN120729361A_ABST
Patent Text Reader

Abstract

The invention discloses a power line carrier communication protocol data link layer simulation method, which comprises the following steps of: constructing a physical layer interface simulation module, simulating power line carrier or wireless air interface transmission through TCP socket communication, and creating a high-priority task process to process time slot-level time sequence synchronization for triggering a physical layer transceiving action at a specified time slot; configuring a time sequence synchronization control mechanism, obtaining a timestamp carried by a beacon frame sent by a concentrator, calling a clock synchronization function to align a site local clock with the timestamp when receiving the head of the beacon frame, adding delay compensation before sending data, and delaying and starting a physical layer receiving action to offset IP network transmission delay when receiving the data; a data frame processing flow is realized, a header callback function is controlled through a registration frame to respond to a physical layer state change, TCP message data is cached by using an annular queue, and a physical layer interface simulation module analyzes a message, distributes a memory and processes a load at a specified time slot after time sequence synchronization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of power line carrier technology, and in particular to a power line carrier communication protocol data link layer simulation method. Background Art

[0002] With the rapid development of smart grids, the Internet of Things, and industrial automation technologies, power line communication (PLC), a key technology for data transmission utilizing existing power line infrastructure, has demonstrated significant advantages in areas such as remote meter reading, distribution network automation, and smart home networks. However, the complex and volatile power line channel environment, characterized by signal attenuation, noise interference, and multipath effects, places extremely high demands on the reliability and real-time performance of communication protocols. As a core component of the power line communication protocol stack, the data link layer is responsible for key functions such as media access control, frame transmission management, and timing synchronization. Its performance directly impacts the stability and efficiency of the entire communication system.

[0003] Existing power line carrier communication simulation methods mostly focus on physical layer or application layer modeling, and lack refined simulation of data link layer timing synchronization and dynamic compensation mechanisms. Traditional simulation platforms often use static timing configuration or simple delay simulation, which makes it difficult to accurately reflect the dynamic changes in IP network transmission delay, resulting in deviations between simulation results and real scenarios. For example, in a TCP / IP-based simulation environment, the randomness of network transmission delay may cause misalignment in the timing of data frame transmission and reception. If the sending / receiving actions are not accurately compensated, the effectiveness of media access mechanisms such as CSMA / CA (Carrier Sense Multiple Access / Collision Avoidance) will be affected, thereby reducing network throughput and transmission reliability. In addition, when processing data frames, traditional methods often use fixed cache structures or low-priority task scheduling, which makes it difficult to meet the needs of rapid parsing and response of large numbers of data packets in high-real-time scenarios, and can easily cause cache overflows or processing delays.

[0004] To address these challenges, some recent research has attempted to optimize simulation performance by introducing clock synchronization mechanisms (such as IEEE 1588v2) or software-defined radio (SDR) platforms. However, these solutions often rely on high-precision hardware and require complex configuration, making them difficult to cost-effectively deploy in general-purpose simulation environments. Furthermore, existing methods still suffer from low frame processing efficiency and accumulated synchronization errors when addressing scenarios unique to power line carrier communications, such as multi-node coordination and bursty data transmission. These issues hinder the accurate evaluation and optimization of protocol performance.

[0005] Furthermore, according to the latest State Grid regulations, power communication terminals must support both RF wireless and PLC power line carrier dual-mode communications. Existing simulation methods fail to address the independent timing control and differentiated parameter configuration required for dual-mode collaboration, making it difficult to meet State Grid's requirements for verifying the dual-mode compatibility of terminal equipment. Summary of the Invention

[0006] The purpose of the embodiment of the present invention is to provide a data link layer simulation method for a power line carrier communication protocol. By constructing a high-priority task process to achieve time slot-level timing synchronization, combined with dynamic delay compensation and a ring queue cache mechanism, the problems of timing misalignment, processing delay and cache overflow in traditional power line carrier communication simulation are effectively solved.

[0007] To solve the above technical problems, a first aspect of an embodiment of the present invention provides a power line carrier communication protocol data link layer simulation method, comprising the following steps:

[0008] Build a physical layer interface simulation module to simulate power line carrier or wireless air interface transmission through TCP socket communication, and create a high-priority task process to handle time slot-level timing synchronization to trigger physical layer transmission and reception actions at specified time slots;

[0009] Configure a timing synchronization control mechanism to obtain the timestamp carried in the beacon frame sent by the concentrator. When receiving the beacon frame header, call the clock synchronization function to align the site's local clock with the timestamp. Add delay compensation before sending data. When receiving data, delay the start of the physical layer reception action to offset IP network transmission delay.

[0010] Implement the data frame processing flow, respond to physical layer status changes by registering the frame control header callback function, use the circular queue to cache TCP message data, and have the physical layer interface simulation module parse the message, allocate memory and process the load in the specified time slot after timing synchronization to complete the closed-loop operation of the data link layer simulation.

[0011] Furthermore, calling a clock synchronization function to align a local clock of a site with the timestamp when receiving the beacon frame header includes:

[0012] Define the beacon frame header parsing conditions. The beacon frame header is defined as the frame control header part of the media access control protocol data unit. When the physical layer interface simulation module demodulates the frame control header, it triggers the call of the clock synchronization function.

[0013] Perform clock synchronization operations, call a clock synchronization function, and set the tick time of the site's local clock to the timestamp value carried by the beacon frame. The timestamp value is derived from the local clock sampling value when the concentrator sends the beacon frame.

[0014] Control the clock synchronization accuracy, calibrate the clock deviation through the microsecond time function of the operating system, and control the clock error between the site and the concentrator within the clock error preset threshold. The clock error preset threshold is associated with the time slot level timing tolerance defined by the power line carrier communication protocol.

[0015] Furthermore, the step of calibrating the clock deviation by using the microsecond-level time function of the operating system to control the clock error between the site and the concentrator within a preset clock error threshold includes:

[0016] The physical layer clock reference of the power line carrier communication protocol is set to a 25MHz crystal oscillator frequency, where 1 tick time unit is defined as 1 / 25 microsecond. The current time obtained by the operating system's microsecond time function is multiplied by the conversion coefficient PHY_TICKS_PER_US to obtain the simulation system tick time value. The conversion coefficient PHY_TICKS_PER_US is fixed at 25.

[0017] When the clock synchronization function is called, the second count and microsecond count of the beacon frame timestamp are extracted. The second count is multiplied by 1,000,000 and added to the microsecond count to obtain the total microsecond value. The total microsecond value is then multiplied by the conversion coefficient to convert it to the target tick time and overwritten into the site's local clock.

[0018] The preset threshold of the clock error is set to 1 microsecond, which is associated with the minimum precision unit of the operating system time function. Through integer operations of microsecond-level time sampling and tick time conversion, it is ensured that the absolute time deviation between the site and the concentrator does not exceed the threshold.

[0019] Furthermore, the adding of delay compensation before sending data and delaying the start of the physical layer receiving action when receiving data to offset the IP network transmission delay includes:

[0020] Before the physical layer interface simulation module calls the socket send function, a fixed delay threshold is added to simulate the physical layer modulation delay, wherein the fixed delay threshold is a preset value shorter than the actual modulation delay of the physical layer;

[0021] When receiving data, a physical layer receiving action is started within a preset time window before a timeout protection period of a receiving time slot.

[0022] Furthermore, before the physical layer interface simulation module calls the socket sending function, adding a fixed delay threshold to simulate the physical layer modulation delay includes:

[0023] Associating a fixed delay threshold with the time slot boundary constraint of the power line carrier communication protocol so that the start time of the sending window after the delay is increased does not exceed the start boundary of the current time slot. The fixed delay threshold is used to compensate for the timing deviation caused by the lack of a physical layer modulation process in IP network transmission. The value range of the fixed delay threshold is smaller than the modulation delay measurement value of the actual physical layer hardware platform.

[0024] In the high-priority task process, a delay operation is implemented through a microsecond timer of the operating system, so that the calling timing of the socket sending function is aligned with the time slot-level timing requirement of the physical layer simulation.

[0025] Furthermore, when receiving data, starting a physical layer receiving action within a preset time window before a timeout protection limit of a receiving timeslot includes:

[0026] The starting boundary of the timeout protection period of the associated receiving timeslot, wherein the timeout protection period is the timeout threshold of the guard timer started by the physical layer interface simulation module in the receiving timeslot;

[0027] Delaying the calling of the physical layer receiving action function in the high-priority task process so that the execution time point of the action function is the start time of the timeout protection limit of the current receiving time slot minus the preset time window length;

[0028] Delayed start allows TCP packet data to be processed after it reaches the ring queue due to transmission delays on the IP network.

[0029] Furthermore, the registering of the frame control header callback function to respond to the physical layer state change, using the circular queue to cache TCP message data, and the physical layer interface simulation module parsing the message, allocating memory and processing the load in the designated time slot after timing synchronization include:

[0030] Register a corresponding callback function according to the frame type of the media access control protocol data unit, the frame control header callback function is a media access control layer processing function that responds to the switching of the physical layer state machine, and the frame type includes a beacon frame, a soft confirmation frame, and a coordination frame;

[0031] Receive TCP messages through an independent listening thread and store them in a circular queue, and perform a splicing operation on fragmented TCP messages, where the fragmented TCP messages are defined as data packets carrying a private message header, whose header includes a 6-byte media access control address and a payload length identifier;

[0032] The high priority task process extracts the complete MAC PDU payload from the circular queue in a specified time slot after timing synchronization, allocates dynamic memory to store the payload data, and calls the frame control header callback function to process the data according to the physical layer state switch.

[0033] Furthermore, extracting the complete MAC PDU payload from the ring queue and allocating dynamic memory to store the payload data includes:

[0034] When the high-priority task process arrives at the designated receiving time slot after timing synchronization, the TCP message segment carrying the private message header is extracted from the head of the ring queue, and the data integrity is verified according to the payload length identifier in the private message header. If fragmented messages exist, a memory reassembly operation is performed according to a preset splicing condition;

[0035] When a complete MAC PDU payload is identified, the RTOS memory pool management interface is called to allocate a dynamic memory block, the size of which is determined by the MAC PDU payload length, and the payload data cached in the circular queue is copied to the dynamic memory block;

[0036] The frame control header callback function is triggered according to the physical layer state machine switching event, and the dynamic memory block pointer and the associated time slot information are passed to the data link layer task process, and the data link layer performs protocol parsing and memory release operations.

[0037] Furthermore, the power line carrier communication protocol data link layer simulation method also includes a dynamic networking routing control mechanism:

[0038] Constructing a proxy communication module, the proxy communication module establishing a TCP connection with all network nodes, presetting a routing table in the proxy communication module, the routing table storing the logical connection relationship of the network nodes;

[0039] When the proxy communication module receives a TCP message from a source node, it performs the following operations:

[0040] Parsing the source media access control address, the target media access control address and the frame type carried in the TCP message;

[0041] Querying the routing table and determining a forwarding path corresponding to the target media access control address according to the logical connection relationship;

[0042] If the target media access control address is associated with a child node in a multi-layer relay topology, cross-layer direct communication is prohibited, and the TCP message is only forwarded to the next hop node specified by the routing table.

[0043] Accordingly, the second aspect of an embodiment of the present invention provides an electric power device, comprising: at least one processor; and a memory connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the power line carrier communication protocol data link layer simulation method as described above.

[0044] Accordingly, a third aspect of an embodiment of the present invention provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the above-mentioned power line carrier communication protocol data link layer simulation method.

[0045] The above technical solutions of the embodiments of the present invention have the following beneficial technical effects:

[0046] 1. By creating high-priority task processes, the triggering of physical layer transmission and reception actions is strictly bound to the time slot-level timing, solving the timing misalignment problem caused by task scheduling delays in traditional simulations. In the communication scenario between the concentrator and the station, the high-priority task can force the triggering of physical layer actions in the specified time slot, avoiding the delay jitter caused by competition in the operating system task queue. This improves the simulation accuracy of the protocol stack for mechanisms such as CSMA / CA and reduces frame conflicts and retransmissions caused by timing deviations.

[0047] 2. To address the inherent delay characteristics of TCP / IP network transmission, the system effectively addresses the impact of network delay on frame alignment in the simulation environment by real-time monitoring of the timestamps carried in the concentrator beacon frames, combining local clock synchronization with delay compensation at the sender and receiver ends. When receiving data at a site, the system delays the initiation of physical layer reception to offset random delays in IP network transmission (such as router queue blocking or link congestion), ensuring that data frames are demodulated and parsed within the physical layer time slot. Dynamic delay compensation is added at the sender end to avoid frame transmission timeouts or receiver buffer overflows caused by network delays, thereby improving the consistency of data link layer simulation with real-world scenarios.

[0048] 3. A circular queue structure is used to cache TCP message data, significantly improving the efficiency and stability of data frame processing by recycling a fixed-size memory space. Compared with traditional linear cache structures, the circular queue does not require frequent data movement or dynamic memory allocation, reducing performance losses caused by memory fragmentation. In power line carrier communications, high-priority task processes need to quickly process a large number of data packets within a time slot. The first-in-first-out (FIFO) feature of the circular queue enables efficient data enqueue and dequeue operations. At the same time, the cyclic update mechanism of the head and tail pointers avoids the computational overhead caused by data movement.

[0049] 4. Through independent parameter configuration and a unified task scheduling mechanism for the dual-mode physical layer interface, the RF+PLC dual-mode collaboration scenario required by State Grid can be replicated within a single simulation system. The dual-mode interfaces share ring queues and high-priority process resources, avoiding redundant overhead. Differentiated timing parameters (such as slot width and modulation delay) ensure consistency between simulation results and the behavior of the actual dual-mode hardware platform, significantly improving the efficiency of verifying the protocol stack's compatibility with State Grid's dual-mode specifications. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 This is a flow chart of a method for simulating a data link layer of a power line carrier communication protocol provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0051] To make the objectives, technical solutions, and advantages of the present invention more clearly understood, the present invention will be further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings. It should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present invention. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present invention.

[0052] Please refer to Figure 1 A first aspect of an embodiment of the present invention provides a method for simulating a data link layer of a power line carrier communication protocol, comprising the following steps:

[0053] Step S100, construct a dual-mode parallel simulation physical layer interface module that supports RF wireless communication and PLC power line carrier, simulate power line carrier and wireless air interface transmission respectively through two independent TCP socket communications, and create a high-priority task process to handle the independent time slot-level timing synchronization of the dual modes, which is used to trigger the physical layer transmission and reception actions in the specified time slot.

[0054] The physical layer interface simulation module includes dual-mode support: Separate physical layer interface instances are created for PLC power line carrier (PLC) and RF wireless communication, each associated with a dedicated TCP socket channel. The dual-mode interfaces share the same high-priority task process but maintain independent timing parameter sets (including slot width, modulation delay threshold, and clock reference frequency) to ensure that timing control for both modes does not interfere with each other. The physical layer state machine switches the dual-mode configuration based on the channel identifier (PLC_CH / RF_CH), enabling the protocol stack to uniformly schedule heterogeneous channels. Power line carrier (PLC_CH) and wireless air interface (RF_CH) transmissions are simulated via two independent TCP sockets. An example of a differentiated dual-mode configuration is as follows: PLC mode: slot width = 1ms, fixed delay threshold = 112.5μs, clock reference = 25MHz; RF mode: slot width = 0.5ms, fixed delay threshold = 60μs, clock reference = 40MHz. The high-priority task process loads the corresponding parameter set based on the channel identifier (PLC_CH / RF_CH), triggering physical layer transmission and reception at the specified time slot.

[0055] Power line carrier and wireless air interface transmission are simulated through TCP socket communication, abstracting the signal transmission characteristics of the physical layer into the interactive logic of the network protocol layer. Specifically, the reliable transmission characteristics of the TCP protocol are used to simulate the delay, packet loss, and noise interference of the power line channel. For example, by adjusting the socket's sending window size or introducing a random packet loss mechanism, fluctuations in communication quality caused by sudden load changes or device access can be simulated. At the same time, a high-priority task process is created to handle time slot-level timing synchronization. The core of this is to strictly bind the physical layer's transceiver operations to the simulation clock. For example, in power line carrier communication, communication between the concentrator and the station must follow the time slot allocation rules. The high-priority process can force the operating system to prioritize the physical layer transceiver tasks within the specified time slot, avoiding timing misalignment caused by other low-priority tasks preempting CPU resources.

[0056] Step S200, configure the timing synchronization control mechanism, obtain the timestamp carried by the beacon frame sent by the concentrator, call the clock synchronization function when receiving the beacon frame header to align the site local clock with the timestamp, add delay compensation before sending data, and delay the start of the physical layer receiving action when receiving data to offset the IP network transmission delay.

[0057] Timing synchronization control is a key step in data link layer simulation, and its core lies in achieving clock alignment of distributed nodes through beacon frames. When the concentrator sends a beacon frame, the timestamp it carries reflects the global time reference of the current network layer. After receiving the beacon frame header, the station must immediately call the clock synchronization function to align the local clock with the timestamp and further optimize the simulation accuracy through dynamic delay compensation. For example, adding delay compensation before sending data can offset the inherent delay of TCP network transmission (such as jitter caused by router queue processing time or link congestion); and delaying the start of the physical layer receiving action when receiving data can balance the matching problem between IP network delay and physical layer time slot, avoiding data truncation or frame errors caused by premature start of the receiving end. This two-way compensation mechanism effectively resolves the contradiction between network delay and physical layer time slot in the simulation environment, providing a reliable foundation for the simulation of media access control protocols such as CSMA / CA.

[0058] Step S300 implements the data frame processing flow, responds to physical layer status changes by registering a frame control header callback function, uses a circular queue to cache TCP message data, and has the physical layer interface simulation module parse the message, allocate memory, and process the load in the specified time slot after timing synchronization, completing the closed-loop operation of the data link layer simulation.

[0059] The efficiency of the data frame processing process directly impacts the real-time performance of the simulation system. By registering a frame control header callback function, physical layer status changes (such as frame arrival and transmission completion) can trigger responses from the data link layer. For example, when the physical layer receives a complete frame, the callback function triggers frame checking, address filtering, and payload parsing. The introduction of a ring queue optimizes the data caching mechanism. By recycling fixed memory space, the ring queue avoids the fragmentation problem of dynamic memory allocation and supports multi-threaded safe access, making it suitable for data processing in high-concurrency scenarios. For example, in power line carrier communication, the concentrator needs to process uplink data from multiple stations simultaneously. The ring queue can buffer TCP packets in FIFO order and parse them in batches within time slots by high-priority tasks, significantly improving throughput. Furthermore, when parsing packets after time slot synchronization, the physical layer interface simulation module dynamically allocates memory to store payload data. This process incorporates the segmented transmission and retransmission mechanisms commonly used in power line communication, ensuring that the simulation results are consistent with the behavior of the real protocol stack.

[0060] Furthermore, in step S200, when receiving the beacon frame header, calling the clock synchronization function to align the site local clock with the timestamp includes:

[0061] Step S211, defining the beacon frame header parsing conditions. The beacon frame header is defined as the frame control header part of the media access control protocol data unit. When the physical layer interface simulation module demodulates the frame control header, the call of the clock synchronization function is triggered.

[0062] In the power line carrier communication protocol, the beacon frame is the core control frame of the data link layer, and its header structure must follow specific format specifications. By parsing the frame control header of the media access control protocol data unit (MAC PDU), the conditions for triggering clock synchronization are defined. During the demodulation process, the physical layer interface simulation module will prioritize identifying the synchronization identification field (such as frame type, sequence number or synchronization code) in the frame control header. When the beacon frame header is detected, the clock synchronization function call is immediately triggered to ensure that the synchronization operation is accurately intervened at the boundary between the physical layer and the data link layer. For example, in the beacon frame header, the concentrator will embed the timestamp field as the global time reference, and the station can trigger the subsequent synchronization process by parsing this field, avoiding the accumulation of delays due to redundant parsing of the frame payload data.

[0063] Step S212: perform clock synchronization operation, call the clock synchronization function, set the tick time of the site local clock to the timestamp value carried by the beacon frame, and the timestamp value is derived from the local clock sampling value when the concentrator sends the beacon frame.

[0064] The core of the clock synchronization operation is to align the local clock of the site with the timestamp of the concentrator. When the site receives the beacon frame header, it calls the clock synchronization function and directly sets the tick time (i.e., clock counting unit) of the local clock to the timestamp value carried by the beacon frame. This timestamp is derived from the local clock sampling when the concentrator sends the beacon frame, and its accuracy must match the time slot tolerance defined by the power line carrier protocol. For example, in the IEEE 1588v2 protocol, the master and slave nodes achieve microsecond-level synchronization through timestamp exchange, and the concentrator here is equivalent to the master clock node. The site achieves rapid alignment by directly replacing the local clock value, and completes the initial synchronization through a single timestamp transmission, avoiding complex time difference calculations. It is suitable for scenarios with high real-time requirements in power line communications.

[0065] Step S213 controls the clock synchronization accuracy, calibrates the clock deviation through the microsecond time function of the operating system, and controls the clock error between the site and the concentrator within a preset clock error threshold. The preset clock error threshold is associated with the time slot level timing tolerance defined by the power line carrier communication protocol.

[0066] To ensure that synchronization accuracy meets protocol requirements, the clock deviation is dynamically calibrated through the microsecond-level time functions provided by the operating system (such as Linux's gettimeofday or clock_gettime). In specific implementation, after setting the local clock, the site will continuously monitor the clock error with the concentrator and adjust the frequency or phase of the local clock by comparing the difference between the actual operating system time and the beacon frame timestamp. For example, if the error exceeds a preset threshold (such as 1 microsecond), the calibration algorithm is triggered and the clock output is fine-tuned using a PLL (phase-locked loop) or software compensation mechanism. This threshold is related to the time slot-level timing tolerance defined by the power line carrier protocol. For example, in HPLC, the time slot width is usually in the millisecond level, so the synchronization error needs to be controlled within 1% of the time slot width to avoid frame misalignment. In addition, by combining a temperature compensation algorithm, clock drift caused by environmental changes can be further reduced to ensure long-term synchronization stability.

[0067] Furthermore, step S213 of calibrating the clock deviation by using the microsecond-level time function of the operating system to control the clock error between the site and the concentrator within a preset clock error threshold includes:

[0068] Step S213a: The physical layer clock reference of the power line carrier communication protocol is set to the preset crystal oscillator frequency, and the current time obtained by the operating system microsecond time function is multiplied by the conversion coefficient to obtain the simulation system tick time value.

[0069] For example, the physical layer clock reference of the power line carrier communication protocol can be set to a 25MHz crystal oscillator frequency, where 1 tick time unit is defined as 1 / 25 microsecond. The current time obtained by the operating system's microsecond time function is multiplied by the conversion coefficient PHY_TICKS_PER_US to obtain the simulation system tick time value. The conversion coefficient PHY_TICKS_PER_US is fixed to 25.

[0070] The physical layer clock reference of the power line carrier communication protocol is set to a 25MHz crystal oscillator frequency. The core of this approach is to establish a precise mapping between the physical units of the hardware clock (e.g., crystal oscillator periods) and the abstract time units (ticks) of the simulation system. The current time is obtained with microsecond precision using the operating system's microsecond-level time functions (e.g., clock_gettime(CLOCK_MONOTONIC)). Multiplying this by the conversion factor PHY_TICKS_PER_US = 25 converts real time to the simulation system's tick time units, where 1 microsecond corresponds to 25 ticks. In power line communication, a 25MHz crystal oscillator frequency supports finer-grained time slot divisions (e.g., 100μs per time slot corresponds to 2500 ticks), thus meeting the clock accuracy requirements of carrier modulation (e.g., OFDM subcarrier spacing). By binding the operating system time to the hardware clock reference, the simulation system can emulate the clock behavior of the real physical layer, ensuring the accuracy of the protocol stack for timing-sensitive operations (e.g., symbol synchronization and frame alignment).

[0071] Step S213b: When the clock synchronization function is called, the second count and microsecond count of the beacon frame timestamp are extracted, the second count is multiplied by 1000000 and added to the microsecond count to obtain the total microsecond value, which is then multiplied by the conversion coefficient to convert it to the target tick time and overwritten into the site local clock.

[0072] The timestamp carried in the beacon frame contains both second- and microsecond-count fields, and the conversion process must strictly adhere to the clock representation specifications of the power line carrier protocol. For example, if the beacon frame timestamp is sec = 1690000000, usec = 123456, the total microsecond value is 1690000000 × 1,000,000 + 123,456 = 1,690,000,123,456 μs. Multiplying by the conversion factor 25 yields the target tick value of 42,250,003,086,400. This conversion is performed using integer arithmetic to avoid floating-point errors and ensure accurate overwriting of the station's local clock. In simulations, by converting the beacon frame timestamp to tick values, stations can synchronize directly to the concentrator's clock reference without the need for complex phase adjustment algorithms, significantly reducing computational complexity.

[0073] In step S213c, the preset threshold of the clock error is set to 1 microsecond, which is associated with the minimum precision unit of the operating system time function. Through integer operations of microsecond-level time sampling and tick time conversion, it is ensured that the absolute time deviation between the site and the concentrator does not exceed the threshold.

[0074] The preset clock error threshold is set to 1 microsecond, balancing simulation accuracy with the limitations of hardware time functions. Operating system microsecond-level time functions (such as Linux's clock_gettime) typically have a minimum precision of 1 microsecond. Converting tick values ​​through integer operations (such as multiplication and addition) ensures that the error is solely due to jitter in the time function itself. For example, if the operating system time sampling error is ±0.5μs, this corresponds to a ±12.5-tick error after conversion. However, through threshold verification (such as comparing the tick difference between the site and the concentrator to see if it exceeds 25 ticks, or 1μs), the absolute time deviation can be controlled within the threshold. In power line carrier communications, a 1μs error corresponds to 25 ticks, which is far less than the slot-level tolerance (e.g., a 1ms slot corresponds to 25,000 ticks), thus preventing frame misalignment or retransmissions. Furthermore, by periodically calling the clock synchronization function (e.g., once per second), long-term error accumulation due to crystal oscillator drift or ambient temperature changes can be further suppressed.

[0075] Furthermore, adding delay compensation before sending data in step S200 and delaying starting the physical layer receiving action when receiving data to offset the IP network transmission delay includes:

[0076] Step S221 : Before the physical layer interface simulation module calls the socket sending function, a fixed delay threshold is added to simulate the physical layer modulation delay. The fixed delay threshold is a preset value shorter than the actual modulation delay of the physical layer.

[0077] The core purpose of adding a fixed delay threshold before the physical layer interface simulation module calls the socket send function is to simulate the inherent delay of the physical layer modulation process. The setting of this threshold must be based on the actual processing time of the modulator in the power line carrier communication protocol. For example, OFDM modulation requires the completion of operations such as symbol mapping and IFFT transformation. The fixed delay threshold is usually a preset proportion of the actual modulation delay (such as 90%). For example, in the HPLC protocol, the modulation delay may be determined by the crystal oscillator frequency (such as 25MHz) and the symbol period (such as 125μs). By lowering the threshold (such as setting it to 112.5μs), headroom can be reserved to offset the random delay of IP network transmission. In addition, the dynamic adjustment strategy of the fixed delay threshold can be combined with network monitoring data (such as RTT measurement results) to further optimize the compensation accuracy and ensure the timing alignment between the sender and the receiver.

[0078] Step S222 , when receiving data, starting the physical layer receiving action within a preset time window before the timeout protection limit of the receiving time slot.

[0079] When receiving data, a pre-set time window is set before the receive slot's timeout protection limit. This proactively reserves a time buffer to offset the uncertainty of IP network transmission delays. For example, in power line carrier communications, if the IP network delay between the concentrator and the site is 50μs, the receiver must start receiving 50μs before the start of the slot to ensure that even if data packets arrive late due to network congestion, they can still fully capture the physical layer signal. This mechanism draws on HARQ (Hybrid Automatic Repeat Request) technology in wireless networks. By pre-starting the receive buffer and combining it with timeout protection (such as timer interrupts), it prevents data truncation or loss due to delays. Furthermore, the size of the time window must match the protocol-defined slot tolerance. For example, in HPLC, where the slot width is 1ms, the receiver can set a 500μs pre-start window to ensure frame reception within the delay fluctuation range. Furthermore, the timeout protection period should be set in conjunction with network jitter statistics (such as those measured by MTR tools) to balance the risk of misjudgment with delay tolerance, avoiding data loss due to an overly small window or resource waste due to an overly long window.

[0080] Furthermore, before the physical layer interface simulation module calls the socket send function in step S221, a fixed delay threshold is added to simulate the physical layer modulation delay, including:

[0081] Step S221a, associate the fixed delay threshold with the time slot boundary constraint of the power line carrier communication protocol so that the start time of the sending window after the delay is increased does not exceed the start boundary of the current time slot. The fixed delay threshold is used to compensate for the timing deviation caused by the lack of physical layer modulation process in IP network transmission. The numerical range of the fixed delay threshold is smaller than the modulation delay measurement value of the actual physical layer hardware platform.

[0082] Setting a fixed delay threshold is used to address the timing discrepancy between the IP network simulation environment and the real physical layer. In real power line carrier communications (such as the State Grid HPLC system), physical layer hardware modulation has inherent delays (such as the encoding / modulation processing time of FPGA or ASIC chips), while TCP / IP network transmission only completes packet forwarding and lacks this physical process. By implanting a fixed delay threshold (typically lower than the delay measured in real hardware), a time slot boundary constraint is actively established: a short wait is forced before calling the socket send function, so that the start time of the data send window is strictly aligned with the start boundary of the current time slot. This threshold meets dual constraints—it must compensate for the timing deviation caused by the lack of physical modulation and ensure that the sending window after the delay does not intrude into the next time slot (such as the 1ms time slot division in the State Grid standard). Its numerical range is strictly set according to the lower limit of the modulation delay measurement value of the real hardware platform (such as the HPLC carrier module), ensuring that the simulation system maintains the protocol timing accuracy while avoiding the risk of time slot misalignment caused by excessive delay.

[0083] Step S221b: Implement a delay operation through the operating system's microsecond timer in the high-priority task process, so that the timing of calling the socket send function is aligned with the time slot-level timing requirement of the physical layer simulation.

[0084] The implementation of the microsecond timer relies on the precise time control capabilities of the operating system (such as the usleep() function in Linux). In the high-priority task process (i.e., the PHY_STUB task), the timer starts immediately after the physical layer state machine triggers the send action, and performs a blocked wait according to the preset delay threshold. The key technology lies in mapping the operating system's microsecond time resolution (1μs) to the tick time system of the power line carrier protocol through a conversion factor (such as PHY_TICKS_PER_US=25). This mapping allows the timing of calling the socket send function to be precisely controlled within the protocol valid window of the current time slot, thereby reproducing the time slot-level timing behavior of the real physical layer in the simulation environment. As the highest priority task, the PHY_STUB process's exclusive use of CPU resources ensures the determinism of the delay operation and avoids timing inaccuracies caused by system scheduling jitter.

[0085] Through the collaborative mechanism described above, a functionally equivalent replacement for the physical layer modulation delay is achieved in the simulation system. On the one hand, the fixed delay threshold fills the timing gap between the IP network and the real physical layer, strictly limiting the data transmission window to the protocol time slot boundaries. On the other hand, the microsecond timer leverages the native high-precision timing capabilities of the operating system to ensure accurate execution of delay compensation. The combination of the two enables the simulation system to maintain consistent time slot-level timing logic with the real HPLC system even without hardware, providing a realistic physical layer interaction experience for the data link layer. This not only solves the problem of difficulty in obtaining a real environment, but also significantly improves debugging efficiency, compressing the verification process that originally relied on hardware for minutes to seconds.

[0086] Furthermore, in step S222, when receiving data, starting the physical layer receiving action within a preset time window before the timeout protection limit of the receiving timeslot includes:

[0087] Step S222a, associating the timeout protection limit start boundary of the receiving timeslot, where the timeout protection limit is the timeout threshold of the guard timer started by the physical layer interface simulation module in the receiving timeslot.

[0088] The timeout protection limit is set to directly map the time slot protection mechanism of the real power line carrier communication protocol (such as the State Grid HPLC specification). When the receiving time slot starts, the physical layer interface simulation module (PHY_STUB) will initialize a guard timer (Guard Timer), whose timeout threshold strictly follows the time slot boundary defined by the protocol (for example, a typical value is 90%-95% of the time slot length). This time limit serves as a hard cutoff boundary for the receiving action. If valid data reception is not completed within this period, the physical layer will forcibly terminate the current time slot operation and trigger the next time slot scheduling. This design reproduces the physical constraints of the real hardware platform on the channel occupancy time, ensuring the consistency of the simulation system and the protocol timing logic.

[0089] Step S222b: Delay calling the physical layer receiving action function in the high priority task process so that the execution time point of the action function is the timeout protection period start time of the current receiving time slot minus the preset time window length.

[0090] The core of the delayed start mechanism is to proactively mitigate the uncertainties of IP network transmission. In the high-priority task process (PHY_STUB), the call to the physical layer receive action function (e.g., phy_start_rx) is deliberately delayed until the timeout protection period starts, minus the preset time window duration. This strategy leverages the buffering effect of the time window to offset the random delay introduced by the Com_Agent relay. Technically, the delay is precisely calculated using the operating system's microsecond-level timer (e.g., Linux timerfd) and bound to the time slot scheduling list. This allows the receive window opening timing to dynamically adapt to network conditions, avoiding both wasted resources caused by premature starts and data loss caused by late starts.

[0091] Step S222c: Delayed start is used to allow the TCP message data to be processed after it reaches the ring queue due to transmission delay on the IP network.

[0092] The asynchronous caching capability of the ring queue is the technical cornerstone of this step. An independent listening thread (thread_recv) continuously receives TCP packets and stores them in the ring queue, unconstrained by the physical layer's start and stop functions. A delayed start mechanism ensures that IP network transmission delays are absorbed within the time window when PHY_STUB processes queued data. At this point, the packets cached in the ring queue (including complete MAC PDUs after fragment reassembly) can be extracted and processed by PHY_STUB according to protocol timing, achieving ideal zero-data-drop reception in the simulation environment. This improves the reception success rate of time-sensitive beacon frames, particularly from the original 95% to nearly 100%.

[0093] By combining the protocol constraints of the guard timer, the network adaptability of delayed start, and the asynchronous buffer depth of the ring queue, a triple technical effect is achieved in a simulation environment detached from real hardware: First, the time slot boundary control logic of real power line carrier communication (such as the State Grid HPLC protocol) is accurately reproduced, ensuring the timing consistency between the simulation system and the physical layer protocol; second, the delayed start window dynamically adapts to IP network transmission delays (such as the 5% packet loss rate measured by Com_Agent), converting random delays into deterministic processing opportunities, and completely eliminating reception advances / lags and timing misalignments caused by network jitter; third, relying on the continuous monitoring and fragment reassembly mechanism of the ring queue, the complete processing of all TCP packets (including sensitive beacon frames) is guaranteed, solving the difficulties of high randomness and high closure difficulty. It provides highly reliable underlying support for large-scale dynamic networking debugging and complex random bug reproduction, enabling R&D personnel to achieve debugging controllability and efficiency that surpasses real hardware environments.

[0094] Furthermore, in step S300, the frame control header callback function is registered to respond to the physical layer state change, the TCP message data is buffered by the ring queue, and the physical layer interface simulation module parses the message, allocates memory, and processes the load in the specified time slot after timing synchronization, including:

[0095] Step S310: register a corresponding callback function according to the frame type of the media access control protocol data unit. The frame control header callback function is a media access control layer processing function that responds to the physical layer state machine switching. The frame types include beacon frame, soft confirmation frame, and coordination frame.

[0096] In step S320, a separate listening thread receives dual-mode TCP packets (PLC / RF channels) and stores them in the same circular queue. The fragmented TCP packets are concatenated, and a 1-byte channel identifier (0x01 = PLC, 0x02 = RF) is added to the fragmented packet header to distinguish the dual-mode data sources. A fragmented TCP packet is defined as a data packet with a private header containing a 6-byte media access control address and a payload length identifier.

[0097] In step S330, the high-priority task process extracts the complete MAC PDU payload from the ring queue in the specified time slot after timing synchronization, allocates dynamic memory to store the payload data, and calls the frame control header callback function to process the data according to the physical layer state switch.

[0098] Furthermore, extracting the complete MAC PDU payload from the ring queue and allocating dynamic memory to store the payload data in step S330 includes:

[0099] Step S331, when the high-priority task process reaches the designated receiving time slot after timing synchronization, the TCP message segment carrying the private message header is extracted from the head of the circular queue, and the data integrity is verified according to the payload length identifier in the private message header. If there is a fragmented message, the memory reorganization operation is performed according to the preset splicing conditions.

[0100] When the designated receive time slot after timing synchronization is triggered (such as the precise time slot window after beacon synchronization), the high-priority task process (PHY_STUB) extracts the TCP segment containing the private header from the head of the circular queue. The payload length identifier (the next 4 bytes) of the private header (struct_priv_hdr_t) serves as the core verification basis. By comparing the actual received data length with the identifier value, it is determined whether there is a fragmented message. If fragmentation is detected (such as the length identifier value is greater than the current buffered data volume), the reassembly operation is performed in the memory according to the preset splicing conditions (such as the start identifier 0xFFFFFFFF of the continuous message header). This mechanism ensures that the fragmented messages transmitted on the IP network are ultimately restored completely, eliminating the problem of incomplete MAC PDU data caused by TCP streaming transmission from the root, and providing a complete protocol data unit for subsequent processing.

[0101] Step S332: When a complete MAC PDU payload is identified, the RTOS memory pool management interface is called to allocate a dynamic memory block, the size of which is determined by the MAC PDU payload length, and the payload data cached in the circular queue is copied to the dynamic memory block.

[0102] After identifying the complete MAC PDU payload, the memory pool management interface transplanted from the real RTOS is called to dynamically allocate memory blocks according to the MAC PDU payload length; this achieves precise matching of memory block sizes: the allocated space is determined by the MAC PDU payload length (including the frame control header and payload), avoiding memory waste or overflow. In addition, although zero-copy optimization is possible, a copy mechanism is actively adopted (copying from the circular queue buffer to the dynamic memory block) to fully replicate the hardware behavior of the real carrier module - in the real system, physical copies are required when the physical layer and data link layer transfer data through shared memory. This ensures that the simulation environment and the hardware platform remain completely consistent in the processing link, ensuring the credibility of the debugging results.

[0103] Step S333: trigger the frame control header callback function according to the physical layer state machine switching event, pass the dynamic memory block pointer and the associated time slot information to the data link layer task process, and the data link layer performs protocol parsing and memory release operations.

[0104] Physical layer state machine transition events (e.g., PHY_STATUS_PD → PHY_STATUS_RX_FRAME) trigger the frame control header callback function. At this point, the dynamic memory block pointer and time slot information (e.g., BPTs time slot number) are passed to the data link layer (DL) task process. The DL layer performs protocol parsing based on the frame type (beacon / soft acknowledgment / coordination frame) and immediately releases the dynamic memory block after processing. By binding state machine events to callback functions, the notification mechanism of state transitions from a real physical layer chip to the data link layer is accurately simulated. Memory allocation and release responsibilities are clearly assigned to the physical and data link layers (simulating the responsibilities of real hardware), avoiding the risk of memory leaks common in simulation environments.

[0105] A three-step collaborative process builds a data processing chain equivalent to real hardware. Slice verification and reassembly ensure data integrity during unreliable network layer transmission; dynamic memory allocation and copying replicate hardware resource management constraints; and state machine triggering and cross-layer transfer enable precise simulation of protocol stack layer interactions. Ultimately, this achieves the core goal: ensuring that the runtime behavior of modules above the data link layer (including memory usage, timing response, and exception handling) is completely consistent with that of real carrier modules in a pure software environment, independent of physical hardware.

[0106] Furthermore, the power line carrier communication protocol data link layer simulation method also includes a dynamic networking routing control mechanism: constructing a proxy communication module, the proxy communication module establishes a TCP connection with all network nodes, and pre-sets a routing table in the proxy communication module, and the routing table stores the logical connection relationship of the network nodes.

[0107] When the proxy communication module receives a TCP packet from the source node, it performs the following operations:

[0108] Step S410: Parse the source media access control address, target media access control address and frame type carried in the TCP message.

[0109] After receiving the TCP message sent by the source node, the proxy communication module first parses the source media access control address (Source MAC) and destination media access control address (Destination MAC) embedded in the message header and identifies the frame type field (such as beacon frame, service data frame or relay control frame). The source MAC address is used to identify the logical identity of the sending node (such as the concentrator is identified as 0x0001, and the meter node is identified as 0x1001-0xFFFF), and the destination MAC address specifies the intended recipient of the data frame; the analysis of the frame type determines the triggering conditions of the subsequent routing strategy (such as beacon frames need to be broadcast to the entire network, and service data frames need to be directed unicast). This step provides basic input parameters for routing decisions by deeply deconstructing the TCP message header metadata, ensuring that the forwarding behavior is strictly consistent with the addressing specifications of the power line carrier communication protocol.

[0110] Step S420: query the routing table and determine the forwarding path corresponding to the target media access control address according to the logical connection relationship.

[0111] The proxy communication module queries the preset routing table based on the parsed target MAC address. The routing table stores the logical connection relationship of network nodes in the form of key-value pairs (such as concentrator → repeater 1 → meter node group). The routing table is generated through static configuration or dynamic learning protocol, and clearly defines the hierarchical affiliation between nodes (such as concentrator as root node, repeater as secondary node, and meter as leaf node). During the query, if the target MAC address matches a leaf node (such as meter 0x1001), the unique forwarding path is determined according to the tree topology rules: data must be transmitted via the first-hop link from the root node to the secondary node, and direct connection across levels is prohibited. This mechanism abstracts the physical TCP fully connected network into a logical tree topology, forcing data to be transmitted along the hierarchical path defined by the protocol.

[0112] Step S430: If the target media access control address is associated with a child node in a multi-layer relay topology, cross-layer direct communication is prohibited, and the TCP message is only forwarded to the next hop node specified by the routing table.

[0113] When the target MAC address is associated with a subnode in a multi-layer relay topology (e.g., meter 0x1001 belongs to repeater 0x0201), the proxy communication module only forwards the TCP message to the next-hop node specified in the routing table (e.g., repeater 0x0201) and discards unauthorized cross-layer direct connection requests. For example, if the concentrator (0x0001) attempts to directly access the meter (0x1001), but the routing table indicates that the meter must be relayed through repeater 0x0201, the proxy module will intercept the direct connection message and redirect it to the repeater. This operation replicates the relay rules of power line carrier communication at the TCP / IP transport layer through the mandatory constraints of the routing table, avoiding the destruction of the layer isolation required by the protocol due to the fully connected nature of the network layer.

[0114] This mechanism accurately replicates the tree-like networking characteristics of power line carrier communications in a TCP / IP-based simulation environment by imposing rigid constraints on the logical topology through routing tables. The proxy communication module acts as a virtual relay hub, abstracting the fully connected physical layer network into the hierarchical topology required by the protocol. This not only retains the reliability advantages of TCP transmission, but also ensures that data frames strictly follow the hop-by-hop forwarding rule from concentrator to repeater to terminal meter through a three-stage pipeline operation of address resolution, path query, and hierarchical isolation. This fundamentally eliminates topological chaos caused by direct connections at the network layer and provides underlying support for the simulation and verification of advanced features such as multi-hop routing and relay load balancing.

[0115] Furthermore, a software module simulates the collaborative operation of the "PLC communication module + meter" hardware combination. The virtual meter module runs as an independent process, generating meter service data (such as periodic meter reading requests and rate parameter updates) according to the State Grid DL / T 645 protocol and passing this service data to the PLC protocol application layer via a socket interface. The application layer encapsulates the service data into MAC frames and passes them to the data link layer simulation module for processing. Simultaneously, response commands from the concentrator (such as timing commands and load control) are parsed by the protocol stack and returned to the virtual meter module for service logic verification. This implementation enables the simulation system to fully simulate the entire power line carrier communication process, from service triggering to protocol encapsulation to timing synchronization, without relying on hardware meters, meeting the State Grid's verification requirements for meter communication scenarios.

[0116] Accordingly, a second aspect of an embodiment of the present invention provides an electric power device, comprising: at least one processor; and a memory connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the power line carrier communication protocol data link layer simulation method as described above.

[0117] Accordingly, a third aspect of an embodiment of the present invention provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the above-mentioned power line carrier communication protocol data link layer simulation method.

[0118] The embodiment of the present invention aims to provide a method for simulating a data link layer of a power line carrier communication protocol, which has the following effects:

[0119] 1. By creating high-priority task processes, the triggering of physical layer transmission and reception actions is strictly bound to the time slot-level timing, solving the timing misalignment problem caused by task scheduling delays in traditional simulations. In the communication scenario between the concentrator and the station, the high-priority task can force the triggering of physical layer actions in the specified time slot, avoiding the delay jitter caused by competition in the operating system task queue. This improves the simulation accuracy of the protocol stack for mechanisms such as CSMA / CA and reduces frame conflicts and retransmissions caused by timing deviations.

[0120] 2. To address the inherent delay characteristics of TCP / IP network transmission, the system effectively addresses the impact of network delay on frame alignment in the simulation environment by real-time monitoring of the timestamps carried in the concentrator beacon frames, combining local clock synchronization with delay compensation at the sender and receiver ends. When receiving data at a site, the system delays the initiation of physical layer reception to offset random delays in IP network transmission (such as router queue blocking or link congestion), ensuring that data frames are demodulated and parsed within the physical layer time slot. Dynamic delay compensation is added at the sender end to avoid frame transmission timeouts or receiver buffer overflows caused by network delays, thereby improving the consistency of data link layer simulation with real-world scenarios.

[0121] 3. A circular queue structure is used to cache TCP message data, significantly improving the efficiency and stability of data frame processing by recycling a fixed-size memory space. Compared with traditional linear cache structures, the circular queue does not require frequent data movement or dynamic memory allocation, reducing performance losses caused by memory fragmentation. In power line carrier communications, high-priority task processes need to quickly process a large number of data packets within a time slot. The first-in-first-out (FIFO) feature of the circular queue enables efficient data enqueue and dequeue operations. At the same time, the cyclic update mechanism of the head and tail pointers avoids the computational overhead caused by data movement.

[0122] 4. Through independent parameter configuration and a unified task scheduling mechanism for the dual-mode physical layer interface, the RF+PLC dual-mode collaboration scenario required by State Grid can be replicated within a single simulation system. The dual-mode interfaces share ring queues and high-priority process resources, avoiding redundant overhead. Differentiated timing parameters (such as slot width and modulation delay) ensure consistency between simulation results and the behavior of the actual dual-mode hardware platform, significantly improving the efficiency of verifying the protocol stack's compatibility with State Grid's dual-mode specifications.

[0123] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0124] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0125] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0126] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0127] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered by the scope of protection of the claims of the present invention.

Claims

1. A method for simulating the data link layer of a power line carrier communication protocol, characterized in that: The steps include: Step S100: construct a physical layer interface simulation module, simulate power line carrier or wireless air interface transmission through TCP socket communication, and create a high-priority task process to handle time slot-level timing synchronization, which is used to trigger physical layer transmission and reception actions at specified time slots; Step S200: Configure a timing synchronization control mechanism to obtain the timestamp carried in the beacon frame sent by the concentrator. Upon receiving the beacon frame header, call a clock synchronization function to align the site's local clock with the timestamp. Add delay compensation before sending data. When receiving data, delay the start of the physical layer reception action to offset IP network transmission delay. Step S300 implements the data frame processing flow, responds to physical layer status changes by registering a frame control header callback function, uses a circular queue to cache TCP message data, and the physical layer interface simulation module parses the message, allocates memory, and processes the load in the specified time slot after timing synchronization to complete the closed-loop operation of the data link layer simulation.

2. The power line carrier communication protocol data link layer simulation method according to claim 1, characterized in that: The calling of a clock synchronization function to align a local clock of a site with the timestamp when receiving the beacon frame header in step S200 includes: Step S211, defining a beacon frame header parsing condition, where the beacon frame header is defined as a frame control header portion of a media access control protocol data unit. When the physical layer interface simulation module demodulates the frame control header, a call to a clock synchronization function is triggered. Step S212: Perform clock synchronization, call a clock synchronization function, and set the tick time of the site's local clock to the timestamp value carried by the beacon frame. The timestamp value is derived from the local clock sampling value when the concentrator sends the beacon frame. Step S213 controls the clock synchronization accuracy, calibrates the clock deviation through the microsecond time function of the operating system, and controls the clock error between the site and the concentrator within a preset clock error threshold. The preset clock error threshold is associated with the time slot level timing tolerance defined by the power line carrier communication protocol.

3. The power line carrier communication protocol data link layer simulation method according to claim 2, characterized in that: The step S213 of calibrating the clock deviation by using the microsecond time function of the operating system to control the clock error between the station and the concentrator within a preset clock error threshold includes: Step S213a, setting the physical layer clock reference of the power line carrier communication protocol to the preset crystal oscillator frequency, and multiplying the current time obtained by the operating system's microsecond time function by the conversion coefficient to obtain the simulation system tick time value; Step S213b: When the clock synchronization function is called, the second count and microsecond count of the beacon frame timestamp are extracted. The second count is multiplied by 1,000,000 and added to the microsecond count to obtain the total microsecond value. The total microsecond value is then multiplied by the conversion coefficient to convert it into the target tick time, which is then overwritten into the site's local clock. In step S213c, the preset threshold of the clock error is set to 1 microsecond, which is associated with the minimum precision unit of the operating system time function. Through integer operations of microsecond-level time sampling and tick time conversion, it is ensured that the absolute time deviation between the site and the concentrator does not exceed the threshold.

4. The power line carrier communication protocol data link layer simulation method according to claim 1, characterized in that: The adding of delay compensation before sending data in step S200 and delaying the start of the physical layer receiving action when receiving data to offset the IP network transmission delay include: Step S221: Before the physical layer interface simulation module calls the socket send function, a fixed delay threshold is added to simulate the physical layer modulation delay, where the fixed delay threshold is a preset value shorter than the actual modulation delay of the physical layer; Step S222 , when receiving data, starting the physical layer receiving action within a preset time window before the timeout protection limit of the receiving time slot.

5. The power line carrier communication protocol data link layer simulation method according to claim 4, characterized in that: The step S221 of increasing a fixed delay threshold to simulate a physical layer modulation delay before the physical layer interface simulation module calls the socket send function includes: Step S221a, associating a fixed delay threshold with the time slot boundary constraint of the power line carrier communication protocol so that the start time of the sending window after the delay is increased does not exceed the start boundary of the current time slot. The fixed delay threshold is used to compensate for the timing deviation caused by the lack of a physical layer modulation process in IP network transmission. The value range of the fixed delay threshold is smaller than the modulation delay measurement value of the actual physical layer hardware platform; Step S221b: Implementing a delay operation in the high-priority task process through the operating system's microsecond timer to align the timing of calling the socket send function with the time slot-level timing requirement of the physical layer simulation.

6. The power line carrier communication protocol data link layer simulation method according to claim 4, characterized in that: The step S222 of starting the physical layer receiving action in a preset time window before the timeout protection limit of the receiving time slot when receiving data includes: Step S222a, associating the timeout protection limit start boundary of the receiving timeslot, wherein the timeout protection limit is the timeout threshold of the guard timer started by the physical layer interface simulation module in the receiving timeslot; Step S222b, delaying the calling of the physical layer receiving action function in the high-priority task process so that the execution time point of the action function is the start time of the timeout protection limit of the current receiving time slot minus the preset time window length; Step S222c: Delayed start is used to allow the TCP message data to arrive at the ring queue due to the IP network transmission delay and then be processed.

7. The power line carrier communication protocol data link layer simulation method according to claim 1, characterized in that: The step S300 includes responding to physical layer status changes by registering a frame control header callback function, caching TCP message data using a circular queue, and parsing messages, allocating memory, and processing loads by the physical layer interface simulation module in a designated time slot after timing synchronization, including: Step S310: registering a corresponding callback function according to the frame type of the media access control protocol data unit, wherein the frame control header callback function is a media access control layer processing function that responds to the switching of the physical layer state machine. The frame types include beacon frames, soft confirmation frames, and coordination frames. Step S320: Receive TCP messages through an independent listening thread and store them in a circular queue, and perform a splicing operation on the fragmented TCP messages, wherein the fragmented TCP messages are defined as data packets carrying a private message header, wherein the header includes a 6-byte media access control address and a payload length identifier; In step S330, the high-priority task process extracts the complete MAC PDU payload from the circular queue in the designated time slot after timing synchronization, allocates dynamic memory to store the payload data, and calls the frame control header callback function to process the data according to the physical layer state switch.

8. The power line carrier communication protocol data link layer simulation method according to claim 7, characterized in that: The step S330 of extracting the complete MAC PDU payload from the ring queue and allocating dynamic memory to store the payload data includes: Step S331: When the high-priority task process arrives at the designated receiving time slot after timing synchronization, the TCP message segment carrying the private message header is extracted from the head of the ring queue, and the data integrity is verified according to the payload length identifier in the private message header. If fragmented messages exist, a memory reassembly operation is performed according to a preset splicing condition; Step S332: When a complete MAC PDU payload is identified, the RTOS memory pool management interface is called to allocate a dynamic memory block, the size of which is determined by the MAC PDU payload length, and the payload data cached in the circular queue is copied to the dynamic memory block. Step S333, triggering the frame control header callback function according to the physical layer state machine switching event, passing the dynamic memory block pointer and the associated time slot information to the data link layer task process, and the data link layer performing protocol parsing and memory release operations.

9. The method for simulating the data link layer of the power line carrier communication protocol according to any one of claims 1 to 8, characterized in that: It also includes dynamic networking routing control mechanisms: Constructing a proxy communication module, the proxy communication module establishing a TCP connection with all network nodes, presetting a routing table in the proxy communication module, the routing table storing the logical connection relationship of the network nodes; When the proxy communication module receives a TCP message from a source node, it performs the following operations: Parsing the source media access control address, the target media access control address and the frame type carried in the TCP message; Querying the routing table and determining a forwarding path corresponding to the target media access control address according to the logical connection relationship; If the target media access control address is associated with a child node in a multi-layer relay topology, cross-layer direct communication is prohibited, and the TCP message is only forwarded to the next hop node specified by the routing table.

10. An electric power device, characterized in that: include: at least one processor; And a memory connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the power line carrier communication protocol data link layer simulation method as described in any one of claims 1-9.

Citation Information

Patent Citations

  • Test method for evaluating HPLC (High Performance Liquid Chromatography) deepening function

    CN113746501A

  • Dynamic synchronization method and system for communication data of combat simulation platform

    CN119922082A

  • Portable power line carrier communication environment simulator

    CN202872800U

Cited By

  • Collection terminal for communication quality monitoring

    CN121098746A

  • Method for realizing accurate synchronization of time sequence in simulator based on shared memory

    CN121542072A

  • A method for timing accurate synchronization in a simulator based on shared memory

    CN121542072B

  • Parallel redundancy Ethernet receiving and processing method based on annular sliding window algorithm and related equipment

    CN121644016A

  • Data transmission method, electronic device, storage medium and computer program product

    CN122069259A