CN108337292B - Brain wave data transmission server based on twisted framework - Google Patents

Brain wave data transmission server based on twisted framework Download PDF

Info

Publication number
CN108337292B
CN108337292B CN201711478864.4A CN201711478864A CN108337292B CN 108337292 B CN108337292 B CN 108337292B CN 201711478864 A CN201711478864 A CN 201711478864A CN 108337292 B CN108337292 B CN 108337292B
Authority
CN
China
Prior art keywords
user
data
database
equipment
protocol
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711478864.4A
Other languages
Chinese (zh)
Other versions
CN108337292A (en
Inventor
王亢
周国民
李国军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Police College
Original Assignee
Zhejiang Police College
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Police College filed Critical Zhejiang Police College
Priority to CN201711478864.4A priority Critical patent/CN108337292B/en
Publication of CN108337292A publication Critical patent/CN108337292A/en
Application granted granted Critical
Publication of CN108337292B publication Critical patent/CN108337292B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/08Network architectures or network communication protocols for network security for authentication of entities
    • H04L63/0815Network architectures or network communication protocols for network security for authentication of entities providing single-sign-on or federations
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A brain wave data transmission server based on a twisted framework is based on a C/S architecture, the server is a server side for transmitting, forwarding and storing brain wave data, the server side comprises a communication module, a brain wave data analysis module and a database module, and in the communication module, factory Devictory and UserFactory are respectively used for managing communication protocols of a device DevProtocol and a user UserProtocol; the protoTrans module is an electroencephalogram data analysis module, and the input parameter is a received equipment TCP message and is returned by a dictionary variable in a { key: value } form; the database module contains a user table, a device history table and a user device association table. The invention provides a unified management session, provides rich language expansion capability, improves the working efficiency and has better effectiveness, reliability and safety performance.

Description

Brain wave data transmission server based on twisted framework
Technical Field
The invention relates to the field of network programming, in particular to a server based on brain wave data transmission.
Background
In the modern society, the research on brain waves is becoming widespread. Through research and analysis on brain waves of the human brain, the mental state and the physiological state of the human can be known, and further the emotion and the health state of the human can be known. In the aspect of analyzing human emotion, brain waves can know whether teenagers are in love early, whether criminal suspects lie or not and the like. In the aspect of analyzing the health of patients, brain waves are necessary conditions for diagnosing epilepsy and are the most objective basis for studying sleep. In general, the research and application of brain waves are increasing.
In practical application, the collected brain wave data can be analyzed and stored by utilizing a server technology, so that the application of the brain waves can be further enhanced. For example, when a worker dozes off or reacts slowly, some parameters of the corresponding brain waves are lower (or higher) than a threshold value, so as to send out a warning to avoid accidents; and (3) carrying out storage management on electroencephalogram data of electroencephalogram related symptoms (such as hypomnesis caused by insufficient sleep), and comprehensively analyzing historical data to deepen the cognition of symptom rules. The server technology based on brain wave communication has good research and practical values.
The brain wave data acquired from the terminal equipment includes brain wave raw waveform data and statistical data (e.g., alpha, beta, gamma, etc. parameters). The terminal equipment packs and sends the brain wave data to the server through TCP/IP communication. The server receives the TCP message, analyzes the data and stores the data in a database for subsequent query. Meanwhile, the server also supports an online client, and transmits real-time data of the equipment terminal through the server or reads historical data from a database so as to be used for graphical display and analysis of client software.
Disclosure of Invention
In order to overcome the defects of poor compatibility, conversation and expansibility of the conventional server, the invention provides the brain wave data transmission server based on the twisted framework with good compatibility, conversation and expansibility, and the invention adopts the twisted framework for design so as to enhance the effectiveness and reliability of the server.
The technical scheme adopted by the invention is as follows:
a server for brain wave data transmission based on a twisted frame is a server end for transmitting, forwarding and storing brain wave data, and comprises a communication module, a brain wave data analysis module and a database module;
two factory objects, namely DevFactory and UserFactor y, are instantiated in the communication module and are respectively used for managing communication protocols between a device DevProtocol, a user UserProtocol and a server; the DevProtocol protocol realizes the login and logout of the equipment, the analysis of the reported data, the storage of a database with a complete record and the forwarding of the analyzed data to the associated online users; the user protocol realizes the login and logout of the user, analyzes the command issued by the user and executes the corresponding command in a non-blocking way;
the relation of many-to-many between the User and the equipment, in order to realize that the on-line state and intercommunication of the other party can be obtained in real time between the DevProtocol and the User Protocol, two dictionaries are set up: user _ dev _ priv and dev _ user _ priv. The user _ dev _ priv stores a dictionary with a certain user ID number of key and a list of the online device DevProtocol instances with control authority of value, namely { userid1: [ device instance 1. ], …, useridx: [ device instance 1. ] }. Similarly, dev _ user _ priv stores a dictionary with a key device ID number and a value list of user UserProtocol instances associated with the key device ID number, namely { devid1: [ user instance 1. ], …, devidy: [ user instance 1. ] }. When the device is successfully connected or disconnected, the DevProcol protocol calls an updateinlinedcevice () function, queries a database to obtain all users associated with the device, and then adds/deletes a DevProcol instance of the device in a user _ dev _ priv dictionary; when a user logs in/out, an update lieuser () function is called, a database is queried, all equipment associated with the user is obtained, and then a user protocol instance is added/deleted in a dev _ user _ priv dictionary. Therefore, in the D evProtocol protocol of the device, as long as the dev _ user _ priv dictionary is queried through the getolineuser () function, all online users associated with the device are obtained, so that the device can forward brain wave data; and calling a getolinedevice () function by a user protocol, inquiring a user _ dev _ priv dictionary, obtaining all the current online devices with control authority, and realizing the control and inquiry of the online devices.
Further, after receiving brain wave data sent by the equipment, the server triggers a dataReceived () event in a Dev Protocol, wherein the event processing comprises equipment validity authentication, data analysis, complete record storage after analysis in a historical data table of a database and data forwarding to an online user with control authority;
the brain wave data analysis is completed in a protoTrans module, after the equipment is connected with a server, the data uploaded by the equipment is analyzed by calling a neuroData () function in a pr otoTrans module in a DevProtocol protocol; the interface function protoTra ns. neurodata () takes a Python character string as an input parameter, and converts the Python character string into a C language character string by using a PyArg _ parsetup () function; calling parsNeuroPa packet () to analyze the data message given by the character string according to a specified protocol; and constructing a { key: value } dictionary by using a Py _ BuildValue () function of the analyzed data, returning the { key: value } dictionary to a Python program, and generating a corresponding dynamic library file by using a configuration tool provided by Python by a data analysis module.
Further, the server receives a TC P message with/without a parameter command sent by a user, and triggers a dataReceived () event in a user protocol, wherein the event processing comprises user validity authentication, command analysis and command execution;
if the received command and parameters are legal, directly executing; if the parameter is illegal or the parameter is wrong, returning error information; if the command needs a long time to inquire historical data and the like, a deferToTh read () function is introduced from twisted.
Furthermore, the database is operated by using the object mapping sqlalchemy, a table in the database or a record in the table can be directly completed by an operation class or a class instance of the sqlalchemy, and the addition, deletion and query of the database can be realized by using a tool sqlalchemy in the ORM;
and calling a function auth _ dev _ history () in a database db module in the DevProtocol protocol to insert the parsed record into a database historical data table. Each record comprises each statistical parameter defined by a media field and original waveform data defined by a Blob field, wherein each statistical parameter is once inserted into a historical data table in an 'insert intro' manner, the Blob field is empty at the moment, and then the original waveform data in the record refreshes the Blob field in the 'insert intro' record in an 'update' manner; at the moment, the record is written into the database cache, and the comm it () function of the MySQLdb is called at regular intervals to really write the record in the cache into the database.
After the DevProtocol and UserProtocol protocols are started, an overtime timer is started. And refreshing the overtime timer every time the dataReceived () event of the equipment/user, and when the overtime timer is not refreshed for a long time, considering that the equipment/user and the equipment/user are disconnected, and automatically triggering a connectionLost event by software to disconnect the TCP connection.
In the invention, the designed server software adopts a modular design method, and the software is compiled by adopting Py thon language, so that the cross-platform performance is good; a Twisted non-blocking network frame is adopted, a reactor is used for monitoring a server port, a Factory is used for configuring some permanent configurations, and a Protocol is used for managing network communication; c language is adopted to analyze the data uploaded by the equipment, the analyzed data is returned to the Python main process in a dictionary mode, and the flexibility and the high efficiency of the C language are fully utilized; and the MySQL open source database is used for storing the analyzed device statistical parameters and the original waveform data and supporting the historical data query of the user. The functions are respectively as follows:
the designed server is realized by adopting a modularized method and mainly comprises a conversation realization part, a brain wave data analysis part and a database part.
In the implementation of the session, the client is divided into two major categories, namely equipment and a user, and the two major categories are respectively implemented in the modules dev and user. The objects DevFactory and UserFactory are used for managing the connection of the device and the client of the user respectively.
In the DevFactory unit, a protocol DevProtocol is instantiated and is responsible for management of the DevP protocol unit. In this unit, the initialization of device services, the connection of devices, the addition/deletion of devices, the configuration of device persistent data, and operations on device databases are included. The device protocol management device is an abstract factory, and the core function is to manage the connection event of the device, and instantiate the network communication of the device protocol management device client.
In the DevProtocol unit, the event processing is used after the device establishes the connection. The method comprises the steps of initializing equipment, successfully establishing equipment connection, failing or interrupting the connection of the equipment, and analyzing and storing equipment data. Its main role is to take over the communication of the processing object after the DevFactory instantiates an object. Specifically, when a device client makes a TCP connection request, the DevProtocol unit calls a function connectionMade () to process the TCP connection event, and obtains information such as an IP address and a port. After the device establishes TCP connection, the device sends data to the server, and triggers an event dataReceived () event to perform corresponding event processing, so as to realize the analysis, forwarding and storage of the data. Specifically, if the user does not allow to receive the data reported by the device, the data is directly discarded; if the user allows receiving, combining and splitting several received TCP messages, so that a complete database record comprising the statistical parameters and the original waveform data is obtained after analysis; carrying out validity check on the analyzed data, if the serial number cannot be found in a database equipment table, determining that the data is illegal equipment, and directly calling a loseConnection () to disconnect the TCP connection; for legal equipment, before the connection is disconnected, the validity verification is not carried out any more, and an addDevice () function is called to add the equipment terminal; calling a self-defined getonlineuser () function to acquire all online users having the authority to read the equipment, and forwarding data analyzed by the equipment terminal to each online user; and storing the analyzed complete statistical parameters and the analyzed original waveform data into a historical data table dev _ history of the database for subsequent user query.
In the data analysis in the above process, the TCP data packet received in the dataReceived () event is represented in the form of Python string variable. The data analysis part is completed in a protocol rans module, the module is realized by C language, and the flexibility and the high efficiency of the C language are utilized to improve the efficiency of protocol analysis. The interface function prototrans. neurodata () uses a Py thon character string as an input parameter, and converts the Py thon character string into a C language character string by using a PyArg _ parsettuple () function. And calling partNeuroPacket () to analyze the data message given by the character string according to a specified protocol. The parsed data is returned to the Python program by constructing a { key: value } dictionary using a Py _ Bui ldValue () function. And the data analysis module adopts a configuration tool provided by Python to generate a corresponding dynamic library file. The specific method comprises the following steps: py script is written, wherein the most important is Ext _ modules ═ Ext intension (MOD, sources [ 'pretransn.c' ]) ]), and the module name and the C file name of the module specific implementation are specified, namely protoTrans and prototrans.c, respectively. The module can be called by Python after a dynamic file prototrans. so is generated after compiling and installing are successfully performed by executing Python etup.
In the process of record saving, a function auth _ dev _ his tory () in a database db module is called to insert the record into a historical data table dev _ history, and the record is written into a database cache at the moment. And calling a commit () function of the MySQLdb at regular intervals, and really writing the records in the cache into the database. Each record includes the respective statistical parameters defined in the media field and the original waveform data defined in the Blob field, wherein the respective statistical parameters are once inserted into the history data table in the manner of "insert intro" (when the B lob field is empty), and then the original waveform data in this record refreshes the Blob field in the just "insert intro" record in the manner of "update".
Also, in the userfactor unit, a protocol UserProtocol is instantiated and is responsible for management of the UserProtocol unit. This unit includes initialization of user services, addition/deletion of users, and manipulation of user tables in the database. The user protocol unit is used for managing events such as communication aspects of users, control of starting/ending acquisition of equipment data, inquiry of equipment historical data and the like.
The database consists of four tables, namely a user table, an equipment history table and a user and equipment association table. The table stores corresponding specific information. The user table includes information such as a user id number, a user name, a password, an IP address, a port number, and a latest access time. The user table and the device table may add and store serial numbers for authentication when the client accesses. The user equipment association table may add the associated sequence number. And the equipment history table records the successfully analyzed equipment data.
The administrator needs to add information in advance for the serial number authentication and the serial number mutual query in the subsequent database. The design of the table adopts an object mapping sqlalchemy tool, which is equivalent to instantiating a database and can be managed conveniently. With the hierarchical _ Base object in the sql, data tables corresponding to all Base derivative classes can be created through Base. The introduction of the thread pool at engine creation time can improve efficiency and reduce resource consumption. The operation on the database is completed through the Session module. A Session factory can be created through an engine, an object Session is instantiated by a factory method, and the specific operation of the object can be completed by the aid of add, commit and other methods.
In the invention, a method for uniformly managing the session is designed in consideration of the communication realization of the session; considering the requirements of the server and different client sessions, the client is abstracted into two major classes of equipment and users which are respectively used for management and users, and the designed server can meet the requirement of simultaneous connection of a plurality of clients, namely the equipment and the users are in a many-to-many relationship; analyzing and converting the electroencephalogram data uploaded by the equipment into a format, and storing the electroencephalogram data into a database for subsequent data analysis; considering that the data is always sent after the device is powered on and only the data is sent but not received, the data of the device received by the server, those needing to be stored and those not needing to be stored, are determined by the user through signaling. The invention has the following beneficial effects:
1) the portability is strong, and the designed server has good cross-platform performance and can run on platforms such as Linux, Window and Ios which are mainstream at present.
2) The modular design method enables the code structure to be rich in three-dimensional sense, reduces the code coupling degree and facilitates modification and maintenance.
3) Based on the non-blocking mode driven by the asynchronous event, no waiting exists in the processing, and the time consumption can be greatly reduced.
4) The expandability is strong, the C language is utilized for mixed editing, and the data processing efficiency of the server is improved.
5) The confidentiality is enhanced, the defect of poor confidentiality caused by easy reading of Python language is overcome by compiling codes of the extension module, and the code safety is improved.
Drawings
Fig. 1 a network framework of a server.
Fig. 2 is a functional block diagram of the server side.
Fig. 3 is a flow chart of a user terminal session implementation.
Fig. 4 is a flow diagram of a device terminal session implementation.
Fig. 5 is a flow chart of a device terminal data forwarding user terminal.
FIG. 6 is a flow diagram of a database data storage implementation.
Fig. 7 is a brain wave data analysis path diagram.
Fig. 8socket communication timeout processing flowchart.
Detailed Description
The invention is further described below with reference to the accompanying drawings.
Referring to fig. 1 to 8, fig. 1 is a basic C/S (client/server) network framework, which is a server for electroencephalogram data transmission based on a twisted framework. And the communication between the client and the server is realized by utilizing a Socket method based on TCP. The client is divided into an equipment client and a user client, and the equipment client can send data to the user client through the server.
FIG. 2 is a functional block diagram of a designed server. Briefly, the server is designed to be divided into three major parts: the brain wave analysis system comprises a main module, a brain wave data analysis module and a database module. The main module is a client session realization part which comprises equipment, a user client and server session realization module and a user equipment association module. The database module is connected with the MySQL database, so that operations such as database access can be realized. The administrator needs to add the authentication information of the client to the database in advance.
Figure 3 is a flow chart illustrating a process for a server to implement a session with a user terminal. The specific process is as follows:
1.1) the server starts, calls the listenstcp listening port, initializes the user activity () factory, calls the reactor method reactor run () to enter the listening loop.
1.2) UserFactory () instantiates a UserProtocol protocol to prepare for processing the network event of the user terminal.
1.3) when a user TCP connection request exists, triggering a connectionMade () event and establishing user connection. Refreshing access time, establishing heartbeat time, and preparing for disconnection overtime.
1.4) after the connection is successfully established, the received data can trigger an event dataReceived (), and the data sent by the user is received.
1.5) analyzing the data content sent by the user. If the user does not log in, the user must be a login command, otherwise, the connection is directly disconnected; if the command is a login command and the command is accessed for the first time, calling a getUserInfo () function, inquiring a database user table, judging whether the command is legal, if so, allowing login, and if not, directly disconnecting the connection; if the command is a login command but the user logs in, inquiring whether the IP and the port of the command are the same as the IP and the port which are successfully logged in last time, if so, ignoring the command, and if not, logging out of the login last time and logging in again. Is not the first access. If the access is the first access, a getUserInfo () function is called to judge whether the sequence number is legal or not. If the access is not the first access, namely the first access shows that the flag bit is False, the verification process is directly skipped, and the equipment terminal is directly added.
1.6) after the user terminal logs in, judging whether a new user terminal is accessed, returning to the step 1.3), and circulating again. Meanwhile, whether the user access time exceeds the set time timeout of the user is judged.
1.7) if the set time timeout is exceeded, triggering a connectionLost () event, disconnecting, deleting the user, and emptying the cache. The clearing of the cache represents the end of a user session.
1.8) if the received command and the received parameters are legal, directly executing; if the parameter is illegal or the parameter is wrong, an error message is returned. If the command needs a long time to inquire historical data and the like, a deferToTh read () function is introduced from twisted.
The device session is implemented as shown in fig. 4, and the specific steps are as follows:
2.1) starting the server. Invoking a function of reactivor. listenttcp (), initializing the plant Dev2Factory, monitoring a corresponding TCP port, invoking reactivor. run (), entering a monitoring cycle, and preparing for device terminal event processing.
2.2) DevFactory () instantiates DevProtocol for processing communication events of the device.
2.3) when the device terminal accesses, triggering a connectionMade () event and establishing device connection. And acquiring the current time and preparing for TCP timeout.
2.4) after the connection is established, the data reported by the equipment triggers a dataReceived () event, receives the data and processes the data. The data processing of the equipment terminal comprises data analysis, user forwarding, database storage and other operations. The focus here is on the introduction of the session implementation of the device terminal.
2.5) trigger dataReceived () event, the data is parsed.
2.6) if the equipment is not logged in, extracting the serial number of the equipment from the data, and querying a database for verification. If it is already logged in, authentication is skipped.
2.7) judging whether the serial number exists in the database, if so, instantiating the serial number, the equipment name and the equipment id, and calling an addDevice () function to log in the equipment terminal. And marking the mark position of the first access as False for subsequent login to skip authentication. And the non-existent serial number directly calls a transport attribute loseConnection () method to disconnect, and the illegal equipment terminal is deleted.
2.8) judging whether a new equipment terminal is accessed, if so, 2.3) repeating the steps, and circulating again. Meanwhile, the server side judges whether the information that the socket is closed by the equipment terminal is received.
2.9) receives the close connection information, a connectionLost () event is triggered, which invokes the delDeDevice () function to delete the logged in device. The device terminal deletion indicates the end of a terminal session.
With reference to fig. 5, the procedure of the device data sending ue is as follows:
3.1) in 2.4), after the device terminal establishes connection and triggers a dataReceived () event, the data of the device terminal is forwarded to the user terminal.
3.2) firstly judging whether the received data is empty or not, and directly ending when the received data is empty. If the data exists, calling an interface function getonlineuser () to acquire all online users to prepare for forwarding the data.
3.3) judging whether the obtained user exists or not, and directly ending the nonexistent user. The existing user continues with the next step.
3.4) if the user exists, assigning the current time () to the starttime to prepare for forwarding time. And to traverse through each of the on-line users,
3.5) each online user after traversing sends the device data to each online user terminal by using the write method of the transport attribute.
3.6) time consuming for log printing and forwarding. And the primary equipment terminal data forwarding user terminal equipment is finished.
Database management includes addition and deletion of databases by administrators, verification, and storage of device data. With reference to fig. 6, a process of storing device data in the database is described, which is specifically as follows:
4.1) after the server runs, calling a function db _ init _ test () in a database db module to initialize tables and fields in the database.
4.2) in 2.4), the terminal triggers dataReceive () event after accessing, and starts data processing.
4.3) after the event dataReceived () is triggered, firstly judging whether the data is empty or not, and directly ending when the data is empty. Data that is not empty is subject to subsequent processing.
4.4) non-null data calls an interface function protoTrans. NeuroData () to analyze, and the successfully analyzed data is stored in a dictionary recordDict. And performing database authentication and logging in qualified equipment.
4.5) further judging whether the analyzed data is null or not, and calling a function addRecord () to add the equipment data into the buffer recordBuff for the analyzed data which is not null.
4.6) under a timing program, when a certain condition is met, a function auth _ dev _ history () is called to add the device data in the cache to the database, so that the storage of the device history data is completed. And ending the storage process in the database.
Fig. 7 is a flow chart of electroencephalogram data analysis, and the specific analysis process is as follows:
5.1) in 2.4), after the device side triggers a dataReceived () event, an interface function prototrans. neurodata () is called to analyze data, and the analyzed correct data is finally stored in a database.
5.2) in the module protoTrans, firstly calling a partNeuroPacket () function to perform pre-analysis on the data packet, and performing header checksum verification on the data packet.
5.3) checking the correct data will continue to call the function parseNeuroLab () to parse the content and output the data. The parsed data is stored in 4.4) dictionary recordDict for later use.
Fig. 8 illustrates a timeout error detection mechanism that occurs during communication. When there is no data transfer in the connection, an exception and error report is provided over time. The specific process steps are as follows:
6.1) when the terminal accesses, triggering a consectmame () event, refreshing the access time of the terminal and preparing for overtime.
6.2) triggering dataReceived () event handling data. The time for judging and processing a terminal is compared with the set overtime time.
6.3) if the time for processing the terminal is more than the timeout time timeout, triggering a connetio nLost event and disconnecting the TCP connection. If the time does not exceed the timed timeout time, the connection is disconnected when the time exceeds the timed time.
Other function spaces are reserved in the embodiment, and the method has good expansibility. For example, the session realization can be realized by only adding corresponding processing methods at the terminal and adding corresponding processing methods at the server, so that the session expansibility can be realized, and the realization of the session is enriched.

