#include #if MODULE_SLAVE == 1 void nbus_slave_unicastToModuleGet(nBus_TypeDef *nbus){ switch(nbus->function_code.function){ case CMD_ECHO: { for(uint8_t i=3 ; irx_length-1 ; i++){ nbus->tx_buffer[i+1] = nbus->rx_buffer[i]; } nbus->tx_length += (nbus->rx_length-4); } break; case CMD_SENSOR_CNT: { nbus->tx_buffer[4] = nbus->interface->getSensorCount(); nbus->tx_length += 1; } break; case CMD_DATA: { //response: sensor1_index:sensor1_data | sensor2_index:sensor2_data | ... nbus->tx_length += nbus->interface->getData(0 , &nbus->tx_buffer[4]); } break; case CMD_SENSOR_TYPE: { //response: sensor1_index:sensor1_type | sensor2_index:sensor2_type | ... for(uint8_t i = 0; i < nbus->interface->getSensorCount() ; i++){ nbus->tx_buffer[4+2*i] = i; nbus->tx_buffer[5+2*i] = nbus->interface->getType(i); nbus->tx_length += 2; } } break; case CMD_INFO: { switch(nbus->rx_buffer[3]){ case INFO_MODULE_NAME: nbus->tx_buffer[4] = MODULE_NAME[0]; nbus->tx_buffer[5] = MODULE_NAME[1]; nbus->tx_buffer[6] = MODULE_NAME[2]; nbus->tx_buffer[7] = MODULE_NAME[3]; nbus->tx_buffer[8] = MODULE_NAME[4]; nbus->tx_buffer[9] = MODULE_NAME[5]; nbus->tx_buffer[10] = MODULE_NAME[6]; nbus->tx_buffer[11] = MODULE_NAME[7]; nbus->tx_length += 8; break; case INFO_MODULE_TYPE: nbus->tx_buffer[4] = MODULE_TYPE[0]; nbus->tx_buffer[5] = MODULE_TYPE[1]; nbus->tx_buffer[6] = MODULE_TYPE[2]; nbus->tx_length += 3; break; case INFO_MODULE_UUID: // Reference manual: Unique device ID registers uint32_t (*unique_id_3) = (uint32_t*)(0x1FF80064); // BASE address + 0x14 0ffset *(nbus->tx_buffer) = (uint32_t)unique_id_3; nbus->tx_length += 4; break; case INFO_MODULE_FW: nbus->tx_buffer[4] = VERSION_FW[0]; nbus->tx_buffer[5] = '.'; nbus->tx_buffer[6] = VERSION_FW[1]; nbus->tx_length += 3; break; case INFO_MODULE_HW: nbus->tx_buffer[4] = VERSION_HW[0]; nbus->tx_buffer[5] = '.'; nbus->tx_buffer[6] = VERSION_HW[1]; nbus->tx_length += 3; break; } } break; default: { setErrorResponse(nbus, ILLEGAL_FUNCTION); } } } void nbus_slave_unicastToModuleSet(nBus_TypeDef *nbus){ switch(nbus->function_code.function){ case CMD_PARAM: { //same as nbus_unicastToSensorSet 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; case CMD_SLEEP: { nbus->tx_buffer[4] = OK_CODE; nbus->tx_length += 1; } break; case CMD_WAKEUP: { nbus->tx_buffer[4] = OK_CODE; nbus->tx_length += 1; } break; default: { setErrorResponse(nbus, ILLEGAL_FUNCTION); } } } #endif