Code Monkey home page Code Monkey logo

icsc's Introduction

ICSC

Inter-Chip Serial Communications

A simple to use yet powerful system for communicating using RS232, RS485, etc between Arduinos, chipKITs, PCs, etc.

Packet format

All values are 8-bit and symbolic names are ASCII standard values.

Preamble:

 76543210
+--------+
| SOH    |
+--------+
| SOH    |
+--------+
| SOH    |
+--------+
| SOH    |
+--------+

Packet:

 76543210
+--------+
| SOH    |
+--------+
| DestID |
+--------+
| OrigID |
+--------+
| Cmd    |
+--------+
| DatLen |
+--------+
| STX    |
+--------+
| Data 0 |
| Data 1 |
| ...    |
| Data N |
+--------+
| ETX    |
+--------+
| Cksum  |
+--------+
| EOT    |
+--------+

Checksum is sum of all bytes between (but not including) SOH, STX, ETX and EOT, modulus 256.

Special destination address 0x00 is the broadcast. All stations will receive and act upon messages sent to this address.

Addresses that equate to the ASCII symbols SOH etc should be avoided.

Packet Reception

Packet reception and identification is through a 6-byte sliding window identifying the header of a packet. As bytes arrive they enter the top of the window and they work their way down to the bottom as more bytes arrive. When the first byte of the window is SOH, the last byte is STX, and the Dest ID is either 0x00 or the ID of the receiving station, it is assumed a valid packet is arriving. From this point on DatLen bytes are then read into the data buffer. If the next three bytes do not equal ETX, the valid checksum, and EOT, then the packet is rejected. Otherwise the function associated with Command is executed.

ChainDuino Use

See example file RemoteLEDReciever and RemoteLEDSender for small change that makes this work with ChainDuinos http://largewire.com/

icsc's People

Contributors

majenkotech avatar mattdreimer avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

icsc's Issues

ICSC_CATCH_ALL Not working unless defined as a char < ASCII 128

I was struggling to register a command using ICSC_CATCH_ALL, it would not work until i figured out that

define ICSC_CATCH_ALL 0xFF

was causing the issue

I changed to 0x7F (ASCII 127 which is the 'DEL' character) and everything worked beautifully.

I'm not a very good C/C++ programmer but I am guessing this is because #define isn't treating it as an unsigned char and thus limiting to the non-extended ASCII table.

Single Master / Multi Slave issue

Hi.
I want to use multi slave and one master connection.
My slaves are sending data to master after every 3 seconds.
Please guide me to use this lib in that condition.

Some warnings from compiler

Hello !
I apologize if this is wrong place to put it here.
When I compile with last version of ArduinoIDE 1.8.8 I receive some warnings, like :

....\libraries\ICSC-master\ICSC.cpp: In member function 'boolean ICSC::process()':
....\libraries\ICSC-master\ICSC.cpp:323:59: warning: comparison is always false due to limited range of data type [-Wtype-limits] _commands[i].commandCode == ICSC_CATCH_ALL )

I ignore this message, I just wanted to point this out.

`ICSC.send` to station 9 is received by all registered stations

I have 11 Arduinos talking to each other with ICSC, when they all boot up the master node runs through a loop to make sure the rest are alive by sending a ping to each one in succession and ensuring a pong comes back.

When the master gets to ICSC.send(9, 'P', 'p');, all of the stations receive the message instead of just the 9th.

STM32

Hello dear friend, i apologize if this is wrong place to put it here.

How can we use this nice library with the STM32 32bit devices ?

I try to compile a working project from arduino but choose it as STM32 and i got error:

'Building file: C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp'
'Starting C++ compile'
"C:\sloeber/arduinoPlugin/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -Wall -Wextra -DDEBUG_LEVEL=DEBUG_ALL -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8002000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10609 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103CB -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103CB -mthumb -march=armv7-m -D__STM32F1__ "-IC:/Users/TasosStr/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple" "-IC:/Users/TasosStr/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/include" "-IC:/Users/TasosStr/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/stm32f1/include" "-IC:/Users/TasosStr/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/stm32f1" "-IC:/Users/TasosStr/Arduino/hardware/Arduino_STM32/STM32F1/system/libmaple/usb/usb_lib" -I"C:\Users\TasosStr\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple" -I"C:\Users\TasosStr\Arduino\hardware\Arduino_STM32\STM32F1\variants\generic_stm32f103c" -I"C:\Users\TasosStr\Arduino\libraries\Bounce2" -I"C:\Users\TasosStr\Arduino\hardware\Arduino_STM32\STM32F1\libraries\EEPROM" -I"C:\Users\TasosStr\Arduino\libraries\ICSC" -I"C:\Users\TasosStr\Arduino\libraries\Streaming" -MMD -MP -MF"libraries/ICSC/ICSC.cpp.d" -MT"libraries/ICSC/ICSC.cpp.o" -D__IN_ECLIPSE__=1 -x c++ "C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp" -o "libraries/ICSC/ICSC.cpp.o"
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp: In member function 'void _ICSC::begin(unsigned char, long unsigned int)':
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:61:37: error: no matching function for call to '_ICSC::begin(unsigned char&, long unsigned int&, USBSerial*, int)'
begin(station, baud, &Serial, -1);
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:61:37: note: candidates are:
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:59:6: note: void _ICSC::begin(unsigned char, long unsigned int)
void _ICSC::begin(unsigned char station, unsigned long baud)
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:59:6: note: candidate expects 2 arguments, 4 provided
In file included from C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:36:0:
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:191:14: note: void _ICSC::begin(unsigned char, long unsigned int, int)
void begin(unsigned char station, unsigned long baud, int dePin);
^
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:191:14: note: candidate expects 3 arguments, 4 provided
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:196:14: note: void _ICSC::begin(unsigned char, long unsigned int, HardwareSerial*)
void begin(unsigned char station, unsigned long baud, HardwareSerial sdev);
^
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:196:14: note: candidate expects 3 arguments, 4 provided
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:197:14: note: void _ICSC::begin(unsigned char, long unsigned int, HardwareSerial
, int)
void begin(unsigned char station, unsigned long baud, HardwareSerial sdev, int dePin);
^
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:197:14: note: no known conversion for argument 3 from 'USBSerial
' to 'HardwareSerial*'
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp: In member function 'void _ICSC::begin(unsigned char, long unsigned int, int)':
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:66:40: error: no matching function for call to '_ICSC::begin(unsigned char&, long unsigned int&, USBSerial*, int&)'
begin(station, baud, &Serial, dePin);
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:66:40: note: candidates are:
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:59:6: note: void _ICSC::begin(unsigned char, long unsigned int)
void _ICSC::begin(unsigned char station, unsigned long baud)
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:59:6: note: candidate expects 2 arguments, 4 provided
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:64:6: note: void _ICSC::begin(unsigned char, long unsigned int, int)
void _ICSC::begin(unsigned char station, unsigned long baud, int dePin)
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:64:6: note: candidate expects 3 arguments, 4 provided
In file included from C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:36:0:
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:196:14: note: void _ICSC::begin(unsigned char, long unsigned int, HardwareSerial*)
void begin(unsigned char station, unsigned long baud, HardwareSerial sdev);
^
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:196:14: note: candidate expects 3 arguments, 4 provided
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:197:14: note: void _ICSC::begin(unsigned char, long unsigned int, HardwareSerial
, int)
void begin(unsigned char station, unsigned long baud, HardwareSerial sdev, int dePin);
^
C:\Users\TasosStr\Arduino\libraries\ICSC/ICSC.h:197:14: note: no known conversion for argument 3 from 'USBSerial
' to 'HardwareSerial*'
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp: In member function 'boolean _ICSC::send(unsigned char, unsigned char, char, unsigned char, char*)':
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:199:19: warning: unused variable 'del' [-Wunused-variable]
unsigned char del;
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp: At global scope:
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:624:6: warning: unused parameter 'command' [-Wunused-parameter]
void _ICSC::respondToPing(unsigned char station, char command, unsigned char len, char *data)
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp: In member function 'int _ICSC::serialRead()':
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:170:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp: In member function 'int _ICSC::serialAvailable()':
C:/Users/TasosStr/Arduino/libraries/ICSC/ICSC.cpp:183:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
libraries\ICSC/subdir.mk:18: recipe for target 'libraries/ICSC/ICSC.cpp.o' failed
make: *** [libraries/ICSC/ICSC.cpp.o] Error 1

