Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/30/06 11:02
Modified:
  01/30/06 11:03

Read: times


 
#108687 - State Machine
Responding to: ???'s previous message
Thanks Russell

I to was doing it this way although I only support Modbus RTU and I have a similiar state machine principle. Where by I perform what ever action I am commanded to do.

I then compile a reply message in a typdef struct, run a CRC on the entire structure and send it off.

The problem comes when a device reads a whole heap of registers (in my case I am running 30 odd 16bit counters) while I happily store these in RAM (using 60bytes) I don't really want to copy them across to my struct to then send it out the serial port. that uses another 60bytes (the order is all different) also the customer for whatever reason doesn't want them in consequtive modbus registers, so I was going to fill the blanks in on the fly.

In short the way that I am doing it now - as per my previous posts - is to use a ring buffer on the serial port and fill the port buffer a little at a time keeping a runningCRC for each byte sent.

So i do this (psuedo code)
SendByte(Address)
runningCRC(Address, 1bytetocalc, 0xFFFF CRC init)

Sendbyte(FunctionCode)
runningCRC(FunctionCode, 1bytetocalc, lastCRC)

SendByte(DataBytes)
runningCRC(DataBytes, 1bytetocalc, lastCRC)

SendByte(DataHi)
runningCRC(DataHi, 1bytetocalc, lastCRC)

SendByte(DataLo)
runningCRC(DataLo, 1bytetocalc, lastCRC)

:
: ~60bytes in here
:

SendByte(DataHi)
runningCRC(DataHi, 1bytetocalc, lastCRC)

SendByte(DataLo)
runningCRC(DataLo, 1bytetocalc, lastCRC)

SendByte(RunningCRC Lo Byte)

SendByte(RunningCRC Hi Byte)

This is not quite a s pretty as lading the structure and then sending it all off in one bang but it does mean that I save on 60bytes of RAM.

Any further ideas appreciated.

Regards

Marshall


List of 12 messages in thread
TopicAuthorDate
Sending a large array out a serial port            01/01/70 00:00      
   Solved as per above            01/01/70 00:00      
   state it more clearly            01/01/70 00:00      
      More Clearly Defined Question            01/01/70 00:00      
   State Machine            01/01/70 00:00      
      State Machine            01/01/70 00:00      
         data consistency            01/01/70 00:00      
            ISR Calculating the CRC            01/01/70 00:00      
   A possibly irelevant thought...            01/01/70 00:00      
      Protocol Intercharacter Timeout            01/01/70 00:00      
   a simplification            01/01/70 00:00      
      Buffer size            01/01/70 00:00      

Back to Subject List