libJelling-calc/include/libJelling/bluetooth.h

100 lines
3.0 KiB
C++

/*
* AUTHOR : Xavier Bruni
*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* As long as you retain this notice you can do whatever you want with this
* stuff. If we meet some day, and you think this stuff is worth it, you can
* buy me a beer in return.
* ----------------------------------------------------------------------------
*/
#define LIB_JELLING
#define BLUETOOTH_H_INCLUDED
extern "C"{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MonochromeLib.h"
#include "syscall.h"
#include "libfx.h"
#include "others.h"
}
#include "libJelling/message.h"
/*
This bluetooth library is working with the 3-pin port of your calculator.
This library is compatible with SuperH-3 and SuperH-4 processor :
This include : Graph 35+, 75, 85 & 95.
This library has been written for the following bluetooth module : HC-05, HC-06
RAM can contain approximately 50KO of data. Each message can't do more than 32KO
You can't send more than 1ko -including header- from your smartphone to the calculator. In fact, the reception buffer has a size of 1ko max.
Without the header : 1000 - 46 = 954o
for sending : 256-46 = 210
If the 32 ko buffer is full, it will return a FUL packet.
*/
class Bluetooth{
public:
Bluetooth();
// listen for new message. This function is non blocking. maxSize is the maximum length of message to receive.
// it will return NOT_ENOUG_RAM if it can not allocate that much. call this function early in your code, you'll have more chance to have enough ram.
// There is no maximum restriction, but RAM is about 50KO. 32KO should be the maximum.
int listen(int maxSize, int timer, void(*)(void), int time);
// Properly terminate the bluetooth communication.
int stop();
// Send a message. There is no maximum size. Indead, you will be limited by the RAM size (approx. 50ko)
int sendMessage(Message *message);
// get last message.
Message& getLastMessage();
// set the sender name (for header)
int setSender(const char *senderName);
// set message ID
int setID(unsigned int id);
// set it to 1 if you want to allow message reception. it will delete previous message on new reception !! save it if you would like to keep it !!
unsigned int allowReception;
unsigned int unread;
// point on the 32ko of data.
char* ptr;
// point to the 1ko to receive
char* ptr1ko;
// call by a timer every 25ms. It CAN NOT recept more than 1 ko in a row.
// use (5) and (6) to send bigger message from your device.
void receptMessage();
int timer;
private:
// total size of all send packet
int sentPacketsTotalSize;
// total szie of all received packets
int receivedPacketsTotalSize;
int max;
char sender[10];
unsigned int caltoID;
unsigned int androidID;
unsigned int secondTry;
// for ACK
char lastType;
unsigned int lastID;
bool isWaitingAck;
// Keep the last message in memory
Message msg;
};
#define RETURN Timer_Start(this->timer);return;