mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-10-24 18:20:15 -04:00
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2023 Fancy Code.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#ifndef PROTOCOL_HANDLE_H
|
|
#define PROTOCOL_HANDLE_H
|
|
#include "StatusCode.h"
|
|
#include <memory>
|
|
enum PROTOCOL_COMMAND
|
|
{
|
|
ASK_IPC_MISSION = 0x8101,
|
|
REPLY_IPC_MISSION = 0x0101,
|
|
PROTOCOL_COMMAND_END
|
|
};
|
|
class VProtocolParam
|
|
{
|
|
public:
|
|
VProtocolParam(const PROTOCOL_COMMAND &command) : mCommand(command) {}
|
|
virtual ~VProtocolParam() = default;
|
|
const PROTOCOL_COMMAND mCommand;
|
|
};
|
|
template <typename T>
|
|
class ProtocolParam : public VProtocolParam
|
|
{
|
|
|
|
public:
|
|
ProtocolParam(const PROTOCOL_COMMAND &command, T &value) : VProtocolParam(command), mData(value) {}
|
|
virtual ~ProtocolParam() = default;
|
|
|
|
public:
|
|
/**
|
|
* @brief
|
|
* Protocol data.
|
|
*/
|
|
T mData;
|
|
};
|
|
class ProtocolHandle
|
|
{
|
|
public:
|
|
ProtocolHandle() = default;
|
|
virtual ~ProtocolHandle() = default;
|
|
virtual void *GetProtocolDataBuff(void) { return nullptr; }
|
|
virtual size_t GetProtocolDataLength(void) { return 0; }
|
|
|
|
public:
|
|
static std::shared_ptr<ProtocolHandle> CreateProtocolData(const std::shared_ptr<VProtocolParam> ¶m);
|
|
static void ProtocolAnalysis(const void *data, const size_t &length);
|
|
static size_t GetKeyHeadLength(void);
|
|
static StatusCode GetDataLength(const void *keyHead, const size_t &headLength, size_t &dataLength);
|
|
};
|
|
#endif |