04:15:42 Build Finished (took 2s.571ms)

Can you please help me ?

Thank you.

Best Regards,
Tasos

Advanced examples

Hi, thanks for this Library, would it be possible to create some more advanced examples showing how to send multiple byte/different types of data? For example I want to send the data contained in this this and obviously receive it at the other end :-

struct dataStruct{unsigned long Packet; int Accel; int Brake; int Steer; byte SwA; byte SwB; byte SwC; byte SwD;}myData;

I've tried :-

        icsc.send('B',(uint8_t)myData, sizeof(myData));

But get the error :-

"invalid cast from type 'dataStruct' to type 'uint8_t {aka unsigned char}'"

and :-

        icsc.send('B',myData, sizeof(myData));

But get the error :-

"no matching function for call to 'ICSC::send(char, dataStruct&, unsigned int)'"

Structs are fairly new to me so wondering how to handle this? And I haven't even started looking at what to do at the receiving end yet.

ICSC and STM32F103C8T6

Hello !
I apologize if this is wrong place to put it here.
ICSC is a great library. Work perfectly with Arduino.

From ICSC/example, I compiled PingMaster.ino for Arduino Uno :
Sketch uses 3682 bytes (11%) of program storage space. Maximum is 32256 bytes.
Global variables use 327 bytes (15%) of dynamic memory, leaving 1721 bytes for local variables. Maximum is 2048 bytes.

I tryed to compile (Arduino IDE 1.8.6) ICSC for STM32F103C8 but something is incompatible:
Sketch uses 75680 bytes (115%) of program storage space. Maximum is 65536 bytes.
Global variables use 6544 bytes (31%) of dynamic memory, leaving 13936 bytes for local variables. Maximum is 20480 bytes.
Sketch too big;

How can we use this library with TM32F103C8 ?
Can you please help me ?

Thank you.

How master can recieve msg from slave ?

I have problem
i am create test project in proteus
1213123
Master:
` #include <ICSC.h>
const int buttonPin = 3;
const int ledPin = 4;
const int portreadyled = 5;
const int dePin = 2;
int buttonState = 0;
ICSC icsc(Serial,'A',dePin);

void setup() {
// put your setup code here, to run once:
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
pinMode(2,OUTPUT);
Serial.begin(9600);
icsc.begin();
icsc.registerCommand('G',&check);
delay(2000);
digitalWrite(ledPin, HIGH);
delay(100);
icsc.send('B', 'S');

}

void loop() {
icsc.process();
}
void check(unsigned char src, char command, unsigned char len, char *data)
{
digitalWrite(ledPin, LOW);

} `

Slave :
` #include <ICSC.h>
#include <String.h>
const int buttonPin = 3;
const int ledPin = 4;
const int dePin = 2;
int buttonState = 0;

ICSC icsc(Serial,'B',dePin);
void setup() {
// put your setup code here, to run once:
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
pinMode(2,OUTPUT);
Serial.begin(9600);
icsc.begin();
icsc.registerCommand('S',&stat);
}
void loop() {

icsc.process();

//icsc.send('A', 'G');
}
void stat(unsigned char src, char command, unsigned char len, char *data)
{

delay(1000);
for (int i=0; i <= 15; i++){
icsc.send('A', 'G');
icsc.process();
delay(50);
}

} `
Algorithm:
master send to slave command and led is high
slave recieve command wait and 15times try send to master command for led is LOW

