Background technology
Controller area network network (CAN Controller Area Network) be German Bosch company from the beginning of the eighties for solving a kind of serial data communication agreement that control numerous the Hyundai Motor and the exchanges data between the tester are developed.In September, 1991 PHILIP company formulate and song cloth CAN technical specification 2.0A, B version, 2.0A has provided the CAN message format of definition in CAN technical specification release 1.2 once, 20B has defined two kinds of message formats of the expansion of standard; In November, 1993, International Organization for Standardization was formally issued the ISO11898 standard about the CAN bus, used for standardization, the standardization of CAN bus and had paved road.CAN bus communication medium can be twisted-pair feeder, coaxial cable and optical fiber, and communication distance can reach 10km (5kbps) farthest, and flank speed can reach 1M bps (40m); Replace traditional station address coded system with the data block coding coding mode, define 211 or 1129 different data blocks, allow each node receive the data of designated identification sign indicating number respectively by the method for filtering with the identification code of 11 or 29 bits composition.The CAN bus is an open system, but there is not strictness to follow the seven layer reference model of the open system interconnection of International Organization for Standardization (OSI), for the consideration to real-time and factor such as reduce cost, the CAN bus has only adopted the two-layer of most critical wherein, i.e. physical layer and data link layer.
At present, can only wired connection between each node on the CAN network.
Infrared communication generally adopts the near infrared ray in the infrared band, and wavelength is between 0.75um to 25um.After Infrared Data Association (IRDA) sets up, for the infrared product that guarantees different vendor can obtain best communication effect, the infrared communication agreement is limited to the scope of the optical wavelength that the infrared data communication is adopted within the 850nm to 900nm, but because ultrared wavelength is shorter, diffracting power to barrier is poor, so be more suitable for being applied in the occasion that needs short-distance wireless communication, carry out point-to-point straight line transfer of data.That infrared communication has is with low cost, easy to connect, be simple and easy to and the characteristics of compact conformation, therefore in small-sized mobile device, obtained to use widely.1993, initiate to have set up (the Infrared Data Association of Infrared Data Association by companies more than 20 such as HP, COMPAQ, INTEL, be called for short IRDA), on June 28th, 1993, the kickoff meeting of Infrared Data Association has been attended in representative from 120 multidigits of 50 many enterprises, and just sets up unified infrared communication typical problem and be in agreement.After 1 year, the issue of the infrared data communication standard of first IRDA, i.e. IRDA1.0.
IRDA1.0 abbreviates SIR (Serial InfraRed) as, and it is based on a kind of asynchronous, the semiduplex infrared communication mode that HP-SIR develops.SIR is a support with the asynchronous communication transceiver (UART) of system, by to the compression of the waveform of serial data pulse with the waveform of the light signal electric pulse that received is expanded this coding and decoding process (3/16 EnDec) realize the infrared data transmission.Because be subjected to the restriction of UART communication speed, the highest communication speed of SIR has only 115.2Kbps, the flank speed of everybody the computer serial port known just.1996, IRDA issued the IRDA1.1 standard, and promptly Fast InfraRed abbreviates FIR as.Compare with SIR, because FIR no longer relies on UART, its highest communication speed has had qualitative leap, can reach the level of 4Mbps.FIR has adopted brand-new 4PPM modulation (Pulse Position Modulation), promptly distinguish the data message that is transmitted by the phase place of analyzing pulse, its Principle of Communication and SIR are distinct, but because the speed of FIR below 115.2Kbps still adopts the sort of coding and decoding process of SIR, so it still can carry out communication with the low-speed device of supporting SIR, only when communication the other side also supports FIR, just communication speed is risen to higher level.
Summary of the invention
Technical problem to be solved by this invention is: a kind of infrared communication gateway based on the CAN network is provided, it can will be not suitable for the CAN node or the CAN network of wired connection, couple together by the infrared communication interface, and the wireless data transmission between realization CAN node and CAN backbone network or the CAN network.
The present invention solves the problems of the technologies described above the technical scheme that is adopted:
Based on the infrared communication gateway of CAN network, it comprises: CAN field network interface, infrared communication interface, single-chip microcomputer; Single-chip microcomputer is arranged between CAN field network interface and the infrared communication interface;
Described CAN field network interface is for receiving, send the network interface of CAN protocol data;
Described infrared communication interface is for receiving, send the communication interface of infrared communication protocol data;
Described single-chip microcomputer is the single-chip microcomputer that converts the CAN protocol data to the infrared communication protocol data or the infrared communication protocol data transaction is become the CAN protocol data.
This gateway working method is: the CAN field network interface of gateway is realized the transmission and the verification of the CAN packet of CAN node or other CAN network, and give single-chip microcomputer with packet, single-chip microcomputer carries out the infrared communication protocol encapsulation with the CAN protocol analysis and to data, sends out by the infrared communication interface then.Perhaps, accept the infrared data based on the CAN agreement of Radio infrared CAN node or the transmission of other CAN network by the infrared communication interface of gateway, by single-chip microcomputer it is carried out verification and unpack after be converted to standard CAN field network data, send on CAN node or the CAN network by CAN field network interface again.
The present invention has following advantage: it can couple together by the infrared communication interface being not suitable for the CAN node or the CAN network of wired connection, and realizes the transfer of data between this CAN node and CAN backbone network or the CAN network.Can be used for connecting onboard wireless CAN network node, such node can be transmitted and be transformed into the CAN backbone network based on the measuring and control data of CAN agreement by infrared interface based on the infrared communication interface.Its anti-electromagnetic interference capability is strong; The reliability height; With low cost; High directivity; Easy to connect; Be simple and easy to use; Can adapt to the requirement of different control module and vehicle as required.
Embodiment
Embodiment of the invention gateway as shown in Figure 1, it comprises: CAN field network interface, infrared communication interface, single-chip microcomputer (protocol converter); Single-chip microcomputer is arranged between CAN field network interface and the infrared communication interface, and single-chip microcomputer is an embedded scm.
Described CAN field network interface is for receiving, send the network interface of CAN protocol data;
Described infrared communication interface is for receiving, send the communication interface of infrared communication protocol data;
Described single-chip microcomputer is the single-chip microcomputer that converts the CAN protocol data to the infrared communication protocol data or the infrared communication protocol data transaction is become the CAN protocol data.
Described CAN field network interface comprises the interface circuit that network packet receives, sends as shown in Figure 2; The data that receive or transmit are carried out the buffer circuit of anti-interference process; Receive, transmit the field network protocol encoding and decoding interface circuit of CAN2.0A/B normal data bag.
Described Infrared Wireless Communication interface comprises the physical layer interface circuit of reception, transmission infrared signal as shown in Figure 3; The coding-decoding circuit of IFRD1.1 protocol data; The clock of infrared interface and control circuit.Described embedded scm comprises: data and program storage, peripheral interface circuit, embedded OS, protocol conversion and encoding and decoding software systems.
Embodiment of the invention user mode as shown in Figure 4, it is CAN node and the CAN node bus network connection device by infrared communication.
Certainly, also can couple together between the CAN bus network by the mode of embodiment of the invention gateway with infrared communication.
As shown in Figure 5, on-the-spot subnet interface circuit U 11 adopts the 82C250 chip, and on-the-spot subnet interface buffer circuit U8, U9 adopt 6N 137 chips, and CAN protocol chip U5 adopts the SJA1000 chip.Workflow is as follows: gateway can transmit data at any one time by arbitrary node on CAN network interface and the CAN bus, do not conflict for guaranteeing that data transmit between this many host nodes, the CAN controller carries out bus access according to priority, any moment has only the unique node (this moment, this node was a host node) that obtains bus control right could send data on bus, guarantees the flexibility of communication; The short frame of The data sends, and data length mostly is 8 bytes most, can satisfy the requirement of control command, data in the common automobile, and this short frame transmits the real-time that has guaranteed communication; The CAN agreement adopts the CRC check and the strong error processing capacity is provided, and has guaranteed reliability of data communication.The maximum characteristics of CAN agreement are to have abolished traditional station address coding, and the communicating data block in generation is encoded, and the identification code of data block can be made up of 11 or 29 bits, so definable 211 or 229 different data blocks.
As shown in Figure 6, infrared receiving/transmission interface U14 adopts TM4100/TR2, and infrared protocol coding-decoding circuit U9 adopts MCP2120.Workflow is as follows: by the infrared communication data that TM4100/TR2 acceptance is sent by infrared CAN node, and this data-interface and IrDA1.2 compatibility, transmission rate can reach 115.2kbps.Send these data to MCP2120, data are carried out simple verification and decoding, send embedded protocol converter then to by MCP2120.Perhaps, receive the packet that protocol converter sends, and asynchronous continuous data flow is encoded, make each data bit can both convert the pulse that meets infrared standard to, and transmit a TM4100/TR2, send to corresponding infrared CAN node by it by MCP2120.
As shown in Figure 6, embedded protocol converter is made up of CPU (U1), program storage (U3) and data storage (U4).
CAN agreement monitoring and conversion work flow process be as shown in Figure 7: after gateways and starting is finished initialization, search for remote server in local area network (LAN) inside according to given operational factor, and set up network with it and connect, the data of CAN bus are converted to the data of network format, according to regularly sending with two kinds of data-transmission modes of burst, simultaneously remote monitoring data and operational order are converted to the CAN bus format, are dealt on the CAN bus.Finish the format conversion of data and order.
Infrared protocol monitoring and conversion work flow process be as shown in Figure 8: adopt interrupt mode to realize data communication.System initial state is set to wait for the state that receives data that when data were come, system directly got off Data Receiving.If the transmission data are then given control signal of infrared transmission module by fault diagnosis system, just begin to send data then.Perhaps, receive with the sign log-on data by interrupting, the size of specified data and initial address then, and data are deposited in the memory of appointment according to certain form.Data format is the size of data counter of two bytes, after connect data, connect the verification of a byte again.Consider the passivity that receives data in the real work, our system initial state is set to wait for the state that receives data, with the external interrupt response state of system is changed into the transmission data mode, and we just can realize sending the initiative of data like this.For the ease of the operating state of observing system, we are provided with a LED lamp and come the state of indication mechanism.
CAN/ infrared protocol data transaction is in the following way: Frame carries data from the transmitter to the receiver as shown in Figure 9, and the RTR position is " recessiveness " position, the numeric representation of data length sign indicating number DLC be the DLC value of corresponding data frame; Node on the CAN bus can be in reception, transmission, mistake activation, mistake approval and bus and close this five kinds of states, and wherein back three kinds is the fault state.Any one node is after detecting the bus free time (continuous 7 " recessiveness " position), just can send data, enter transmit status, what at first send is a start of frame bits (" dominance " position), as the synchronizing signal of other all the node transceive data on the bus, other nodes also can send data simultaneously.Sending the arbitration field interval, the every transmission one digit number of node certificate, the testbus state if detected state is consistent with the data bit of transmission, then continues to send the next bit data simultaneously, if what send is " recessiveness " position, and detected be " dominance " when position, show that this node clashes with the node with higher priority, then withdraws from transmission automatically on data/address bus, change accepting state over to, wait for sending data when bus is idle more next time.All be provided with in the interface circuit of each node and send make mistakes counter and the reception counter of makeing mistakes.When node detects mistake in receiving course, receive the counter of makeing mistakes and add 1, send out mismark simultaneously, if receive the message success, then receive the counter of makeing mistakes and subtract 1 (reducing to till 0); When node during in transmit status, send an error flag, then send the counter of makeing mistakes and add 8, and successfully send a message, send the counter of makeing mistakes and subtract 1; When the value of two counters all less than 128 the time, node is in " mistake activation " state, normally transceive data; When the value of any one counter more than or equal to 128 the time, node is in " mistake approval " state, still normal transceive data; When the value of transmitting counter more than or equal to 256 the time, node becomes " bus is closed not busy " state, sends driver and closes the spare time automatically, no longer influences bus, but still can the testbus state.After detecting on the bus 11 continuous " recessiveness " positions and taking place 128 times, two error counters are clear 0, and node is automatically changeb to " mistake activation " state from " bus is closed " state.
The infrared communication encoding and decoding are in the following way: coding as shown in figure 10, if the transmission low level, then TXIR will export the low level of 7 clock cycle, the high level of 3 clock cycle then, 6 remaining clock cycle are low level.If transmission high level, then TXIR whole output low levels (16 clock cycle constitute a bit time) in 16 clock cycle.Decode as shown in figure 11, if the low level of receiving, then RXIR will export the low level of 3 clock cycle, remaining maintenance high level; If receive high level, then RXIR is a high level all in 16 clock cycle, and RX will keep corresponding high or low level in 16 clock cycle.