500SL Send code
This commit is contained in:
parent
fc74aac1c9
commit
67226aaddc
@ -1,7 +1,23 @@
|
|||||||
void Generate_Code()
|
|
||||||
|
//Generate line1 and line 2 with 14 chars
|
||||||
|
void Generate_Code14()
|
||||||
{
|
{
|
||||||
//scroll chars
|
byte tmp_byte;
|
||||||
|
|
||||||
|
//scroll chars line 1
|
||||||
|
tmp_byte = line1_14[13];
|
||||||
|
for (int i = 12; i >= 0; i--)
|
||||||
|
{
|
||||||
|
line1_14[i + 1] = line1_14[i];
|
||||||
|
}
|
||||||
|
line1_14[0] = tmp_byte;
|
||||||
|
|
||||||
|
|
||||||
|
//scroll chars line 2
|
||||||
|
tmp_byte = line2_14[0];
|
||||||
|
for (int i = 1; i <= 13; i++)
|
||||||
|
{
|
||||||
|
line2_14[i - 1] = line2_14[i];
|
||||||
|
}
|
||||||
|
line2_14[13] = tmp_byte;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,9 @@ bool watchdog_send = false; //500SL Wachtdog send, thus switched to ve
|
|||||||
//void Linx500SL_Watchdog();
|
//void Linx500SL_Watchdog();
|
||||||
//void Linx500SL_SendCode();
|
//void Linx500SL_SendCode();
|
||||||
|
|
||||||
|
char line1_14[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4'};
|
||||||
|
char line2_14[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'};
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ void setup() {
|
|||||||
//init debug port
|
//init debug port
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
if(digitalRead(pin_LASERTYPE) == false)
|
if (digitalRead(pin_LASERTYPE) == false)
|
||||||
{
|
{
|
||||||
Serial.println("Lasertype set to : Linx 500SL - baudrate 19k2");
|
Serial.println("Lasertype set to : Linx 500SL - baudrate 19k2");
|
||||||
//init serial ports
|
//init serial ports
|
||||||
@ -60,24 +63,28 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//init I2C Display
|
//init I2C Display
|
||||||
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
for(;;); // Don't proceed, loop forever
|
for (;;); // Don't proceed, loop forever
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the buffer
|
// Clear the buffer
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setCursor(10,0);
|
display.setCursor(10, 0);
|
||||||
display.println(F("RS232 Sniffer v1.0"));
|
display.println(F("RS232 Sniffer v1.0"));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
display.display();
|
display.display();
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(10,0);
|
display.setCursor(10, 0);
|
||||||
if(lasertype==1) {display.println(F("Linx 500SL"));}
|
if (lasertype == 1) {
|
||||||
if(lasertype==2) {display.println(F("MundiScan 2000"));}
|
display.println(F("Linx 500SL"));
|
||||||
display.setCursor(0,10);
|
}
|
||||||
|
if (lasertype == 2) {
|
||||||
|
display.println(F("MundiScan 2000"));
|
||||||
|
}
|
||||||
|
display.setCursor(0, 10);
|
||||||
display.println(F("Sniffer mode selected"));
|
display.println(F("Sniffer mode selected"));
|
||||||
display.display();
|
display.display();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
@ -88,19 +95,23 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
if(digitalRead(pin_MODE) != b_mode)
|
if (digitalRead(pin_MODE) != b_mode)
|
||||||
{
|
{
|
||||||
b_mode = digitalRead(pin_MODE);
|
b_mode = digitalRead(pin_MODE);
|
||||||
if(b_mode)
|
if (b_mode)
|
||||||
{
|
{
|
||||||
Serial.println("Mode : Sniffer");
|
Serial.println("Mode : Sniffer");
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setCursor(10,0);
|
display.setCursor(10, 0);
|
||||||
if(lasertype==1) {display.println(F("Linx 500SL"));}
|
if (lasertype == 1) {
|
||||||
if(lasertype==2) {display.println(F("MundiScan 2000"));}
|
display.println(F("Linx 500SL"));
|
||||||
display.setCursor(0,10);
|
}
|
||||||
|
if (lasertype == 2) {
|
||||||
|
display.println(F("MundiScan 2000"));
|
||||||
|
}
|
||||||
|
display.setCursor(0, 10);
|
||||||
display.println(F("Sniffer mode selected"));
|
display.println(F("Sniffer mode selected"));
|
||||||
display.display();
|
display.display();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@ -111,10 +122,14 @@ void loop() {
|
|||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setCursor(10,0);
|
display.setCursor(10, 0);
|
||||||
if(lasertype==1) {display.println(F("Linx 500SL"));}
|
if (lasertype == 1) {
|
||||||
if(lasertype==2) {display.println(F("MundiScan 2000"));}
|
display.println(F("Linx 500SL"));
|
||||||
display.setCursor(0,10);
|
}
|
||||||
|
if (lasertype == 2) {
|
||||||
|
display.println(F("MundiScan 2000"));
|
||||||
|
}
|
||||||
|
display.setCursor(0, 10);
|
||||||
display.println(F("Send mode selected"));
|
display.println(F("Send mode selected"));
|
||||||
display.display();
|
display.display();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
@ -123,7 +138,7 @@ void loop() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(b_mode)
|
if (b_mode)
|
||||||
{
|
{
|
||||||
if (MySerial1.available() > 0) {
|
if (MySerial1.available() > 0) {
|
||||||
// read the incoming byte:
|
// read the incoming byte:
|
||||||
@ -148,15 +163,15 @@ void loop() {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
now = millis();
|
now = millis();
|
||||||
if(now - prev >= 5000)
|
if (now - prev >= 5000)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Laser 500SL
|
//Laser 500SL
|
||||||
if(lasertype == 1)
|
if (lasertype == 1)
|
||||||
{
|
{
|
||||||
if(!watchdog_send)
|
if (!watchdog_send)
|
||||||
{
|
{
|
||||||
display.setCursor(0,20);
|
display.setCursor(0, 20);
|
||||||
|
|
||||||
display.setTextColor(WHITE, BLACK);
|
display.setTextColor(WHITE, BLACK);
|
||||||
|
|
||||||
@ -166,16 +181,25 @@ void loop() {
|
|||||||
Serial.println("Linx 500SL : Sending WatchDog command to switch to VectorService Protocol");
|
Serial.println("Linx 500SL : Sending WatchDog command to switch to VectorService Protocol");
|
||||||
|
|
||||||
Linx500SL_Watchdog();
|
Linx500SL_Watchdog();
|
||||||
if(!watchdog_send) {Serial.println("Linx 500SL : Error !! --> No Response from laser");}
|
if (!watchdog_send) {
|
||||||
if(watchdog_send) {Serial.println("Linx 500SL : Laser switched to VectorService Protocol !!");}
|
Serial.println("Linx 500SL : Error !! --> No Response from laser");
|
||||||
|
}
|
||||||
|
if (watchdog_send) {
|
||||||
|
Serial.println("Linx 500SL : Laser switched to VectorService Protocol !!");
|
||||||
|
}
|
||||||
|
|
||||||
display.setCursor(0,20);
|
display.setCursor(0, 20);
|
||||||
display.setTextColor(WHITE, BLACK);
|
display.setTextColor(WHITE, BLACK);
|
||||||
if(!watchdog_send) {display.println(F("No Response laser !! "));}
|
if (!watchdog_send) {
|
||||||
if(watchdog_send) {display.println(F("Laser Connected !! "));}
|
display.println(F("No Response laser !! "));
|
||||||
|
}
|
||||||
|
if (watchdog_send) {
|
||||||
|
display.println(F("Laser Connected !! "));
|
||||||
|
}
|
||||||
display.display();
|
display.display();
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
// ik even geen laser heb ;-)
|
||||||
|
watchdog_send = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -183,7 +207,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lasertype == 2)
|
if (lasertype == 2)
|
||||||
{
|
{
|
||||||
Serial.println(".");
|
Serial.println(".");
|
||||||
MySerial1.println("P1 : Hallo Frank");
|
MySerial1.println("P1 : Hallo Frank");
|
||||||
|
|||||||
@ -3,29 +3,24 @@ byte SL500_SEQ = 00;
|
|||||||
byte SL500_CRC = 00;
|
byte SL500_CRC = 00;
|
||||||
byte SL500_XOR = 00;
|
byte SL500_XOR = 00;
|
||||||
|
|
||||||
|
|
||||||
//char SL500SL_WD[] = {204,170,0,0,0,1,0,0,0,1,0,19,0,0,0,43,0,0,0};
|
|
||||||
char SL500_WD[] = {0xCC,0xAA,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x13,0x00,0x00,0x00,0x2B,0x00,0x00,0x00};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Send Wachtdog and wait for a reply to switch 500SL laser into VectorService Protocol
|
//Send Wachtdog and wait for a reply to switch 500SL laser into VectorService Protocol
|
||||||
|
|
||||||
//Wachdog command CC AA 00 00 00 01 00 00 00 01 00 13 00 00 00 2B [SEQ] [CRC] [XOR]
|
//Wachdog command CC AA 00 00 00 01 00 00 00 01 00 13 00 00 00 2B [SEQ] [CRC] [XOR]
|
||||||
|
|
||||||
void Linx500SL_Watchdog()
|
void Linx500SL_Watchdog()
|
||||||
{
|
{
|
||||||
|
char SL500_WD[] = {0xCC, 0xAA, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x13, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
byte p2_rec_byte;
|
byte p2_rec_byte;
|
||||||
|
|
||||||
while ((!watchdog_send) && count < 15)
|
while ((!watchdog_send) && count < 5)
|
||||||
{
|
{
|
||||||
|
|
||||||
SL500_SEQ = SL500_SEQ + 1;
|
SL500_SEQ++;
|
||||||
SL500_WD[16] = SL500_SEQ;
|
SL500_WD[16] = SL500_SEQ;
|
||||||
|
|
||||||
Linx500_Checksum(16);
|
Linx500_Checksum(SL500_WD, 16);
|
||||||
|
|
||||||
SL500_WD[17] = SL500_CRC;
|
SL500_WD[17] = SL500_CRC;
|
||||||
SL500_WD[18] = SL500_XOR;
|
SL500_WD[18] = SL500_XOR;
|
||||||
@ -48,7 +43,7 @@ void Linx500SL_Watchdog()
|
|||||||
p2_rec_byte = MySerial1.read();
|
p2_rec_byte = MySerial1.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p2_rec_byte == 204)
|
if (p2_rec_byte == 204)
|
||||||
{
|
{
|
||||||
watchdog_send = true;
|
watchdog_send = true;
|
||||||
}
|
}
|
||||||
@ -61,33 +56,90 @@ void Linx500SL_Watchdog()
|
|||||||
//500SL Send Code
|
//500SL Send Code
|
||||||
void Linx500SL_SendCode()
|
void Linx500SL_SendCode()
|
||||||
{
|
{
|
||||||
Generate_Code();
|
|
||||||
|
|
||||||
|
char line1[60] = {0xCC, 0xAA, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x37, 0x00, 0x00, 0x00, 0x25, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x000, 0x00};
|
||||||
|
char line2[60] = {0xCC, 0xAA, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x37, 0x00, 0x00, 0x00, 0x25, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x000, 0x00};
|
||||||
|
|
||||||
|
//pos 20 = Remote update Field
|
||||||
|
//pos 16 = SEQ
|
||||||
|
//pos 25 = Start tekst
|
||||||
|
#define pos_seq 16
|
||||||
|
#define pos_txt 25
|
||||||
|
|
||||||
|
Generate_Code14();
|
||||||
|
|
||||||
|
//Line 1
|
||||||
|
SL500_SEQ++;
|
||||||
|
line1[pos_seq] = SL500_SEQ;
|
||||||
|
Serial.println("");
|
||||||
|
Serial.print("Linx500SL --> Line 1 : ");
|
||||||
|
for (int i = 0; i <= 13; i++)
|
||||||
|
{
|
||||||
|
line1[pos_txt + (i * 2)] = line1_14[i];
|
||||||
|
line1[pos_txt + (i * 2) + 1] = 0;
|
||||||
|
Serial.write(line1_14[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Linx500_Checksum(line1, pos_txt + 28);
|
||||||
|
|
||||||
|
line1[pos_txt + 28] = SL500_CRC;
|
||||||
|
line1[pos_txt + 28 + 1] = SL500_XOR;
|
||||||
|
|
||||||
|
//Write all chars to Serial port
|
||||||
|
for (int i = 0; i <= (pos_txt + 28 + 1); i++)
|
||||||
|
{
|
||||||
|
MySerial1.write(line1[i]);
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
//Line 2
|
||||||
|
SL500_SEQ++;
|
||||||
|
line2[pos_seq] = SL500_SEQ;
|
||||||
|
Serial.println("");
|
||||||
|
Serial.print("Linx500SL --> Line 2 : ");
|
||||||
|
for (int i = 0; i <= 13; i++)
|
||||||
|
{
|
||||||
|
line2[pos_txt + (i * 2)] = line2_14[i];
|
||||||
|
line2[pos_txt + (i * 2) + 1] = 0;
|
||||||
|
Serial.write(line1_14[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Linx500_Checksum(line2, pos_txt + 28);
|
||||||
|
|
||||||
|
line2[pos_txt + 28] = SL500_CRC;
|
||||||
|
line2[pos_txt + 28 + 1] = SL500_XOR;
|
||||||
|
|
||||||
|
//Write all chars to Serial port
|
||||||
|
for (int i = 0; i <= (pos_txt + 28 + 1); i++)
|
||||||
|
{
|
||||||
|
MySerial1.write(line2[i]);
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Linx 500 SL Calculate CRC and XOR
|
||||||
void Linx500_Checksum(int char_count)
|
void Linx500_Checksum(char *cmd_line, int char_count)
|
||||||
{
|
{
|
||||||
|
|
||||||
long val_crc = 0;
|
long val_crc = 0;
|
||||||
long val_xor = 0;
|
long val_xor = 0;
|
||||||
|
|
||||||
//Checksum Calculation
|
//Checksum Calculation
|
||||||
for (int i = 0; i <= char_count; i++)
|
for (int i = 0; i <= char_count; i++)
|
||||||
{
|
{
|
||||||
val_crc = val_crc + SL500_WD[i];
|
val_crc = val_crc + cmd_line[i];
|
||||||
val_xor = val_xor ^ SL500_WD[i];
|
val_xor = val_xor ^ cmd_line[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
val_crc = 255 - (val_crc % 256);
|
val_crc = 255 - (val_crc % 256);
|
||||||
|
|
||||||
Serial.print("Checksum : ");
|
Serial.println("");
|
||||||
Serial.println(val_crc);
|
Serial.print("Checksum : CRC = ");
|
||||||
Serial.println(val_xor);
|
Serial.print(val_crc, HEX);
|
||||||
|
Serial.print (" XOR = ");
|
||||||
|
Serial.print(val_xor, HEX);
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
SL500_CRC = val_crc;
|
SL500_CRC = val_crc;
|
||||||
SL500_XOR = val_xor;
|
SL500_XOR = val_xor;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user