master react only on 5
why ?

Pre-amble

Not a big issue, more out of interest really, I was writing a Node.js script to send serial packets compatible with the ICSC format so "sniffed" the output of an Arduino sending a packet just to check it was correct and noticed that while the Readme says there is a pre-amble of four SOH characters, in reality only the one at the start of the actual packet seems to be used. It works fine with a single SOH character so I'm sticking with that but was wondering if this was a deliberate change or a bug?

ICSC as repeater and Save Address in EEPROM

Hello dear,

I need you're light (if i am in wrong place i apologize).

If i use MAX485 i can have until 32 device's to talk each other,but with you're lovely library we can have much more devices ...
How can i use it as a repeater ( in case if i want to expand it in the middle of loop (with an arduino MEGA ) eg, in address 20 i want to create a new loop and send the address range 33 - 40 ...

And a second question please, how can i address each device and store it to EEPROM and when power up ? with the previous version i have done

LocalID = EEPROM.read(EEPROM_ID_Address);
ICSC.begin(LocalID, 19200, 2);

and was working ok, with new version i can't do this :-(

Thank you in Advance...

Best Regards,
Tasos

C header file for raspberry

Great library. I need to hook it up with RasPi, could you please add or provide a link to a header file mentioned on the sourceforge website?

Function Send() not working - hardware seral atmega2560

Sorry for my not good English.
I migrate from old version of library to new so I can use software serial.
During migration I found that function Send() not working.
This is on hardware serial Serial1 on arduino mega.
Code stop at this function and waits until infinity.
I research proglem and function
waitForTransmitToComplete();
This function does flush of serial and here code "freezes"

void ICSC::waitForTransmitToComplete()
{
Serial.println("w 1");
if (_dePin == -1) //Skip flush
return;
Serial.println("w 2");

#if defined(ARDUINO) && ARDUINO >= 100
#if ARDUINO >= 104
// Arduino 1.0.4 and upwards does it right
Serial.println("w 3");
_dev->flush();
Serial.println("w 4");
#else
// Between 1.0.0 and 1.0.3 it almost does it - need to compensate
// for the hardware buffer. Delay for 2 bytes worth of transmission.
Serial.println("w 5");
_dev->flush();
Serial.println("w 6");

delayMicroseconds((20000000UL/9600)+1);

Serial.println("w 7");

I can see control print Serial.println("w 5");
and not see Serial.println("w 6");

I think there is problem in line
_dev->flush();

Can I comment this line?
What is right way to continue use ICSC library?
Thank you.

Possibility of acknowledgement and retransmission?

Hi, I love this library, I was searching for something along these lines for a while and was very excited to find this as nothing else was quite right.
This works great as it stands and I love the functionality, especially the way that the commands are registered to a function for easy handling, great job there! But, as with most things I have a question/suggestion/request...

I am running this over RS485 (MAX485 chips) with the collision handling enabled and so far testing is a success in the sense that collisions are detected and packets that collide do get re-sent, but there's no guarantee that the target "id" actually received the packet, so, I was wondering how possible it would be to enhance it to allow confirmation that the target has received the packet and re-transmit if not received, similar to a TCP stack. Even better would be the ability to have some sort of return value, sort of like a remote function call but I am probably dreaming here. This of course means that you'd have to be certain that each station has a unique ID or you will end up in a mess, but that's a small price to pay.

I was going to start writing my own sort of a message queue but I'm not that great at this sort of programming so it'd be a dogs breakfast, and thus I thought I might ask the question as someone might have already done this in a way that could be slotted into this library, or someone may just have a brilliant idea.

Thanks!

how to make longer packet lengths

I'm trying to send a string of up to 54 characters from master to slave.

The characters are integers from 0 to 1000. Could you tell me how to do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.