Exemplo n.º 1
0
	ByteStream EstFilterMessageFormat::buildCommand_set(const InertialChannels& channels, uint16 sampleRateBase)
	{
		//container to hold the command's field data
		ByteStream fieldData;

		//add the command selector byte
		fieldData.append_uint8(static_cast<uint8>(Inertial_Commands::cmd_setCurrent));

		//add the number of channels
		fieldData.append_uint8(static_cast<uint8>(channels.size()));

		//loop through each channel in the vector of channels
		for(InertialChannel ch : channels)
		{
			//if we find a channel not in the descriptor set
			if(ch.descriptorSet() != DescriptorSet::DESC_SET_DATA_EST_FILTER)
			{
				throw Error("InertialChannel (" + Utils::toStr(ch.channelField()) + ") is not in the Estimation Filter descriptor set");
			}

			//validate the sample rate for the channel
			ch.validateSampleRate(sampleRateBase);

			//add the field descriptor and rate decimation
			fieldData.append_uint8(ch.fieldDescriptor());
			fieldData.append_uint16(ch.rateDecimation(sampleRateBase));
		}

		//build and return the command bytes
		return GenericInertialCommand::buildCommand(CMD_ID, fieldData.data());
	}
Exemplo n.º 2
0
    ByteStream ReadSingleSensor::buildCommand(NodeAddress nodeAddress, uint8 channelNumber)
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(WirelessProtocol::cmdId_readSingleSensor); //Command ID
        cmd.append_uint16(nodeAddress);                             //Node address    (2 bytes)
        cmd.append_uint8(0x01);                                     //Command Byte
        cmd.append_uint8(channelNumber);                            //Channel number

        return cmd;
    }
Exemplo n.º 3
0
	//==========================================================================================
	//ESTIMATION FILTER MESSAGE FORMAT
	ByteStream EstFilterMessageFormat::buildCommand_get()
	{
		//container to hold the command's field data
		ByteStream fieldData;

		//add the command selector byte
		fieldData.append_uint8(static_cast<uint8>(Inertial_Commands::cmd_getCurrent));

		//"get" has no channels, so add 0 
		fieldData.append_uint8(0);

		//build and return the command bytes
		return GenericInertialCommand::buildCommand(CMD_ID, fieldData.data());
	}
    ByteStream InertialPacketBuilder::buildPacket()
    {
        uint8 payloadLen = 0;

        ByteStream payloadBytes;

        //loop through all the fields
        for(InertialDataField field : m_fields)
        {
            //field length = (1 field len byte + 1 field desc byte + n field data bytes)
            size_t fieldLen = (1 + 1 + field.fieldData().size());
            
            //increase the payload length 
            payloadLen += static_cast<uint8>(fieldLen);

            //add the field length byte to the payloadBytes
            payloadBytes.append_uint8(static_cast<uint8>(fieldLen));

            //add the field descriptor byte to the payloadBytes
            payloadBytes.append_uint8(field.fieldDescriptor());

            //add the field data bytes to the payloadBytes (if any)
            payloadBytes.appendByteStream(field.fieldData());
        }

        ByteStream result;

        //add the first two "Sync" bytes
        result.append_uint16(InertialPacketInfo::INERTIAL_PACKET_START_OF_PACKET);

        //add the descriptor set byte
        result.append_uint8(m_descriptorSet);

        //add the payload length byte
        result.append_uint8(payloadLen);

        //add the payloadBytes that we just built up
        result.appendByteStream(payloadBytes);

        //calculate the checksum for the packet from all the bytes
        uint16 checksum = result.calculateFletcherChecksum(0, result.size() - 1);

        //add the checksum bytes
        result.append_uint16(checksum);

        //return the result bytes that we created
        return result;
    }
    ByteStream BaseStation_ReadEeprom_v2::buildCommand(uint16 eepromAddress)
    {
        //build the command ByteStream
        ByteStream cmd;

        cmd.append_uint8(0xAA);                                                   //Start of packet
        cmd.append_uint8(0x0E);                                                   //Delivery Stop Flag
        cmd.append_uint8(0x30);                                                   //App Data Type
        cmd.append_uint16(WirelessProtocol::BASE_STATION_ADDRESS);                //Base Station Address
        cmd.append_uint8(0x04);                                                   //Payload length
        cmd.append_uint16(WirelessProtocol::cmdId_base_readEeprom_v2);            //Command ID
        cmd.append_uint16(eepromAddress);                                         //eeprom address to read
        cmd.append_uint16(cmd.calculateSimpleChecksum(1, 9));                     //checksum
        
        //return the built command bytes
        return cmd;
    }
    ByteStream BaseStation_SetBeacon_v2::buildCommand(uint32 utcTime)
    {
        //build the command ByteStream
        ByteStream cmd;

        cmd.append_uint8(0xAA);                                               //Start of packet
        cmd.append_uint8(0x0E);                                               //Delivery Stop Flag
        cmd.append_uint8(0x30);                                               //App Data Type
        cmd.append_uint16(WirelessProtocol::BASE_STATION_ADDRESS);            //Base Station Address
        cmd.append_uint8(0x06);                                               //Payload length
        cmd.append_uint16(WirelessProtocol::cmdId_base_setBeacon);            //Command ID
        cmd.append_uint32(utcTime);                                           //Timestamp for Beacon
        cmd.append_uint16(cmd.calculateSimpleChecksum(1, 11));                //checksum

        //return the built command bytes
        return cmd;
    }
