So and I’m kinda constructing a suped-up power wheels car. There’s been a couple bumps in a road but it’s been mostly a nice learning experience. There’s a lot of little things that pop up when working with upgrading inductive motors in one of was software Debouncing for the gas pedal so the logic below is just an example of what I use my code to resolve this issue. First when you detect that your switch is either open or closed, start a timer in some form. In my case I use a global variable, or a stack/local variable in the current function then I loop over it multiple times incrementing either a register or the value the variable. If each time I loop over the bun is still in a close position I can safely assume that it’s been Debounce and held down for at least some human period of time and it’s not some sort of electrical false positive. You can of course adjust the sleep time between checks or the amount of intervals you like to adjust through. In my case I felt that 200 µs 100 times was a reliable way to the sense that the signals Mindy bounced however if you want to tweak it you may.
if (GAS_PIN & (1 << GAS_BIT))
{ // is switch open?
while (debouncer != 100 )
{
if (!(GAS_PIN & (1 << GAS_BIT)))
{
lcd_write_instruction_4d(lcd_Clear);
_delay_us(80);
lcd_write_instruction_4d(lcd_SetCursor | lcd_LineOne);
_delay_us(80);
lcd_write_string_4d(“Opps, Debounced”);
_delay_us(80);
return;
}
_delay_us(200);
debouncer++;
}
//Do something
}
GoDaddy Backups
Well,
I got lucky today. Apparently, my hosting is so old GoDaddy actually offers 30 backup and file revisions and I got a copy of my old Database back. Guess I got lucky this time. It’s a shame the DB Backup’s copy itself using the same name. My bad copy ended up overwriting my good copy in 24 hours. Look’s like I may be in luck with importing my older work. 🙂
Reverse Engineering the RS485 protocol
Well this weekend I had quite an adventure with RS485.
I ran into a couple issues on the way.
One was Identifying the baud rate of what your vampire tapping into.
One way is to use an Oscilloscope and find the shortest pause and calculate the baud rate from that.
Take the shortest pulse, then measure it in Microseconds (US aka 10^-5 in scientific notation aka 0.00000X). Take that value then plug it in here, (1 / 0.000026 = 38461.53…) there for 38461 is your baud rate… where 26 Microseconds is your shortest pulse.
An example on how to eye out the shortest pulse is below.
Now afterward’s There’s an issue just by merely vampire tapping into the wires with RS-485. An issue that arises is Discovering which way the traffic flows. On RS-45 unlike RS-232 there is no RX in TX line is only A and B. So determining the direction which data is flowing on the line is not really possible Unless you already where the underlying Sender / Receiver protocol. So one way to get around this is to actually split the connections physically and run them into your laptop with a RS-485 the USB converter, Read the data then send the same data out of the port. You can do this with the rig like I made below. In this case I use a red wire to transfer power that is required for the receiver and green for the ground. This power usage is purely for the UC on the receiving side, RS-485 itself does not require ground reference or power reference to ran along in the communication even though sometimes it is included it. In picture three see the solder points bridging the two green connectors on the left side and then to solder points bridging the connections on the right side.
Here’s a chart I found.
Time | Baud Rate |
3333µs (3.3ms) | 300 |
833µs | 1200 |
416µs | 2400 |
208µs | 4800 |
104µs | 9600 |
69µs | 14400 |
52µs | 19200 |
34µs | 28800 |
26µs | 38400 |
17.3µs | 57600 |
8µs | 115200 |
4.34µs | 230400 |
I wrote a MITM code using USB to RS485 modules and the following code below in VB.net
You can adjust the code below to the correct comport as needed.
Imports System.Text
Public Class Form1
Delegate Sub ListboxItem(data As String)
Dim func1 As ListboxItem = AddressOf Listbox1Item
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each MyPort In System.IO.Ports.SerialPort.GetPortNames()
ComboBox1.Items.Add(MyPort)
ComboBox2.Items.Add(MyPort)
Next
ComboBox1.SelectedIndex = 0
ComboBox2.SelectedIndex = 1
End Sub
Dim Buffer1Index As Integer = 0
Dim Buffer1(32) As Byte
Private Sub SerialPort1_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Me.Invoke(func1, {“r1”})
Buffer1(Buffer1Index) = SerialPort1.ReadByte()
SerialPort2.Write(Buffer1(Buffer1Index))
If Buffer1Index > 1 Then
If (Buffer1(Buffer1Index) = &HAUS And Buffer1(Buffer1Index – 1) = &HDUS) Or Buffer1(Buffer1Index) = &HDUS Then
Dim strTemp As New StringBuilder(128)
strTemp.Append(“[” & SerialPort1.PortName.ToString & “]”)
For b = 0 To Buffer1Index
strTemp.Append(” ” & Conversion.Hex(Buffer1(b)))
Next
Me.Invoke(func1, {strTemp.ToString})
Buffer1Index = 0
Else
Buffer1Index += 1
End If
Else
Buffer1Index += 1
End If
End Sub
Dim Buffer2Index As Integer = 0
Dim Buffer2(32) As Byte
Private Sub SerialPort2_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort2.DataReceived
Me.Invoke(func1, {“r2”})
Buffer2(Buffer2Index) = SerialPort2.ReadByte()
SerialPort1.Write(Buffer2(Buffer2Index))
If Buffer2Index > 1 Then
If Buffer2(Buffer2Index) = &HAUS And Buffer2(Buffer2Index – 1) = &HDUS Or Buffer2(Buffer2Index) = &HDUS Then
Dim strTemp As New StringBuilder(128)
strTemp.Append(“[” & SerialPort2.PortName.ToString & “]”)
For b = 0 To Buffer2Index
strTemp.Append(” ” & Conversion.Hex(Buffer2(b)))
Next
Me.Invoke(func1, {strTemp.ToString})
Buffer2Index = 0
Else
Buffer2Index += 1
End If
Else
Buffer2Index += 1
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SerialPort1.BaudRate = 1200
SerialPort2.BaudRate = 1200
SerialPort1.PortName = ComboBox1.SelectedItem
SerialPort2.PortName = ComboBox2.SelectedItem
‘SerialPort1.Open()
SerialPort2.Open()
End Sub
Sub Listbox1Item(ByVal data As String)
ListBox1.Items.Add(Now.TimeOfDay.ToString & ” ” & data)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim OutputString As String = “”
For Each MyLine In ListBox1.Items
OutputString &= MyLine
Next
Dim File1 = IO.File.CreateText(“Serial1.txt”)
File1.WriteLine(OutputString)
File1.Flush()
End
End Sub
End Class
ESP8266 NON-OS SDK
Once I get my Blog up and running I will be using this to document alot of my finding’s with the ESP 8266 on the NON-OS SDK.
CVC22350 – Traffic Trial Unsafe Speed, Convicted.
UPDATE: Opening Brief filed, Preparing for Battle http://controllingtheinter.net/2018/02/27/traffic-court-cvc-22350-basic-speed-law-continued-appellants-opening-brief/ So, I’ll be posting as I go through this process, I am working on getting this document for anyone who cares to take interest in their own traffic adventures.
So I showed outside the trial court and I recognized the officer standing about. I peeked over and saw that he didn’t have any document on him other than one sheet of paper which was a citation he gave me during the stop. So instead of talking to him outside bartering for a plea, I ended up planning to proceed to trial.
The first case that was called was with an attorney versus a CHP officer. The attorney did the worst job I’ve ever seen representing someone in a case. He did not cross-examine any evidence or even apply any of the evidence code to the documents the officer was offering. He ended up scoring his client a $1000 fine, I’m sure that was on top of his fee for basically throwing in the towel.
The case was very short and after that, I was called to go second, I’ll tell you after seeing that attorney perform I felt a lot more confident.
One particular piece to note here is the commissioner is correct in this case. I mistakingly used the federal rules of evidence instead of the California evidence code. State courts are not bound to the federal rules of evidence, even the hearsay rule is redefined as California Evidence code 1200. So foundation such as FRE 612 Writing Used to Refresh a Witness foundation is not required when testifying from refreshed memory through writings just so long as the writing can be cross-examined per evidence code 771. I assume that taking time like this officer did just goes towards his credibility as a witness however this Commissioner didn’t give two squats on whether or not the officer truly remember what happened.
So here my objection to the foundation for the officers in our reading was correct and timely, the officer alone cannot testify as to the accuracy of the radar rating, however, the Commissioner overruled anyways. In order to properly admit the radar reading the certificate should have been admitted beforehand. This is not an incredibly huge issue as I’ll cross-examine him about this more in detail after he stops testifying, However, in a fair trial foundation must be laid before testifying to that fact.
Now one particular thing to note here if I ever have another trial again is how I worded my hearsay objection. When I was objecting to hearsay I was objecting on the grounds that the officer was testifying to the existence of a writing that was not in court to be cross-examined. However, to my surprise, the Commissioner stores these records on file and asked if I like to see the documents. This was a little bit shocked however I can understand why they keep it on file for ease of access for situations like this.
Now one super important thing to note about the calibration as per the vehicle code Calibration Record must be certified by independence facility. These facilities are normally private entities owned by someone who is not a public official or tied to the government. In that case in order for the record to be admitted and must be the exception of evidence code 1271 and one of the requirements of 1271 is to be accompanied by a valid affidavit signed by a public notary, this is to satisfy the testimony of a Custodian of records as to the mode and preparation of the document. Absent of this testimony the business record exception is not meet.
Here kind of threw me for a little bit i.e. should have been more on my toes on this one, but the Commissioner points to a certified stamp that is on the back of calibration record saying that it fulfills a requirement of 1270C Testimony from the custodian/affidavit. This couldn’t have been more wrong I believe the certification may fulfill requirements of 1531, however, there are no sworn statements with this stamp by public notary which is an affidavit requirement, and even if there was no testimony as to how the document was created/prepped. I could be wrong on this particular point so I don’t make this my primary argument for trial I then start moving towards attacking the survey.
At this point here the cat is out of the bag and I go back and forth with the Commissioner about my logic in regards to the requirements of the survey and even provided case law referencing to a case with the same exact circumstances. The commissioner doesn’t bother reading it declares it nonbinding and shuffles it aside. Now after trial and doing my research I found this. The Trial Court Must Follow Appellate Precedent. A published decision of the Court of Appeal is binding on all trial courts, irrespective of which appellate district or division rendered it. (Auto Equity Sales, Inc. v. Super. Ct. (Hesenflow) (1962) 57 Cal.2d 450, 455 – appellate department of superior court acted in excess of jurisdiction by refusing to follow a decision of the Court of Appeal.) A trial court may not rule contrary to an appellate opinion simply because it thinks that the appellate decision was “wrongly decided.” (Cuccia v. Super. Ct. (People) (2007) 153 Cal. App. 4th 347, 353.) Does this apply if the case was generated in the “Appellate Department, Superior Cout, Venuta”, no sadly lesson learned on my end. Now what can happen is upon a defendant’s application, the superior court can certify the case for transfer to a California Court Of Appeals in the District it is in, There are only 6 in California. This is necessary to secure uniformity of decision’s and to settle important questions of law, A hearing and decision pursuant to California Rules of Court, rules 62 and 64(c)(1)(A). At that point, the case will be certified under a court that looks like this “Court of Appeal, Second District, Division 1, California.”, at that point, all trial courts within California are bound.
At this particular point, I knew I was getting it convicted and it was not a fair trial. I would have to appeal the conviction. I think if the Commissioner were to side with me on the law she would have quite an issue with everyone behind me who hear the arguments and then insist that their case would also need to be dismissed if the officer failed to bring the survey which I don’t believe very many if any of the officers did.