|
|
@@ -1,12 +1,95 @@
|
|
|
#include "nbus_impl.h"
|
|
|
+#include "app_bridge.h"
|
|
|
+
|
|
|
+
|
|
|
+inline static void setErrorResponse(nBus_TypeDef *nbus, uint8_t code){
|
|
|
+ nbus->function_code.error = 1;
|
|
|
+ nbus->tx_buffer[4] = code;
|
|
|
+ nbus->tx_length += 1;
|
|
|
+}
|
|
|
|
|
|
|
|
|
void nbus_unicastToSensorGet(nBus_TypeDef *nbus){
|
|
|
- ;
|
|
|
+ switch(nbus->function_code.function){
|
|
|
+ case 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;
|
|
|
+ }
|
|
|
+ nbus->tx_buffer[4] = nbus->interface->getParam(nbus->rx_buffer[3], (nBus_param_t)nbus->tx_buffer[4]);
|
|
|
+ nbus->tx_length += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case CMD_DATA:
|
|
|
+ {
|
|
|
+ uint8_t cnt = nbus->interface->getData(&nbus->tx_buffer[4]);
|
|
|
+ nbus->tx_length += cnt;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ setErrorResponse(nbus, ILLEGAL_FUNCTION);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void nbus_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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void nbus_unicastToModuleGet(nBus_TypeDef *nbus){
|
|
|
@@ -27,30 +110,53 @@ void nbus_unicastToModuleGet(nBus_TypeDef *nbus){
|
|
|
}
|
|
|
nbus->tx_length += (nbus->rx_length-4);
|
|
|
}
|
|
|
+
|
|
|
break;
|
|
|
|
|
|
- case CMD_PARAM:
|
|
|
+ case CMD_SENSOR_CNT:
|
|
|
{
|
|
|
- nbus->tx_buffer[4] = OK_CODE;
|
|
|
+ nbus->tx_buffer[4] = nbus->interface->getSensorCount();
|
|
|
nbus->tx_length += 1;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
+ case SENSOR_TYPE:
|
|
|
+ {
|
|
|
+ //response: sensor1_index:sensor2_type | sensor1_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;
|
|
|
+
|
|
|
default:
|
|
|
{
|
|
|
- nbus->function_code.error = 1;
|
|
|
- nbus->tx_buffer[4] = ILLEGAL_FUNCTION;
|
|
|
- nbus->tx_length += 1;
|
|
|
+ setErrorResponse(nbus, ILLEGAL_FUNCTION);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void nbus_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;
|
|
|
}
|
|
|
@@ -72,9 +178,7 @@ void nbus_unicastToModuleSet(nBus_TypeDef *nbus){
|
|
|
|
|
|
default:
|
|
|
{
|
|
|
- nbus->function_code.error = 1;
|
|
|
- nbus->tx_buffer[4] = ILLEGAL_FUNCTION;
|
|
|
- nbus->tx_length += 1;
|
|
|
+ setErrorResponse(nbus, ILLEGAL_FUNCTION);
|
|
|
}
|
|
|
}
|
|
|
|