wu_xinjun
2022-03-07 e1f883778b1a51241a018a7f0c5918f91026aae7
read change log and readme.md
4个文件已修改
251 ■■■■■ 已修改文件
README.md 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/engine/MessageThreads.py 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/engine/devices.py 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/protos/aerial.proto 195 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
README.md
@@ -1,18 +1,8 @@
# 华能煤堆实时三维重建采集端和服务端
## 运行环境
## TODO
1. Python版本:3.9
2. 第三方包:flask pika protobuf
## 创建环境
Just click ```JustDoubleClickMe.bat``` file to auto setiing the env, which is located in the ```env``` folder.
## 运行采集端
Double click to run  ```startClient.bat```
## 运行服务端
Double click to run  ```startServer.bat```
1. 根据proto数据结构,重新优化src\engine\MessageThreads.py的相关内容;
2. 采集端:修改src\engine\devices.py内的相机的数据采集线程;
3. 服务端:增加图像数据的消息解析;
4. src\engine\MessageThreads.py内添加数据发送和接收线程。
src/engine/MessageThreads.py
@@ -13,13 +13,13 @@
class Message(object):
    def __init__(self,sender_id,sender_key,body,routing_key):
        self.sender_id = sender_id
        self.sender_key = sender_key
        self.body = body
        self.routing_key = routing_key
# class Message(object):
#     def __init__(self,sender_id,sender_key,body,routing_key):
#         self.sender_id = sender_id
#         self.sender_key = sender_key
#         self.body = body
#         self.routing_key = routing_key
# 根据新的数据结构改写run
class senderThread(threading.Thread):
    def __init__(self, MQparameters,input_msg_queue,sender_id,exchangeName,exchangeType):
        super(senderThread,self).__init__()
@@ -48,7 +48,6 @@
                        data= self.queue.get()
                        if isinstance(data, pb.CapturedData):
                            msg = pb.DataMessage()
                            msg.
                        else:
                            body = msg.body
                            routing_key = msg.routing_key
@@ -64,6 +63,7 @@
                    print(e)
                    break
# 根据新的数据结构改写run
class receiverThread(threading.Thread):
    def __init__(self, MQparameters,received_msg_queue,output_response_queue,exchangeName,exchangeType,receiver_id):
        super(receiverThread,self).__init__()
@@ -103,6 +103,7 @@
        raise NotImplementedError(
            "Need to implement the callback function")
# 根据rabbitmq重新设置消息参数
class device_state_senderThread(senderThread):
    def __init__(self, 
        MQparameters,
@@ -116,7 +117,7 @@
                    "device_state",
                    "fanout"
                   )