Exemplo n.º 7
0
    ByteStream ShortPing::buildCommand(NodeAddress nodeAddress)
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(WirelessProtocol::cmdId_shortPing);
        cmd.append_uint16(nodeAddress);    //Node address    (2 bytes)

        return cmd;
    }
Exemplo n.º 8
0
    ByteStream LongPing::buildCommand(NodeAddress nodeAddress)
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(0xAA);                                     //Start of Packet
        cmd.append_uint8(0x05);                                     //Delivery Stop Flag
        cmd.append_uint8(0x00);                                     //App Data Type
        cmd.append_uint16(nodeAddress);                             //Node address    (2 bytes)
        cmd.append_uint8(0x02);                                     //Payload length
        cmd.append_uint16(WirelessProtocol::cmdId_longPing);        //Command ID    (2 bytes)

        //calculate the checksum of bytes 2-8
        uint16 checksum = cmd.calculateSimpleChecksum(1, 7);

        cmd.append_uint16(checksum);        //Checksum        (2 bytes)

        return cmd;
    }
Exemplo n.º 9
0
	ByteStream StartNonSyncSampling::buildCommand(NodeAddress nodeAddress)
	{
		//build the command ByteStream
		ByteStream cmd;
		cmd.append_uint8(0xAA);				//Start of Packet
		cmd.append_uint8(0x05);				//Delivery Stop Flag
		cmd.append_uint8(0x00);				//App Data Type
		cmd.append_uint16(nodeAddress);		//Node address	(2 bytes)
		cmd.append_uint8(0x02);				//Payload length
		cmd.append_uint16(0x38);			//Command ID	(2 bytes)

		//calculate the checksum of bytes 2-10
		uint16 checksum = cmd.calculateSimpleChecksum(1, 7);

		cmd.append_uint16(checksum);		//Checksum		(2 bytes)

		return cmd;
	}
Exemplo n.º 10
0
    ByteStream BaseStation_Ping_v2::buildCommand()
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(0xAA);                                        //Start of Packet
        cmd.append_uint8(0x0E);                                        //Delivery Stop Flag
        cmd.append_uint8(0x30);                                        //App Data Type
        cmd.append_uint16(WirelessProtocol::BASE_STATION_ADDRESS);     //Base Station Address
        cmd.append_uint8(0x02);                                        //Payload length
        cmd.append_uint16(WirelessProtocol::cmdId_basePing_v2);        //Command ID

        //calculate the checksum of bytes 2-8
        uint16 checksum = cmd.calculateSimpleChecksum(1, 7);

        cmd.append_uint16(checksum);    //Checksum

        return cmd;
    }