Claims (2)

1. A brain wave data transmission server based on a twisted frame is characterized in that: the server is a server end for transmitting, forwarding and storing brain wave data, and the server end comprises a communication module, a brain wave data analysis module and a database module;
two factory objects, namely DevFactory and UserFactory, are instantiated in the communication module and are respectively used for managing communication protocols between a device DevProtocol, a user UserProtocol and a server; the DevProtocol protocol realizes the login and logout of the equipment, the analysis of the reported data, the storage of a database with a complete record and the forwarding of the analyzed data to the associated online users; the user protocol realizes the login and logout of the user, analyzes the command issued by the user and executes the corresponding command in a non-blocking way;
the relation of many-to-many between the user and the equipment, in order to realize that the DevProtocol and the UserProtocol can obtain the online state of the other side and communicate with each other in real time, two dictionaries are set up: user _ dev _ priv and dev _ user _ priv, where the user _ dev _ priv stores a dictionary with a certain user ID number of key and a list of online device protocol instances with control authority of value, that is, { userid1, [ device instance 1, ], …, userdx: [ device instance 1, ] }, and similarly, the dev _ user _ priv stores a dictionary with a certain device ID number of key and a list of user protocol instances associated therewith of value, that is, { devid1: [ user instance 1, ], …, devidy: [ user instance 1, ] }, and when a device is connected or disconnected, the protocol calls an updationlineredfunction to query a database to obtain all users associated with the device, and then adds/deletes the device instance () in the device _ priv; when a user logs in/out, calling an updatenlieuser () function, inquiring a database to obtain all equipment associated with the user, and then adding/deleting a user protocol instance in a dev _ user _ priv dictionary, so that in a dev protocol of the equipment, all online users associated with the equipment are obtained as long as the dev _ user _ priv dictionary is inquired through a getolineuser () function, and the equipment can forward brain wave data; a user protocol calls a getolinedevice () function, queries a user _ dev _ priv dictionary, obtains all online devices with current control authority, and realizes control and query of the online devices;
after receiving brain wave data sent by equipment, the server triggers a dataReceived () event in a DevProtocol protocol, wherein the event processing comprises the steps of equipment validity authentication, data analysis, complete record storage after analysis to a historical data table of a database and data forwarding to an online user with control authority;
the brain wave data analysis is completed in a protoTrans module, after the equipment is connected with a server, the data uploaded by the equipment is analyzed by calling a neuroData () function in the protoTrans module in a DevProtocol protocol; the interface function prototrans. neurodata () takes a Python character string as an input parameter, and converts the Python character string into a C language character string by using a PyArg _ parsettuple () function; calling partNeuroPacket () to analyze the data message given by the character string according to a specified protocol; constructing a { key: value } dictionary by using a Py _ BuildValue () function of the analyzed data, returning the { key: value } dictionary to a Python program, and generating a corresponding dynamic library file by a data analysis module by using a statuses tool provided by Python;
the server receives a TCP message with/without a parameter command sent by a user, and triggers a dataReceived () event in a user protocol, wherein the event processing comprises user validity authentication, command analysis and command execution;
if the received command and parameters are legal, directly executing; if the parameter is illegal or the parameter is wrong, returning error information; if the command needs to take a long time to inquire historical data and the like, a deferToThread () function is led in from twisted.
The database is operated by using the object mapping sqlalchemy, a table in the database or a record in the table can be directly completed through an sqlalchemy operation class or class instance, and the addition, deletion and query of the database can be realized through a tool sqlalchemy in the ORM;
calling an auth _ dev _ history () function in a database db module in a DevProtocol protocol to insert parsed records into a database historical data table, wherein each record comprises each statistical parameter defined by a media field and original waveform data defined by a Blob field, wherein each statistical parameter is inserted into the historical data table in a 'insert _ intro' manner at one time, the Blob field is empty at the moment, and then the original waveform data in the record refreshes the Blob field in the 'insert _ intro' record in an 'update' manner; and writing the record into a database cache, calling a commit () function of the MySQLdb at regular intervals, and really writing the record in the cache into the database.
2. The twisted frame-based brain wave data transmission server of claim 1, wherein: after the DevProtocol and the UserProtocol are started, the overtime timer is refreshed again by each dataReceived () event of the equipment/user, when the overtime timer is not refreshed for a long time, the equipment/user and the equipment/user are considered to be disconnected, the software automatically triggers the connectionLost event, and the TCP connection is disconnected.
CN201711478864.4A 2017-12-29 2017-12-29 Brain wave data transmission server based on twisted framework Active CN108337292B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711478864.4A CN108337292B (en) 2017-12-29 2017-12-29 Brain wave data transmission server based on twisted framework

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711478864.4A CN108337292B (en) 2017-12-29 2017-12-29 Brain wave data transmission server based on twisted framework

