Method and apparatus for controlling photoelectric detection system, computing device, and storage medium
By introducing a message distribution center and asynchronous communication session instance into the photoelectric detection system, the device messages are parsed and distributed, solving the data transmission efficiency problem when multiple detection systems are networked together, and realizing distributed control and efficient information transmission.
Patent Information
- Application Number
- CN202211351693.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-31
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2042-10-31
AI Technical Summary
When multiple photoelectric detection systems need to be networked together or a single detection system has multiple control nodes, the traditional point-to-point information transmission method results in low data transmission efficiency and complex and redundant processing logic.
The system employs a message distribution center processing class instance and an asynchronous communication session class instance. The message receiving thread parses the device messages and encapsulates them into target messages. After being aggregated in the message distribution center, the messages are distributed to the message sending threads of the corresponding devices according to the message type, thereby achieving decoupling and distributed control between devices.
It reduces the coupling between devices, improves data transmission efficiency, and supports distributed control of photoelectric detection systems.
Smart Images

Figure CN115695515B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of photoelectric detection system technology, and in particular to a control method, device, computing equipment, and storage medium for a photoelectric detection system. Background Technology
[0002] A photoelectric detection system typically consists of photoelectric sensors and related processing and control components, including infrared / visible light detectors, laser rangefinders, servo turntables, image processing units, communication control units, and display control units. The display control unit is primarily responsible for equipment status monitoring, displaying infrared / visible light images, and providing a human-machine interface for equipment control.
[0003] Currently, the display control software in the display control system is mainly based on the TCP / IP protocol for point-to-point information transmission. That is, the display control software establishes communication connections with each device according to the pre-planned IP address and port, and opens up independent threads for receiving and sending data packets between the display control software and the device.
[0004] However, while this control method can meet the application requirements of a single photoelectric detection system, it becomes complex and redundant when distributed control is needed—that is, when multiple detection systems need to be networked together or a single detection system has multiple control nodes (e.g., multiple control seats). This affects data transmission efficiency. Therefore, a new control method for photoelectric detection systems is urgently needed. Summary of the Invention
[0005] To address the issue that traditional control methods can negatively impact data transmission efficiency when multiple detection systems need to be networked together or when a single detection system has multiple control nodes, this invention provides a control method, apparatus, computing device, and storage medium for a photoelectric detection system.
[0006] In a first aspect, embodiments of the present invention provide a control method for a photoelectric detection system, applied to display and control software. The photoelectric detection system includes multiple devices, including:
[0007] Create a message distribution center processing class instance, and create asynchronous communication session class instances for each device based on the communication protocol of each device; each asynchronous communication session class instance is configured with a message receiving thread and a message sending thread corresponding to the device;
[0008] Register the message types subscribed to by each device and the instance of the asynchronous communication session class in the message distribution center;
[0009] For each of the message receiving threads, when the current message receiving thread receives a first message sent by a corresponding device, the first message is parsed and encapsulated into a target message, and the target message is sent to the message distribution center;
[0010] The message distribution center distributes the target message to a message sending thread corresponding to a device subscribing to the message type according to the message type of the target message;
[0011] For each of the message sending threads, when the current message sending thread receives the target message, the target message is converted into a second message according to the communication protocol of the current device, and the second message is sent to the current device.
[0012] Preferably, before the message distribution center processing class instance is created, the method further comprises:
[0013] A communication interface class and a communication interface subclass are designed;
[0014] A receiving protocol interface class and a sending protocol interface class are designed;
[0015] A message distribution interface class, a communication session interface class, and an asynchronous communication session interface class are designed;
[0016] A message distribution center processing class is designed.
[0017] Preferably, the message distribution center processing class instance is created by registering, based on the asynchronous communication session interface class and the message distribution center processing class, a first callback function for each device to send a message to the message distribution center and a second callback function for the message distribution center to send a message to each device.
[0018] Preferably, the asynchronous communication session class instance of each device is created based on the communication protocol of each device, and the method comprises:
[0019] For each asynchronous communication session class instance corresponding to each device, the following steps are performed:
[0020] Based on the communication interface subclass, network parameters of the current asynchronous communication session class instance are set; the network parameters include an IP address and a port of the current device;
[0021] Based on the receiving protocol interface class and the communication protocol of the current device, a message data receiving and parsing protocol of the current device is associated to register a receiving callback function of the current device;
[0022] Based on the sending protocol interface class and the communication protocol of the current device, a message data sending and parsing protocol of the current device is associated to register a sending callback function of the current device.
[0023] Preferably, for each message receiving thread, when the current message receiving thread receives a first message sent by a corresponding device, the first message is parsed and encapsulated into a target message, and the target message is sent to the message distribution center, comprising:
[0024] For each message receiving thread, the following is performed:
[0025] When a first message sent by the current device is received, the message data receiving and parsing protocol of the current device is called using the corresponding receiving callback function to parse the first message;
[0026] According to the type of the first message, the parsing result is encapsulated into a target message of the corresponding type;
[0027] The target message is sent to the message distribution center using the first callback function.
[0028] Preferably, the message distribution center distributes the target message to the message sending thread corresponding to the device subscribing to the message type according to the message type of the target message, comprising: when the target message is received, the message distribution center calls the second callback function corresponding to all devices registering the message type according to the message type of the target message, to distribute the target message to the message sending thread of each corresponding device.
[0029] Preferably, for each message sending thread, when the current message sending thread receives the target message, the target message is converted into a second message according to the communication protocol of the current device, and the second message is sent to the current device, comprising:
[0030] For each message receiving thread, the following is performed:
[0031] When the current message receiving thread receives the target message, the message data sending and parsing protocol of the current device is called using the corresponding sending callback function to convert the target message into a second message, and the second message is sent to the current device.
[0032] In a second aspect, an embodiment of the present application further provides a control device of a photoelectric detection system, applied to a display control software, the photoelectric detection system being provided with a plurality of devices, comprising:
[0033] A creating unit is configured to create a message distribution center processing class instance, and create asynchronous communication session class instances of the devices based on communication protocols of the devices; each asynchronous communication session class instance is provided with a message receiving thread and a message sending thread corresponding to the device;
[0034] The registration unit is configured to register, at the message distribution center, message types subscribed by each device and the asynchronous communication session class instance.
[0035] The receiving unit is configured to, for each message receiving thread, when the current message receiving thread receives a first message sent by a corresponding device, parse and encapsulate the first message into a target message, and send the target message to the message distribution center.
[0036] The distribution unit is configured to, according to the message type of the target message, distribute the target message to a message sending thread corresponding to a device subscribing to the message type by the message distribution center.
[0037] The sending unit is configured to, for each message sending thread, when the current message sending thread receives the target message, convert the target message into a second message according to a communication protocol of a current device, and send the second message to the current device.
[0038] In a third aspect, an embodiment of the present application further provides a computing device, including a memory and a processor, the memory stores a computer program, and the processor executes the computer program to implement the method in any embodiment of the present application.
[0039] In a fourth aspect, an embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program, when executed in a computer, causes the computer to execute the method in any embodiment of the present application.
[0040] The embodiments of the present application provide a control method and device of a photoelectric detection system, a computing device and a storage medium. First, a message distribution center processing class instance is created, and asynchronous communication session class instances of devices are created based on communication protocols of the devices. Then, message types subscribed by the devices and the asynchronous communication session class instances are registered at the message distribution center. Next, a message receiving thread parses and encapsulates a first message sent by a corresponding device into a target message, and sends the target message to the message distribution center. Then, the message distribution center distributes the target message to a message sending thread of a corresponding device according to a message type of the target message. Finally, each message sending thread receiving the target message converts the target message into a second message according to a communication protocol of the corresponding device, and sends the second message to the corresponding device, so as to reduce coupling degrees between devices. When multiple photoelectric detection systems need to be jointly networked or a single detection system has multiple control nodes, distributed control of the photoelectric detection system can be implemented, and data transmission efficiency is improved. BRIEF DESCRIPTION OF DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings described below are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained from these drawings without creative labor.
[0042] Figure 1 is a control method flow chart of a photoelectric detection system provided by an embodiment of the present application;
[0043] Figure 2 is a UML diagram of a photoelectric detection system provided by an embodiment of the present application;
[0044] Figure 3 is another UML diagram of a photoelectric detection system provided by an embodiment of the present application;
[0045] Figure 4 is still another UML diagram of a photoelectric detection system provided by an embodiment of the present application;
[0046] Figure 5 is yet another UML diagram of a photoelectric detection system provided by an embodiment of the present application;
[0047] Figure 6 is a hardware architecture diagram of an electronic device provided by an embodiment of the present application;
[0048] Figure 7 is a control device structure diagram of a photoelectric detection system provided by an embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0050] As described above, the control method of the existing photoelectric detection system is mainly based on point-to-point information transmission of TCP / IP protocol, that is, the display and control software establishes a communication connection with each device according to a pre-planned IP address and port, and separately opens an independent thread for receiving and sending data messages between the display and control software and the device. However, this control method can meet the application requirements of a single photoelectric detection system, but when there is a distributed control requirement, that is, multiple detection systems need to be networked together or a single detection system has multiple control nodes (for example, there are multiple control seats), the original point-to-point information transmission processing logic will become complex and redundant, affecting the data transmission efficiency.
[0051] To solve the above technical problems, the inventors can consider creating a message distribution center, parsing the first message sent by each device into a target message through a message receiving thread, and then gathering it in the message distribution center. The message distribution center distributes the target message to the message sending thread of the corresponding device according to the message type of the target message, and then the message sending thread converts the target message into a second message that can be received by the corresponding device, thereby reducing the coupling degree between devices, realizing the distributed control of the photoelectric detection system, and improving the data transmission efficiency.
[0052] The specific implementation of the above concept is described below.
[0053] Please refer to Figure 1 The embodiment of the present application provides a control method of a photoelectric detection system, applied to display and control software, the photoelectric detection system being provided with a plurality of devices, and the method comprises the following steps:
[0054] Step 100: creating a message distribution center processing class instance, and creating an asynchronous communication session class instance of each device based on the communication protocol of each device; each asynchronous communication session class instance is provided with a message receiving thread and a message sending thread corresponding to the device;
[0055] Step 102: registering the message type and the asynchronous communication session class instance subscribed by each device in the message distribution center;
[0056] Step 104: for each message receiving thread, when the current message receiving thread receives a first message sent by the corresponding device, the first message is parsed and encapsulated into a target message, and the target message is sent to the message distribution center;
[0057] Step 106: the message distribution center distributes the target message to the message sending thread corresponding to the device subscribing to the message type according to the message type of the target message;
[0058] Step 108: for each message sending thread, when the current message sending thread receives the target message, the target message is converted into a second message according to the communication protocol of the current device, and the second message is sent to the current device.
[0059] In the embodiment of the application, first, a message distribution center processing class instance is created, and asynchronous communication session class instances of each device are created based on the communication protocol of each device; then, message types subscribed by each device and the asynchronous communication session class instances are registered in the message distribution center; then, the message receiving thread analyzes and encapsulates the first message sent by the corresponding device into a target message, and sends the target message to the message distribution center; then, the message distribution center distributes the target message to the message sending thread of the corresponding device according to the message type of the target message; finally, each message sending thread receiving the target message converts the target message into a second message according to the communication protocol of the corresponding device, and sends the second message to the corresponding device, so as to reduce the coupling degree between devices, and when multiple photoelectric detection systems need to be jointly networked or a single detection system has multiple control nodes, distributed control of the photoelectric detection system can be realized, and data transmission efficiency is improved.
[0060] The following describes Figure 1 the execution mode of each step shown.
[0061] For step 100:
[0062] In some embodiments, before the message distribution center processing class instance is created, the following steps S1-S4 are further included:
[0063] Step S1, design a communication interface class and a communication interface subclass;
[0064] Step S2, design a receiving protocol interface class and a sending protocol interface class;
[0065] Step S3, design a message distribution interface class, a communication session interface class and an asynchronous communication session interface class;
[0066] Step S4, design a message distribution center processing class.
[0067] In step S1, the communication interface class and the communication interface subclass are designed, including the design of a communication io interface class class i_io and the design of a typical UDP communication interface subclass class io_udp.
[0068] The main interfaces are described as follows:
[0069] 1. The class i_io of communication io interface is a pure virtual function, including the operation interfaces for providing the initialization (init), opening (open), closing (close), judging the connection state (is_connected), synchronous reading and writing (read, write), setting the asynchronous reading callback (do_read, set_on_read_callback), setting the asynchronous writing callback (do_write, set_on_write_callback) and the like of the communication io port.
[0070] 2. The class io_udp of UDP communication interface subclass inherits from i_io, used for implementing the UDP communication, and adding the asynchronous reading callback function (on_read) and the asynchronous writing callback function (on_write) and the like.
[0071] As shown in the UML class diagram of the communication interface class and the communication interface subclass, the specific interface description is as follows: Figure 1
[0072] 1. The class i_io of communication io interface
[0073] / / initialize the communication, info is the communication IP port or serial number, which is processed in the UDP communication interface subclass
[0074] virtual bool init(std::string info)=0;
[0075] virtual bool open()=0; / / open
[0076] virtual bool close()=0; / / close
[0077] virtual bool is_connected()=0; / / connection state
[0078] / / synchronous reading and writing communication
[0079] virtual int read(unsigned char*buffer,int size)=0;
[0080] virtual int write(unsigned char*buffer,int size)=0;
[0081] / / asynchronous reading communication, the buffer is processed through the callback function
[0082] virtual bool do_read(unsigned char*buffer, int size) = 0;
[0083] virtual bool set_on_read_callback(function_on_read fn) = 0;
[0084] / / Asynchronous write communication, through the callback function to achieve the processing of the buffer buffer
[0085] virtual bool do_write(unsigned char*buffer, int size) = 0;
[0086] virtual bool set_on_write_callback(function_on_write fn) = 0;
[0087] 2. UDP communication interface subclass class io_udp
[0088] / / Inherited from i_io, implement UDP communication
[0089] class io_udp: public i_io
[0090] / / Asynchronous read callback function, used to call fn_on_read_callback
[0091] virtual void on_read(const boost::system::error_code&err, size_t size);
[0092] / / Asynchronous write callback function, used to call fn_on_write_callback
[0093] virtual void on_write(const boost::system::error_code&err, size_t size);
[0094] / / Set the value of the corresponding option through the option Key
[0095] void set_option(enum_opt_name opt_name);
[0096] / / Callback function variable, used to store callback functions from session
[0097] function_on_read fn_on_read_callback;
[0098] function_on_write fn_on_write_callback;
[0099] In step S2, the design of the receiving protocol interface class and the sending protocol interface class, including the design of the receiving protocol interface base class class i_protocol_in and the sending protocol interface base class class i_protocol_out.
[0100] The main interface is described as follows:
[0101] The receiving protocol interface base class class i_protocol_in is mainly used for parsing the first message from the data receiving buffer of the device and encapsulating the corresponding target message into the receiving message queue of the device.
[0102] The sending protocol interface base class class i_protocol_out is mainly used for putting the target message from the outside (message distribution center) into the sending message queue of the device and converting it into the second message of the corresponding device and putting it into the data sending buffer.
[0103] As shown in FIG. 1, it is a UML class diagram of the receiving protocol interface class and the sending protocol interface class, and the specific interface is described as follows: Figure 2
[0104] 1. The receiving protocol interface base class class i_protocol_in
[0105] / / Parse the first message from the data receiving buffer of the device and encapsulate the corresponding message into the receiving message queue of the device.
[0106] virtual int translate_from_bin_buffer(const unsigned char*buffer, int&size, std::string str_session="") = 0;
[0107] virtual bool has_next_msg() = 0; / / Judge whether the receiving message queue of the device is empty
[0108] virtual shared_message get_msg() = 0; / / Get the receiving message of the device
[0109] virtual shared_message pop_msg() = 0; / / dequeue a message from the device's receive queue
[0110] 2. Send protocol interface base class class i_protocol_out
[0111] / / put the message pointed to by input parameter ptr_msg into the device's send queue after filtering
[0112] virtual int translate_from_msg(shared_message ptr_msg, std::string str_session = "") = 0;
[0113] / / dequeue a message from the device's send queue and translate it into a corresponding second message and put it into the device's data send buffer
[0114] virtual int translate_to_bin_buffer(unsigned char* buffer, int size, std::string str_session = "") = 0;
[0115] virtual bool has_next_bin_tanslation() = 0; / / determine if the device's send queue is empty
[0116] In step S3, the message distribution interface class, the communication session session interface class and the asynchronous communication session session interface class are designed, mainly including the design of the message distribution interface class class i_message_pin, the design of the communication session session interface class class i_session, and the design of the typical asynchronous communication session session interface class class async_session.
[0117] The main interface is described as follows:
[0118] 1. The message distribution interface class class i_message_pin mainly provides message processing interface (process_message) and registration message processing callback function (set_notify_function) and other operation interfaces.
[0119] 2. Communication session interface base class i_session inherits i_message_pin interface, mainly used to send and receive target information in the way of subscription push, including operation interfaces such as opening (start), closing (stop), associating communication IO (set_io), associating device message data sending and parsing protocol (set_protocol_out), associating device message data receiving and parsing protocol (set_protocol_in), setting subscription message type (set_msg_type) and the like.
[0120] 3. Asynchronous communication session interface class async_session inherits i_session interface, mainly used for specific implementation of asynchronous sending and receiving of messages, and increases operation interfaces such as registering receiving callback function and sending callback function (fn_on_read_process, fn_on_write_process) in communication IO, first callback function (message_notify_function) for sending messages to message distribution center.
[0121] As shown in Figure 3 , it is a UML class diagram of message distribution interface class, communication session interface class and asynchronous communication session interface class, and specific interface descriptions are as follows:
[0122] 1. Message distribution interface class i_message_pin
[0123] / / Receive target messages subscribed from message distribution center and process
[0124] virtual void process_message(shared_message ptr_msg)=0;
[0125] / / Register callback function for pushing messages to message distribution center
[0126] virtual void set_notify_function(message_notify_function fn)=0;
[0127] / / Get class name
[0128] virtual std::string get_class_name()=0;
[0129] 2. Communication session interface base class i_session
[0130] / / Inherit i_message_pin interface, mainly used to design the way of subscribing push to send and receive target information
[0131] class i_session:public i_message_pin
[0132] virtual bool start()=0; / / Open session
[0133] virtual bool stop()=0; / / Close session
[0134] / / Set io and receive and send protocol when initializing
[0135] virtual bool set_io(i_io*ptr_io)=0; / / Set communication IO
[0136] virtual bool set_protocol_out(i_protocol_out*ptr_out)=0; / / Set device message data sending and parsing protocol
[0137] virtual bool set_protocol_in(i_protocol_in*ptr_in)=0; / / Set device message data receiving and parsing protocol
[0138] / / Timer, mainly for disconnecting and reconnecting
[0139] virtual void monitor_state()=0;
[0140] / / Set the message type of the target message that needs to be received, multiple messages can be received
[0141] inline void set_msg_type(std::vector<message::E_MSGType>&e_msg_type)
[0142] 3. Asynchronous communication session session interface class class async_session
[0143] / / Inherit i_session interface, mainly used for specific implementation of asynchronous message sending and receiving
[0144] class async_session:public i_session
[0145] / / Callback function registered in io
[0146] bool fn_on_read_process(const boost::system::error_code&err, size_tsize); / / Receive callback function
[0147] bool fn_on_write_process(const boost::system::error_code&err, size_tsize); / / Send callback function
[0148] void do_monitor_state(int time); / /
[0149] void start_read(); / / Start the loop for receiving the first message.
[0150] void do_read(); / / Performs the operation of receiving the first message.
[0151] void start_writer(); / / Starts the loop for sending the second message.
[0152] void do_writer(); / / Performs the operation of sending the second message.
[0153] std::string class_name_; / / class name
[0154] / / The sending interval is determined by the constructor parameter when the session is created.
[0155] int write_interval_;
[0156] / / Save pointers to the I / O and protocols used in this session
[0157] i_io*io_;
[0158] i_protocol_in*protocol_in_;
[0159] i_protocol_out*protocol_out_;
[0160] / / Read / write buffer
[0161] boost::array<unsigned char,max_buffer_size> in_buffer_;
[0162] int in_size_;
[0163] boost::array<unsigned char,max_buffer_size> out_buffer_;
[0164] int out_size_;
[0165] / / first callback function to send a message to the message dispatch center
[0166] message_notify_function msg_notify_fn_;
[0167] bool running_;
[0168] / / timer
[0169] boost::shared_ptr<boost::asio::steady_timer> monitor_timer_;
[0170] boost::shared_ptr<boost::asio::steady_timer> write_timer_;
[0171] In step S4, the message dispatch center processing class is designed, specifically, the class message_dispatch_center is designed, and the operation interfaces of target message registration (register_message_pin), target message uninstallation (unregister_message_pin), target message processing loop (message_dispatch_process), target message processing (process_current_message), target message distribution (notify_message_to_pins), etc. are provided.
[0172] As shown in Figure 4 , it is a UML class diagram of the message dispatch center processing class, and the specific interface description is as follows:
[0173] / / register the class instance of the message type msgType of the target message
[0174] bool register_message_pin(int type, param_pin pin);
[0175] / / unregister the class instance of the message type msgType of the target message
[0176] bool unregister_message_pin(int type, param_pin pin);
[0177] / / Target message enqueue
[0178] bool post_message(shared_message ptr_msg);
[0179] / / Target message processing loop
[0180] void message_dispatch_process();
[0181] / / Extract target message
[0182] shared_message pop_current_message();
[0183] / / Target message processing
[0184] void process_current_message(shared_message& ptr_msg);
[0185] / / Send target message to all instances of a class registered for a certain msg_type
[0186] void notify_message_to_pins(shared_message& ptr_msg);
[0187] message_list messages_; / / Target message list
[0188] boost::mutex messages_mutex_; / / Target message mutex
[0189] boost::interprocess::interprocess_semaphore messages_semaphore_; / / Target message semaphore
[0190] boost::mutex map_mutex_; / / Target message map mutex
[0191] pin_list_mutex_map pin_list_mutex_map_; / / Semaphore map, key is msgType
[0192] pin_list_map pin_list_map_; / / The key is msgType, and the value is the queue of class instances registered for that type.
[0193] boost::thread_groupprocess_threads_; / / thread group
[0194] bool running_; / / Running status flag
[0195] In some implementations, creating a message distribution center processing class instance includes: registering a first callback function for each device to send a message to the message distribution center and a second callback function for the message distribution center to send a message to each device, based on the asynchronous communication session interface class and the message distribution center processing class.
[0196] In the embodiments of the invention, by registering a first callback function for each device to send a message to the message distribution center and a second callback function for the message distribution center to send a message to each device, it is possible to realize the distribution of the target message by parsing the first message of each device into the target message and sending the target message to the message distribution center, and by having the message distribution center send the target message to each device that subscribes to the message type of the target message.
[0197] In some implementations, asynchronous communication session class instances for each device are created based on their respective communication protocols, including:
[0198] For each asynchronous communication session class instance corresponding to a device, execute:
[0199] Based on the communication interface subclass, set the network parameters of the current asynchronous communication session instance; the network parameters include the IP address and port of the current device.
[0200] Based on the receiving protocol interface class and the current device's communication protocol, associate the current device's message data receiving and parsing protocol to register the current device's receiving callback function;
[0201] Based on the sending protocol interface class and the current device's communication protocol, associate the current device's message data sending and parsing protocol to register the current device's sending callback function.
[0202] In the embodiment of the present application, the device using UDP for asynchronous transmission creates an instance of the async_session class and configures the parameters of the relevant communication interface class io_udp (IP address, port settings, registers the receiving callback function async_session::fn_on_read_process() of the first message received by the IO receiving device, registers the sending callback function async_session::fn_on_write_process() of the second message sent to the IO sending device, and associates the i_protocol_in and i_protocol_out classes of the corresponding device to call the message data receiving parsing protocol and the message data sending parsing protocol). By calling the receiving callback function of the current device, the first message can be parsed using the message data receiving parsing protocol; by calling the sending callback function of the current device, the target message can be converted using the message data sending parsing protocol to convert the second message that the current device can receive, thereby completing the first message transmission of each device to the message distribution center and the second message sending of the message distribution center to each device.
[0203] For step 102:
[0204] In the embodiment of the present application, the first callback function message_dispatch_center::post_message() of the communication session class async_session of the subscribed device sending a message to the message distribution center is registered according to the message type msgType, and the message processing thread of the message distribution center is started, so that the message distribution center distributes the target message to the device subscribing to the message type according to the message type of the target message.
[0205] For step 104:
[0206] In some embodiments, for each message receiving thread, when the current message receiving thread receives the first message sent by the corresponding device, the first message is parsed and encapsulated as a target message, and the target message is sent to the message distribution center, including:
[0207] For each message receiving thread, the following is performed:
[0208] When the first message sent by the current device is received, the message data receiving parsing protocol of the current device is called by using the corresponding receiving callback function to parse the first message;
[0209] According to the type of the first message, the parsing result is encapsulated as a target message of the corresponding type;
[0210] The target message is sent to the message distribution center by using the first callback function.
[0211] In the embodiment, in the packet receiving thread of the async_session communication session, when the io_udp receives the first packet of the device, the packet data receiving parsing protocol protocol_comm_in::translate_from_bin_buffer() is first called in the associated receiving callback function async_session::fn_on_read_process() to parse the first packet, and the target message of the corresponding type is encapsulated and then put into the receiving message queue of the device, and then the first callback function message_dispatch_center::post_message() is used to forward to the message dispatch center queue of the message dispatch center.
[0212] For step 106:
[0213] In some embodiments, the message dispatch center distributes the target message to the packet sending thread corresponding to the device subscribing to the message type according to the message type of the target message, including: when the target message is received, the message dispatch center calls the second callback function of all devices registering the message type according to the message type of the target message, to distribute the target message to the packet sending thread of each corresponding device.
[0214] In the embodiment, in the message_dispatch_center message processing thread, it is judged whether the message dispatch center queue is empty, if empty, continue to wait, if not empty, extract the target message, and according to the message type, distribute the target message to the sending message queue of the corresponding device in the communication session class async_session::process_message() of all devices registering the message type.
[0215] For step 108:
[0216] In some embodiments, for each packet sending thread, when the current packet sending thread receives the target message, the target message is converted into a second packet according to the communication protocol of the current device, and the second packet is sent to the current device, including:
[0217] For each packet receiving thread, the following is performed:
[0218] When the current packet receiving thread receives the target message, the packet data sending parsing protocol of the current device is called by using the corresponding sending callback function to convert the target message into a second packet, and the second packet is sent to the current device.
[0219] In the embodiment, in the packet sending thread of the async_session communication session, it is judged whether the sending message queue of the device is empty, if yes, the waiting continues, if not, the target message is extracted, and the target message is first converted into the second packet of the corresponding device by calling the packet data sending analysis protocol protocol_comm_out::translate_to_bin_buffer(), and then the second packet in the buffer is sent to the device end through the io_udp, so as to complete the distribution of the target message.
[0220] In addition, when there are multiple devices and multiple control nodes, only the analysis and conversion interfaces of the first packet of the corresponding i_protocol_in and i_protocol_out device and the target message need to be modified, and the corresponding message type and communication session instance are registered to the message distribution center, so that the device distributed display and control method of the photoelectric detection system can be realized. When the device or the control node needs to be increased or reduced, the same principle applies.
[0221] As shown in Figure 6 , Figure 7 , the embodiment of the present application provides a control device of a photoelectric detection system. The device embodiment can be realized by software, or by hardware or a combination of software and hardware. From the hardware layer, as shown in Figure 6 , a hardware architecture diagram of a computing device where the control device of the photoelectric detection system provided by the embodiment of the present application is located, in addition to the processor, the memory, the network interface, and the non-volatile memory shown in Figure 6 , the computing device where the device in the embodiment is usually also provided with other hardware, such as a forwarding chip responsible for processing packets, etc. Taking the software implementation as an example, as shown in Figure 7 , as a logically meaningful device, it is formed by the CPU of the computing device where it is located reading the corresponding computer program in the non-volatile memory into the memory and running.
[0222] As shown in Figure 7 , the control device of the photoelectric detection system provided by the embodiment is applied to a display and control software, and the photoelectric detection system is provided with multiple devices, which includes:
[0223] The creating unit 701 is configured to create a message distribution center processing class instance, and create an asynchronous communication session class instance of each device based on the communication protocol of each device; each asynchronous communication session class instance is provided with a packet receiving thread and a packet sending thread corresponding to the device;
[0224] The registering unit 702 is configured to register the message type and the asynchronous communication session class instance subscribed by each device in the message distribution center;
[0225] The receiving unit 703 is configured to, for each message receiving thread, when the current message receiving thread receives a first message sent by a corresponding device, parse and encapsulate the first message into a target message, and send the target message to the message distribution center;
[0226] The distribution unit 704 is configured to, according to a message type of the target message, distribute the target message to a message sending thread corresponding to a device subscribing to the message type by the message distribution center;
[0227] The sending unit 705 is configured to, for each message sending thread, when the current message sending thread receives the target message, convert the target message into a second message according to a communication protocol of the current device, and send the second message to the current device.
[0228] In an embodiment of the present application, the creating unit 701, before executing the creating of the message distribution center processing class instance, is further configured to execute:
[0229] designing a communication interface class and a communication interface subclass;
[0230] designing a receiving protocol interface class and a sending protocol interface class;
[0231] designing a message distribution interface class, a communication session interface class and an asynchronous communication session interface class;
[0232] designing a message distribution center processing class.
[0233] In an embodiment of the present application, the creating unit 701, when executing the creating of the message distribution center processing class instance, is configured to execute:
[0234] based on the asynchronous communication session interface class and the message distribution center processing class, registering a first callback function of each device sending a message to the message distribution center and a second callback function of the message distribution center sending a message to each device.
[0235] In an embodiment of the present application, the creating unit 701, when executing the creating of the asynchronous communication session class instance based on the communication protocol of each device, is configured to execute:
[0236] for each asynchronous communication session class instance corresponding to each device, executing:
[0237] based on the communication interface subclass, setting network parameters of the current asynchronous communication session class instance; the network parameters include an IP address and a port of the current device;
[0238] based on the receiving protocol interface class and the communication protocol of the current device, associating a message data receiving and parsing protocol of the current device to register a receiving callback function of the current device;
[0239] Based on the sending protocol interface class and the communication protocol of the current device, a message data sending analysis protocol of the current device is associated to register a sending callback function of the current device.
[0240] In an embodiment of the present application, the receiving unit 703 is configured to perform the following steps:
[0241] For each message receiving thread, the following steps are performed:
[0242] When a first message sent by the current device is received, a message data receiving analysis protocol of the current device is invoked by using a corresponding receiving callback function to analyze the first message;
[0243] According to the type of the first message, the analysis result is encapsulated into a target message of a corresponding type;
[0244] The target message is sent to the message distribution center by using the first callback function.
[0245] In an embodiment of the present application, the distribution unit 704 is configured to perform the following steps:
[0246] When the target message is received, the message distribution center invokes all second callback functions corresponding to devices registered for the message type of the target message to distribute the target message to message sending threads of the corresponding devices.
[0247] In an embodiment of the present application, the sending unit 705 is configured to perform the following steps:
[0248] For each message receiving thread, the following steps are performed:
[0249] When the current message receiving thread receives the target message, a message data sending analysis protocol of the current device is invoked by using a corresponding sending callback function to convert the target message into a second message, and the second message is sent to the current device.
[0250] It can be understood that the structure of the embodiment of the present application does not constitute a specific limitation on the control device of the photoelectric detection system. In other embodiments of the present application, the control device of the photoelectric detection system can include more or fewer components than the illustration, or combine certain components, or split certain components, or different component arrangements. The illustrated components can be implemented in hardware, software, or a combination of software and hardware.
[0251] The information interaction, execution process, and other contents among the modules in the above device are based on the same concept as the method embodiments of the present application, and the specific contents can be referred to the description in the method embodiments of the present application, which will not be described here.
[0252] The embodiment of the present application also provides a computing device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to realize the control method of the photoelectric detection system in any of the embodiments of the present application.
[0253] The embodiment of the present application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to execute the control method of the photoelectric detection system in any of the embodiments of the present application.
[0254] Specifically, a system or device provided with a storage medium storing software program codes realizing the functions of any of the above embodiments, and a computer (or CPU or MPU) of the system or device reads out and executes the program codes stored in the storage medium.
[0255] In this case, the program codes read from the storage medium can realize the functions of any of the above embodiments, and thus the program codes and the storage medium storing the program codes constitute a part of the present application.
[0256] The storage medium for providing the program codes includes a floppy disk, a hard disk, a magneto-optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a nonvolatile memory card, and a ROM. Alternatively, the program codes can be downloaded from a server computer via a communication network.
[0257] In addition, it should be clear that not only the program codes read by the computer can be executed, but also part or all of the actual operations can be completed by operating systems and the like operating on the computer based on the instructions of the program codes, so as to realize the functions of any of the above embodiments.
[0258] In addition, it should be understood that the program codes read from the storage medium can be written into the memory provided in the expansion board inserted into the computer or the memory provided in the expansion module connected to the computer, and then part or all of the actual operations can be executed by the CPU and the like installed on the expansion board or the expansion module based on the instructions of the program codes, so as to realize the functions of any of the above embodiments.
[0259] It should be noted that, in the present document, relational terms such as first and second and the like can be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises", "comprising", or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0260] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware, and the foregoing program can be stored in a computer readable storage medium, and the program performs the steps of the above-mentioned method embodiments when executed; and the foregoing storage medium includes various storage media that can store program codes, such as ROM, RAM, magnetic disk or optical disk.
[0261] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A control method for a photoelectric detection system, characterized in that, The photoelectric detection system is applied to display control software and is provided with a plurality of devices, including: creating a message distribution center processing class instance, and creating an asynchronous communication session class instance of each device based on a communication protocol of each device; each asynchronous communication session class instance is provided with a message receiving thread and a message sending thread corresponding to the device; registering a message type subscribed by each device and the asynchronous communication session class instance in the message distribution center; for each message receiving thread, when a first message sent by the corresponding device is received by the current message receiving thread, the first message is parsed and encapsulated into a target message, and the target message is sent to the message distribution center; the message distribution center distributes the target message to a message sending thread corresponding to a device subscribing to the message type according to the message type of the target message; wherein one device receives one or more types of target messages; for each message sending thread, when the target message is received by the current message sending thread, the target message is converted into a second message according to the communication protocol of the current device, and the second message is sent to the current device; before the message distribution center processing class instance is created, further comprising: designing a communication interface class and a communication interface subclass; designing a receiving protocol interface class and a sending protocol interface class; designing a message distribution interface class, a communication session interface class and an asynchronous communication session interface class; designing a message distribution center processing class; the message distribution center processing class at least contains a target message registration operation interface, a target message unloading operation interface, a target message processing loop operation interface, a target message processing operation interface and a target message distribution operation interface; the message distribution center processing class instance includes: based on the asynchronous communication session interface class and the message distribution center processing class, registering a first callback function of each device sending a message to the message distribution center and a second callback function of the message distribution center sending a message to each device; the asynchronous communication session class instance of each device is created based on the communication protocol of each device, including: for each asynchronous communication session class instance corresponding to each device, the following is performed: based on the communication interface subclass, setting network parameters of the current asynchronous communication session class instance; the network parameters include an IP address and a port of the current device; based on the receiving protocol interface class and the communication protocol of the current device, associating a message data receiving and parsing protocol of the current device to register a receiving callback function of the current device; based on the sending protocol interface class and the communication protocol of the current device, associating a message data sending and parsing protocol of the current device to register a sending callback function of the current device.
2. The method of claim 1, wherein, the message receiving thread, when a first message sent by the corresponding device is received by the current message receiving thread, the first message is parsed and encapsulated into a target message, and the target message is sent to the message distribution center, including: for each message receiving thread, the following is performed: When receiving the first message sent by the current device, a message data receiving analysis protocol of the current device is called by using the corresponding receiving callback function to analyze the first message; According to the type of the first message, the analysis result is encapsulated into a target message of a corresponding type; The target message is sent to the message distribution center by using the first callback function.
3. The method of claim 1, wherein, The message distribution center distributes the target message to a message sending thread corresponding to a device subscribing to the message type according to the message type of the target message, including: when receiving the target message, the message distribution center calls a second callback function corresponding to all devices registering the message type to distribute the target message to the message sending thread of each corresponding device.
4. The method of claim 1, wherein, For each message sending thread, when the current message sending thread receives the target message, the target message is converted into a second message according to the communication protocol of the current device, and the second message is sent to the current device, including: For each message receiving thread, the following is performed: When the current message receiving thread receives the target message, a message data sending analysis protocol of the current device is called by using the corresponding sending callback function to convert the target message into a second message, and the second message is sent to the current device.
5. A control device of a photodetection system for implementing the method according to any one of claims 1 to 4, characterized in that, The photoelectric detection system is provided with a plurality of devices, including: A creating unit is configured to create a message distribution center processing class instance and create asynchronous communication session class instances of the devices based on communication protocols of the devices; each asynchronous communication session class instance is provided with a message receiving thread and a message sending thread corresponding to the device; A registering unit is configured to register, in the message distribution center, message types subscribed by the devices and the asynchronous communication session class instances; A receiving unit is configured to, for each message receiving thread, when a first message sent by a corresponding device is received by the current message receiving thread, analyze and encapsulate the first message into a target message, and send the target message to the message distribution center; A distributing unit is configured to distribute, by the message distribution center, the target message to a message sending thread corresponding to a device subscribing to the message type according to the message type of the target message; A sending unit is configured to, for each message sending thread, when the target message is received by the current message sending thread, convert the target message into a second message according to the communication protocol of the current device, and send the second message to the current device.
6. A computing device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the method of any one of claims 1-4 when executing the computer program.
7. A computer readable storage medium, which stores a computer program, and the computer program causes a computer to execute the method of any one of claims 1-4 when the computer program is executed in the computer.