writting octet should be good
This commit is contained in:
+56
-3
@@ -1,8 +1,61 @@
|
||||
#include "pmacEthernetCmd.h"
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
std::vector<unsigned char> EthernetCommand::serialize() {
|
||||
return std::vector<unsigned char>();
|
||||
std::vector<char> EthernetCommand::serialize() {
|
||||
std::vector<char> serialized = bData.size() + 8;
|
||||
// Requested type value
|
||||
serialized.at(0) = static_cast<char>(requestType);
|
||||
// Request value
|
||||
serialized.at(1) = static_cast<char>(request);
|
||||
// wValue
|
||||
serialized.at(2) = static_cast<char>((wValue >> 8) & 0xFF);
|
||||
serialized.at(3) = static_cast<char>(wValue & 0xFF);
|
||||
// wIndex
|
||||
serialized.at(4) = static_cast<char>((wIndex >> 8) & 0xFF);
|
||||
serialized.at(5) = static_cast<char>(wIndex & 0xFF);
|
||||
// wLength
|
||||
serialized.at(6) = static_cast<char>((wLength >> 8) & 0xFF);
|
||||
serialized.at(7) = static_cast<char>(wLength & 0xFF);
|
||||
|
||||
// Package
|
||||
int dataLength = bData.size();
|
||||
for (int i = 0; i < dataLength; i++) {
|
||||
serialized.at(8 + i) = bData.at(i);
|
||||
}
|
||||
return bData;
|
||||
}
|
||||
|
||||
void EthernetCommand::deserialize(std::vectro<unisgned char> data) {}
|
||||
void EthernetCommand::write(std::vector<char> command) {
|
||||
if (command.size() > ETHERNET_DATA_SIZE) {
|
||||
printf("ERROR - TRUNCATED\n");
|
||||
command.resize(ETHERNET_DATA_SIZE);
|
||||
}
|
||||
|
||||
bool isControlMessage =
|
||||
command.size() == 1 && isCharControlCommand(command.at(0));
|
||||
|
||||
if (isControlMessage) {
|
||||
requestType = RequestType::VR_UPLOAD;
|
||||
request = Request::VR_CTRL_RESPONSE;
|
||||
wValue = command.at(0);
|
||||
wIndex = 0;
|
||||
wLenght = htons(0);
|
||||
bData = command.erase();
|
||||
} else {
|
||||
requestType = RequestType::VR_DOWNLOAD;
|
||||
request = Request::VR_PMAC_GETRESPONSE;
|
||||
wValue = 0;
|
||||
wIndex = 0;
|
||||
wLenght = command.size();
|
||||
bData = command;
|
||||
}
|
||||
}
|
||||
|
||||
bool EthernetCommand::isCharControlCommand(char &c) {
|
||||
constexpr int32_t bitmask = 1 << CTRLB | 1 << CTRLC | 1 << CTRLF |
|
||||
1 << CTRLG | 1 << CTRLP | 1 << CTRLV;
|
||||
|
||||
return static_cast<int32_t>(*c) & bitmask;
|
||||
}
|
||||
|
||||
+22
-3
@@ -26,12 +26,31 @@ class EthernetCommand {
|
||||
VR_IPADDRESS = 0xE0
|
||||
};
|
||||
|
||||
std::vector<unsigned char> serialize();
|
||||
void deserialize(std::vectro<unisgned char> data);
|
||||
std::vector<char> serialize();
|
||||
|
||||
void write(std::vector<char> command);
|
||||
|
||||
private:
|
||||
const char CTRLB = '\2';
|
||||
const char CTRLC = '\3';
|
||||
const char CTRLF = '\6';
|
||||
const char CTRLG = '\7';
|
||||
const char CTRLP = '\16';
|
||||
const char CTRLV = '\22';
|
||||
|
||||
bool isCharControlCommand(char &c);
|
||||
|
||||
const unsigned ETHERNET_DATA_SIZE = 1492;
|
||||
|
||||
/*
|
||||
1 for Request Type
|
||||
1 for Request
|
||||
2 for wValue
|
||||
2 for wIndex
|
||||
2 for wLength
|
||||
*/
|
||||
constexpr ETHERNET_HEADER_SIZE = 8;
|
||||
|
||||
/*
|
||||
Command Data
|
||||
*/
|
||||
@@ -41,7 +60,7 @@ class EthernetCommand {
|
||||
unsigned short wIndex;
|
||||
unsigned short wLength; // lenght of data, will not be necessary since
|
||||
// vector know is lenght
|
||||
std::vector<unsigned char> bData;
|
||||
std::vector<char> bData;
|
||||
};
|
||||
|
||||
#endif
|
||||
+4
-49
@@ -5,37 +5,12 @@ PmacPvt::PmacPvt(const char *portName, int maxAddr, int interfaceMask,
|
||||
int interruptMask, int asynFlags, int autoConnect,
|
||||
int priority, int stackSize) {}
|
||||
|
||||
asynStatus PmacPvt::writeInt32(asynUser *pasynUser, epicsInt32 value) {
|
||||
asynPrint(pasynUser, ASYN_TRACE_FLOW, "pmacAsynIPPort::writeInt32\n");
|
||||
|
||||
if (pasynUser->reason == FLUSH_HARDWARE) {
|
||||
/*
|
||||
According to the Turbo PMAC user manual, p. 414:
|
||||
0 - failed 1 - success
|
||||
*/
|
||||
if (pmacFlush(pPmacPvt, pasynUser) == 1) {
|
||||
return asynSuccess;
|
||||
} else {
|
||||
return asynError;
|
||||
}
|
||||
} else {
|
||||
return pPmacPvt->pint32->write(pPmacPvt->int32Pvt, pasynUser, value);
|
||||
}
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::readInt64(asynUser *pasynUser, epicsInt64 *value) {
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::getBounds(asynUser *pasynUser, epicsInt32 *low,
|
||||
epicsInt32 *high) {
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::writeOctet(asynUser *pasynUser, const char *value,
|
||||
size_t maxChars, size_t *nActual) {
|
||||
return asynStatus();
|
||||
EthernetCommand outCommand = {};
|
||||
outCommand.write(std::vector<char>(value, value + maxChars));
|
||||
asynPortDriver::writeOctet(pasynUser, outCommand.data(), outCommand.size(),
|
||||
nActual);
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::readOctet(asynUser *pasynUser, char *value, size_t maxChars,
|
||||
@@ -45,26 +20,6 @@ asynStatus PmacPvt::readOctet(asynUser *pasynUser, char *value, size_t maxChars,
|
||||
|
||||
asynStatus PmacPvt::flushOctet(asynUser *pasynUser) { return asynStatus(); }
|
||||
|
||||
asynStatus PmacPvt::setInputEosOctet(asynUser *pasynUser, const char *eos,
|
||||
int eosLen) {
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::getInputEosOctet(asynUser *pasynUser, char *eos,
|
||||
int eosSize, int *eosLen) {
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::setOutputEosOctet(asynUser *pasynUser, const char *eos,
|
||||
int eosLen) {
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
asynStatus PmacPvt::getOutputEosOctet(asynUser *pasynUser, char *eos,
|
||||
int eosSize, int *eosLen) {
|
||||
return asynStatus();
|
||||
}
|
||||
|
||||
/*
|
||||
PMAC specific function
|
||||
*/
|
||||
|
||||
@@ -28,51 +28,15 @@ class PmacPvt : public asynPortDriver {
|
||||
unsigned int inBufHead;
|
||||
unsigned int inBufTail;
|
||||
|
||||
asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value) override;
|
||||
asynStatus readInt64(asynUser *pasynUser, epicsInt64 *value) override;
|
||||
asynStatus getBounds(asynUser *pasynUser, epicsInt32 *low,
|
||||
epicsInt32 *high) override; // replace getBoundsInt32
|
||||
|
||||
/*
|
||||
What is the replacement for
|
||||
|
||||
- registerInterruptUserInt32
|
||||
- cancelInterruptUserInt32
|
||||
|
||||
?
|
||||
*/
|
||||
|
||||
asynStatus writeOctet(asynUser *pasynUser, const char *value,
|
||||
size_t maxChars, size_t *nActual) override;
|
||||
asynStatus readOctet(asynUser *pasynUser, char *value, size_t maxChars,
|
||||
size_t *nActual, int *eomReason) override;
|
||||
asynStatus flushOctet(asynUser *pasynUser) override;
|
||||
|
||||
asynStatus setInputEosOctet(asynUser *pasynUser, const char *eos,
|
||||
int eosLen) override;
|
||||
asynStatus getInputEosOctet(asynUser *pasynUser, char *eos, int eosSize,
|
||||
int *eosLen) override;
|
||||
asynStatus setOutputEosOctet(asynUser *pasynUser, const char *eos,
|
||||
int eosLen) override;
|
||||
asynStatus getOutputEosOctet(asynUser *pasynUser, char *eos, int eosSize,
|
||||
int *eosLen) override;
|
||||
|
||||
/*
|
||||
What is the replacement for
|
||||
|
||||
- registerInterruptUserOctet
|
||||
- cancelInterruptUserOctet
|
||||
|
||||
?
|
||||
*/
|
||||
|
||||
private:
|
||||
asynStatus readResponse(asynUser *pasynUser, size_t maxchars,
|
||||
size_t *nbytesTransfered, int *eomReason);
|
||||
int pmacReadReady(asynUser *pasynUser);
|
||||
int pmacFlush(asynUser *pasynUser);
|
||||
asynStatus sendPmacGetBuffer(asynUser *pasynUser, size_t maxchars,
|
||||
size_t *nbytesTransfered);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user