For the command M2001, please read this post.
And the code is in Snapmaker Firmware repository as well.
Cheers Edwin