#include "nbus_slave.h" #if MODULE_SLAVE == 1 void nbus_slave_unicastToSensorGet(nBus_TypeDef *nbus){ switch(nbus->function_code.function){ case CMD_SENSOR_TYPE: { nBus_sensorType_t t = nbus->interface->getType(nbus->sensorInfo.address); if (t == TYPE_UNKNOWN) { setErrorResponse(nbus, ILLEGAL_DEVICE_ADDRESS); break; } nbus->tx_buffer[4] = t; nbus->tx_length += 1; } break; case CMD_PARAM: { if (nbus->rx_length >= 5){ if (nbus->interface->hasParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3]) == 0) { setErrorResponse(nbus, PARAM_NOT_IMPLEMENTED); break; } nbus->tx_buffer[4] = nbus->tx_buffer[3]; nbus->tx_buffer[5] = nbus->interface->getParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3]); nbus->tx_length += 2; } else { nBus_param_t* params = nbus_interface_allParams(); for(uint8_t i=0; i < nbus_interface_allParamsCount() ; i++){ if(nbus->interface->hasParam(i, params[i])){ nbus->tx_buffer[4+2*i] = params[i]; nbus->tx_buffer[5+2*i] = nbus->interface->getParam(i, params[i]); nbus->tx_length += 2; } } } // alebo nbus->memoryInterface->getParam(nbus->sensorInfo.address, 0x05); } break; case CMD_DATA: { uint8_t cnt = nbus->interface->getData(nbus->sensorInfo.address, &nbus->tx_buffer[4]); if (cnt == 0){ setErrorResponse(nbus, DEVICE_BUSY); return; } nbus->tx_length += cnt; } break; default: { setErrorResponse(nbus, ILLEGAL_FUNCTION); } } } void nbus_slave_unicastToSensorSet(nBus_TypeDef *nbus){ switch(nbus->function_code.function){ case CMD_PARAM: { nBus_param_t p = nbus->interface->setParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3], nbus->tx_buffer[4]); if (p == PARAM_NONE) { setErrorResponse(nbus, PARAM_NOT_IMPLEMENTED); break; } nbus->tx_buffer[4] = OK_CODE; nbus->tx_length += 1; } break; case CMD_DATA: { nbus->interface->setData(&nbus->rx_buffer[3]); nbus->tx_buffer[4] = OK_CODE; nbus->tx_length += 1; } break; default: { setErrorResponse(nbus, ILLEGAL_FUNCTION); } } } #endif