Edit:
Fixed it!
Old post:
I am attempting to receive a program from my calculator with an Arduino UNO. But there seems to be a problem, I tell the calculator that I can accept the program, but it is not responding with the VAR header.
Code:
Code:
#include <TIVar.h>
#include <CBL2.h>
#include <TICL.h>
#define LINE_RED 7
#define LINE_WHITE 6
#define DATA_MAX 255
#define null 0
#define NULL 0
TICL* ticl;
uint8_t recvHeader[4];
uint8_t recvData[DATA_MAX];
uint8_t sendHeader[4];
uint8_t sendData[DATA_MAX];
typedef struct{
uint16_t size;
uint8_t type;
uint8_t name[8];
uint8_t version;
uint8_t archived;
} variableHeader;
variableHeader *varHeader = (variableHeader*)recvData;
uint8_t varState = 0;
void setup() {
Serial.begin(9600);
ticl = new CBL2(LINE_RED, LINE_WHITE);
ticl->resetLines();
ticl->setVerbosity(true, &Serial);
}
void loop() {
int ret;
getData();
}
void getData(){
int length = 0;
int ret = 0;
ret = ticl->get(recvHeader, recvData, &length, DATA_MAX);
if(ret){
return;
}
Serial.println("Handling packet");
uint8_t machineId = recvHeader[0];
uint8_t commandId = recvHeader[1];
if(machineId != 0x83){
return;
}
switch(commandId){
// Variable header
case VAR:
varState = 1;
sendACK();
sendCTS();
break;
// Ready?
case RDY:
sendACK();
sendCTS();
break;
}
}
/*
uint16_t size;
uint8_t type;
uint8_t name[8];
uint8_t version;
uint8_t archived;
*/
void handleProgram(){
uint16_t programLength = recvData[13] + (recvData[14] << 8);
Serial.println(programLength, HEX);
for(int i = 0; i < programLength; i++){
Serial.println(recvData[15 + i], HEX);
}
}
void sendCommand(uint8_t command, uint8_t machine, uint16_t data){
sendHeader[0] = machine;
sendHeader[1] = command;
sendHeader[2] = data & 0xFF;
sendHeader[3] = data >> 8;
ticl->send(sendHeader, null, 0, null);
}
void sendACK(){
sendCommand(ACK, CALC83, 0);
}
void sendCTS(){
sendCommand(CTS, CALC83, 0);
}
Serial output:
Quote:
Recv typ 0x68 from EP 0x83 len 11
Handling packet
snd type 0x56 as EP 0x83 len 0
snd type 0x9 as EP 0x83 len 0