From MicroCART Senior Design
The network subsystem is responsible for handling network packets sent across the network, using both UDP and TCP protocols.
Creating a New Network Packet
To create a new network packet, follow the procedure below:
- The packets are currently located in the packets folder, so open up a file browser to that folder.
- Copy an existing packet, the motor_control.h & motor_control.cpp files are a good base file. Rename them to something unique for its purpose.
- Edit Makefile.am in the packets folder and add the .cpp file to the list of files to be compiled
- Edit the source code & change the class name & add any data fields the class needs to the header file.
- Add an opcode for the packet to src/defines.h. This opcode is a unique identifier to identify this packet from all the other packets sent out by the system.
- Make sure to change the opcode for the packet in the .cpp file.
- Edit all_packets.h and add an include for the new packet header file.
- Edit base_packet.cpp. Look for the read method, and follow the existing code to add the new packet.
- Edit the .cpp file and make sure the data for the packet is being read / written in the read / write methods.
- Consider adding getter / setter methods to access the packet data
- Recompile (From the root of the project)