char *GetAttributesRequest::encode(int seq, int &sz) { int n; char *p = m_buf; { char *h = getHeader(seq, n); memcpy(p, h, n); p += n; } unsigned short attrNum = m_attrNames.size(); BINARY_SET_DATA_S_INCR(p, unsigned short, attrNum); for (C::iterator i=m_attrNames.begin(); i!=m_attrNames.end(); i++) { const char *str = i->c_str(); BINARY_SET_STRING_INCR(p, str); } { char *f = getFooter(n); memcpy(p, f, n); p += n; } sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char * NSQueryResult::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); unsigned short found = m_service? 1: 0; BINARY_SET_DATA_S_INCR(p, unsigned short, found); if (found) { const char *n = m_service->name(); BINARY_SET_STRING_INCR(p, n); unsigned short k = m_service->kind(); BINARY_SET_DATA_S_INCR(p, unsigned short, k); const char *h = m_service->hostname(); BINARY_SET_STRING_INCR(p, h); int port = m_service->port(); BINARY_SET_DATA_L_INCR(p, int, port); } p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *NSPingerRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); BINARY_SET_DATA_L_INCR(p, Service::Kind, m_kind); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *GetGravityModeRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); BINARY_SET_STRING_INCR(p, m_name); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char * NSPingerResult::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); unsigned short v = m_active? 1: 0; BINARY_SET_DATA_S_INCR(p, unsigned short, v); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *SetDynamicsModeRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); BINARY_SET_STRING_INCR(p, m_name); BINARY_SET_BOOL_INCR(p, m_dynamics); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *NSQueryRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); unsigned short k = m_kind; BINARY_SET_DATA_S_INCR(p, unsigned short, k); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *GetAngularVelocityRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); { BINARY_SET_STRING_INCR(p, m_name); } p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *SetMassRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); { BINARY_SET_STRING_INCR(p, m_name); } BINARY_SET_DOUBLE_INCR(p, m_mass); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *GetLinearVelocityResult::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); BINARY_SET_STRING_INCR(p, m_name); BINARY_SET_DOUBLE_INCR(p, m_x); BINARY_SET_DOUBLE_INCR(p, m_y); BINARY_SET_DOUBLE_INCR(p, m_z); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *RawDataEncoder::encode(int seq, int &sz) { char *p = m_buf; { int n; char *h = getHeader(seq, n); memcpy(p, h, n); p += n; } if (seq == 0) { int n; char *pp = getDataHeader(n); memcpy(p, pp, n); p += n; } else { // Image data int N = packetNum(); int datalen = 0; if (seq + 1 < N) { datalen = UNIT_DATA_SIZE; } else { // last packet int datasize = getDataLen(); int left = datasize % UNIT_DATA_SIZE; datalen = left != 0? left: UNIT_DATA_SIZE; } BINARY_SET_DATA_S_INCR(p, unsigned short, datalen); char *data = getData(); char *pp = data + UNIT_DATA_SIZE*(seq-1); memcpy(p, pp, datalen); p += datalen; } { int n; char *f = getFooter(n); memcpy(p, f, n); p += n; } sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *NoDataEncoder::encode(int seq, int &sz) { int n; char *p = m_buf; char *h = getHeader(seq, n); memcpy(p, h, n); p += n; char *f = getFooter(n); memcpy(p, f, n); p += n; sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *AddForceToPartsRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); BINARY_SET_STRING_INCR(p, m_name); BINARY_SET_STRING_INCR(p, m_parts); BINARY_SET_DOUBLE_INCR(p, m_x); BINARY_SET_DOUBLE_INCR(p, m_y); BINARY_SET_DOUBLE_INCR(p, m_z); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *AddTorqueRequest::encode(int seq, int &sz) { char *p = m_buf; p = setHeader(p, seq); { BINARY_SET_STRING_INCR(p, m_name); } BINARY_SET_DOUBLE_INCR(p, m_x); BINARY_SET_DOUBLE_INCR(p, m_y); BINARY_SET_DOUBLE_INCR(p, m_z); BINARY_SET_BOOL_INCR(p, m_relf); p = setFooter(p); sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
char *DisplayText::encode(int seq, int &sz) { int n; char *p = m_buf; { char *h = getHeader(seq, n); memcpy(p, h, n); p += n; } { BINARY_SET_DATA_S_INCR(p, short, m_fs); BINARY_SET_DATA_S_INCR(p, short, m_color); BINARY_SET_STRING_INCR(p, m_msg.c_str()); } { char *f = getFooter(n); memcpy(p, f, n); p += n; } sz = p - m_buf; setPacketSize(m_buf, sz); return m_buf; }
void config(char baud, char recon, char timeo, int packetSize) { int baudrate = -1; switch (baud) { case 'a': baudrate = B0; break; case 'b': baudrate = B50; break; case 'c': baudrate = B75; break; case 'd': baudrate = B110; break; case 'e': baudrate = B134; break; case 'f': baudrate = B150; break; case 'g': baudrate = B200; break; case 'h': baudrate = B300; break; case 'i': baudrate = B600; break; case 'j': baudrate = B1200; break; case 'k': baudrate = B1800; break; case 'l': baudrate = B2400; break; case 'm': baudrate = B4800; break; case 'n': baudrate = B9600; break; case 'o': baudrate = B19200; break; case 'p': baudrate = B38400; break; case 'q': baudrate = B57600; break; case 'r': baudrate = B115200; break; case 's': baudrate = B230400; break; case 't': baudrate = B460800; break; default: break; } int reconect_tries = -1; switch (recon) { case 'a': reconect_tries = 1; break; case 'b': reconect_tries = 3; break; case 'c': reconect_tries = 5; break; case 'd': reconect_tries = 7; break; default: break; } /* int timeout = -1; switch (timeo) { case 'a': timeout = 2; break; case 'b': timeout = 3; break; case 'c': timeout = 5; break; case 'd': timeout = 8; break; default: break; } */ set_basic_definitions(/*timeout,*/ reconect_tries, 0, baudrate, packetSize); setPacketSize(packetSize); }