Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax errors, no idea where to start #316

Closed
bazfum opened this issue Jul 31, 2023 · 8 comments
Closed

Syntax errors, no idea where to start #316

bazfum opened this issue Jul 31, 2023 · 8 comments
Assignees
Labels
bug Something isn't working protocol 7 Specific to protocol 7 question Further information is requested

Comments

@bazfum
Copy link

bazfum commented Jul 31, 2023

I saw this and remembered I had an E-Brain sitting around from a clearance sale 20 years ago. I've flashed my Pico and installed Ruby and the GEM on a Raspberry Pi 400. I extracted the voice file from the ISO as well. I then copied the example script to a file as-is to verify things work before hacking around more. Unfortunately I get some syntax errors, and having never used Ruby before I'm at a loss. Any help would be appreciated.

pi@raspberrypi:~ $ ruby ebrain.ruby
Traceback (most recent call last):
2: from ebrain.ruby:1:in <main>' 1: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in require'
/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:85:in require': cannot load such file -- timex_datalink_client (LoadError) 3: from ebrain.ruby:1:in

'
2: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:149:in require' 1: from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:160:in rescue in require'
/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb:160:in `require': /var/lib/gems/2.7.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client.rb:127: syntax error, unexpected ',' (SyntaxError)
serial_device:,
^

@synthead synthead self-assigned this Aug 2, 2023
@synthead synthead added the question Further information is requested label Aug 2, 2023
@synthead
Copy link
Owner

synthead commented Aug 2, 2023

Heya! Very fun story about your e-BRAIN, and thanks for filing this issue!

It appears that you're attempting to use this lib with an old Ruby version! This lib uses omitted keyword arguments, which is a feature introduced in Ruby 3.1.0:

  • Values in Hash literals and keyword arguments can be omitted. [Feature #14579]

    • {x:, y:} is syntax sugar for {x: x, y: y}.
    • foo(x:, y:) is syntax sugar for foo(x: x, y: y).

You can see what Ruby version you're running with this command:

$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

To get a newer version of Ruby, I recommend rbenv! This will let you build and install Ruby as a local installation in your home directory. This allows you to install any recent version without relying on your distro to supply it for you.

Here's how you can get rbenv running on your Raspberry Pi 400!

First, clone rbenv to ~/.rbenv:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv

Then add rbenv as a hook to your ~/.bashrc:

echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc

Log out of your console and log back in to load the eval you added to your ~/.bashrc. Then, add the ruby-build plugin to your local rbenv installation (in ~/.rbenv):

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Now you have rbenv! You can now install Ruby 3.2.2 (the latest stable version as of this writing) like this:

rbenv install -v 3.2.2

And then you can set Ruby 3.2.2 as the default Ruby (for only your local Bash sessions) with:

rbenv global 3.2.2

With your new Ruby available, you'll want to install the timex_datalink_client gem for the Ruby 3.2.2 installation:

gem install timex_datalink_client

And you should be good to go! Try running your script; it'll probably work great from here 👍

Let me know how it goes!

@synthead
Copy link
Owner

synthead commented Aug 2, 2023

I just filed this issue! This should help folks in the future 👍

Edit: shipped a PR to address ☝️:

@synthead
Copy link
Owner

synthead commented Aug 2, 2023

Just shipped a fix to README.md to mention the minimum Ruby version, too:

@bazfum
Copy link
Author

bazfum commented Aug 2, 2023

Thanks, that got me through a lot of progress! I had to update the Pi more than I'd expected since the compiler wasn't working, and then had to trace down a few dependancies but that's par for the course. I'm now getting some data transferred and then an error:

jac@pi400:~ $ ruby ebrain.ruby
78 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 AA AA AA AA AA
07 20 00 00 07 C2 FF
26 90 05 0E 44 53 49 20 54 6F 79 73 20 70 72 65 73 65 6E 74 73 2E 2E 2E 65 42 72 61 69 6E 21 00 00 00 00 00 36 63
26 91 05 01 02 00 00 00 02 00 07 1E 02 10 00 08 00 01 15 00 7C 90 3E FE 00 97 A5 44 E2 FF 1C 9A 36 FF 00 04 82 64
26 91 05 02 55 01 84 03 30 63 FE 00 00 30 69 FE 00 00 02 02 00 78 ..FEFB /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client/notebook_adapter.rb:35:in chr': -261 out of char range (RangeError) from /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client/notebook_adapter.rb:35:in block (2 levels) in write'
from /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client/notebook_adapter.rb:32:in each' from /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client/notebook_adapter.rb:32:in block in write'
from /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client/notebook_adapter.rb:31:in each' from /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client/notebook_adapter.rb:31:in write'
from /home/jac/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/timex_datalink_client-0.12.2/lib/timex_datalink_client.rb:113:in write' from ebrain.ruby:111:in

'

@synthead
Copy link
Owner

synthead commented Aug 2, 2023

Hey great! I'm really glad this got the gem working! Thank you for sharing your progress!

This is a really interesting one! I was able to reproduce this on my end, and I found that the negative integer (that's supposed to represent a byte) is originating from this method:

def time_formatted(device_time)
device_time_midnight = Time.new(device_time.year, device_time.month, device_time.day)
seconds = (time - device_time_midnight).to_i
five_minutes = seconds / FIVE_MINUTES_SECONDS
lsb_msb_format_for(five_minutes)
end

I discovered that the negative number comes from comparing dates between the current time and calendar events. At some point, an error state happens when the synced time is too far in the future compared to an event.

The unit tests for this class still pass because all the times in the tests are fixed. The complete code example in the protocol 7 documentation doesn't work because it uses Time.now to get the current time, which is constantly changing.

I'll get a fix up for this soon! In the meantime, you can simply omit the calendar events or set the events to a later time, i,e, 2023 instead of 2022. For example, here is the updated events array with the updated year that is tested to work:

events = [
  TimexDatalinkClient::Protocol7::Eeprom::Calendar::Event.new(
    time: Time.new(2023, 12, 13, 9, 0, 0),
    phrase: breakfast_with_cousins
  ),
  TimexDatalinkClient::Protocol7::Eeprom::Calendar::Event.new(
    time: Time.new(2023, 12, 13, 19, 0, 0),
    phrase: crashing_around_the_house
  )
]

@bazfum
Copy link
Author

bazfum commented Aug 2, 2023

Interesting. After making those changes the file transmits fine as far as the Pi is concerned. It seems like getting it to receive all the data happily will require some trial and error on LED positioning. Thanks for all the assistance!

@synthead
Copy link
Owner

synthead commented Aug 2, 2023

Ah great! I'm glad to hear that! Have fun playing with your e-BRAIN! 😄

The e-BRAIN has a really insensitive optical sensor, and yeah, you really have to blast it with light for it to transfer reliably. I haven't tested syncing it with a CRT, but it seems like it would be difficult to have a successful transfer that way, too.

On my DIY Notebook Adapter, I have an external LED soldered to it, and it works great. On a Datalink 150, I can sync it from several feet away. It also syncs to an e-BRAIN nicely. You might consider soldering an LED onto your own adapter for a reliable transfer 🙂

Here's my personal Teensy LC with an LED soldered onto it!

image

More information about this here!

@synthead
Copy link
Owner

Hi @bazfum! I just released version 0.12.3 with fixes to accommodate for your issues!

Here are the pull requests that target the problems you were seeing:

This new release does not add any functional changes to any current happy paths, so if your code is working now, it should continue to work. However, if your Ruby version is too old or your e-BRAIN calendar events are in the past, meaningful errors will now be raised (instead of the obscure, uncaught ones in v0.12.2).

Additionally, the protocol 7 (e-BRAIN) documentation now uses calendar event times based on the device time by using times for tomorrow. This will ensure that the complete code example will always work, no matter what the current time is 👍

To obtain the latest version of timex_datalink_client, simply do this in a console:

gem update timex_datalink_client

This should produce output like this:

$ gem update timex_datalink_client
Updating installed gems
Updating timex_datalink_client
Successfully installed timex_datalink_client-0.12.3
Parsing documentation for timex_datalink_client-0.12.3
Installing ri documentation for timex_datalink_client-0.12.3
Done installing documentation for timex_datalink_client after 0 seconds
Parsing documentation for timex_datalink_client-0.12.3
Done installing documentation for timex_datalink_client after 0 seconds
Gems updated: timex_datalink_client

Since you got your e-BRAIN working, I'll go ahead and close this issue since the bugs have been fixed 👍 Feel free to reopen this issue or file a new one if you run into any more problems!

@synthead synthead added the protocol 7 Specific to protocol 7 label Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working protocol 7 Specific to protocol 7 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants