Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert chirpmon.cpp to UNIX format #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 93 additions & 93 deletions host/pixymon/chirpmon.cpp
Original file line number Diff line number Diff line change
@@ -13,96 +13,96 @@
// end license header
//

#include <QDebug>
#include <QMutexLocker>
#include <stdexcept>
#include "chirpmon.h"
#include "interpreter.h"
ChirpMon::ChirpMon(Interpreter *interpreter, USBLink *link) : m_mutex(QMutex::Recursive)
{
m_hinterested = true;
m_client = true;
m_interpreter = interpreter;
if (setLink(link)<0)
throw std::runtime_error("Unable to connect to device.");
}
ChirpMon::~ChirpMon()
{
}
int ChirpMon::serviceChirp()
{
uint8_t type;
ChirpProc recvProc;
void *args[CRP_MAX_ARGS+1];
int res;
while(1)
{
if ((res=recvChirp(&type, &recvProc, args, true))<0)
return res;
handleChirp(type, recvProc, args);
if (type&CRP_RESPONSE)
break;
}
return 0;
}
int ChirpMon::handleChirp(uint8_t type, ChirpProc proc, void *args[])
{
if (type==CRP_RESPONSE)
{
m_interpreter->handleResponse(args);
return 0;
}
return Chirp::handleChirp(type, proc, args);
}
void ChirpMon::handleXdata(void *data[])
{
m_interpreter->handleData(data);
}
int ChirpMon::sendChirp(uint8_t type, ChirpProc proc)
{ // this is only called when we call call()
int res;
// if we're programming (defining the program), put all the calls in m_program
// otherwise pass the call the Chirp::sendChirp() so it gets sent out.
// todo: save the call and use the chirp thread to send (so send and receive are handled by
// same thread. not sure how important that is...)
if (m_interpreter->m_programming && !(type&CRP_INTRINSIC))
{
// put on queue
// only copy data (not header). Header hasn't been written to buffer yet.
m_interpreter->addProgram(ChirpCallData(type, proc, m_buf+m_headerLen, m_len));
return 0;
}
res = Chirp::sendChirp(type, proc);
return res;
}
int ChirpMon::execute(const ChirpCallData &data)
{
QMutexLocker locker(&m_mutex);
int res;
// copy into chirp buffer-- remember to skip the header space
memcpy(m_buf+m_headerLen, data.m_buf, data.m_len);
m_len = data.m_len;
if ((res=Chirp::sendChirp(data.m_type, data.m_proc))<0)
return res;
if ((res=serviceChirp())<0)
return res;
return 0;
}
#include <QDebug>
#include <QMutexLocker>
#include <stdexcept>
#include "chirpmon.h"
#include "interpreter.h"

ChirpMon::ChirpMon(Interpreter *interpreter, USBLink *link) : m_mutex(QMutex::Recursive)
{
m_hinterested = true;
m_client = true;
m_interpreter = interpreter;

if (setLink(link)<0)
throw std::runtime_error("Unable to connect to device.");
}

ChirpMon::~ChirpMon()
{
}


int ChirpMon::serviceChirp()
{
uint8_t type;
ChirpProc recvProc;
void *args[CRP_MAX_ARGS+1];
int res;

while(1)
{
if ((res=recvChirp(&type, &recvProc, args, true))<0)
return res;
handleChirp(type, recvProc, args);
if (type&CRP_RESPONSE)
break;
}
return 0;
}


int ChirpMon::handleChirp(uint8_t type, ChirpProc proc, void *args[])
{
if (type==CRP_RESPONSE)
{
m_interpreter->handleResponse(args);
return 0;
}

return Chirp::handleChirp(type, proc, args);
}

void ChirpMon::handleXdata(void *data[])
{
m_interpreter->handleData(data);
}

int ChirpMon::sendChirp(uint8_t type, ChirpProc proc)
{ // this is only called when we call call()
int res;

// if we're programming (defining the program), put all the calls in m_program
// otherwise pass the call the Chirp::sendChirp() so it gets sent out.
// todo: save the call and use the chirp thread to send (so send and receive are handled by
// same thread. not sure how important that is...)
if (m_interpreter->m_programming && !(type&CRP_INTRINSIC))
{
// put on queue
// only copy data (not header). Header hasn't been written to buffer yet.
m_interpreter->addProgram(ChirpCallData(type, proc, m_buf+m_headerLen, m_len));
return 0;
}

res = Chirp::sendChirp(type, proc);

return res;
}

int ChirpMon::execute(const ChirpCallData &data)
{
QMutexLocker locker(&m_mutex);
int res;

// copy into chirp buffer-- remember to skip the header space
memcpy(m_buf+m_headerLen, data.m_buf, data.m_len);
m_len = data.m_len;
if ((res=Chirp::sendChirp(data.m_type, data.m_proc))<0)
return res;
if ((res=serviceChirp())<0)
return res;

return 0;
}