Publications (2)

Publication Number Publication Date
CN108337292A CN108337292A (en) 2018-07-27
CN108337292B true CN108337292B (en) 2020-10-13

Family

ID=62924510

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711478864.4A Active CN108337292B (en) 2017-12-29 2017-12-29 Brain wave data transmission server based on twisted framework

Country Status (1)

Country Link
CN (1) CN108337292B (en)

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8493855B2 (en) * 2009-03-31 2013-07-23 Infineon Technologies Ag Network retransmission protocols using a proxy node
US8930374B2 (en) * 2012-06-29 2015-01-06 Nokia Corporation Method and apparatus for multidimensional data storage and file system with a dynamic ordered tree structure
CN105496379A (en) * 2015-12-17 2016-04-20 无锡桑尼安科技有限公司 Health monitoring system

Also Published As

Publication number Publication date
CN108337292A (en) 2018-07-27

Similar Documents

Publication Publication Date Title
CN105786998A (en) Database middleware system and method for processing data through database middleware system
US6085237A (en) User-friendly interface for setting expressions on an SNMP agent
CN102497427B (en) Method and device for realizing data acquisition services of renewable energy source monitoring system
CN103795762B (en) A kind of test method and system of reverse proxy
CN111752799A (en) Service link tracking method, device, equipment and storage medium
CN108132873A (en) Systematic procedure daily record prints and long-range multiple terminals daily record debugging control system
WO2016169145A1 (en) Cloud terminal log processing method, device and system
CN107179977A (en) Database Full-automatic monitoring system based on mpm models
CN111984561A (en) IPMI command processing method, system, device and medium for BMC
CN105812432B (en) Cloud document processing method and device
CN104539449B (en) A kind of failure information processing method and relevant apparatus
CN104967667B (en) A kind of software stability test remote monitoring system based on cloud service
CN107846609B (en) Real-time transmission method, device and system for control room data
CN108337292B (en) Brain wave data transmission server based on twisted framework
CN111302177A (en) Equipment running state feedback monitoring method and device
WO2016091141A1 (en) Method and apparatus for information collection
CN114500178A (en) Intelligent internet of things gateway capable of self-operation and self-maintenance
CN107066538B (en) Data statistics method and device
CN110233747B (en) Data reporting method and cloud platform
CN111611134A (en) Time monitoring method and device, application terminal and storage medium
CN111625412A (en) Flume-based data acquisition method, system, device and storage medium
CN110278219B (en) Procedural Internet of things equipment simulation tool and simulation method
CN103107991B (en) A kind of many NVT event-handling method, NVC and safety monitoring platform
CN102664764B (en) Call control flow testing tool based on media gateway control protocol and method thereof
CN109040003A (en) A kind of method that local area network carries out safety management

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant