1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// FGMC protocol handler
#ifndef FGMC_PROTOCOL_H
#define FGMC_PROTOCOL_H
#include <RepRapFirmware.h>
#include <General/IPAddress.h>
#if SUPPORT_MULTICAST_DISCOVERY
#include "fgmc_header.h"
/// array size definitions
#define SIZE_EEPROM_MAC_ADDRESS 6
#define SIZE_EEPROM_PRODUCT_KEY 15
#define SIZE_EEPROM_SERIAL_NUMBER 5
#define SIZE_EEPROM_TEST_NUMBER 9
#define SIZE_EEPROM_NOC_CODE 50
/// fgmc port
//#define FGMC_PORT 10002
//#define FGMC_IP IP_BYTES2ADDR(239, 255, 2, 3) // Broadcast-IP
constexpr size_t IP_MAX_IFACES = 1;
class FGMCProtocol
{
public:
/// constructor
FGMCProtocol() noexcept;
/// this function initializes fgmc protocoll class
void init() noexcept;
/// this handles a fgmc frame
/// \param nConn connection
/// \param inputBufferAddress fgmc request frame
/// \param rxLength receive frame length
void handleStream(unsigned int iFaceId, uint8_t* inputBufferAddress, uint32_t rxLength) noexcept;
private:
/// this functions sends fgmc frame
/// \param pOutPointer sciopta network buffer
/// \param cmd cmd
/// \param length length
/// \param packetId packedId
/// \param segmentIndex segmentIndex
/// \param segmentCount segmentCount
void sendGenericHeader(uint8_t* tx_netbuf, FGMCCommand cmd, uint32_t length, uint32_t packetId, uint32_t segmentIndex, uint32_t segmentCount) noexcept;
/// fgmc command "upload network informations"
/// \param inPacketId packedId
void cmdUnetinf(uint32_t inPacketId) noexcept;
/// fgmc command "download network information"
/// \param pInCmdHeader request header network information header
/// \param inPacketId packedId
void cmdDnetinf(FGMC_ReqDownloadNetInfoHeader* pInCmdHeader, uint32_t inPacketId) noexcept;
/// fgmc command "reboot"
/// \param inPacketId packedId
void cmdReboot(uint32_t inPacketId) noexcept;
/// fgmc command "identify"
/// \param pInCmdHeader request header identify
/// \param inPacketId packedId
void cmdIdentify(FGMC_ReqIdentify* pInCmdHeader, uint32_t inPacketId) noexcept;
/// fgmc command "get firmware version"
/// \param inPacketId packedId
void cmdGetFirmwareVersion(uint32_t inPacketId) noexcept;
/// fgmc command "get supported commands"
/// \param inPacketId packedId
void cmdGetSupportedCommands(uint32_t inPacketId) noexcept;
void macToString(uint32_t interface) noexcept;
// connection data pointer
unsigned int iface_id_;
// product key from eeprom
// char eeprom_product_key_[SIZE_EEPROM_PRODUCT_KEY];
// char eeprom_noc_code_[SIZE_EEPROM_NOC_CODE];
// variables will be initialized at init phase
FGMCHwTypeId fgmc_device_id_;
uint32_t fgmc_application_type_;
uint8_t tx_netbuf_[SIZE_FGMC_RES_MAX];
struct InterfaceData
{
char unique_id_[SIZE_FGMC_DEST_ID];
IPAddress configuredIpAddress, configuredNetmask, configuredGateway;
static constexpr uint32_t ringBufferSize = 10;
uint32_t packetIdBuffer[ringBufferSize];
uint32_t packetIdIndex;
InterfaceData() noexcept;
/// insert used packet-id
/// \param packetId packedId
void insertPacketId(uint32_t packetId) noexcept;
/// check if packet id is already used
/// \param packetId packedId
bool isPacketInBuffer(uint32_t packetId) noexcept;
};
InterfaceData ifaceData[IP_MAX_IFACES];
};
#endif // SUPPORT_MULTICAST_DISCOVERY
#endif // FGMC_PROTOCOL_H
|