b15f/firmware/requests.cpp

154 lines
2.7 KiB
C++
Raw Normal View History

2019-03-26 14:02:58 +00:00
#include "requests.h"
void rqTestConnection()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint8_t dummy = usart.readByte();
usart.writeByte(USART::MSG_OK);
usart.writeByte(dummy);
usart.flush();
2019-03-26 14:02:58 +00:00
}
void rqBoardInfo()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
usart.writeByte(3); // Anzahl an Strings
usart.writeStr(DATE, sizeof(DATE));
usart.writeStr(TIME, sizeof(TIME));
usart.writeStr(FSRC, sizeof(FSRC));
usart.writeByte(USART::MSG_OK);
usart.flush();
2019-03-26 14:02:58 +00:00
}
void rqTestIntConv()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint16_t d = usart.readInt();
usart.writeInt(d * 3);
usart.flush();
2019-03-26 14:02:58 +00:00
}
2019-03-26 15:30:49 +00:00
void rqDigitalWrite0()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint8_t port = usart.readByte();
2019-04-03 06:40:14 +00:00
dio0.writePortA(port);
2019-03-26 15:30:49 +00:00
2019-04-02 13:32:51 +00:00
usart.writeByte(USART::MSG_OK);
usart.flush();
2019-03-26 15:30:49 +00:00
}
void rqDigitalWrite1()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint8_t port = usart.readByte();
2019-04-03 06:40:14 +00:00
dio1.writePortA(port);
2019-03-26 15:30:49 +00:00
2019-04-02 13:32:51 +00:00
usart.writeByte(USART::MSG_OK);
usart.flush();
2019-03-26 15:30:49 +00:00
}
void rqDigitalRead0()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
2019-04-03 06:40:14 +00:00
uint8_t port = dio0.readPortB();
2019-04-02 13:32:51 +00:00
usart.writeByte(port);
usart.flush();
2019-03-26 15:30:49 +00:00
}
void rqDigitalRead1()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
2019-04-03 06:40:14 +00:00
uint8_t port = dio1.readPortB();
2019-04-02 13:32:51 +00:00
usart.writeByte(port);
usart.flush();
2019-03-26 15:30:49 +00:00
}
2019-04-03 07:34:22 +00:00
void rqReadDipSwitch()
{
usart.initTX();
uint8_t port = dsw.readPortB();
usart.writeByte(port);
usart.flush();
}
2019-03-26 15:30:49 +00:00
void rqAnalogWrite0()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint16_t value = usart.readInt();
2019-04-03 06:40:14 +00:00
dac0.setValue(value);
2019-03-26 15:30:49 +00:00
2019-04-02 13:32:51 +00:00
usart.writeByte(USART::MSG_OK);
usart.flush();
2019-03-26 15:30:49 +00:00
}
void rqAnalogWrite1()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint16_t value = usart.readInt();
2019-04-03 06:40:14 +00:00
dac1.setValue(value);
2019-03-26 15:30:49 +00:00
2019-04-02 13:32:51 +00:00
usart.writeByte(USART::MSG_OK);
usart.flush();
2019-03-26 15:30:49 +00:00
}
void rqAnalogRead()
{
2019-04-02 13:32:51 +00:00
usart.initTX();
uint8_t channel = usart.readByte();
2019-04-03 06:40:14 +00:00
uint16_t value = adu.getValue(channel);
2019-04-02 13:32:51 +00:00
usart.writeInt(value);
usart.flush();
2019-03-26 15:30:49 +00:00
}
2019-03-27 09:33:26 +00:00
void rqAdcDacStroke()
{
2019-04-02 13:32:51 +00:00
uint8_t channel_a = usart.readByte();
uint8_t channel_b = usart.readByte();
2019-03-27 09:49:26 +00:00
2019-04-02 13:32:51 +00:00
int16_t start = static_cast<int16_t>(usart.readInt());
int16_t delta = static_cast<int16_t>(usart.readInt());
int16_t count = static_cast<int16_t>(usart.readInt());
2019-03-27 09:33:26 +00:00
count *= delta;
2019-04-03 06:40:14 +00:00
dio1.writePortA(0xFF);
2019-03-27 09:33:26 +00:00
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-03 06:40:14 +00:00
dac0.setValue(i);
2019-03-27 14:48:36 +00:00
wdt_reset();
2019-03-28 14:22:17 +00:00
2019-04-03 06:40:14 +00:00
uint16_t val_a = adu.getValue(channel_a);
uint16_t val_b = adu.getValue(channel_b);
2019-04-02 14:19:42 +00:00
usart.initTX();
2019-04-02 13:32:51 +00:00
usart.writeInt(val_a);
usart.writeInt(val_b);
2019-04-02 14:19:42 +00:00
usart.flush();
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-03 06:40:14 +00:00
dw.word[0] = adu.getValue(channel_a);
dw.word[1] = adu.getValue(channel_b);
2019-03-28 14:22:17 +00:00
uint8_t ret = 0;
do
{
wdt_reset();
2019-04-02 13:32:51 +00:00
ret = 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 14:19:42 +00:00
usart.initTX();
2019-04-02 13:32:51 +00:00
usart.writeByte(USART::MSG_OK);
2019-04-02 14:19:42 +00:00
usart.flush();
2019-03-27 09:33:26 +00:00
}