Exemplo n.º 1
0
/**
 * Send a message on the CAN bus through the CAN driver in FRC_NetworkCommunication
 *
 * Trusted messages require a 2-byte token at the beginning of the data payload.
 * If the message being sent is trusted, make space for the token.
 *
 * @param messageID The messageID to be used on the CAN bus
 * @param data The up to 8 bytes of data to be sent with the message
 * @param dataSize Specify how much of the data in "data" to send
 * @return Status of send call
 */
int32_t CANJaguar::sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize)
{
    static constexpr uint32_t kTrustedMessages[] = {
	    LM_API_VOLT_T_EN, LM_API_VOLT_T_SET, LM_API_SPD_T_EN, LM_API_SPD_T_SET,
	    LM_API_VCOMP_T_EN, LM_API_VCOMP_T_SET, LM_API_POS_T_EN, LM_API_POS_T_SET,
	    LM_API_ICTRL_T_EN, LM_API_ICTRL_T_SET};
    int32_t status=0;

    for (uint8_t i=0; i<(sizeof(kTrustedMessages)/sizeof(kTrustedMessages[0])); i++)
    {
	if ((kFullMessageIDMask & messageID) == kTrustedMessages[i])
	{
	    uint8_t dataBuffer[8];
	    dataBuffer[0] = 0;
	    dataBuffer[1] = 0;
	    // Make sure the data will still fit after adjusting for the token.
	    if (dataSize > 6)
	    {
		// TODO: I would rather this not have to set the global error
		wpi_setGlobalWPIErrorWithContext(ParameterOutOfRange, "dataSize > 6");
		return 0;
	    }
	    for (uint8_t j=0; j < dataSize; j++)
	    {
		dataBuffer[j + 2] = data[j];
	    }
	    FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, dataBuffer, dataSize + 2, &status);
	    return status;
	}
    }
    FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, data, dataSize, &status);
    return status;
}
Exemplo n.º 2
0
/**
 * Maps the specified key (where the key is the name of the {@link
 * SmartDashboardNamedData}
 * to the specified value in this table.
 * The value can be retrieved by calling the get method with a key that is equal
 * to the original key.
 * @param value the value
 */
void SmartDashboard::PutData(NamedSendable *value) {
  if (value == nullptr) {
    wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
    return;
  }
  PutData(value->GetName(), value);
}
Exemplo n.º 3
0
/**
 * Returns the value at the specified key.
 * @param keyName the key
 * @return the value
 */
Sendable *SmartDashboard::GetData(llvm::StringRef key) {
  std::shared_ptr<ITable> subtable(m_table->GetSubTable(key));
  Sendable *data = m_tablesToData[subtable];
  if (data == nullptr) {
    wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
    return nullptr;
  }
  return data;
}
Exemplo n.º 4
0
/**
 * Maps the specified key to the specified value in this table.
 * The key can not be nullptr.
 * The value can be retrieved by calling the get method with a key that is equal
 * to the original key.
 * @param keyName the key
 * @param value the value
 */
void SmartDashboard::PutData(llvm::StringRef key, Sendable *data) {
  if (data == nullptr) {
    wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
    return;
  }
  std::shared_ptr<ITable> dataTable(m_table->GetSubTable(key));
  dataTable->PutString("~TYPE~", data->GetSmartDashboardType());
  data->InitTable(dataTable);
  m_tablesToData[dataTable] = data;
}
Exemplo n.º 5
0
/**
 * Get an instance of an Analog Module.
 * 
 * Singleton analog module creation where a module is allocated on the first use
 * and the same module is returned on subsequent uses.
 * 
 * @param moduleNumber The analog module to get (1 or 2).
 * @return A pointer to the AnalogModule.
 */
AnalogModule* AnalogModule::GetInstance(UINT8 moduleNumber)
{
	if (CheckAnalogModule(moduleNumber))
	{
		return (AnalogModule*)GetModule(nLoadOut::kModuleType_Analog, moduleNumber);
	}

	// If this wasn't caught before now, make sure we say what's wrong before we crash
	char buf[64];
	snprintf(buf, 64, "Analog Module %d", moduleNumber);
	wpi_setGlobalWPIErrorWithContext(ModuleIndexOutOfRange, buf);

	return NULL;
}
Exemplo n.º 6
0
/**
 * Get an instance of an Digital Module.
 * Singleton digital module creation where a module is allocated on the first use
 * and the same module is returned on subsequent uses.
 *
 * @param moduleNumber The digital module to get (1 or 2).
 */
DigitalModule* DigitalModule::GetInstance(uint8_t moduleNumber)
{
	if (CheckDigitalModule(moduleNumber))
	{
		return (DigitalModule *)GetModule(nLoadOut::kModuleType_Digital, moduleNumber);
	}

	// If this wasn't caught before now, make sure we say what's wrong before we crash
	char buf[64];
	sprintf(buf, "Digital Module %d", moduleNumber);
	wpi_setGlobalWPIErrorWithContext(ModuleIndexOutOfRange, buf);

	return NULL;
}