Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 450 → Rev 513

/QMK-Groundstation/branches/libMK/libMK/Parser.cpp
1,4 → 1,5
#include <Parser.h>
#include <iostream>
 
/**
* create a frame that can be send to the MK using the
9,7 → 10,7
* to look at the possible commands that are already coded
* in data
*/
void Parser::create_frame(char cmd, int address, char * data, unsigned int length) {
void Parser::create_frame(char * send_data, char cmd, int address, char * data, unsigned int length) {
//if # is cmd we do not touch anything, because
// the command is already encoded in data
if (cmd != '#') {
23,7 → 24,7
char * send_data = (char *)malloc(buf_len);
*/
Parser::encode64(data, length);
char send_data[150];
send_data[0]='#';
send_data[1]=(char)address+'a';
send_data[2]=cmd;
50,14 → 51,15
unsigned char x,y,z;
 
int decLen = 0;
/*
//FIXME: dies wieder einklammern!
if (data[ptrIn] == 0) {
return -1;
 
std::cout << "decode64" << offset << " " << len << std::endl;
FlightLog::log_data(data, len);
if (data[offset] == 0) {
//return -1;
//TODO: catch error to show that something went wrong during the decode process
//throw "Nothing received";
FlightLog::warning("incorrect data received");
}
*/
//decode data
while(len) {
a = data[offset++] - '=';
199,26 → 201,18
int CRC = 0;
 
if (rx[1] == 127)
{
rx[1] = 0;
}
 
for(int i=0; i < length-2; i++)
{
CRC+=rx[i];
}
CRC+=rx[i];
 
CRC = CRC % 4096;
 
if(rx[length - 2] != ('=' + (CRC / 64)))
{
return false;
}
 
if(rx[length - 1] != ('=' + CRC % 64))
{
return false;
}
 
return true;
}
231,9 → 225,7
unsigned int tmpCRC = 0;
 
for(int i = 0; i < length; i++)
{
tmpCRC += tx[i];
}
 
tmpCRC %= 4096;
 
241,4 → 233,3
tx[length+1] = '=' + tmpCRC % 64;
tx[length+2] = '\0';
}