Exemplo n.º 11
0
    ByteStream ReadEeprom_v2::buildCommand(NodeAddress nodeAddress, uint16 eepromAddress)
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(0xAA);                                     //Start of Packet
        cmd.append_uint8(0x05);                                     //Delivery Stop Flag
        cmd.append_uint8(0x00);                                     //App Data Type
        cmd.append_uint16(nodeAddress);                             //Node address    (2 bytes)
        cmd.append_uint8(0x04);                                     //Payload length
        cmd.append_uint16(WirelessProtocol::cmdId_readEeprom_v2);   //Command ID    (2 bytes)
        cmd.append_uint16(eepromAddress);                           //EEPROM Address (2 bytes)

        //calculate the checksum of bytes 2-10
        uint16 checksum = cmd.calculateSimpleChecksum(1, 9);

        cmd.append_uint16(checksum);        //Checksum        (2 bytes)

        return cmd;
    }
    ByteStream StartNonSyncSampling_v2::buildCommand(NodeAddress nodeAddress)
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(WirelessPacket::ASPP_V1_START_OF_PACKET_BYTE);    //Start of Packet
        cmd.append_uint8(0x05);                                            //Delivery Stop Flag
        cmd.append_uint8(0x00);                                            //App Data Type
        cmd.append_uint16(nodeAddress);                                    //Node Address
        cmd.append_uint8(10);                                              //Payload Length
        cmd.append_uint16(WirelessProtocol::cmdId_startLdc_v2);            //Command ID
        cmd.append_uint64(Utils::getCurrentSystemTime());

        //calculate the checksum of bytes 2-16
        uint16 checksum = cmd.calculateSimpleChecksum(1, 15);

        cmd.append_uint16(checksum);        //Checksum        (2 bytes)

        return cmd;
    }
Exemplo n.º 13
0
    ByteStream AutoBalance_v2::buildCommand(NodeAddress nodeAddress, uint8 channelNumber, float targetPercent)
    {
        //build the command ByteStream
        ByteStream cmd;
        cmd.append_uint8(0xAA);                                               //Start of Packet
        cmd.append_uint8(0x05);                                               //Delivery Stop Flag
        cmd.append_uint8(0x00);                                               //App Data Type
        cmd.append_uint16(nodeAddress);                                       //Node address
        cmd.append_uint8(0x07);                                               //Payload Length
        cmd.append_uint16(WirelessProtocol::cmdId_autoBalance_v2);            //Command Id
        cmd.append_uint8(channelNumber);                                      //Channel Number
        cmd.append_float(targetPercent);                                      //Target Percentage Value

        //calculate the checksum of bytes 2-13
        uint16 checksum = cmd.calculateSimpleChecksum(1, 12);

        cmd.append_uint16(checksum);        //Checksum

        return cmd;
    }
    ByteStream BaseStation_RfSweepStart::buildCommand(uint32 min, uint32 max, uint32 interval, uint16 options)
    {
        //build the command ByteStream
        ByteStream cmd;

        cmd.append_uint8(0xAA);                                             //Start of packet
        cmd.append_uint8(0x0E);                                             //Delivery Stop Flag
        cmd.append_uint8(WirelessPacket::packetType_baseCommand);           //App Data Type
        cmd.append_uint16(WirelessProtocol::BASE_STATION_ADDRESS);          //Base Station Address
        cmd.append_uint8(0x10);                                             //Payload length
        cmd.append_uint16(WirelessProtocol::cmdId_base_rfScan);             //Command ID
        cmd.append_uint16(options);
        cmd.append_uint32(min);
        cmd.append_uint32(max);
        cmd.append_uint32(interval);
        cmd.append_uint16(cmd.calculateSimpleChecksum(1, 21));              //checksum

        //return the built command bytes
        return cmd;
    }
Exemplo n.º 15
0
WirelessPacket buildAutoCalCompletionResponse(int nodeAddress)
{
	ByteStream payload;
	payload.append_uint16(0x0064);	//cmd id
	payload.append_uint8(0x00);	//completion flag
	payload.append_uint8(0x00);	//ch1 error flag
	payload.append_float(0.0f);	//ch1 offset
	payload.append_uint8(0x00);	//ch2 error flag
	payload.append_float(0.0f);	//ch2 offset
	payload.append_uint8(0x00);	//ch3 error flag
	payload.append_float(0.0f);	//ch3 offset
	payload.append_float(20.5f);//temperature

	//build the correct packet response first
	WirelessPacket packet;
	packet.deliveryStopFlags(DeliveryStopFlags::fromByte(0x07));
	packet.type(WirelessPacket::packetType_reply);
	packet.nodeAddress(nodeAddress);
	packet.payload(payload.data());

	return packet;
}
Exemplo n.º 16
0
WirelessPacket buildAutoCalNodeRecResponse(int nodeAddress)
{
	ByteStream payload;
	payload.append_uint16(0x0064);	//cmd id
	payload.append_uint8(0x00);	//status flag
	payload.append_float(5.0f);	//time to completion

	WirelessPacket packet;
	packet.deliveryStopFlags(DeliveryStopFlags::fromByte(0x07));
	packet.type(WirelessPacket::packetType_NodeReceived);
	packet.nodeAddress(nodeAddress);
	packet.payload(payload.data());

	return packet;
}