8 #include "networktables2/connection/NetworkTableConnection.h"
9 #include "networktables2/connection/BadMessageException.h"
13 ioStream(new
DataIOStream(_ioStream)), typeManager(_typeManager) {
16 NetworkTableConnection::~NetworkTableConnection(){
20 void NetworkTableConnection::SetIOStream(
IOStream* stream)
22 ioStream->SetIOStream(stream);
25 void NetworkTableConnection::close() {
34 void NetworkTableConnection::flush() {
41 void NetworkTableConnection::sendMessageHeader(
42 NetworkTableMessageType messageType) {
45 ioStream->writeByte((uint8_t) messageType);
49 void NetworkTableConnection::sendKeepAlive() {
52 sendMessageHeader(KEEP_ALIVE);
57 void NetworkTableConnection::sendClientHello() {
60 sendMessageHeader(CLIENT_HELLO);
61 ioStream->write2BytesBE(PROTOCOL_REVISION);
65 void NetworkTableConnection::sendServerHelloComplete() {
68 sendMessageHeader(SERVER_HELLO_COMPLETE);
73 void NetworkTableConnection::sendProtocolVersionUnsupported() {
76 sendMessageHeader(PROTOCOL_VERSION_UNSUPPORTED);
77 ioStream->write2BytesBE(PROTOCOL_REVISION);
85 sendMessageHeader(ENTRY_ASSIGNMENT);
86 ioStream->writeString(entry.
name);
87 ioStream->writeByte(entry.GetType()->id);
88 ioStream->write2BytesBE(entry.GetId());
97 sendMessageHeader(FIELD_UPDATE);
98 ioStream->write2BytesBE(entry.GetId());
105 int messageType = ioStream->readByte();
106 switch (messageType) {
111 uint16_t protocolRevision = ioStream->read2BytesBE();
112 adapter.clientHello(protocolRevision);
115 case SERVER_HELLO_COMPLETE: {
116 adapter.serverHelloComplete();
119 case PROTOCOL_VERSION_UNSUPPORTED: {
120 uint16_t protocolRevision = ioStream->read2BytesBE();
121 adapter.protocolVersionUnsupported(protocolRevision);
124 case ENTRY_ASSIGNMENT: {
125 std::string* entryName = ioStream->readString();
126 TypeId typeId = ioStream->readByte();
129 char exceptionMessageBuffer[50];
130 sprintf (exceptionMessageBuffer,
"Unknown data type: %#x", typeId);
133 EntryId entryId = ioStream->read2BytesBE();
134 SequenceNumber entrySequenceNumber = ioStream->read2BytesBE();
136 adapter.offerIncomingAssignment(
new NetworkTableEntry(entryId, *entryName, entrySequenceNumber, entryType, value));
142 EntryId entryId = ioStream->read2BytesBE();
143 SequenceNumber entrySequenceNumber = ioStream->read2BytesBE();
146 char exceptionMessageBuffer[50];
147 sprintf (exceptionMessageBuffer,
"Received update for unknown entry id: %d", entryId);
152 adapter.offerIncomingUpdate(entry, entrySequenceNumber, value);
157 char exceptionMessageBuffer[50];
158 sprintf (exceptionMessageBuffer,
"Unknown Network Table Message Type: %d", messageType);
virtual EntryValue readValue(DataIOStream &is)=0
NetworkTableConnection(IOStream *stream, NetworkTableEntryTypeManager &typeManager)
void SendValue(DataIOStream &iostream)
SequenceNumber GetSequenceNumber()
NetworkTableEntryType * GetType(TypeId type)
virtual void deleteValue(EntryValue value)