# 根据rabbitmq重新设置消息参数
class device_state_receiverThread(receiverThread):
    def __init__(self, 
        MQparameters,
@@ -135,7 +136,7 @@
        response_tag = f"{time.asctime()} received: {body}."
        print(response_tag)
        ch.basic_ack(delivery_tag = method.delivery_tag)
# 根据rabbitmq重新设置消息参数
class alarm_state_senderThread(senderThread):
    def __init__(self, 
        MQparameters,
@@ -149,7 +150,7 @@
                    "alarm_state",
                    "fanout"
                   )
    # 根据rabbitmq重新设置消息参数
class alarm_state_receiverThread(receiverThread):
    def __init__(self, 
        MQparameters,
@@ -168,7 +169,7 @@
        response_tag = f"{time.asctime()} received: {body}."
        print(response_tag)
        ch.basic_ack(delivery_tag = method.delivery_tag)
# 根据rabbitmq重新设置消息参数
class command_request_senderThread(senderThread):
    def __init__(self, 
        MQparameters,
@@ -182,7 +183,7 @@
                    "command_request",
                    "topic"
                   )
# 根据rabbitmq重新设置消息参数
class command_request_receiverThread(receiverThread):
    def __init__(self, 
        MQparameters,
@@ -206,7 +207,7 @@
        print(response_tag)
        self.response_queue.put(Message(self.receiver_id,self.receiver_id,response_tag,''))
        ch.basic_ack(delivery_tag = method.delivery_tag)
# 根据rabbitmq重新设置消息参数
class command_response_senderThread(senderThread):
    def __init__(self, 
        MQparameters,
@@ -220,7 +221,7 @@
                    "command_response",
                    "fanout"
                   )
# 根据rabbitmq重新设置消息参数
class command_response_receiverThread(receiverThread):
    def __init__(self, 
        MQparameters,
@@ -240,6 +241,7 @@
        ch.basic_ack(delivery_tag = method.delivery_tag)
# TODO
class image_data_senderThread(senderThread):
    def __init__(self, 
        MQparameters,
@@ -254,6 +256,9 @@
                    "fanout"
                   )
class image_data_receiverThread(receiverThread):
    pass
src/engine/devices.py
@@ -94,6 +94,7 @@
        """stop the thread"""
        self.is_stop = True
# TODO根据新的数据结构修改队消息队列。
    def run(self):
        print("CaptureThread started")
        encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), self.image_quality]
src/protos/aerial.proto
@@ -81,8 +81,7 @@
  string capture_device =2;                   // 采集设备
  int32 capture_port = 3;                     // 采集设备序号
  DataField DataField = 4;
  string data_type = 5;                         // 采集数据
  string data_type = 5;                         // 数据类型 image udp
}
message DataMessage{
@@ -90,105 +89,127 @@
  string sending_device = 2;
  string target_device = 3;
  CapturedData CapturedData = 5;
}
message StateData {
 int64 state_time = 1;
 string state_device = 2;
 DataField DataField = 4;
}
message StateMessage {
  int64 sending_time = 1;
  string sending_device = 2;
  string target_device = 3;
  CapturedData StatedData = 5;
}
message CommandData {
  SysCommand SysCommand = 1;
  SubCommand SubCommand = 2;
}
message CommandMessage {
}
message ImagesMessage
{
  bytes image1  = 1;
  bytes image2  = 2;
  bytes image3  = 3;
  bytes image4  = 4;
  bytes image5  = 5;
}
message MicroWaveMessage
{
  int32 length = 1;                           // 数据长度
  bytes data = 2;                            // 数据内容
}
message CommandRequest{
}
message StateMessage{
  string message_type = 1;
  int64 generate_time = 2;
  string generate_device = 3;
  string target_device = 4;
  string message_uuid = 5;
  string str_body = 6;
  int64 sending_time = 1;
  string sending_device = 2;
  string target_device = 3;
  CommandData CommandData =4;
}
// message ImagesMessage
// {
//   bytes image1  = 1;
//   bytes image2  = 2;
//   bytes image3  = 3;
//   bytes image4  = 4;
//   bytes image5  = 5;
// }
message RequestCommand {
  int32 sync_word = 1;              // 同步字
  string device_id = 2;             // 设备ID
  SysCommand sys_command = 3;       // 命令1
  SubCommand sub_command = 4;       // 命令2
  DataField data1 = 5;              // 数据1
  DataField data2 = 6;              // 数据2
  int32 checksum = 7;               // 校验码
}
// message MicroWaveMessage
// {
//   int32 length = 1;                           // 数据长度
//   bytes data = 2;                            // 数据内容
// }
enum ResponseState
{
  SUCCESS = 0;                  // 成功
  FAILURE = 1;                  // 失败
  ABNORMAL = 2;                 // 异常
  INFICIENT_POWER = 3;          // 电量不足
  OTHER = 4;                    // 其他
}
// message CommandRequest{
message ResponseCommand
{
    string device_id = 1;        // 设备ID
    SysCommand sys_command = 2;  // 命令1
    SubCommand sub_command = 3;  // 命令2
    ResponseState state = 4;     // 响应状态
    int32 data_length = 5;       // 数据长度
    bytes data = 6;              // 数据
    int32 checksum = 7;          // 校验码
}
// }
// message StateMessage{
//   string message_type = 1;
//   int64 generate_time = 2;
//   string generate_device = 3;
//   string target_device = 4;
//   string message_uuid = 5;
//   string str_body = 6;
// }
// 服务端向采集端发送的主指令
enum ControlSysCommand {
  DUST_CLEANER_COMMAND = 0;
}
// 服务端向采集端发送的子命令
enum ControlSubCommand {
  // dust cleaner sub commands
  DUST_CLEANER_ONETIME_CLEAN_SELF         = 0;
  DUST_CLEANER_ONETIME_CLEAN_CAMERA       = 1;
  DUST_CLEANER_CLOSE_PERIOD_CLEAN_SELF    = 2;
  DUST_CLEANER_CLOSE_PERIOD_CLEAN_CAMERA  = 3;
  DUST_CLEANER_PERIOD_CLEAN_SELF          = 4;
  DUST_CLEANER_PERIOD_CLEAN_CAMERA        = 5;
}
// dust cleaner command message
message DustCleanerMessage  {
  uint32 period = 1;
}
// 控制上位机消息
message ControllMessage {
  int32 sync_word = 1;                // 同步字
  ControlSysCommand sys_command = 3;  // 主命令
  ControlSubCommand sub_command = 4;  // 子命令
  DataField data = 5;                 // 数据
  int32 checksum = 7;                 // 校验码
}
// message RequestCommand {
//   int32 sync_word = 1;              // 同步字
//   string device_id = 2;             // 设备ID
//   SysCommand sys_command = 3;       // 命令1
//   SubCommand sub_command = 4;       // 命令2
//   DataField data1 = 5;              // 数据1
//   DataField data2 = 6;              // 数据2
//   int32 checksum = 7;               // 校验码
// }
// enum ResponseState
// {
//   SUCCESS = 0;                  // 成功
//   FAILURE = 1;                  // 失败
//   ABNORMAL = 2;                 // 异常
//   INFICIENT_POWER = 3;          // 电量不足
//   OTHER = 4;                    // 其他
// }
// message ResponseCommand
// {
//     string device_id = 1;        // 设备ID
//     SysCommand sys_command = 2;  // 命令1
//     SubCommand sub_command = 3;  // 命令2
//     ResponseState state = 4;     // 响应状态
//     int32 data_length = 5;       // 数据长度
//     bytes data = 6;              // 数据
//     int32 checksum = 7;          // 校验码
// }
// // 服务端向采集端发送的主指令
// enum ControlSysCommand {
//   DUST_CLEANER_COMMAND = 0;
// }
// // 服务端向采集端发送的子命令
// enum ControlSubCommand {
//   // dust cleaner sub commands
//   DUST_CLEANER_ONETIME_CLEAN_SELF         = 0;
//   DUST_CLEANER_ONETIME_CLEAN_CAMERA       = 1;
//   DUST_CLEANER_CLOSE_PERIOD_CLEAN_SELF    = 2;
//   DUST_CLEANER_CLOSE_PERIOD_CLEAN_CAMERA  = 3;
//   DUST_CLEANER_PERIOD_CLEAN_SELF          = 4;
//   DUST_CLEANER_PERIOD_CLEAN_CAMERA        = 5;
// }
// // dust cleaner command message
// message DustCleanerMessage  {
//   uint32 period = 1;
// }
// // 控制上位机消息
// message ControllMessage {
//   int32 sync_word = 1;                // 同步字
//   ControlSysCommand sys_command = 3;  // 主命令
//   ControlSubCommand sub_command = 4;  // 子命令
//   DataField data = 5;                 // 数据
//   int32 checksum = 7;                 // 校验码
// }