b15f/firmware/requests.cpp

122 lines
2.8 KiB
C++
Raw Normal View History

2019-03-26 14:02:58 +00:00
#include "requests.h"
void rqTestConnection()
{
2019-04-02 08:59:37 +00:00
uint8_t dummy = ((USART*) &usart)->readByte();
((USART*) &usart)->writeByte(USART::MSG_OK);
((USART*) &usart)->writeByte(dummy);
2019-03-26 14:02:58 +00:00
}
void rqBoardInfo()
{
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(3); // Anzahl an Strings
2019-03-27 14:48:36 +00:00
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeStr(DATE, sizeof(DATE));
((USART*) &usart)->writeStr(TIME, sizeof(TIME));
((USART*) &usart)->writeStr(FSRC, sizeof(FSRC));
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-26 14:02:58 +00:00
}
void rqTestIntConv()
{
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeInt(((USART*) &usart)->readInt() * 3);
2019-03-26 14:02:58 +00:00
}
2019-03-26 15:30:49 +00:00
void rqDigitalWrite0()
{
2019-04-02 08:59:37 +00:00
uint8_t port = ((USART*) &usart)->readByte();
((MCP23S17*) &beba0)->writePortA(port);
2019-03-26 15:30:49 +00:00
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-26 15:30:49 +00:00
}
void rqDigitalWrite1()
{
2019-04-02 08:59:37 +00:00
uint8_t port = ((USART*) &usart)->readByte();
((MCP23S17*) &beba1)->writePortA(port);
2019-03-26 15:30:49 +00:00
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-26 15:30:49 +00:00
}
void rqDigitalRead0()
{
2019-04-02 08:59:37 +00:00
uint8_t port = ((MCP23S17*) &beba0)->readPortB();
((USART*) &usart)->writeByte(port);
2019-03-26 15:30:49 +00:00
}
void rqDigitalRead1()
{
2019-04-02 08:59:37 +00:00
uint8_t port = ((MCP23S17*) &beba1)->readPortB();
((USART*) &usart)->writeByte(port);
2019-03-26 15:30:49 +00:00
}
void rqAnalogWrite0()
{
2019-04-02 08:59:37 +00:00
uint16_t value = ((USART*) &usart)->readInt();
((TLC5615*) &dac0)->setValue(value);
2019-03-26 15:30:49 +00:00
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-26 15:30:49 +00:00
}
void rqAnalogWrite1()
{
2019-04-02 08:59:37 +00:00
uint16_t value = ((USART*) &usart)->readInt();
((TLC5615*) &dac1)->setValue(value);
2019-03-26 15:30:49 +00:00
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-26 15:30:49 +00:00
}
void rqAnalogRead()
{
2019-04-02 08:59:37 +00:00
uint8_t channel = ((USART*) &usart)->readByte();
uint16_t value = ((ADU*) &adu)->getValue(channel);
((USART*) &usart)->writeInt(value);
2019-03-26 15:30:49 +00:00
}
2019-03-27 09:33:26 +00:00
void rqAdcDacStroke()
{
2019-04-02 08:59:37 +00:00
uint8_t channel_a = ((USART*) &usart)->readByte();
uint8_t channel_b = ((USART*) &usart)->readByte();
2019-03-27 09:49:26 +00:00
2019-04-02 08:59:37 +00:00
int16_t start = static_cast<int16_t>(((USART*) &usart)->readInt());
int16_t delta = static_cast<int16_t>(((USART*) &usart)->readInt());
int16_t count = static_cast<int16_t>(((USART*) &usart)->readInt());
2019-03-28 12:32:24 +00:00
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-27 09:33:26 +00:00
count *= delta;
2019-03-28 12:32:24 +00:00
for(int16_t i = start; i < count; i += delta)
2019-03-27 09:33:26 +00:00
{
2019-04-02 08:59:37 +00:00
((TLC5615*) &dac0)->setValue(i);
2019-03-27 14:48:36 +00:00
wdt_reset();
2019-03-28 14:22:17 +00:00
2019-04-02 08:59:37 +00:00
uint16_t val_a = ((ADU*) &adu)->getValue(channel_a);
uint16_t val_b = ((ADU*) &adu)->getValue(channel_b);
((USART*) &usart)->writeInt(val_a);
((USART*) &usart)->writeInt(val_b);
2019-03-29 12:35:18 +00:00
/*union doubleword
2019-03-28 14:22:17 +00:00
{
uint16_t word[2];
uint8_t byte[4];
};
union doubleword dw;
2019-04-02 08:59:37 +00:00
dw.word[0] = ((ADU*) &adu)->getValue(channel_a);
dw.word[1] = ((ADU*) &adu)->getValue(channel_b);
2019-03-28 14:22:17 +00:00
uint8_t ret = 0;
do
{
wdt_reset();
2019-04-02 08:59:37 +00:00
ret = ((USART*) &usart)->writeBlock(&(dw.byte[0]), 4);
2019-03-28 14:22:17 +00:00
if(ret == 0)
return;
2019-03-29 12:35:18 +00:00
} while(ret != USART::MSG_OK);*/
2019-03-27 09:33:26 +00:00
}
2019-04-02 08:59:37 +00:00
((USART*) &usart)->writeByte(USART::MSG_OK);
2019-03-27 09:33:26 +00:00
}